|
creativity
v1.3.0
Agent-based model of creativity and piracy
|
Class to store a equation. More...
#include <creativity/data/Equation.hpp>
Classes | |
| class | Proxy |
| Proxy object returned by << that allows more variables to be appended with +. More... | |
Public Member Functions | |
| Equation ()=delete | |
| Not default constructible. | |
| Equation (Equation &&move)=default | |
| Move constructor. | |
| Equation (const Equation ©)=default | |
| Copy constructor. | |
| Equation (const std::shared_ptr< const Variable > &y) | |
| Creates an equation with the given dependent variable. | |
| Proxy | operator% (const std::shared_ptr< const Variable > &var) |
| Adds a variable (lvalue version). More... | |
| Proxy | operator% (double c) |
% d for double d is equivalent to % ConstantVariable(d). | |
| Equation | operator+ (const std::shared_ptr< const Variable > &var) const & |
| The addition operator duplicates the called-upon Equation an adds a new term to the duplicate, then returns it. | |
| Equation | operator+ (const std::shared_ptr< const Variable > &var) && |
| The addition operator called on a temporary adds a new term to the temporary, then returns it. | |
| Equation | operator+ (double c) const & |
| Adding a double constant (typically 0 or 1) converts the constant to a ConstantVariable. | |
| Equation | operator+ (double c) && |
| Adding a double constant (typically 0 or 1) converts the constant to a ConstantVariable. | |
| std::shared_ptr< const Variable > | depVar () const |
| Accesses the dependent variable. | |
| unsigned int | numVars () const |
| Returns the number of independent variables. | |
| bool | hasConstant () const |
| Returns true if the model includes a constant, false if it does not. More... | |
| std::vector< std::string > | names () const |
| Returns the names of the variables in the same order they will be returned by begin()/end(). | |
| std::list< std::shared_ptr< const Variable > >::const_iterator | begin () const |
| Const access to the beginning iterator of independent variables. More... | |
| std::list< std::shared_ptr< const Variable > >::const_iterator | end () const |
| Const access to the past-the-end iterator of independent variables. | |
Protected Member Functions | |
| void | addVar (const std::shared_ptr< const Variable > &var) |
| Internal method to add a variable to the model. | |
Protected Attributes | |
| std::shared_ptr< const Variable > | dep_var_ |
| The dependent variable. | |
| std::list< std::shared_ptr< const Variable > > | indep_vars_ {{ConstantVariable::create()}} |
| The independent variables; the first is always a ConstantVariable. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Equation &eq) |
Overloaded so that an Equation can be sent to an output stream, resulting in output such as y ~ const + x1 + x2. | |
Class to store a equation.
The class is constructed with the dependent variable, then has an equation added to it using the % operator. For example:
// Constructing a single equation Equation model(depvar); model % 1 + var1 + var2; model % var3; // Building on another equation: Equation model2 = model1 + var4; // rvalue construction Equation(depvar) + 1 + var1 + var2;
NB: The left-shift operator (<<) would make more logical sense than %, but has the unfortunately pitfall of being of lower precedence than +, which means, in the above example, the 1+var1+var2 term would construct a single, compound variable rather than adding 3 separate variables to the equation.
| std::list<std::shared_ptr<const Variable> >::const_iterator creativity::data::Equation::begin | ( | ) | const |
Const access to the beginning iterator of independent variables.
If an explicit constant of 0 has been added to the model, this will skip the constant; otherwise the constant will be the first element.
| bool creativity::data::Equation::hasConstant | ( | ) | const |
Adds a variable (lvalue version).
If the value is a ConstantVariable with value 0, the constant is removed from the equation; other ConstantVariable values replace (or re-add, if previously removed) the constant. Other types of variables are added to the equation.
1.8.12