nodes_value_containers.hpp 6.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
/** @file feature_creation/node/value_storage/node_value_containers.hpp
 *  @brief Centeral storage area for all descriptor matrix data
 *
 *  This file contains definitions where all descriptor/feature data is stored permanently or in temporary storage arrays
 *  All Nodes's (except ModelNodes) value_ptr/test_value_ptrs point to data here.
 *
 *  @author Thomas A. R. Purcell (tpurcell)
 *  @bug No known bugs.
 */
10
11
#ifndef NODE_VALUE_ARR
#define NODE_VALUE_ARR
Thomas Purcell's avatar
Thomas Purcell committed
12

Thomas Purcell's avatar
Thomas Purcell committed
13
#include <algorithm>
Thomas Purcell's avatar
Thomas Purcell committed
14
15
16
17
18
19
20
#include <memory>
#include <vector>

#include<utils/enum.hpp>

namespace node_value_arrs
{
21
22
23
24
    extern std::vector<double> TEMP_STORAGE_ARR; //!< Array to temporarily store feature training data
    extern std::vector<double> VALUES_ARR; //!< Training data of the stored features
    extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< Array to temporarily store feature test data
    extern std::vector<double> TEST_VALUES_ARR; //!< Value of the stored features test data
Thomas Purcell's avatar
Thomas Purcell committed
25
    extern std::vector<double> D_MATRIX; //!< The descriptor matrix
26
27
    extern std::vector<int> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot for the training data
    extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register to see which feature is stored in each slot for the test data
Thomas Purcell's avatar
Thomas Purcell committed
28

29
    extern int N_SELECTED; //!< Number of features selected
30
31
    extern int N_SAMPLES; //!< Number of training samples for each feature
    extern int N_SAMPLES_TEST; //!< Number of test samples for each feature
Thomas Purcell's avatar
Thomas Purcell committed
32
33
    extern int N_STORE_FEATURES; //!< Number of features with stored values
    extern int N_RUNGS_STORED; //!< Number of rungs with values stored
Thomas Purcell's avatar
Thomas Purcell committed
34

Thomas Purcell's avatar
Thomas Purcell committed
35
    /**
36
37
     * @brief Initialize the node value arrays
     * @details Using the size of the initial feature space constructor the storage arrays
Thomas Purcell's avatar
Thomas Purcell committed
38
     *
39
40
41
     * @param n_samples Number of training samples for each feature
     * @param n_samples_test Number of test samples for each feature
     * @param n_primary_feat Number of primary features
Thomas Purcell's avatar
Thomas Purcell committed
42
     */
43
    void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat);
Thomas Purcell's avatar
Thomas Purcell committed
44
45

    /**
46
47
     * @brief Resize the node value arrays
     * @details Using the updated number of features increase the size of the storage arrays
Thomas Purcell's avatar
Thomas Purcell committed
48
49
50
51
52
     *
     * @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
     */
53
    void resize_values_arr(int n_dims, int n_feat, bool use_temp);
Thomas Purcell's avatar
Thomas Purcell committed
54

55
    /**
56
57
     * @brief Initialize the descriptor matrix
     * @details Initialize an empty descriptor matrix
58
59
60
61
62
     *
     */
    void initialize_d_matrix_arr();

    /**
63
64
     * @brief Resize the descriptor matrix
     * @details Using the number of newly selected features increase the size of the descriptor matrix
65
66
67
68
69
     *
     * @param n_select Number of features to select
     */
    void resize_d_matrix_arr(int n_select);

Thomas Purcell's avatar
Thomas Purcell committed
70
    /**
71
     * @brief Get a reference slot/feature register of the training data
Thomas Purcell's avatar
Thomas Purcell committed
72
     *
73
     * @param ind The Node's arr_ind
74
     * @param offset(int) Offset integer for TEMP_STORE_ARRAY
Thomas Purcell's avatar
Thomas Purcell committed
75
76
77
     *
     * @return The register element for a given feature index and offset
     */
78
    inline int& temp_storage_reg(int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES];}
Thomas Purcell's avatar
Thomas Purcell committed
79

