reno.components.Piecewise#
- class reno.components.Piecewise(equations, conditions)#
Bases:
EquationPartA conditional allowing evaluation of two or more condition equations to determine which output equation to use.
- Mathematically allows something like:
⎧ 1 if t < 4
- f(t) = ⎨ 5 if 4 <= t < 7
⎩ 9 + t if 7 <= t
Methods
__init__(equations, conditions)Create a piecewise ("if-else operation") node.
astype(dtype)Returns a symbolic operation to convert the output of this equation to the specified type.
clip(min, max)Returns a symbolic operation for enforcing the output is between the passed min and max.
equal(obj)Returns a symbolic operation for checking equality with passed object.
eval([t, save, force])Evaluate condition equations/functions until a
Trueis returned, and then evaluate and return the corresponding equation.eval_condition(i, *args, **kwargs)Recursively build nested np.where to handle all conditions.
find_parts_of_type(search_type[, ...])Recursively search for all EquationParts in the tree of the specified type.
Get the size of the additional "data" dimension.
get_type()Get the type of the target output of this equation expression.
is_static()Convenience shortcut for
reno.utils.is_static()- True if this equation doesn't rely on any dynamic values (thus constant), False if it does.latex(**kwargs)Get a latex piecewise string (left bracket with eqs and conditions).
mean([axis])Returns a symbolic operation to find the series-wise mean of the array.
not_equal(obj)Returns a symbolic operation for checking inequality with passed object.
parse(arg_strs, refs)Convert a set of argument strings and references into a piecewise node.
pt(**refs)Get a pytensor graph representing this piece of an equation.
pt_condition(i, refs)Get the pytensor equation starting at the ith condition (using ifelse).
pt_condition_str(i, refs)Get the string for the pytensor code for the ith condition (using ifelse).
pt_str(**refs)Construct a string containing relevant pytensor code for this piece of the equation.
seek_refs([include_ref_types])Recursively find a list of all References immediately underneath this part.
series_max()Returns a symbolic operation to find the series-wise maximum of the array.
series_min()Returns a symbolic operation to find the series-wise minimum of the array.
sum([axis])Returns a symbolic operation to find the series-wise sum of the array.
Attributes
dtypeThe type of each underlying value.
shapeThe size of the data dimension, 1 by default.
timeseriesReturns symbolic operation for getting a timeseries view of the data.
- Parameters:
equations (list[EquationPart])
conditions (list[Callable])
- __annotations__ = {}#
- __module__ = 'reno.components'#
- __repr__()#
Return repr(self).
- Return type:
str
- eval(t=0, save=False, force=False, **kwargs)#
Evaluate condition equations/functions until a
Trueis returned, and then evaluate and return the corresponding equation.- Parameters:
t (int)
save (bool)
force (bool)
kwargs (dict)
- Return type:
int | float | ndarray
- eval_condition(i, *args, **kwargs)#
Recursively build nested np.where to handle all conditions.
Note that this does evaluate all equations and all conditions, there are likely ways to improve efficiency/reduce unnecessary compute (e.g. this used to use np.piecewise, but adding data dimensions significantly increased complexity)
- Parameters:
i (int)
args (list)
kwargs (dict)
- Return type:
bool | ndarray
- get_shape()#
Get the size of the additional “data” dimension.
Prefer using
shapeproperty over directly calling this function.“Broadcasts” any size 1 dims to a larger dim node if present.
- Return type:
int
- get_type()#
Get the type of the target output of this equation expression.
Prefer using
dtypeproperty over directly calling this function.- Return type:
type
- latex(**kwargs)#
Get a latex piecewise string (left bracket with eqs and conditions).
Conditions that aren’t EquationParts can’t really be converted meaningfully, so are represented simply with
\\lambda(t).- Parameters:
kwargs (dict)
- Return type:
str
- static parse(arg_strs, refs)#
Convert a set of argument strings and references into a piecewise node.
Parsing a piecewise has to be handled differently from normal operations because of the collection of associated arguments.
- pt(**refs)#
Get a pytensor graph representing this piece of an equation.
- Parameters:
refs (dict[str, TensorVariable])
- Return type:
TensorVariable
- pt_condition(i, refs)#
Get the pytensor equation starting at the ith condition (using ifelse).
Recursively includes all >i conditions.
- Parameters:
i (int)
refs (dict[str, TensorVariable])
- Return type:
TensorVariable
- pt_condition_str(i, refs)#
Get the string for the pytensor code for the ith condition (using ifelse).
Recursively includes all >i conditions.
- Parameters:
i (int)
refs (dict[str, str])
- Return type:
str
- pt_str(**refs)#
Construct a string containing relevant pytensor code for this piece of the equation. This is useful for “compiling” into pymc code.
- Parameters:
refs (dict[str, str])
- Return type:
str