24 #ifndef EMP_DATA_NODE_H 25 #define EMP_DATA_NODE_H 27 #include "../base/vector.h" 28 #include "../base/assert.h" 29 #include "../meta/IntPack.h" 30 #include "../tools/FunctionSet.h" 31 #include "../tools/IndexMap.h" 32 #include "../tools/string_utils.h" 33 #include "../tools/math.h" 83 using type =
typename next_type::template append<this_req>;
94 template <
typename VAL_TYPE>
114 double GetTotal()
const {
emp_assert(
false,
"Calculating total requires a DataNode with the Range or FullRange modifier");
return 0;}
115 double GetMean()
const {
emp_assert(
false,
"Calculating mean requires a DataNode with the Range or FullRange modifier");
return 0;}
116 double GetMin()
const {
emp_assert(
false,
"Calculating min requires a DataNode with the Range or FullRange modifier");
return 0;}
117 double GetMax()
const {
emp_assert(
false,
"Calculating max requires a DataNode with the Range or FullRange modifier");
return 0;}
118 double GetVariance()
const {
emp_assert(
false,
"Calculating variance requires a DataNode with the Stats or FullStats modifier");
return 0;}
120 double GetSkew()
const {
emp_assert(
false,
"Calculating skew requires a DataNode with the Stats or FullStats modifier");
return 0;}
121 double GetKurtosis()
const {
emp_assert(
false,
"Calculating kurtosis requires a DataNode with the Stats or FullStats modifier");
return 0;}
131 void SetInfo(
const std::string &,
const std::string & _d=
"",
const std::string & _k=
"") {
132 (void) _d; (void) _k;
133 emp_assert(
false,
"Invalid call for DataNode config.");
136 void AddDatum(
const VAL_TYPE & val) { val_count++; }
142 os <<
"BASE DataNodeModule.\n";
150 template <
typename VAL_TYPE,
emp::data... MODS>
166 void AddDatum(
const VAL_TYPE & val) { cur_val = val; parent_t::AddDatum(val); }
170 os <<
"DataNodeModule for data::Current. (level " << (int) data::Current <<
")\n";
171 parent_t::PrintDebug(os);
178 template <
typename VAL_TYPE,
emp::data... MODS>
190 const std::string &
GetName()
const {
return name; }
197 void SetName(
const std::string & _in) { name = _in; }
204 void SetInfo(
const std::string & _n,
const std::string & _d=
"",
const std::string & _k=
"") {
205 name = _n; desc = _d; keyword = _k;
210 os <<
"DataNodeModule for data::Info. (level " << (int)
data::Info <<
")\n";
211 parent_t::PrintDebug(os);
218 template <
typename VAL_TYPE,
emp::data... MODS>
227 using base_t::val_count;
237 parent_t::AddDatum(val);
248 os <<
"DataNodeModule for data::Log. (level " << (int) data::Log <<
")\n";
249 parent_t::PrintDebug(os);
257 template <
typename VAL_TYPE,
emp::data... MODS>
266 using base_t::val_count;
267 using parent_t::val_set;
296 os <<
"DataNodeModule for data::Archive. (level " << (int) data::Archive <<
")\n";
297 parent_t::PrintDebug(os);
304 template <
typename VAL_TYPE,
emp::data... MODS>
315 using base_t::val_count;
323 double GetMean()
const {
return total / (double) base_t::val_count; }
333 total += (double) val;
334 if (!val_count || min > (
double) val) min = (
double) val;
335 if (!val_count || max < (
double) val) max = (
double) val;
336 parent_t::AddDatum(val);
349 os <<
"DataNodeModule for data::Range. (level " << (int) data::Range <<
")\n";
350 parent_t::PrintDebug(os);
358 template <
typename VAL_TYPE,
emp::data... MODS>
370 using base_t::val_count;
371 using parent_t::total;
376 : total_vals(), num_vals(), min_vals(), max_vals() { ; }
382 double GetMean()
const {
return total / (double) val_count; }
391 double GetTotal(
size_t update)
const {
return total_vals[update]; }
394 double GetMean(
size_t update)
const {
return total_vals[update] / (double) num_vals[update]; }
397 double GetMin(
size_t update)
const {
return min_vals[update]; }
400 double GetMax(
size_t update)
const {
return max_vals[update]; }
419 os <<
"DataNodeModule for data::FullRange. (level " << (int) data::FullRange <<
")\n";
420 parent_t::PrintDebug(os);
431 template <
typename VAL_TYPE,
emp::data... MODS>
446 using base_t::val_count;
447 using parent_t::total;
454 using parent_t::GetMean;
473 double GetKurtosis()
const {
return double(val_count)*M4 / (M2*M2) - 3.0;}
479 const double n = (double) (val_count + 1);
480 const double delta = ((double) val) - (total/((val_count > 0) ? (
double) val_count : 1.0));
481 const double delta_n = delta / n;
482 const double delta_n2 = delta_n * delta_n;
483 const double term1 = delta * delta_n * (double) val_count;
485 M4 += term1 * delta_n2 * (n*n - 3.0*n + 3.0) + 6.0 * delta_n2 * M2 - 4.0 * delta_n * M3;
486 M3 += term1 * delta_n * (n - 2.0) - 3.0 * delta_n * M2;
489 parent_t::AddDatum(val);
502 os <<
"DataNodeModule for data::Stats. (level " << (int) data::Stats <<
")\n";
503 parent_t::PrintDebug(os);
509 template <
typename VAL_TYPE,
emp::data... MODS>
521 using base_t::val_count;
547 double cur_min = offset;
548 for (
size_t i = 0; i < counts.
size(); i++) {
549 bin_mins[i] = cur_min;
560 void SetupBins(VAL_TYPE _min, VAL_TYPE _max,
size_t num_bins) {
563 double bin_width = ((double) width) / (double) num_bins;
567 for (
size_t & x : counts) x = 0.0;
572 size_t bin_id = bins.
Index((
double) (val - offset));
575 parent_t::AddDatum(val);
580 for (
size_t & x : counts) x = 0.0;
586 os <<
"DataNodeModule for data::Histogram. (level " << (int)
data::FullRange <<
")\n";
587 parent_t::PrintDebug(os);
597 template <
typename VAL_TYPE,
emp::data... MODS>
607 using base_t::in_vals;
610 in_vals = pull_funs.Run();
612 for (
const auto & x : pull_sets) {
613 in_vals.
insert(in_vals.end(), x.begin(), x.end());
620 void AddPull(
const std::function<VAL_TYPE()> & fun) { pull_funs.Add(fun); }
624 os <<
"DataNodeModule for data::Pull. (level " << (int) data::Pull <<
")\n";
625 parent_t::PrintDebug(os);
632 template <
typename VAL_TYPE,
int... IMODS>
647 template <
typename VAL_TYPE,
emp::data... MODS>
651 using parent_t::in_vals;
658 template <
typename... Ts>
659 inline void Add(
const VAL_TYPE & val,
const Ts &... extras) {
660 parent_t::AddDatum(val); Add(extras...);
665 parent_t::PullData_impl();
666 for (
const VAL_TYPE & val : in_vals) parent_t::AddDatum(val);
673 void PrintCurrent(std::ostream & os=std::cout)
const { os << parent_t::GetCurrent(); }
675 const std::string & spacer=
", ",
676 const std::string & eol=
"\n")
const {
678 for (
size_t i=0; i < data.
size(); i++) {
679 if (i>0) os << spacer;
687 os <<
"Main DataNode.\n";
688 parent_t::PrintDebug(os);
void SetName(const std::string &)
Definition: DataNode.h:127
Definition: DataNode.h:510
static const std::string & empty_string()
Definition: string_utils.h:29
double GetMean() const
Get the mean of all values added to this DataNode since the last reset.
Definition: DataNode.h:323
double GetMean() const
Get the mean of all values added to this DataNode since the last reset.
Definition: DataNode.h:382
iterator insert(ARGS &&...args)
Definition: vector.h:201
double GetMean(size_t update) const
Get the mean of all values added to this DataNode during the.
Definition: DataNode.h:394
DataNodeModule()
Definition: DataNode.h:317
VAL_TYPE cur_val
Most recent value passed to this node.
Definition: DataNode.h:153
VAL_TYPE offset
Min value in first bin; others are offset by this much.
Definition: DataNode.h:512
void SetInfo(const std::string &_n, const std::string &_d="", const std::string &_k="")
Set this DataNode's name to.
Definition: DataNode.h:204
double GetMin() const
Definition: DataNode.h:116
Definition: DataNode.h:78
double GetMax() const
Get the maximum of all values added to this DataNode since the last reset.
Definition: DataNode.h:388
double GetTotal() const
Get the sum of all values added to this DataNode since the last reset.
Definition: DataNode.h:379
void SetInfo(const std::string &, const std::string &_d="", const std::string &_k="")
Definition: DataNode.h:131
const std::string & GetKeyword() const
Get this DataNode's keyword.
Definition: DataNode.h:194
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:348
void PullData_impl()
Definition: DataNode.h:609
DataNodeModule()
Definition: DataNode.h:452
Definition: DataNode.h:305
DataNodeModule()
Definition: DataNode.h:187
void SetDescription(const std::string &)
Definition: DataNode.h:128
typename DataModuleRequisiteAdd< MODS... >::type next_type
Definition: DataNode.h:81
Track all values since last Reset()
DataNodeModule()
Definition: DataNode.h:618
std::string name
Name of this data category.
Definition: DataNode.h:181
Definition: DataNode.h:629
void Resize(size_t new_size, double def_value=0.0)
Change the number of indecies in the map.
Definition: IndexMap.h:118
double GetKurtosis() const
Definition: DataNode.h:121
const std::string & GetName() const
Get this DataNode's name.
Definition: DataNode.h:190
void Reset()
Definition: DataNode.h:138
DataNodeModule()
Definition: DataNode.h:229
size_t Index(double index, size_t cur_id=0) const
Determine the ID at the specified index position.
Definition: IndexMap.h:196
double GetTotal(size_t update) const
Get the sum of all values added to this DataNode during the.
Definition: DataNode.h:391
const std::string & GetDescription() const
Get this DataNode's description.
Definition: DataNode.h:192
std::string desc
Description of this type of data.
Definition: DataNode.h:182
double GetMax() const
Definition: DataNode.h:117
Include a signal when each datum is added.
Definition: DataNode.h:598
Track Range data over time.
VAL_TYPE GetHistMin() const
Definition: DataNode.h:528
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:141
DataNodeModule()
Definition: DataNode.h:375
const emp::vector< VAL_TYPE > & GetData() const
Get a vector of all data that has been added since the last reset.
Definition: DataNode.h:279
void AddDatum(const VAL_TYPE &val)
Add.
Definition: DataNode.h:476
Include information (name, keyword, description) for each instance.
double GetStandardDeviation() const
Get the standard deviation of values added since the last reset.
Definition: DataNode.h:460
double GetMin(size_t update) const
Get the minimum of all values added to this DataNode during the.
Definition: DataNode.h:397
const VAL_TYPE & GetCurrent() const
Return the current (most recently added) value.
Definition: DataNode.h:163
DataNodeModule()
Definition: DataNode.h:160
emp::vector< size_t > num_vals
Value counts from previous resets.
Definition: DataNode.h:362
Definition: DataNode.h:219
void Reset()
Reset DataNode, setting the running calucluations of total, min, mean, and max to 0...
Definition: DataNode.h:340
void AddPullSet(const std::function< emp::vector< VAL_TYPE >()> &fun)
Definition: DataNode.h:621
void Reset()
Store the current range statistics in the archive and reset for a new interval.
Definition: DataNode.h:409
void SetupBins(VAL_TYPE _min, VAL_TYPE _max, size_t num_bins)
Definition: DataNode.h:560
const std::string & GetName() const
Definition: DataNode.h:123
emp::FunctionSet< VAL_TYPE()> pull_funs
Functions to pull data.
Definition: DataNode.h:600
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:501
Unknown modifier; will trigger error.
A range of values from a lower limit to and upper limit, of any provided type.
Definition: Range.h:23
double max
Largest value passed in since last reset.
Definition: DataNode.h:309
Track Range + variance, standard deviation, skew, kertosis.
DataNodeModule()
Definition: DataNode.h:524
reverse< Usort< T > > RUsort
Definition: IntPack.h:196
void push_back(PB_Ts &&...args)
Definition: vector.h:189
void AddPull(const std::function< VAL_TYPE()> &fun)
Definition: DataNode.h:620
void SetKeyword(const std::string &_in)
Set this DataNode's keyword to.
Definition: DataNode.h:201
void Add()
Definition: DataNode.h:655
void PullData_impl()
Definition: DataNode.h:100
Base form of DataNodeModule (available in ALL data nodes.)
Definition: DataNode.h:95
Definition: IntPack.h:160
const emp::vector< VAL_TYPE > & GetData(size_t update) const
Get a vector of all data that was added during the.
Definition: DataNode.h:276
data
A set of modifiers are available do describe DataNode.
Definition: DataNode.h:38
size_t size() const
Definition: vector.h:151
void AddDatum(const VAL_TYPE &val)
Add.
Definition: DataNode.h:166
double GetMax(size_t update) const
Get the maximum of all values added to this DataNode during the.
Definition: DataNode.h:400
double GetMin() const
Get the min of all values added to this DataNode since the last reset.
Definition: DataNode.h:326
double min
Smallest value passed in since last reset.
Definition: DataNode.h:308
IndexMap bins
Map of values to which bin they fall in.
Definition: DataNode.h:514
Definition: DataNode.h:648
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:418
double GetMin() const
Get the minimum of all values added to this DataNode since the last reset.
Definition: DataNode.h:385
emp::vector< double > GetBinMins() const
Return a vector containing the lowest value allowed in each bin.
Definition: DataNode.h:544
DataNodeModule()
Definition: DataNode.h:90
void SetKeyword(const std::string &)
Definition: DataNode.h:129
size_t GetResetCount() const
Definition: DataNode.h:404
emp::vector< double > min_vals
Minimums from previous resets.
Definition: DataNode.h:363
void Add(const VAL_TYPE &val, const Ts &...extras)
Methods to provide new data.
Definition: DataNode.h:659
size_t GetHistCount(size_t bin_id) const
Return the count of items in the.
Definition: DataNode.h:535
double GetHistWidth(size_t bin_id) const
Return the width of the.
Definition: DataNode.h:538
double GetTotal() const
Get the sum of all values added to this DataNode since the last reset.
Definition: DataNode.h:320
Definition: DataNode.h:258
Include a signal for data OUTSIDE a range.
Include a signal for data in a range.
size_t val_count
How many values have been loaded?
Definition: DataNode.h:97
double M3
The third moment of the distribution.
Definition: DataNode.h:439
double GetSkew() const
Definition: DataNode.h:120
void PrintLog(std::ostream &os=std::cout, const std::string &spacer=", ", const std::string &eol="\n") const
Definition: DataNode.h:674
VAL_TYPE value_t
Definition: DataNode.h:105
typename next_type::template append< this_req > type
Definition: DataNode.h:83
void PullData()
Method to retrieve new data.
Definition: DataNode.h:664
DataNodeModule()
Definition: DataNode.h:269
VAL_TYPE width
How wide is the overall histogram?
Definition: DataNode.h:513
void PrintDebug(std::ostream &os=std::cout)
Definition: DataNode.h:623
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:585
Track Log + ALL values over time (with purge options)
emp::vector< double > max_vals
Maximums from previous resets.
Definition: DataNode.h:364
Track min, max, mean, total.
static constexpr type_if< T, std::is_integral > Pow(T base, T p)
A fast (O(log p)) integral-power command.
Definition: math.h:150
void resize(size_t new_size)
Definition: vector.h:161
size_t GetResetCount() const
Definition: DataNode.h:283
size_t GetCount() const
Return the number of values that have been added to this node since the last reset.
Definition: DataNode.h:108
const auto & GetArchive() const
Definition: DataNode.h:273
double GetStandardDeviation() const
Definition: DataNode.h:119
Include a signal when new data is added (as a group)
const std::string & GetDescription() const
Definition: DataNode.h:124
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:686
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:209
double GetTotal() const
Definition: DataNode.h:114
Include a signal that triggers BEFORE Reset() to process data.
double GetKurtosis() const
Definition: DataNode.h:473
void Reset()
Reset the DataNode (empties the historgram)
Definition: DataNode.h:579
If we are in emscripten, make sure to include the header.
Definition: array.h:37
size_t GetResetCount() const
Definition: DataNode.h:112
void Reset()
Definition: DataNode.h:289
double GetMean() const
Definition: DataNode.h:115
double GetVariance() const
Definition: DataNode.h:118
double GetVariance() const
Get the variance (squared deviation from the mean) of values added since the last reset...
Definition: DataNode.h:457
Definition: DataNode.h:359
const emp::vector< size_t > & GetHistCounts() const
Return a vector containing the count of items in each bin of the histogram.
Definition: DataNode.h:541
emp::vector< double > total_vals
Totals from previous resets.
Definition: DataNode.h:361
void AdjustAll(double new_weight)
Adjust all index weights to the set provided.
Definition: IndexMap.h:190
void Reset()
Methods to reset data.
Definition: DataNode.h:670
#define emp_assert(...)
Definition: assert.h:199
double total
Total of all data since last reset.
Definition: DataNode.h:307
const std::string & GetKeyword() const
Definition: DataNode.h:125
void Reset()
Reset this node (resets current stats to 0)
Definition: DataNode.h:493
double GetSkew() const
Definition: DataNode.h:466
double GetMax() const
Get the max of all values added to this DataNode since the last reset.
Definition: DataNode.h:329
double M2
The second moment of the distribution.
Definition: DataNode.h:438
void AddDatum(const VAL_TYPE &val)
Definition: DataNode.h:136
void SetName(const std::string &_in)
Set this DataNode's name to.
Definition: DataNode.h:197
void AddDatum(const VAL_TYPE &val)
Add.
Definition: DataNode.h:332
Definition: DataNode.h:70
Definition: DataNode.h:151
const emp::vector< VAL_TYPE > & GetData() const
Get a vector of all data added since the last reset.
Definition: DataNode.h:232
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:169
void AddDatum(const VAL_TYPE &val)
Add.
Definition: DataNode.h:235
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:295
double M4
The fourth moment of the distribution.
Definition: DataNode.h:440
Definition: DataNode.h:432
DataNodeModule()
Definition: DataNode.h:103
Definition: IndexMap.h:23
emp::vector< size_t > counts
Counts in each bin.
Definition: DataNode.h:515
emp::vector< emp::vector< VAL_TYPE > > archive
Data archived from before most recent reset.
Definition: DataNode.h:260
void AddDatum(const VAL_TYPE &val)
Add.
Definition: DataNode.h:571
VAL_TYPE GetHistMax() const
Definition: DataNode.h:532
void PrintCurrent(std::ostream &os=std::cout) const
Methods to Print the templated values that a DataNode can produce.
Definition: DataNode.h:673
Enable data collection on request.
void Reset()
Reset this DataNode (clear the current log of data)
Definition: DataNode.h:241
Generic form of DataNodeModule (should never be used; trigger error!)
Definition: DataNode.h:88
void PrintDebug(std::ostream &os=std::cout)
Print debug information (useful for figuring out which modifiers you included)
Definition: DataNode.h:247
emp::vector< VAL_TYPE > in_vals
What values are waiting to be included?
Definition: DataNode.h:98
typename DataModInfo< CUR_MOD >::reqs this_req
Definition: DataNode.h:82
void SetDescription(const std::string &_in)
Set this DataNode's description to.
Definition: DataNode.h:199
std::string keyword
Short keyword.
Definition: DataNode.h:183
emp::vector< VAL_TYPE > val_set
All values saved since last reset.
Definition: DataNode.h:221