relentless.model.DependentVariable#
- class relentless.model.DependentVariable(*vardicts, **kwvars)#
Dependent quantity.
A dependent variable is composed from other variables. This is an abstract base class for any such variable. In addition to the
valueproperty of theVariable, aDependentVariablemust also define \(compute\) andcompute_derivative()methods that define how it (and its partial derivatives with respect to its dependencies) are computed.The names of the dependencies of the variable are automatically deduced by the base constructor using dictionary keys and keyword arguments and assigned as attributes of the object. For example:
class NewVariable(relentless.variable.DependentVariable): def __init__(self, a, b): super().__init__({'a': a}, b=b)
will create a
NewVariablewith two dependent attributesaandb.Dependencies are typically other
Variableobjects, but they can also be set to scalar values. In these case, the scalar is converted to anIndependentVariablefirst.- Parameters:
vardicts (dict) – Dependencies as entries in an arbitrary number of dictionaries.
kwvars (kwargs) – Dependencies as an arbitrary number of keyword arguments.
Methods
compute()Implementation of the value.
compute_derivative(param)Implementation of the derivative.
derivative(var)Calculate derivative with respect to a
Variable.Attributes
countnamesNames of parameters
Value of the variable.
- abstract compute()#
Implementation of the value.
This method should implement calculation of the variable from the parameter keywords. The parameters will be passed as keyword arguments.
- abstract compute_derivative(param)#
Implementation of the derivative.
This method should implement the partial derivative with respect to the named dependency
paramgiven the current value of this variable. The parameters will be passed as keyword arguments.- Parameters:
param (str) – Name of the dependency.
- derivative(var)#
Calculate derivative with respect to a
Variable.The derivative is evaluated using the
VariableGraph. Any values of the graph that are needed will be updated.
- property value#
Value of the variable.
The variable will be evaluated using the
VariableGraphif it needs to be recomputed.- Type: