creativity  v1.3.0
Agent-based model of creativity and piracy
Classes | Public Member Functions | List of all members
creativity::data::Variable Class Referenceabstract

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...
 

Detailed Description

Abstract base class for model variables.

Subclasses of this are used for simple variables, multiplications of variables, etc.

Member Function Documentation

§ nameBracketed()

virtual std::string creativity::data::Variable::nameBracketed ( const std::string &  bracketL = "(",
const std::string &  bracketR = ")" 
) const
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.

Parameters
bracketLthe left bracket; defaults to a left parenthesis
bracketRthe right bracket; defaults to a right parenthesis

Reimplemented in creativity::data::Logarithm, creativity::data::Exponential, creativity::data::SimpleVariable, and creativity::data::ConstantVariable.

§ populate()

virtual void creativity::data::Variable::populate ( Eigen::Ref< Eigen::VectorXd >  column,
unsigned int  offset = 0,
unsigned int  trim = 0 
) const
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().

Parameters
columnthe column to populate
offsetif specified and non-zero, the number of values to skip from the beginning of the source data (but NOT column).
trimif specified and non-zero, the number of values to leave off the end of the source data (but NOT column).
Exceptions
Variable::SizeErrorif 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.

§ size()

virtual unsigned int creativity::data::Variable::size ( ) const
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.

§ values()

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.

Inheritance diagram for creativity::data::Variable:
[legend]
Collaboration diagram for creativity::data::Variable:
[legend]

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