80
    /**
81
     * @brief Get a reference slot/feature register of the test data
82
     *
83
     * @param ind The Node's arr_ind
84
     * @param offset(int) Offset integer for TEMP_STORE_TEST_ARRAY
85
86
87
     *
     * @return The register element for a given feature index and offset
     */
88
    inline int& temp_storage_test_reg(int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES];}
89

Thomas Purcell's avatar
Thomas Purcell committed
90
    /**
91
     * @brief Access element of the permanent training data storage array
Thomas Purcell's avatar
Thomas Purcell committed
92
     *
93
     * @param feature_ind The _arr_ind of Node to get the training data of
Thomas Purcell's avatar
Thomas Purcell committed
94
     *
95
     * @return pointer to the Node's training data
Thomas Purcell's avatar
Thomas Purcell committed
96
     */
97
    inline double* access_value_arr(int feature_ind){return VALUES_ARR.data() + feature_ind*N_SAMPLES;}
98

99
    /**
100
     * @brief Access element of the permanent test data storage array
101
     *
102
     * @param feature_ind The _arr_ind of Node to get the test data of
103
     *
104
     * @return pointer to the Node's test data
105
106
107
     */
    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
108
    /**
109
     * @brief Access element of temporary storage array for the training data
Thomas Purcell's avatar
Thomas Purcell committed
110
     *
111
     * @param slot The slot of the temporary storage array
Thomas Purcell's avatar
Thomas Purcell committed
112
     *
113
     * @return pointer to the data stored in the specified slot
Thomas Purcell's avatar
Thomas Purcell committed
114
     */
115
    inline double* access_temp_storage(int slot){return TEMP_STORAGE_ARR.data() + slot*N_SAMPLES;}
116

117
    /**
118
     * @brief Access element of temporary storage array for the test data
119
     *
120
     * @param slot The slot of the temporary storage array
121
     *
122
     * @return pointer to the data stored in the specified slot
123
124
125
     */
    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
126
    /**
127
     * @brief Get a Node's value_ptr
Thomas Purcell's avatar
Thomas Purcell committed
128
     *
129
130
     * @param arr_ind Nodes _arr_ind
     * @param feat_ind Nodes _feat_ind
131
     * @param offset(int) the offset for temporary storage access
Thomas Purcell's avatar
Thomas Purcell committed
132
133
134
     *
     * @return The value pointer
     */
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
135
    double* get_value_ptr(int arr_ind, int feat_ind, int offset = 0);
Thomas Purcell's avatar
Thomas Purcell committed
136

137
    /**
138
     * @brief Get a Node's test_value_ptr
139
     *
140
141
     * @param arr_ind Nodes _arr_ind
     * @param feat_ind Nodes _feat_ind
142
     * @param offset(int) the offset for temporary storage access
143
144
145
     *
     * @return The value pointer
     */
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
146
    double* get_test_value_ptr(int arr_ind, int feat_ind, int offset = 0);
147

148
    /**
149
     * @brief Get the pointer to a particular selected Node from sis
150
     *
151
     * @param ind Index of the data in the descriptor matrix
152
     * @return The pointer to the descriptor matrix's data
153
     */
154
    inline double* get_d_matrix_ptr(int ind)
Thomas Purcell's avatar
Thomas Purcell committed
155
    {
156
        return D_MATRIX.data() + ind * N_SAMPLES;
Thomas Purcell's avatar
Thomas Purcell committed
157
    }
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
158

159
160
161
162
    /**
     * @brief Flush the temporary storage register (training data)
     * @details Reset all slots in the register to -1
     */
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
163
    inline void clear_temp_reg(){std::fill_n(TEMP_STORAGE_REG.data(), TEMP_STORAGE_REG.size(), -1);}
164
165
166
167
168

    /**
     * @brief Flush the temporary storage register (test data)
     * @details Reset all slots in the register to -1
     */
Thomas Purcell's avatar
Bug Fix    
Thomas Purcell committed
169
    inline void clear_temp_test_reg(){std::fill_n(TEMP_STORAGE_TEST_REG.data(), TEMP_STORAGE_TEST_REG.size(), -1);}
170

Thomas Purcell's avatar
Thomas Purcell committed
171
172
}

173
#endif