patterns

patterns

Classes that support introducing ‘pre-defined’ spatiotemporal profiles as parameters. These patterns can be based on a callable or on data.

Classes

Name Description
Pattern Base class for evaluating a function as a function of an independent
StateVariable This class is identical to Results, but named to something more generic,

Pattern

patterns.Pattern(
    equation,
    pattern_name=None,
    name=None,
    sim=None,
    module=None,
    debug=False,
    **kwargs,
)

Base class for evaluating a function as a function of an independent variable like age or time, or ‘agent-space’. Based on starsim’s Distribution class can be expanded in functionality.

Parameters

Name Type Description Default
equation str required; a simple string the defines the pattern as a function of var required
pattern_name str the name for this class of pattern (e.g. “temporal”) None
name str the name for this particular pattern (e.g. “seasonal_modulation_exposure”) None
sim Sim usually determined on initialization; the sim to use as input to callable parameters None
module Module usually determined on initialization; the module to use as input to callable parameters None
kwargs dict parameters of the pattern {}

Examples:: pattern = typ.Pattern(“a + var * b”, pars={‘a’:2, ‘b’: 0}) res = pattern(var)

Methods

Name Description
disp Return full display of object
evaluate Generate a discretized representation of the equation for the domain
generate_data NOTE: The variable name of the actual independent variable
init Calculate the starting seed and create the RNG
link_module Shortcut for linking the module
link_sim Shortcut for linking the sim, only overwriting an existing one if overwrite=True
plot Plot the pattern
set Set (change) the equation of this pattern, or one or more of its
show_state Show the state of the object
disp
patterns.Pattern.disp()

Return full display of object

evaluate
patterns.Pattern.evaluate(var)

Generate a discretized representation of the equation for the domain represented by var.

The argument var can represent time, or age. It can be be a single number, a numpy.ndarray or pandas series???

generate_data
patterns.Pattern.generate_data(vmin=0, vmax=128, step=None)

NOTE: The variable name of the actual independent variable in the equation expression should be named var

init
patterns.Pattern.init(trace=None, module=None, sim=None, force=False)

Calculate the starting seed and create the RNG

plot
patterns.Pattern.plot(data_kw=None, fig_kw=None, var_name=None)

Plot the pattern

set
patterns.Pattern.set(*args, equation=None, **kwargs)

Set (change) the equation of this pattern, or one or more of its parameters

show_state
patterns.Pattern.show_state(output=False)

Show the state of the object

StateVariable

patterns.StateVariable()

This class is identical to Results, but named to something more generic, so it can be used in different parts of the code and still make sense from a code-readability perspective. The concept of Results does not necessarily align with the internal-state of a model. A results array may have outputs that are a transformed version of the internal ‘state variables’ and as such ideally we don’t want them to be used directly. A Results array can also map one-to-one to one of the internal state variables, but this is not always guaranteed.

This is a structure that holds an internal state of our system (ie, module) prior to any transformations for output.