pypfilt.pfilter¶
- pypfilt.pfilter.run(ctx, start, end, obs_tables, history=None, save_when=None, save_to=None)¶
Run the particle filter against any number of data streams.
- Parameters
ctx (Context) – The simulation parameters.
start – The start of the simulation period.
end – The (exclusive) end of the simulation period.
obs_tables – A dictionary of observation tables.
history – The (optional) history matrix state from which to resume.
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, which contains the simulation settings, the
History
component, and the summary statistic tables. If no time-steps were performed, this returnsNone
.- Return type
Optional[Result]
- pypfilt.pfilter.step(ctx, snapshot, time_step, step_obs, is_fs)¶
Perform a single time-step for every particle.
- Parameters
ctx (Context) – The simulation parameters.
snapshot (Snapshot) – The current particle states.
time_step (TimeStep) – The time-step details.
step_obs – The list of observations for this time-step.
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
a Boolean array that identifies particles which were resampled.
- Return type
numpy.ndarray
- pypfilt.pfilter.reweight_ensemble(ctx, snapshot, logs)¶
Reweight the particles in each non-reservoir partition of the ensemble.
- pypfilt.pfilter.reweight_partition(ctx, snapshot, logs, partition)¶
Adjust particle weights in response to some observation(s).
- Parameters
- Returns
The effective number of particles (i.e., accounting for weights).
- Return type
float
- pypfilt.pfilter.resample_ensemble(ctx, snapshot, threshold_fraction=None)¶
Resample the particles in each non-reservoir partition of the ensemble.
- class pypfilt.pfilter.Result(settings: ~typing.Dict[str, ~typing.Any], history: ~pypfilt.state.History, tables: ~typing.Dict[str, ~pypfilt.summary.Table], loaded_from_cache: ~typing.Optional[~typing.Any] = None, metadata: ~typing.Dict[~typing.Any, ~typing.Any] = <factory>)¶
The results obtained from running a particle filter pass.
- Parameters
settings (Dict[str, Any]) – The scenario instance settings.
history (History) – The simulation history component.
tables (Dict[str, numpy.ndarray]) – The summary statistic tables.
loaded_from_cache (Optional[Any]) – The time (if any) from which the pass began, starting from a cached simulation state.
metadata (Dict[Any, Any]) – A dictionary that can be used to record additional information about these results.
- class pypfilt.pfilter.Results(estimation: ~typing.Optional[~pypfilt.pfilter.Result] = None, forecasts: ~typing.Dict[~typing.Any, ~pypfilt.pfilter.Result] = <factory>, adaptive_fits: ~typing.Dict[float, ~pypfilt.pfilter.Result] = <factory>, obs: ~typing.List[~typing.Dict[str, ~typing.Any]] = <factory>, metadata: ~typing.Dict[~typing.Any, ~typing.Any] = <factory>)¶
The results obtained from running one or more particle filter passes.
- Parameters
estimation (Optional[Result]) – The results of the estimation pass (if performed).
forecasts (Dict[Any, Result]) – The results of each forecasting pass, indexed by forecasting time.
adaptive_fits (Dict[float, Result]) – The results of the each adaptive fitting pass, indexed by exponent.
obs (List[Dict[str, Any]]) – The available observations.
metadata (Dict[Any, Any]) – A dictionary that can be used to record additional information about these results.
- forecast_times()¶
Return the times for which forecasts were generated.
- adaptive_fit_exponents()¶
Return the exponents for which adaptive fits were generated.