5.15. pypfilt.pfilter

pypfilt.pfilter.run(ctx, start, end, streams, state=None, save_when=None, save_to=None)

Run the particle filter against any number of data streams.

Parameters:
  • ctx (pypfilt.context.Context) – The simulation parameters.
  • start – The start of the simulation period.
  • end – The (exclusive) end of the simulation period.
  • streams – A list of observation streams.
  • state – A previous simulation state as returned by, e.g., this function.
  • save_when – Times at which to save the particle history matrix.
  • save_to – The filename for saving the particle history matrix.
Returns:

The resulting simulation state: a dictionary that contains the simulation parameters ('params'), the particle history matrix ('hist'), and the summary statistics ('summary').

pypfilt.pfilter.step(ctx, hist, hist_ix, step_num, when, step_obs, max_back, is_fs)

Perform a single time-step for every particle.

Parameters:
  • params – The simulation parameters.
  • hist – The particle history matrix.
  • hist_ix – The index of the current time-step in the history matrix.
  • step_num – The time-step number.
  • when – The current simulation time.
  • step_obs – The list of observations for this time-step.
  • max_back – The number of time-steps into the past when the most recent resampling occurred; must be either a positive integer or None (no limit).
  • is_fs – Indicate whether this is a forecasting simulation (i.e., no observations). For deterministic models it is useful to add some random noise when estimating, to allow identical particles to differ in their behaviour, but this is not desirable when forecasting.
Returns:

True if resampling was performed, otherwise False.

pypfilt.pfilter.reweight(ctx, hist, hist_ix, obs, max_back=None)

Adjust particle weights in response to some observation(s).

Parameters:
  • params – The simulation parameters.
  • hist – The particle history matrix.
  • hist_ix – The index of the current time-step in the history matrix.
  • obs – The observation(s) that have been made.
  • max_back – The number of time-steps into the past when the most recent resampling occurred (i.e., how far back the current particle ordering is guaranteed to persist; default is None, no limit).
Returns:

A tuple; the first element (bool) indicates whether resampling is required, the second element (float) is the effective number of particles (i.e., accounting for weights).