Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
data.cpp
Go to the documentation of this file.
1/* Brush
2copyright 2020 William La Cava
3license: GNU/GPL v3
4*/
5
6//internal includes
7#include "data.h"
8
9using namespace Brush::Util;
10using std::min;
11
12namespace Brush{
13
14map<DataType,string> DataTypeName = {
15 {DataType::ArrayB, "ArrayB"},
16 {DataType::ArrayI, "ArrayI"},
17 {DataType::ArrayF, "ArrayF"},
18 {DataType::MatrixB, "MatrixB"},
19 {DataType::MatrixI, "MatrixI"},
20 {DataType::MatrixF, "MatrixF"},
21 {DataType::TimeSeriesB, "TimeSeriesB"},
22 {DataType::TimeSeriesI,"TimeSeriesI"},
23 {DataType::TimeSeriesF, "TimeSeriesF"},
24 {DataType::ArrayBJet, "ArrayBJet"},
25 {DataType::ArrayIJet, "ArrayIJet"},
26 {DataType::ArrayFJet, "ArrayFJet"},
27 {DataType::MatrixBJet, "MatrixBJet"},
28 {DataType::MatrixIJet, "MatrixIJet"},
29 {DataType::MatrixFJet, "MatrixFJet"},
30 {DataType::TimeSeriesBJet, "TimeSeriesBJet"},
31 {DataType::TimeSeriesIJet,"TimeSeriesIJet"},
32 {DataType::TimeSeriesFJet, "TimeSeriesFJet"}
33};
34map<string,DataType> DataNameType = Util::reverse_map(DataTypeName);
35
36const map<DataType,std::type_index> DataTypeID = {
37 {DataType::ArrayB, typeid(ArrayXb)},
38 {DataType::ArrayI, typeid(ArrayXi)},
39 {DataType::ArrayF, typeid(ArrayXf)},
40 {DataType::MatrixB, typeid(ArrayXXb)},
41 {DataType::MatrixI, typeid(ArrayXXi)},
42 {DataType::MatrixF, typeid(ArrayXXf)},
46};
47map<std::type_index,DataType> DataIDType = Util::reverse_map(DataTypeID);
48
49namespace Data{
50
51// we have 3 basic types (bool, integer, float), specialized into
52// arrays, matrices, and timeseries. Notice that all dataset and operators
53// right now only work with arrays. TODO: implement timeseries and matrices.
65
66// /// returns the type_index held in arg
68{
69 return StateTypes.at(arg.index());
70}
71State check_type(const ArrayXf& x, const string t)
72{
73 State tmp;
74
75 if (!t.empty())
76 {
77 // Use DataNameType to get the statetype given the string representation
78 DataType feature_type = DataNameType.at(t);
79
80 if (feature_type == DataType::ArrayB)
81 tmp = ArrayXb(x.cast<bool>());
82 else if (feature_type == DataType::ArrayI)
83 tmp = ArrayXi(x.cast<int>());
84 else if (feature_type == DataType::ArrayF)
85 tmp = ArrayXf(x.cast<float>());
86 else
88 "Invalid feature type. check_type does not support this type: " + t);
89 }
90 else
91 {
92 // get feature types (binary or continuous/categorical)
93 bool isBinary = true;
94 bool isCategorical = true;
95
96 std::map<float, bool> uniqueMap;
97 for(int i = 0; i < x.size(); i++)
98 {
99 if(x(i) != 0 && x(i) != 1)
100 isBinary = false;
101 if(x(i) != floor(x(i)) && x(i) != ceil(x(i)))
102 isCategorical = false;
103 else
104 uniqueMap[x(i)] = true;
105 }
106
107 if (isBinary)
108 {
109 tmp = ArrayXb(x.cast<bool>());
110 }
111 else
112 {
113 if(isCategorical && uniqueMap.size() <= 10)
114 {
115 tmp = ArrayXi(x.cast<int>());
116 }
117 else
118 {
119 tmp = x;
120 }
121 }
122 }
123
124 return tmp;
125}
126
127template<typename StateRef>
128State cast_type(const ArrayXf& x, const StateRef& x_ref)
129{
130 if (std::holds_alternative<ArrayXi>(x_ref))
131 return ArrayXi(x.cast<int>());
132 else if (std::holds_alternative<ArrayXb>(x_ref))
133 return ArrayXb(x.cast<bool>());
134
135 return x;
136}
137
139Dataset Dataset::operator()(const vector<size_t>& idx) const
140{
141 std::map<std::string, State> new_features;
142 for (auto& [key, value] : this->features)
143 {
144 auto& k = key;
145 std::visit([&](auto&& arg)
146 {
147 using T = std::decay_t<decltype(arg)>;
148 if constexpr ( T::NumDimensions == 1)
149 new_features[k] = T(arg(idx));
150 else if constexpr (T::NumDimensions==2)
151 new_features[k] = T(arg(idx, Eigen::internal::all_t{}));
152 else
153 static_assert(always_false_v<T>, "non-exhaustive visitor!");
154 },
155 value
156 );
157 }
158 ArrayXf new_y;
159 if (this->y.size()>0)
160 {
161 new_y = this->y(idx);
162 }
163 // using constructor 1
164 Dataset result(new_features, new_y, this->classification);
165 // Preserve the original feature name and type order from parent
166 // The constructor's init() may have reordered them, so we fix that here
167 result.feature_names = this->feature_names;
168 result.feature_types = this->feature_types;
169 result.feature_name_order_ = this->feature_names;
170
171 // Rebuild features_of_type to match the corrected order
172 result.features_of_type.clear();
173 result.unique_data_types.clear();
174 for (size_t i = 0; i < result.feature_names.size(); ++i) {
175 const auto& name = result.feature_names[i];
176 const auto& ftype = result.feature_types[i];
177 result.features_of_type[ftype].push_back(name);
179 }
180
181 return result;
182}
183
184
186{
187 if (!use_batch)
188 return (*this);
189
190 const auto total_samples = static_cast<size_t>(this->get_n_samples());
191 const auto target_batch_size = static_cast<size_t>(ceil(total_samples * batch_size));
192
193 // Start a new epoch only after every row from the preceding epoch has
194 // been returned. This prevents replacement before a complete pass through
195 // the training partition.
197 {
198 // resets everything
199 batch_cycle_idx.clear();
200 batch_cycle_sizes.clear();
203
204 // repopulate the indexes
205 if (classification)
206 {
207 // Shuffle each class queue. Every batch preserves the original
208 // class prevalence and reserves one slot per class. Once a class
209 // queue is exhausted, that class is sampled with replacement so
210 // later batches still train against it while larger class queues
211 // complete their no-replacement pass.
212 std::map<float, vector<size_t>> class_indices;
213 for (size_t i = 0; i < total_samples; ++i)
214 class_indices[y(i)].push_back(i);
215
216 for (auto& [label, indices] : class_indices)
217 r.shuffle(indices.begin(), indices.end());
218
219 // creating the batches
220 vector<size_t> positions(class_indices.size(), 0); // this gets incremented everytime a row is added to a batch
221 const auto class_count = class_indices.size();
222 const auto current_batch_size = std::max(target_batch_size, class_count);
223 while (true) // this while(true) iterates once for each batch creation
224 {
225 // searches for classes with unseen samples
226 bool has_unseen_rows = false;
227 size_t class_position = 0;
228 for (const auto& [label, indices] : class_indices) {
229 has_unseen_rows |= positions[class_position] < indices.size();
230 ++class_position;
231 }
232 if (!has_unseen_rows) // all rows were added to a batch -- this is the escape condition to the while (true) loop
233 break;
234
235 vector<size_t> counts(class_indices.size(), 0); // will count how many samples per class for the current batch
236 vector<std::pair<float, size_t>> remainders; // will store how many samples are left per class after the current batch
237
238 // free space in the batch. Notice that one sample per class is already being considered here
239 const auto allocatable_slots = current_batch_size - class_count;
240
241 class_position = 0;
242 for (const auto& [label, indices] : class_indices)
243 {
244 counts[class_position] = 1; // this ensures one sample per class
245
246 // find rounded number of slots that will be used for the class
247 // to ensure they keep approximate prevalence w.r.t. original data
248 const float exact = static_cast<float>(indices.size() * allocatable_slots)
249 / static_cast<float>(total_samples);
250 const auto floor_allocation = static_cast<size_t>(std::floor(exact));
251
252 counts[class_position] += floor_allocation;
253 remainders.emplace_back(exact - std::floor(exact), class_position);
254 ++class_position;
255 }
256
257 std::stable_sort(remainders.begin(), remainders.end(),
258 [](const auto& left, const auto& right) {
259 return left.first > right.first;
260 });
261
262 size_t assigned = class_count;
263 for (const auto count : counts)
264 assigned += count - 1;
265 for (size_t i = 0; assigned < current_batch_size; ++i, ++assigned)
266 ++counts[remainders.at(i).second];
267
268 // filling the batch
269 vector<size_t> batch_indices;
270 batch_indices.reserve(current_batch_size);
271 class_position = 0;
272 for (const auto& [label, indices] : class_indices)
273 {
274 const auto available = indices.size() - positions[class_position];
275 const auto unique_count = std::min(counts[class_position], available);
276 for (size_t i = 0; i < unique_count; ++i)
277 batch_indices.push_back(indices[positions[class_position]++]);
278
279 // Repeat only a class that was already exhausted before
280 // this batch began. If its final unseen row was consumed
281 // above, return a smaller final batch instead of repeating
282 // that row immediately.
283 if (available == 0) {
284 for (size_t i = 0; i < counts[class_position]; ++i)
285 batch_indices.push_back(indices.at(r.rnd_int(0, indices.size() - 1)));
286 }
287 ++class_position;
288 }
289 r.shuffle(batch_indices.begin(), batch_indices.end());
290 batch_cycle_idx.insert(batch_cycle_idx.end(), batch_indices.begin(), batch_indices.end());
291 batch_cycle_sizes.push_back(batch_indices.size());
292 }
293 }
294 else
295 {
296 // Regression batches are stratified by target rank. The four
297 // equal-frequency y quartiles are shuffled independently, then
298 // apportioned evenly into each batch without replacement.
299 vector<size_t> sorted_indices(total_samples);
300 std::iota(sorted_indices.begin(), sorted_indices.end(), 0);
301 std::stable_sort(sorted_indices.begin(), sorted_indices.end(),
302 [this](size_t left, size_t right) { return y(left) < y(right); });
303
304 vector<vector<size_t>> quartiles(4);
305 for (size_t rank = 0; rank < total_samples; ++rank)
306 quartiles.at((rank * quartiles.size()) / total_samples).push_back(sorted_indices.at(rank));
307
308 size_t nonempty_quartiles = 0;
309 for (auto& quartile : quartiles) {
310 if (!quartile.empty()) {
311 r.shuffle(quartile.begin(), quartile.end());
312 ++nonempty_quartiles;
313 }
314 }
315
316 vector<size_t> positions(quartiles.size(), 0);
317 const auto current_batch_size = std::max(target_batch_size, nonempty_quartiles);
318 while (true)
319 {
320 bool has_unseen_rows = false;
321 for (size_t quartile = 0; quartile < quartiles.size(); ++quartile)
322 has_unseen_rows |= positions[quartile] < quartiles[quartile].size();
323 if (!has_unseen_rows)
324 break;
325
326 vector<size_t> counts(quartiles.size(), 0);
327 vector<std::pair<float, size_t>> remainders;
328 const auto allocatable_slots = current_batch_size - nonempty_quartiles;
329 for (size_t quartile = 0; quartile < quartiles.size(); ++quartile) {
330 if (quartiles[quartile].empty())
331 continue;
332 counts[quartile] = 1;
333 const float exact = static_cast<float>(quartiles[quartile].size() * allocatable_slots)
334 / static_cast<float>(total_samples);
335 counts[quartile] += static_cast<size_t>(std::floor(exact));
336 remainders.emplace_back(exact - std::floor(exact), quartile);
337 }
338
339 std::stable_sort(remainders.begin(), remainders.end(),
340 [](const auto& left, const auto& right) {
341 return left.first > right.first;
342 });
343 size_t assigned = 0;
344 for (const auto count : counts)
345 assigned += count;
346 for (size_t i = 0; assigned < current_batch_size; ++i, ++assigned)
347 ++counts[remainders.at(i).second];
348
349 vector<size_t> batch_indices;
350 batch_indices.reserve(current_batch_size);
351 for (size_t quartile = 0; quartile < quartiles.size(); ++quartile) {
352 const auto available = quartiles[quartile].size() - positions[quartile];
353 const auto unique_count = std::min(counts[quartile], available);
354 for (size_t i = 0; i < unique_count; ++i)
355 batch_indices.push_back(quartiles[quartile][positions[quartile]++]);
356 }
357 r.shuffle(batch_indices.begin(), batch_indices.end());
358 batch_cycle_idx.insert(batch_cycle_idx.end(), batch_indices.begin(), batch_indices.end());
359 batch_cycle_sizes.push_back(batch_indices.size());
360 }
361 }
362 }
363
364 // get the indices and move the two cursors
365 const auto count = batch_cycle_sizes.at(batch_cycle_batch_cursor++);
366 vector<size_t> indices(batch_cycle_idx.begin() + batch_cycle_cursor,
367 batch_cycle_idx.begin() + batch_cycle_cursor + count);
368 batch_cycle_cursor += count;
369 return (*this)(indices);
370}
371
372std::array<Dataset, 2> Dataset::split(const ArrayXb& mask) const
373{
374 // TODO: assert that mask is not filled with zeros or ones (would create
375 // one empty partition)
376
377 // split data into two based on mask.
378 auto idx1 = Util::mask_to_index(mask);
379 auto idx2 = Util::mask_to_index((!mask));
380 return std::array<Dataset, 2>{ (*this)(idx1), (*this)(idx2) };
381}
382
385
386vector<string> Dataset::get_feature_types() const {
387 // iterate through each feature name in order, get the data type, and return it. This is
388 // used in the python front-end to save the feature types from the training dataset
389 // when calling predict.
390
391 vector<string> python_feature_types;
392 // Iterate through feature_names to preserve order, not through features map
393 for (const auto& name: this->feature_names)
394 {
395 // fmt::print("name:{}\n",name);
396 const auto& value = this->features.at(name);
397
398 // save feature types
399 auto feature_type = StateType(value);
400
401 if (feature_type == DataType::ArrayB)
402 python_feature_types.push_back("ArrayB");
403 else if (feature_type == DataType::ArrayI)
404 python_feature_types.push_back("ArrayI");
405 else if (feature_type == DataType::ArrayF)
406 python_feature_types.push_back("ArrayF");
407 else
409 "get_feature_type does not support the type of this feature yet: " + name +
410 "as a notice, this function is suposed to be used in the python side, to extract data types inferred by Brush type sniffer.");
411 }
412
413 return python_feature_types;
414}
415
416
420{
421 //TODO: populate feature_names, var_data_types, data_types, features_of_type
422 // n_features = this->features.size();
423 // note this will have to change in unsupervised settings
424 // n_samples = this->y.size();
425
426 if (this->features.size() == 0){
428 fmt::format("Error during the initialization of the dataset. It "
429 "does not contain any data\n")
430 );
431 }
432
433 // fmt::print("Dataset::init()\n");
434 // Use the stored original feature name order if available, otherwise iterate through the map.
435 // IMPORTANT: use a value (not a const-ref) to avoid a dangling reference from binding
436 // a const-ref to the temporary produced by a mixed lvalue/prvalue ternary expression.
437 vector<string> names_to_use;
438 if (this->feature_name_order_.empty()) {
439 for (const auto& [name, value] : this->features) {
440 names_to_use.push_back(name);
441 }
442 } else {
443 names_to_use = this->feature_name_order_;
444 }
445
446 for (const auto& name : names_to_use)
447 {
448 // fmt::print("name:{}\n",name);
449 const auto& value = this->features.at(name);
450
451 // save feature types
452 auto feature_type = StateType(value);
453
455 feature_types.push_back( feature_type );
456
457 // add feature to appropriate map list
458 this->features_of_type[feature_type].push_back(name);
459
460 // populate feature names in the original order
461 this->feature_names.push_back(name);
462 }
463
464 // setting the training and validation data indexes
465 auto n_samples = int(this->get_n_samples());
466
467 training_data_idx.resize(0);
468 validation_data_idx.resize(0);
469
470 if (!use_validation)
471 {
472 vector<size_t> idx(n_samples);
473
474 std::iota(idx.begin(), idx.end(), 0);
475
476 std::transform(idx.begin(), idx.end(),
477 back_inserter(training_data_idx),
478 [&](int element) { return element; });
479
480 std::transform(idx.begin(), idx.end(),
481 back_inserter(validation_data_idx),
482 [&](int element) { return element; });
483 }
484 else if (classification) // figuring out training and validation data indexes
485 { // Stratified split for classification problems. TODO: parameters to change stratify behavior? (and set false by default)
486 std::map<float, vector<int>> class_indices; // TODO: I think I can remove many std:: from the code..
487 for (size_t i = 0; i < n_samples; ++i) {
488 class_indices[y[i]].push_back(i);
489 }
490
491 for (auto& class_group : class_indices) {
492 auto& indices = class_group.second;
493
494 int n_class_samples = indices.size();
495
496 vector<size_t> idx(n_class_samples);
497 if (shuffle_split)
498 idx = r.shuffled_index(n_class_samples);
499 else
500 std::iota(idx.begin(), idx.end(), 0);
501
502 auto n_train_samples = int(ceil(n_class_samples*(1.0-validation_size)));
503
504 std::transform(idx.begin(), idx.begin() + n_train_samples,
505 back_inserter(training_data_idx),
506 [&](int element) { return indices[element]; });
507
508 // stratified split so train/validation never overlap when a class is
509 // too small. Now, if a class has no remaining samples for validation,
510 // it contributes only to training (validation gets none for that class).
511 if (n_class_samples - n_train_samples > 0)
512 {
513 std::transform(idx.begin() + n_train_samples, idx.end(),
514 back_inserter(validation_data_idx),
515 [&](int element) { return indices[element]; });
516 }
517 }
518 }
519 else { // regression, or classification without stratification
520 // logic for non-classification problems
521 vector<size_t> idx(n_samples);
522
523 if (shuffle_split)
524 idx = r.shuffled_index(n_samples);
525 else
526 std::iota(idx.begin(), idx.end(), 0);
527
528 // garantee that at least one sample is going to be returned, since
529 // use_batch is true only if batch_size is (0, 1), and ceil will round
530 // up
531 auto n_train_samples = int(ceil(n_samples*(1-validation_size)));
532
533 std::transform(idx.begin(), idx.begin() + n_train_samples,
534 back_inserter(training_data_idx),
535 [&](int element) { return element; });
536
537 if (n_samples - n_train_samples == 0) { // training_data_idx contains all data
539 }
540 else
541 {
542 std::transform(idx.begin() + n_train_samples, idx.end(),
543 back_inserter(validation_data_idx),
544 [&](int element) { return element; });
545 }
546 }
547}
548
550void Dataset::set_batch_size(float new_size) {
551 batch_size = new_size;
552 use_batch = batch_size > 0.0 && batch_size < 1.0;
553 batch_cycle_idx.clear();
554 batch_cycle_sizes.clear();
557}
558
560map<string, State> Dataset::make_features(const ArrayXXf& X,
561 const map<string,State>& Z,
562 const vector<string>& vn,
563 const vector<string>& ft
564 )
565{
566 // fmt::print("Dataset::make_features()\n");
567 map<string, State> tmp_features;
568
569 // fmt::print("vn: {}\n",vn);
570
571 // check variable names
572 vector<string> tmp_feature_names = {};
573 if (vn.empty())
574 {
575 // fmt::print("vn empty\n");
576 for (int i = 0; i < X.cols(); ++i)
577 {
578 string v = "x_"+to_string(i);
579 tmp_feature_names.push_back(v);
580 }
581 }
582 else
583 {
584 if (vn.size() != X.cols())
586 fmt::format("Variable names and data size mismatch: "
587 "{} variable names and {} features in X",
588 vn.size(), X.cols()) );
589 tmp_feature_names = vn;
590 }
591
592 // check variable types
593 vector<string> var_types;
594 if (ft.empty())
595 {
596 for (int i = 0; i < X.cols(); ++i)
597 {
598 var_types.push_back("");
599 }
600 }
601 else {
602 if (ft.size() != X.cols())
604 fmt::format("Feature type names and data size mismatch: "
605 "{} feature type names and {} features in X",
606 ft.size(), X.cols()) );
607
608 var_types = ft;
609 }
610
611 for (int i = 0; i < X.cols(); ++i)
612 {
613 // fmt::print("X({}): {} \n",i,tmp_feature_names.at(i));
614 State tmp = check_type(X.col(i).array(), var_types.at(i));
615
616 tmp_features[tmp_feature_names.at(i)] = tmp;
617 }
618 // fmt::print("tmp_features insert\n");
619 tmp_features.insert(Z.begin(), Z.end());
620
621 // Store the original feature name order (X features first, then Z features)
622 this->feature_name_order_ = tmp_feature_names;
623 for (const auto& [name, value] : Z) {
624 this->feature_name_order_.push_back(name);
625 }
626
627 return tmp_features;
628};
629
631map<string,State> Dataset::copy_and_make_features(const ArrayXXf& X,
632 const Dataset& ref_dataset,
633 const vector<string>& vn
634 )
635{
636 vector<string> tmp_feature_names = {};
637 if (vn.empty())
638 {
639 for (int i = 0; i < X.cols(); ++i)
640 {
641 string v = "x_"+to_string(i);
642 tmp_feature_names.push_back(v);
643 }
644 }
645 else
646 {
647 if (vn.size() != X.cols())
649 fmt::format("Variable names and data size mismatch: "
650 "{} variable names and {} features in X",
651 vn.size(),
652 X.cols()
653 )
654 );
655 tmp_feature_names = vn;
656 }
657
658 if (ref_dataset.features.size() != tmp_feature_names.size())
660 fmt::format("Reference dataset with incompatible number of variables: "
661 "Reference has {} variable names, but X has {}",
662 ref_dataset.features.size(),
663 tmp_feature_names.size()
664 )
665 );
666
667 map<string, State> tmp_features;
668 for (int i = 0; i < X.cols(); ++i)
669 {
670 State tmp = cast_type(
671 X.col(i).array(),
672 ref_dataset.features.at(tmp_feature_names.at(i))
673 );
674
675 tmp_features[tmp_feature_names.at(i)] = tmp;
676 }
677
678 // Store the original feature name order
679 this->feature_name_order_ = tmp_feature_names;
680
681 return tmp_features;
682};
683
684ostream& operator<<(ostream& os, DataType dt)
685{
686 os << DataTypeName[dt];
687 return os;
688}
689
690} // data
691} // Brush
bool classification
whether this is a classification problem
Definition data.h:93
vector< string > feature_name_order_
stores the original feature name order before map sorting
Definition data.h:68
Dataset get_validation_data() const
Definition data.cpp:384
std::map< string, State > features
dataset features, as key value pairs
Definition data.h:84
int get_n_samples() const
Definition data.h:233
Dataset(std::map< string, State > &d, const Ref< const ArrayXf > &y_=ArrayXf(), bool c=false, float validation_size=0.0, float batch_size=1.0, bool shuffle_split=false)
Definition data.h:125
size_t batch_cycle_batch_cursor
Definition data.h:66
vector< size_t > training_data_idx
Definition data.h:57
Dataset get_batch() const
Select the next batch without replacement. Classification batches preserve the prevalence of the rema...
Definition data.cpp:185
vector< string > get_feature_types() const
Definition data.cpp:386
std::vector< DataType > feature_types
types of data in the features.
Definition data.h:75
std::array< Dataset, 2 > split(const ArrayXb &mask) const
Definition data.cpp:372
std::unordered_map< DataType, vector< string > > features_of_type
map from data types to features having that type.
Definition data.h:81
float batch_size
percentage of training data size to use in each batch. if 1.0, then all data is used
Definition data.h:102
bool use_validation
Definition data.h:98
std::vector< string > feature_names
names of the feature types as string representations.
Definition data.h:78
std::vector< DataType > unique_data_types
keeps track of the unique data types in the dataset.
Definition data.h:72
map< string, State > copy_and_make_features(const ArrayXXf &X, const Dataset &ref_dataset, const vector< string > &vn={})
turns input into a feature map, with feature types copied from a reference
Definition data.cpp:631
map< string, State > make_features(const ArrayXXf &X, const map< string, State > &Z={}, const vector< string > &vn={}, const vector< string > &ft={})
turns input data into a feature map
Definition data.cpp:560
void init()
call init at the end of constructors to define metafeatures of the data.
Definition data.cpp:419
float validation_size
percentage of original data used for train. if 0.0, then all data is used for train and validation
Definition data.h:97
vector< size_t > validation_data_idx
Definition data.h:58
vector< size_t > batch_cycle_idx
Definition data.h:63
ArrayXf y
length N array, the target label
Definition data.h:90
float get_batch_size()
Definition data.cpp:549
Dataset get_training_data() const
Definition data.cpp:383
vector< size_t > batch_cycle_sizes
Definition data.h:64
void set_batch_size(float new_size)
Definition data.cpp:550
Dataset operator()(const vector< size_t > &idx) const
return a slice of the data using indices idx
Definition data.cpp:139
size_t batch_cycle_cursor
Definition data.h:65
#define HANDLE_ERROR_THROW(err)
Definition error.h:27
namespace containing Data structures used in Brush
Definition data.cpp:49
std::vector< DataType > StateTypes
Definition data.cpp:54
TimeSeries< bool > TimeSeriesb
TimeSeries convenience typedefs.
Definition types.h:110
State cast_type(const ArrayXf &x, const StateRef &x_ref)
Definition data.cpp:128
TimeSeries< float > TimeSeriesf
Definition types.h:112
DataType StateType(const State &arg)
Definition data.cpp:67
State check_type(const ArrayXf &x, const string t)
determines data types of columns of matrix X.
Definition data.cpp:71
ostream & operator<<(ostream &os, DataType dt)
Definition data.cpp:684
std::variant< ArrayXb, ArrayXi, ArrayXf, ArrayXXb, ArrayXXi, ArrayXXf, TimeSeriesb, TimeSeriesi, TimeSeriesf, ArrayXbJet, ArrayXiJet, ArrayXfJet, ArrayXXbJet, ArrayXXiJet, ArrayXXfJet, TimeSeriesbJet, TimeSeriesiJet, TimeSeriesfJet > State
defines the possible types of data flowing thru nodes.
Definition types.h:140
TimeSeries< int > TimeSeriesi
Definition types.h:111
namespace containing various utility functions
Definition csv.h:19
string to_string(const T &value)
template function to convert objects to string for logging
Definition utils.h:369
void unique_insert(Vector &v, const T &t)
unique insertion into a vector. allows a vector to be used like a set. source: http://www....
Definition utils.h:684
vector< size_t > mask_to_index(const ArrayXb &mask)
convert a boolean mask to an index array
Definition utils.cpp:409
< nsga2 selection operator for getting the front
Definition bandit.cpp:3
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Definition types.h:39
Eigen::Array< int, Eigen::Dynamic, Eigen::Dynamic > ArrayXXi
Definition types.h:42
DataType
data types.
Definition types.h:143
constexpr bool always_false_v
Definition init.h:72
Eigen::Array< bool, Eigen::Dynamic, Eigen::Dynamic > ArrayXXb
Definition types.h:41
map< DataType, string > DataTypeName
Definition data.cpp:14
const map< DataType, std::type_index > DataTypeID
Definition data.cpp:36
Eigen::Array< int, Eigen::Dynamic, 1 > ArrayXi
Definition types.h:40
map< std::type_index, DataType > DataIDType
Definition data.cpp:47
map< string, DataType > DataNameType
Definition data.cpp:34