Empirical
Public Member Functions | Protected Types | Protected Attributes | List of all members
emp::DataFile Class Reference

#include <DataFile.h>

Inheritance diagram for emp::DataFile:
emp::ContainerDataFile< CONTAINER >

Public Member Functions

 DataFile (const std::string &in_filename, const std::string &b="", const std::string &s=",", const std::string &e="\n")
 
 DataFile (std::ostream &in_os, const std::string &b="", const std::string &s=",", const std::string &e="\n")
 
 DataFile (const DataFile &)=default
 
 DataFile (DataFile &&)=default
 
virtual ~DataFile ()
 
DataFileoperator= (const DataFile &)=default
 
DataFileoperator= (DataFile &&)=default
 
const std::string & GetFilename () const
 Get the filename used for this file. More...
 
const std::string & GetLineBegin () const
 Returns the string that is printed at the beginning of each line. More...
 
const std::string & GetSpacer () const
 Returns the string that is printed between elements on each line (i.e. the delimeter). More...
 
const std::string & GetLineEnd () const
 Returns the string that is printed at the end of each line. More...
 
void SetTiming (time_fun_t fun)
 
void SetTimingOnce (size_t print_time)
 
void SetTimingRepeat (size_t step)
 Setup this file to print every 'step' updates. More...
 
void SetTimingRange (size_t first, size_t step, size_t last)
 Setup this file to print only in a specified time range, and a given frequency (step). More...
 
void SetLineBegin (const std::string &_in)
 Print. More...
 
void SetSpacer (const std::string &_in)
 Print. More...
 
void SetLineEnd (const std::string &_in)
 Print. More...
 
