nodes_value_containers.hpp 6.22 KB
Newer Older
1
2
#ifndef NODE_VALUE_ARR
#define NODE_VALUE_ARR
Thomas Purcell's avatar
Thomas Purcell committed
3

Thomas Purcell's avatar
Thomas Purcell committed
4
#include <algorithm>
Thomas Purcell's avatar
Thomas Purcell committed
5
6
7
8
9
10
11
#include <memory>
#include <vector>

#include<utils/enum.hpp>

namespace node_value_arrs
{
Thomas Purcell's avatar
Thomas Purcell committed
12
13
14
15
16
17
18
19
    extern std::vector<double> TEMP_STORAGE_ARR; //!< Array to temporarily store feature values
    extern std::vector<double> VALUES_ARR; //!< Value of the stored features
    extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< Array to temporarily store feature values
    extern std::vector<double> TEST_VALUES_ARR; //!< Value of the stored features test values
    extern std::vector<double> D_MATRIX; //!< The descriptor matrix
    extern std::vector<int> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot
    extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register to see which feature is stored in each slot

20
    extern int N_SELECTED; //!< Number of features selected
Thomas Purcell's avatar
Thomas Purcell committed
21
    extern int N_SAMPLES; //!< Number of samples in the nodes
22
    extern int N_SAMPLES_TEST; //!< Number of samples in the nodes
Thomas Purcell's avatar
Thomas Purcell committed
23
    extern int N_STORE_FEATURES; //!< Number of features with stored values
Thomas Purcell's avatar
Thomas Purcell committed
24
    extern int N_TEMP_STORE_FEATURES; //!< Number of feature that can be stored in TEMP_STORAGE ARRs values
Thomas Purcell's avatar
Thomas Purcell committed
25
    extern int N_RUNGS_STORED; //!< Number of rungs with values stored
Thomas Purcell's avatar
Thomas Purcell committed
26
27


Thomas Purcell's avatar
Thomas Purcell committed
28
29
30
31
32
33
34
35
    /**
     * @brief Get the maximum number of new features for each rung
     *
     * @param new_op operator that will add new features
     * @param n_current_features current number of of features in the rung
     *
     * @return [description]
     */
36
    int get_number_new_features(std::string new_op, int n_current_features);
Thomas Purcell's avatar
Thomas Purcell committed
37

Thomas Purcell's avatar
Thomas Purcell committed
38
39
40
41
42
43
44
45
    /**
     * @brief Get the maximum number of features to store
     *
     * @param allowed_operators list of allowed operators
     * @param n_dims Number of dimensions to store
     * @param n_feats number of features in Phi_0
     * @return [description]
     */
46
    int get_max_number_features(std::vector<std::string> allowed_operators, int n_dims, int n_feats);
Thomas Purcell's avatar
Thomas Purcell committed
47

Thomas Purcell's avatar
Thomas Purcell committed
48
49
50
51
52
    /**
     * @brief set of the value arrays
     * @details Take initial parameters and construct the feature arraies
     *
     * @param n_samples number of samples per feature
53
     * @param n_samples_test number of test samples per feature
Thomas Purcell's avatar
Thomas Purcell committed
54
55
     * @param n_primary_feat number of primary features
     */
56
    void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat);
Thomas Purcell's avatar
Thomas Purcell committed
57
58
59
60
61
62
63
64
65

    /**
     * @brief set of the value arrays
     * @details Take initial parameters and construct the feature arraies
     *
     * @param n_dims Number of dimensions to store
     * @param n_feat number of features to store
     * @param use_temp If true keep the temporary_storage
     */
Thomas Purcell's avatar
Thomas Purcell committed
66
    void resize_values_arr(int n_dims, int n_feat, int max_temp_store, bool use_temp);
Thomas Purcell's avatar
Thomas Purcell committed
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    /**
     * @brief set of the value arrays
     * @details Take initial parameters and construct the feature arraies
     *
     * @param n_samples number of samples per feature
     * @param n_primary_feat number of primary features
     */
    void initialize_d_matrix_arr();

    /**
     * @brief set of the value arrays
     * @details Take initial parameters and construct the feature arraies
     *
     * @param n_select Number of features to select
     */
    void resize_d_matrix_arr(int n_select);

