creativity
v1.3.0
Agent-based model of creativity and piracy
|
Abstract base class for model variables. More...
#include <creativity/data/Variable.hpp>
Classes | |
class | SizeError |
Exception class thrown when attempting to populate a column from a source of an incompatible or unknown size. More... | |
Public Member Functions | |
virtual | ~Variable ()=default |
Virtual destructor. | |
virtual std::string | name () const =0 |
Returns a name for this variable. | |
virtual std::string | nameBracketed (const std::string &bracketL="(", const std::string &bracketR=")") const |
Returns a name for this variable, but with surrounding brackets if this variable needs it–for example, for a multiplication of two variables. More... | |
virtual void | populate (Eigen::Ref< Eigen::VectorXd > column, unsigned int offset=0, unsigned int trim=0) const =0 |
Populates the given column reference with this variable's values. More... | |
Eigen::VectorXd | values (unsigned int rows=0, unsigned int offset=0, unsigned int trim=0) const |
Shortcut wrapper around populate that creates a new column of the given size, calls populate() with it, then returns it. More... | |
virtual unsigned int | size () const =0 |
Returns the intrinsic size of this data. More... | |
Abstract base class for model variables.
Subclasses of this are used for simple variables, multiplications of variables, etc.
|
virtual |
Returns a name for this variable, but with surrounding brackets if this variable needs it–for example, for a multiplication of two variables.
For simple variables and constants, and some non-simple variables such as Logarithm, the brackets are not needed.
bracketL | the left bracket; defaults to a left parenthesis |
bracketR | the right bracket; defaults to a right parenthesis |
Reimplemented in creativity::data::Logarithm, creativity::data::Exponential, creativity::data::SimpleVariable, and creativity::data::ConstantVariable.
|
pure virtual |
Populates the given column reference with this variable's values.
The offset
and trim
parameters allow you to exclude leading or trailing elements from the source data. Note that these elements are not excluded from the populated column: for example, when the data is backed by a column, source.size() - offset - trim
must equal column.size()
.
column | the column to populate |
offset | if specified and non-zero, the number of values to skip from the beginning of the source data (but NOT column ). |
trim | if specified and non-zero, the number of values to leave off the end of the source data (but NOT column ). |
Variable::SizeError | if the given column's size, after adjusting for offset and trim , is not compatible with this variable's size. |
Implemented in creativity::data::Logarithm, creativity::data::Exponential, creativity::data::Power, creativity::data::Division, creativity::data::Addition, creativity::data::Multiplication, creativity::data::SimpleVariable, and creativity::data::ConstantVariable.
|
pure virtual |
Returns the intrinsic size of this data.
If this Variable has no such intrinsic size, such as a ConstantVariable, this throws a SizeError exception. If this variable is an expression with multiple sizes, this method return can return any of the sizes.
Implemented in creativity::data::UnaryExpr, creativity::data::BinaryExpr, creativity::data::SimpleVariable, and creativity::data::ConstantVariable.
Eigen::VectorXd creativity::data::Variable::values | ( | unsigned int | rows = 0 , |
unsigned int | offset = 0 , |
||
unsigned int | trim = 0 |
||
) | const |
Shortcut wrapper around populate that creates a new column of the given size, calls populate() with it, then returns it.
If rows equals 0 (the default if not specified), the size is determined by a call to size(). Note, however, that size() will throw an exception if called on a Variable without an implied size, typically a ConstantVariable.