forpy 2

desk.h
Go to the documentation of this file.
1 /* Author: Christoph Lassner. */
2 #pragma once
3 #ifndef FORPY_UTIL_DESK_H_
4 #define FORPY_UTIL_DESK_H_
5
6 #include "../global.h"
7 #include "../types.h"
8
9 namespace forpy {
10
19 struct TreeDesk {
22 std::vector<TodoMark> marks;
25 std::atomic<size_t> *stored_in_leafs;
28 std::atomic<id_t> *next_id_p;
31 std::vector<std::pair<id_t, id_t>> *tree_p;
32
36 inline void setup(std::atomic<size_t> *silp, std::atomic<id_t> *np,
37 std::vector<std::pair<id_t, id_t>> *tsp) {
38 stored_in_leafs = silp;
39 next_id_p = np;
40 tree_p = tsp;
41 }
45 inline void reset() {
46 marks.clear();
47 stored_in_leafs = nullptr;
48 next_id_p = nullptr;
49 tree_p = nullptr;
50 }
51 };
52
61 struct DeciderDesk {
63 size_t n_samples, input_dim, annot_dim;
65 uint min_samples_at_leaf;
69 id_t *elem_id_p;
70 id_t start_id, end_id, node_id;
72
74 OptSplitV best_res_v, opt_res_v;
76 id_t best_feat_idx;
77 bool presorted, need_sort;
78 std::vector<id_t> feature_indices;
80
82 std::vector<float> full_sum;
84 float *full_sum_p;
85 float fullentropy, maxproxy;
86 const float *annot_p;
87 const uint *class_annot_p;
88 size_t annot_os;
89 const float *weights_p;
90 float full_w;
91 std::vector<id_t> sort_perm;
92 id_t *sort_perm_p;
93 std::vector<id_t> elem_ids_sorted;
94 id_t *elem_ids_sorted_p;
95 std::vector<float> feat_values;
96 float *feat_p;
97 DataV class_feat_values;
98 std::vector<float> left_sum_vec;
99 float *left_sum_p;
101
106 mu::variant<const float *, const double *, const uint *, const uint8_t *>
107 full_feat_p_v;
108
110 bool make_to_leaf;
112 // These only contain valid values if `make_to_leaf` is false.
113 interv_t left_int, right_int;
114 id_t left_id, right_id;
116
122 std::vector<size_t> invalid_counts;
123
127 std::vector<size_t> *node_to_featsel_p;
131 mu::variant<std::vector<float>, std::vector<double>, std::vector<uint32_t>,
132 std::vector<uint8_t>> *node_to_thresh_v_p;
133
134 inline void setup(
135 std::vector<size_t> *ntfp,
136 mu::variant<std::vector<float>, std::vector<double>,
137 std::vector<uint32_t>, std::vector<uint8_t>> *nttp) {
138 node_to_featsel_p = ntfp;
139 node_to_thresh_v_p = nttp;
140 if (ntfp != nullptr) invalid_counts.resize(ntfp->size());
141 }
142 inline void reset() {
143 n_samples = input_dim = annot_dim = 0;
144 min_samples_at_leaf = 0;
145 elem_id_p = nullptr;
146 weights_p = nullptr;
147 full_w = 0.f;
148 start_id = end_id = node_id = 0;
149 node_to_featsel_p = nullptr;
150 node_to_thresh_v_p = nullptr;
151 invalid_counts.clear();
152 }
153 };
154
162 struct LeafDesk {
166 std::vector<Mat<float>> *leaf_regression_map_p;
167 inline void setup(std::vector<Mat<float>> *lrmp) {
168 leaf_regression_map_p = lrmp;
169 };
170 inline void reset() { leaf_regression_map_p = nullptr; }
171 };
172
181 struct RandomDesk {
182 std::mt19937 random_engine;
183 uint seed;
184 inline void setup(const uint &seed) {
185 this->seed = seed;
186 random_engine.seed(seed);
187 };
188 inline void reset() {
189 this->seed = 0;
190 random_engine.seed(1);
191 };
192 };
193
201 struct Desk {
202 inline Desk(int i) : thread_id(i){};
203 TreeDesk t;
204 DeciderDesk d;
205 LeafDesk l;
206 RandomDesk r;
207
208 const int thread_id;
209 inline void setup(
210 std::atomic<size_t> *stored_in_leaf_p, std::atomic<id_t> *next_id_p,
211 std::vector<std::pair<id_t, id_t>> *tree_p,
212 std::vector<size_t> *ntfp = nullptr,
213 mu::variant<std::vector<float>, std::vector<double>,
214 std::vector<uint32_t>, std::vector<uint8_t>> *nttp = nullptr,
215 std::vector<Mat<float>> *lrmp = nullptr, const uint &random_seed = 0) {
217 t.setup(stored_in_leaf_p, next_id_p, tree_p);
218 d.setup(ntfp, nttp);
219 l.setup(lrmp);
220 r.setup(random_seed);
221 };
222 inline void reset() {
223 t.reset();
224 d.reset();
225 l.reset();
226 r.reset();
227 }
228 };
229
230 }; // namespace forpy
231 #endif // FORPY_UTIL_DESK_H_
forpy::DeciderDesk::annot_os
size_t annot_os
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:88
forpy::TreeDesk::next_id_p
std::atomic< id_t > * next_id_p
Definition: desk.h:28
forpy::Desk::Desk
Desk(int i)
Definition: desk.h:202
forpy::DeciderDesk
Desk for decider training.
Definition: desk.h:61
forpy::DeciderDesk::annot_dim
size_t annot_dim
These variables are populated in IDecider::make_node.
Definition: desk.h:64
forpy::DeciderDesk::presorted
bool presorted
Variables used during the threshold optimization.
Definition: desk.h:77
forpy::RandomDesk::reset
void reset()
Definition: desk.h:188
forpy::RandomDesk::seed
uint seed
Definition: desk.h:183
forpy::DeciderDesk::full_feat_p_v
mu::variant< const float *, const double *, const uint *, const uint8_t * > full_feat_p_v
Definition: desk.h:107
forpy::DeciderDesk::left_id
id_t left_id
Return values from IThreshOpt::optimize.
Definition: desk.h:114
forpy::Desk::d
DeciderDesk d
Definition: desk.h:204
forpy::TreeDesk::tree_p
std::vector< std::pair< id_t, id_t > > * tree_p
Definition: desk.h:31
forpy::LeafDesk::setup
void setup(std::vector< Mat< float >> *lrmp)
Definition: desk.h:167
forpy::id_t
size_t id_t
Element id type.
Definition: types.h:106
forpy::DeciderDesk::node_to_featsel_p
std::vector< size_t > * node_to_featsel_p
Definition: desk.h:127
forpy::TreeDesk
Desk for tree training.
Definition: desk.h:19
forpy::DeciderDesk::min_samples_at_leaf
uint min_samples_at_leaf
These variables are populated in IDecider::make_node.
Definition: desk.h:65
forpy::DeciderDesk::reset
void reset()
Definition: desk.h:142
forpy::DeciderDesk::invalid_counts
std::vector< size_t > invalid_counts
Definition: desk.h:122
forpy::DeciderDesk::sort_perm_p
id_t * sort_perm_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:92
forpy::TreeDesk::marks
std::vector< TodoMark > marks
Definition: desk.h:22
forpy::DeciderDesk::class_feat_values
DataV class_feat_values
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:97
forpy::Desk::thread_id
const int thread_id
Definition: desk.h:208
forpy::interv_t
std::pair< id_t, id_t > interv_t
Definition: types.h:141
forpy::TreeDesk::stored_in_leafs
std::atomic< size_t > * stored_in_leafs
Definition: desk.h:25
forpy::TreeDesk::setup
void setup(std::atomic< size_t > *silp, std::atomic< id_t > *np, std::vector< std::pair< id_t, id_t >> *tsp)
Set up all the internal pointers.
Definition: desk.h:36
forpy::DeciderDesk::feat_p
float * feat_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:96
forpy::RandomDesk::random_engine
std::mt19937 random_engine
Definition: desk.h:182
forpy::RandomDesk::setup
void setup(const uint &seed)
Definition: desk.h:184
forpy::DeciderDesk::class_annot_p
const uint * class_annot_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:87
forpy::DataV
typename mu::variant< std::vector< float >, std::vector< double >, std::vector< uint >, std::vector< uint8_t > > DataV
Definition: storage.h:129
forpy::DeciderDesk::start_id
id_t start_id
These variables are populated in IDecider::make_node.
Definition: desk.h:70
forpy::DeciderDesk::full_sum
std::vector< float > full_sum
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:83
forpy::DeciderDesk::sort_perm
std::vector< id_t > sort_perm
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:91
forpy::DeciderDesk::elem_ids_sorted_p
id_t * elem_ids_sorted_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:94
forpy::DeciderDesk::maxproxy
float maxproxy
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:85
forpy::LeafDesk::reset
void reset()
Definition: desk.h:170
forpy::DeciderDesk::weights_p
const float * weights_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:89
forpy::DeciderDesk::input_dim
size_t input_dim
These variables are populated in IDecider::make_node.
Definition: desk.h:64
forpy::OptSplitV
mu::variant< SplitOptRes< float >, SplitOptRes< double >, SplitOptRes< uint >, SplitOptRes< uint8_t > > OptSplitV
Definition: types.h:139
forpy::DeciderDesk::node_to_thresh_v_p
mu::variant< std::vector< float >, std::vector< double >, std::vector< uint32_t >, std::vector< uint8_t > > * node_to_thresh_v_p
Definition: desk.h:132
forpy::DeciderDesk::feature_indices
std::vector< id_t > feature_indices
Variables used during the threshold optimization.
Definition: desk.h:78
forpy::DeciderDesk::n_samples
size_t n_samples
These variables are populated in IDecider::make_node.
Definition: desk.h:64
forpy::DeciderDesk::end_id
id_t end_id
These variables are populated in IDecider::make_node.
Definition: desk.h:70
forpy::Desk::l
LeafDesk l
Definition: desk.h:205
forpy::DeciderDesk::full_w
float full_w
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:90
forpy::DeciderDesk::node_id
id_t node_id
These variables are populated in IDecider::make_node.
Definition: desk.h:70
forpy::DeciderDesk::feat_values
std::vector< float > feat_values
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:95
forpy::DeciderDesk::left_int
interv_t left_int
Return values from IThreshOpt::optimize.
Definition: desk.h:113
forpy::Desk::t
TreeDesk t
Definition: desk.h:202
forpy::Mat
Eigen::Matrix< DT, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Mat
Parameterized Matrix type (row major).
Definition: types.h:52
forpy
Definition: fastdprov.h:13
forpy::DeciderDesk::elem_ids_sorted
std::vector< id_t > elem_ids_sorted
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:93
forpy::DeciderDesk::left_sum_p
float * left_sum_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:99
forpy::Desk
Main thread desk object.
Definition: desk.h:201
forpy::DeciderDesk::fullentropy
float fullentropy
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:85
forpy::DeciderDesk::setup
void setup(std::vector< size_t > *ntfp, mu::variant< std::vector< float >, std::vector< double >, std::vector< uint32_t >, std::vector< uint8_t >> *nttp)
Definition: desk.h:134
forpy::DeciderDesk::best_res_v
OptSplitV best_res_v
Variables used during the threshold optimization.
Definition: desk.h:75
forpy::Desk::setup
void setup(std::atomic< size_t > *stored_in_leaf_p, std::atomic< id_t > *next_id_p, std::vector< std::pair< id_t, id_t >> *tree_p, std::vector< size_t > *ntfp=nullptr, mu::variant< std::vector< float >, std::vector< double >, std::vector< uint32_t >, std::vector< uint8_t >> *nttp=nullptr, std::vector< Mat< float >> *lrmp=nullptr, const uint &random_seed=0)
Definition: desk.h:209
forpy::RandomDesk
Desk for coordinating the random engines.
Definition: desk.h:181
forpy::DeciderDesk::best_feat_idx
id_t best_feat_idx
Variables used during the threshold optimization.
Definition: desk.h:76
forpy::DeciderDesk::elem_id_p
id_t * elem_id_p
Definition: desk.h:69
forpy::Desk::reset
void reset()
Definition: desk.h:222
forpy::LeafDesk::leaf_regression_map_p
std::vector< Mat< float > > * leaf_regression_map_p
Definition: desk.h:166
forpy::DeciderDesk::opt_res_v
OptSplitV opt_res_v
Variables used during the threshold optimization.
Definition: desk.h:75
forpy::DeciderDesk::need_sort
bool need_sort
Variables used during the threshold optimization.
Definition: desk.h:77
forpy::TreeDesk::reset
void reset()
Clear the marks and reset all pointers.
Definition: desk.h:45
forpy::DeciderDesk::full_sum_p
float * full_sum_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:84
forpy::Desk::r
RandomDesk r
Definition: desk.h:206
forpy::DeciderDesk::make_to_leaf
bool make_to_leaf
Return values from IThreshOpt::optimize.
Definition: desk.h:111
forpy::uint
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113
forpy::DeciderDesk::left_sum_vec
std::vector< float > left_sum_vec
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:98
forpy::DeciderDesk::annot_p
const float * annot_p
Variables initialized in IThreshOpt::full_entropy.
Definition: desk.h:86
forpy::DeciderDesk::right_int
interv_t right_int
Return values from IThreshOpt::optimize.
Definition: desk.h:113
forpy::DeciderDesk::right_id
id_t right_id
Return values from IThreshOpt::optimize.
Definition: desk.h:114
forpy::LeafDesk
Desk for leaf manager training.
Definition: desk.h:162