5.4. pypfilt.model¶
All simulation models should derive the following base class:
-
class
pypfilt.model.
Model
¶ The base class for simulation models, which defines the minimal set of methods that are required.
-
init
(ctx, vec)¶ Initialise a matrix of state vectors.
Parameters: - ctx – The simulation context.
- vec – An uninitialised \(P \times S\) matrix of state
vectors, for \(P\) particles and state vectors of length
\(S\) (as defined by
state_size()
). To set, e.g., the first element of each state vector to \(1\), you can use an ellipsis slice:vec[..., 0] = 1
.
-
state_size
()¶ Return the size of the state vector.
-
update
(params, step_date, dt, is_fs, prev, curr)¶ Perform a single time-step.
Parameters: - params – Simulation parameters.
- step_date – The date and time of the current time-step.
- dt – The time-step size (days).
- is_fs – Indicates whether this is a forecasting simulation.
- prev – The state before the time-step.
- curr – The state after the time-step (destructively updated).
-
describe
()¶ Describe each component of the state vector with a tuple of the form
(name, smooth, min, max)
, wherename
is a descriptive name for the variable/parameter,smooth
is a boolean that indicates whether the parameter admits continuous sampling (e.g., post-regularisation), andmin
andmax
define the (inclusive) range of valid values. These tuples must be in the same order as the state vector itself.
-
resume_from_cache
(ctx)¶ Notify the model that a simulation will begin from a saved state.
The model does not need to initialise the state vectors, since these will have been loaded from a cache file, but it may need to update any internal variables (i.e., those not stored in the state vectors).
Note
Models should only implement this method if they need to prepare for the simulation.
-
stat_info
()¶ Describe each statistic that can be calculated by this model as a
(name, stat_fn)
tuple, wherename
is a string that identifies the statistic andstat_fn
is a function that calculates the value of the statistic.Note
Models should only implement this method if they define one or more statistics.
-
is_valid
(hist)¶ Identify particles whose state and parameters can be inspected. By default, this function returns
True
for all particles. Override this function to ensure that inchoate particles are correctly ignored.Note
Models should only implement this method if there are conditions where some particles should be ignored.
-