void SetupLine (const std::string &b, const std::string &s, const std::string &e)
 Set line begin character (. More...
 
virtual void PrintHeaderKeys ()
 Print a header containing the name of each column. More...
 
virtual void PrintHeaderComment (const std::string &cstart="# ")
 Print a header containing comments describing all of the columns. More...
 
virtual void Update ()
 Run all of the functions and print the results as a new line in the file. More...
 
void Update (size_t update)
 
size_t Add (const std::function< void(std::ostream &)> &fun, const std::string &key, const std::string &desc)
 
template<typename T >
size_t AddFun (const std::function< T()> &fun, const std::string &key="", const std::string &desc="")
 Add a function that returns a value to be printed to the file. More...
 
template<typename T >
size_t AddVar (const T &var, const std::string &key="", const std::string &desc="")
 Add a function that always prints the current value of. More...
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddCurrent (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddMean (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddTotal (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddMin (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddMax (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddVariance (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddStandardDeviation (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddSkew (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddKurtosis (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
void AddStats (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
void AddAllStats (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddHistBin (DataNode< VAL_TYPE, MODS... > &node, size_t bin_id, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddInferiority (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 

Protected Types

using fun_t = void(std::ostream &)
 
using time_fun_t = std::function< bool(size_t)>
 

Protected Attributes

std::string filename
 Name of the file that we are printing to (if one exists) More...
 
std::ostream * os
 Stream to print to. More...
 
FunctionSet< fun_tfuns
 Set of functions to call, one per column in the file. More...
 
emp::vector< std::string > keys
 Keywords associated with each column. More...
 
emp::vector< std::string > descs
 Full description for each column. More...
 
time_fun_t timing_fun
 Function to determine updates to print on (default: all) More...
 
std::string line_begin
 What should we print at the start of each line? More...
 
std::string line_spacer
 What should we print between entries? More...
 
std::string line_end
 What should we print at the end of each line? More...
 

Detailed Description

Keep track of everything associated with periodically printing data to a file. Maintain a set of functions for calculating the desired measurements at each point in time that they are required. It also handles the formating of the file.

Member Typedef Documentation

using emp::DataFile::fun_t = void(std::ostream &)
protected
using emp::DataFile::time_fun_t = std::function<bool(size_t)>
protected

Constructor & Destructor Documentation

emp::DataFile::DataFile ( const std::string &  in_filename,
const std::string &  b = "",
const std::string &  s = ",",
const std::string &  e = "\n" 
)
inline
emp::DataFile::DataFile ( std::ostream &  in_os,
const std::string &  b = "",
const std::string &  s = ",",
const std::string &  e = "\n" 
)
inline
emp::DataFile::DataFile ( const DataFile )
default
emp::DataFile::DataFile ( DataFile &&  )
default
virtual emp::DataFile::~DataFile ( )
inlinevirtual

Member Function Documentation

size_t emp::DataFile::Add ( const std::function< void(std::ostream &)> &  fun,
const std::string &  key,
const std::string &  desc 
)
inline

If a function takes an ostream, pass in the correct one. Generic function for adding a column to the DataFile. In practice, you probably want to call one of the more specific ones.

template<typename VAL_TYPE , emp::data... MODS>
void emp::DataFile::AddAllStats ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add multiple functions that pull all stats measurements (mean, variance, min, max, skew, and kurtosis) from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
keyand
descwill have the name of the stat appended to the beginning. Note: excludes standard deviation, because it is easily calculated from variance
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddCurrent ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the current value from the DataNode

Parameters
node.Requires that
nodehave the data::Current modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename T >
size_t emp::DataFile::AddFun ( const std::function< T()> &  fun,
const std::string &  key = "",
const std::string &  desc = "" 
)
inline

Add a function that returns a value to be printed to the file.

template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddHistBin ( DataNode< VAL_TYPE, MODS... > &  node,
size_t  bin_id,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the count of the

Parameters
bin_id'th bin of the histogram from
node.Requires that
nodehave the data::Histogram modifier and at least bins. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddInferiority ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the inferiority (mean divided by max) from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddKurtosis ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the kurtosis from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddMax ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the maximum value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddMean ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the mean value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddMin ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the minimum value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddSkew ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the skewness from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddStandardDeviation ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the standard deviation from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename VAL_TYPE , emp::data... MODS>
void emp::DataFile::AddStats ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add multiple functions that pull common stats measurements (mean, variance, min, and max) from the DataNode

Parameters
node.Requires that
nodehave the data::Stats or data::FullStats modifier.
keyand
descwill have the name of the stat appended to the beginning. Note: excludes standard deviation, because it is easily calculated from variance
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddTotal ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the total value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename T >
size_t emp::DataFile::AddVar ( const T &  var,
const std::string &  key = "",
const std::string &  desc = "" 
)
inline

Add a function that always prints the current value of.

Parameters
var.
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddVariance ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inline

Add a function that always pulls the variance from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
const std::string& emp::DataFile::GetFilename ( ) const
inline

Get the filename used for this file.

const std::string& emp::DataFile::GetLineBegin ( ) const
inline

Returns the string that is printed at the beginning of each line.

const std::string& emp::DataFile::GetLineEnd ( ) const
inline

Returns the string that is printed at the end of each line.

const std::string& emp::DataFile::GetSpacer ( ) const
inline

Returns the string that is printed between elements on each line (i.e. the delimeter).

DataFile& emp::DataFile::operator= ( const DataFile )
default
DataFile& emp::DataFile::operator= ( DataFile &&  )
default
virtual void emp::DataFile::PrintHeaderComment ( const std::string &  cstart = "# ")
inlinevirtual

Print a header containing comments describing all of the columns.

Reimplemented in emp::ContainerDataFile< CONTAINER >.

virtual void emp::DataFile::PrintHeaderKeys ( )
inlinevirtual

Print a header containing the name of each column.

Reimplemented in emp::ContainerDataFile< CONTAINER >.

void emp::DataFile::SetLineBegin ( const std::string &  _in)
inline

Print.

Parameters
_inat the beginning of each line.
void emp::DataFile::SetLineEnd ( const std::string &  _in)
inline

Print.

Parameters
_inat the end of each line.
void emp::DataFile::SetSpacer ( const std::string &  _in)
inline

Print.

Parameters
_inbetween elements (i.e. make
_inthe delimeter).
void emp::DataFile::SetTiming ( time_fun_t  fun)
inline

Provide a timing function with a bool(size_t update) signature. The timing function is called with the update, and returns a bool to indicate if files should print this update.

void emp::DataFile::SetTimingOnce ( size_t  print_time)
inline

Setup this file to print only once, at the specified update. Note that this timing function can be replaced at any time, even after being triggered.

void emp::DataFile::SetTimingRange ( size_t  first,
size_t  step,
size_t  last 
)
inline

Setup this file to print only in a specified time range, and a given frequency (step).

void emp::DataFile::SetTimingRepeat ( size_t  step)
inline

Setup this file to print every 'step' updates.

void emp::DataFile::SetupLine ( const std::string &  b,
const std::string &  s,
const std::string &  e 
)
inline

Set line begin character (.

Parameters
b),columndelimeter (
s),andline end character (
e)
virtual void emp::DataFile::Update ( )
inlinevirtual

Run all of the functions and print the results as a new line in the file.

Reimplemented in emp::ContainerDataFile< CONTAINER >.

void emp::DataFile::Update ( size_t  update)
inline

If Update is called with an update number, call the full version of update only if the update value passes the timing function (that is, the timing function returns true).

Member Data Documentation

emp::vector<std::string> emp::DataFile::descs
protected

Full description for each column.

std::string emp::DataFile::filename
protected

Name of the file that we are printing to (if one exists)

FunctionSet<fun_t> emp::DataFile::funs
protected

Set of functions to call, one per column in the file.

emp::vector<std::string> emp::DataFile::keys
protected

Keywords associated with each column.

std::string emp::DataFile::line_begin
protected

What should we print at the start of each line?

std::string emp::DataFile::line_end
protected

What should we print at the end of each line?

std::string emp::DataFile::line_spacer
protected

What should we print between entries?

std::ostream* emp::DataFile::os
protected

Stream to print to.

time_fun_t emp::DataFile::timing_fun
protected

Function to determine updates to print on (default: all)


The documentation for this class was generated from the following file: