nodes_value_containers.hpp 7.01 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
#include <memory>
#include <vector>

17
18
#include <omp.h>

Thomas Purcell's avatar
Thomas Purcell committed
19
20
21
22
#include<utils/enum.hpp>

namespace node_value_arrs
{
23
24
25
26
    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
27
    extern std::vector<double> D_MATRIX; //!< The descriptor matrix
28
29
    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
30

31
    extern int N_SELECTED; //!< Number of features selected
32
33
    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
34
35
    extern int N_STORE_FEATURES; //!< Number of features with stored values
    extern int N_RUNGS_STORED; //!< Number of rungs with values stored
36
    extern int MAX_N_THREADS; //!< Get the maximum number of threads possible
Thomas Purcell's avatar
Thomas Purcell committed
37
    /**
38
39
     * @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
40
     *
41
42
43
     * @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
44
     */
45
    void initialize_values_arr(int n_samples, int n_samples_test, int n_primary_feat);
Thomas Purcell's avatar
Thomas Purcell committed
46
47

    /**
48
49
     * @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
50
51
52
53
54
     *
     * @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
     */
55
    void resize_values_arr(int n_dims, int n_feat, bool use_temp);
Thomas Purcell's avatar
Thomas Purcell committed
56

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

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

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

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

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

101
    /**
102
     * @brief Access element of the permanent test data storage array
103
     *
104
     * @param feature_ind The _arr_ind of Node to get the test data of
105
     *
106
     * @return pointer to the Node's test data
107
     */
108
    inline double* access_test_value_arr(unsigned long int feature_ind){return TEST_VALUES_ARR.data() + feature_ind*N_SAMPLES_TEST;}
109

Thomas Purcell's avatar
Thomas Purcell committed
110
    /**
111
     * @brief Access element of temporary storage array for the training data
Thomas Purcell's avatar
Thomas Purcell committed
112
     *
113
     * @param slot The slot of the temporary storage array
Thomas Purcell's avatar
Thomas Purcell committed
114
     *
115
     * @return pointer to the data stored in the specified slot
Thomas Purcell's avatar
Thomas Purcell committed
116
     */
117
    inline double* access_temp_storage(unsigned long int slot){return TEMP_STORAGE_ARR.data() + slot*N_SAMPLES;}
118

119
    /**
120
     * @brief Access element of temporary storage array for the test data
121
     *
122
     * @param slot The slot of the temporary storage array
123
     *
124
     * @return pointer to the data stored in the specified slot
125
     */
126
    inline double* access_temp_storage_test(unsigned long int slot){return TEMP_STORAGE_TEST_ARR.data() + slot*N_SAMPLES_TEST;}
127

Thomas Purcell's avatar
Thomas Purcell committed
128
    /**
129
     * @brief Get a Node's value_ptr
Thomas Purcell's avatar
Thomas Purcell committed
130
     *
131
132
     * @param arr_ind Nodes _arr_ind
     * @param feat_ind Nodes _feat_ind
133
     * @param offset(int) the offset for temporary storage access
Thomas Purcell's avatar
Thomas Purcell committed
134
135
136
     *
     * @return The value pointer
     */
137
    double* get_value_ptr(unsigned long int arr_ind, unsigned long int feat_ind, int offset = 0);
Thomas Purcell's avatar
Thomas Purcell committed
138

139
    /**
140
     * @brief Get a Node's test_value_ptr
141
     *
142
143
     * @param arr_ind Nodes _arr_ind
     * @param feat_ind Nodes _feat_ind
144
     * @param offset(int) the offset for temporary storage access
145
146
147
     *
     * @return The value pointer
     */
148
    double* get_test_value_ptr(unsigned long int arr_ind, unsigned long int feat_ind, int offset = 0);
149

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

161
162
163
164
    /**
     * @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
165
    inline void clear_temp_reg(){std::fill_n(TEMP_STORAGE_REG.data(), TEMP_STORAGE_REG.size(), -1);}
166

167
168
169
170
171
172
    /**
     * @brief Flush the temporary storage register (training data)
     * @details Reset all slots in the register to -1
     */
    inline void clear_temp_reg_thread(){std::fill_n(TEMP_STORAGE_REG.data() + N_STORE_FEATURES * 3 * omp_get_thread_num(), N_STORE_FEATURES * 3, -1);}

173
174
175
176
    /**
     * @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
177
    inline void clear_temp_test_reg(){std::fill_n(TEMP_STORAGE_TEST_REG.data(), TEMP_STORAGE_TEST_REG.size(), -1);}
178

Thomas Purcell's avatar
Thomas Purcell committed
179
180
}

181
#endif