Thomas Purcell's avatar
Thomas Purcell committed
85
86
87
88
89
90
91
92
    /**
     * @brief Get a reference slot/feature register
     *
     * @param ind Feature index
     * @param offset Offset integer for TEMP_STORE_ARRAY
     *
     * @return The register element for a given feature index and offset
     */
Thomas Purcell's avatar
Thomas Purcell committed
93
    inline int& temp_storage_reg(int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES];}
Thomas Purcell's avatar
Thomas Purcell committed
94

95
96
97
98
99
100
101
102
    /**
     * @brief Get a reference slot/feature test register
     *
     * @param ind Feature index
     * @param offset Offset integer for TEMP_STORE_TEST_ARRAY
     *
     * @return The register element for a given feature index and offset
     */
Thomas Purcell's avatar
Thomas Purcell committed
103
    inline int& temp_storage_test_reg(int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES];}
104

Thomas Purcell's avatar
Thomas Purcell committed
105
106
107
108
109
110
111
    /**
     * @brief Access element of the permanent storage array
     *
     * @param feature_ind The feature index to access
     *
     * @return pointer to the feature;s data array
     */
112
    inline double* access_value_arr(int feature_ind){return VALUES_ARR.data() + feature_ind*N_SAMPLES;}
113

114
115
116
117
118
119
120
121
122
    /**
     * @brief Access element of the test value array
     *
     * @param feature_ind The feature index to access
     *
     * @return pointer to the feature;s test data array
     */
    inline double* access_test_value_arr(int feature_ind){return TEST_VALUES_ARR.data() + feature_ind*N_SAMPLES_TEST;}

Thomas Purcell's avatar
Thomas Purcell committed
123
124
125
126
127
128
129
    /**
     * @brief Access element of temporary storage array
     *
     * @param slot The slot of the temporary storage arrays
     *
     * @return pointer to the feature's temporary storage
     */
130
    inline double* access_temp_storage(int slot){return TEMP_STORAGE_ARR.data() + slot*N_SAMPLES;}
131

132
133
134
135
136
137
138
139
140
    /**
     * @brief Access element of temporary storage test array
     *
     * @param slot The slot of the temporary storage test arrays
     *
     * @return pointer to the feature's temporary test storage
     */
    inline double* access_temp_storage_test(int slot){return TEMP_STORAGE_TEST_ARR.data() + slot*N_SAMPLES_TEST;}

Thomas Purcell's avatar
Thomas Purcell committed
141
142
143
144
145
146
147
148
    /**
     * @brief Access the value_ptr to a feature
     *
     * @param ind Feature index
     * @param offset the offset for the storage
     *
     * @return The value pointer
     */
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
149
    double* get_value_ptr(int arr_ind, int feat_ind, int offset = 0);
Thomas Purcell's avatar
Thomas Purcell committed
150

151
152
153
154
155
156
157
158
    /**
     * @brief Access the test_value_ptr to a feature
     *
     * @param ind Feature index
     * @param offset the offset for the storage
     *
     * @return The value pointer
     */
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
159
    double* get_test_value_ptr(int arr_ind, int feat_ind, int offset = 0);
160

161
162
163
164
    /**
     * @brief Get the pointer to a primary feature
     *
     * @param ind Index of the primary feature
165
     * @return The pointer to the descriptor matrix's data
166
     */
167
    inline double* get_d_matrix_ptr(int ind)
Thomas Purcell's avatar
Thomas Purcell committed
168
    {
169
        return D_MATRIX.data() + ind * N_SAMPLES;
Thomas Purcell's avatar
Thomas Purcell committed
170
    }
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
171
172
173

    inline void clear_temp_reg(){std::fill_n(TEMP_STORAGE_REG.data(), TEMP_STORAGE_REG.size(), -1);}
    inline void clear_temp_test_reg(){std::fill_n(TEMP_STORAGE_TEST_REG.data(), TEMP_STORAGE_TEST_REG.size(), -1);}
Thomas Purcell's avatar
Thomas Purcell committed
174
175
}

176
#endif