Pomp Class¶
- class pypomp.Pomp(ys: DataFrame, theta: PompParameters, statenames: tuple[str, ...] | list[str], t0: float, rinit: Callable, rproc: Callable, dmeas: Callable | None = None, rmeas: Callable | None = None, par_trans: ParTrans | None = None, nstep: int | None = None, dt: float | None = None, accumvars: tuple[str, ...] | list[str] | None = None, covars: DataFrame | None = None, validate_logic: bool = True, order: str = 'linear')[source]¶
Bases:
PompEstimationMixin,PompAnalysisMixinDefine and fit a partially observed Markov process (POMP) model.
A POMP model describes a time series whose latent state evolves according to a Markov process that is only partially observable through noisy measurements. This class encapsulates the four model components — initial state distribution (
rinit), state transition (rproc), measurement density (dmeas), and measurement simulator (rmeas) — and exposes methods for simulation, particle filtering, iterated filtering, and gradient-based training.Important
The
rinit,rproc,dmeas, andrmeasarguments expect user-defined functions with specific argument names and type hints. ThePompobject raises an error at construction time if these functions do not conform to the specification.rinit: See State Initialization (rinit).
rproc: See State Transition (rproc).
dmeas: See Measurement Density (dmeas).
rmeas: See Measurement Simulator (rmeas).
- Parameters:
ys (pd.DataFrame) – Measurement data frame. The index must contain the observation times as numeric values.
theta (PompParameters) – Initial parameter set(s). Pass a
PompParametersobject with multiple parameter sets to run estimation methods in parallel over multiple starting points.statenames (list of str) – Names of all latent state variables in the process model.
t0 (float) – Initial time for the model, typically just before the first observation.
rinit (callable) – Initial state simulator. See State Initialization (rinit) for the required signature.
rproc (callable) – State transition simulator for a single time step. See State Transition (rproc) for the required signature.
dmeas (callable or None, optional) – Measurement log-density function. Required for particle filtering and iterated filtering. See Measurement Density (dmeas).
rmeas (callable or None, optional) – Measurement simulator. Required for
simulate(). See Measurement Simulator (rmeas).par_trans (ParTrans or None, optional) – Parameter transformation object mapping between the natural parameter space and the estimation space. Defaults to the identity transformation.
covars (pd.DataFrame or None, optional) – Time-varying covariate data frame. The index must contain numeric covariate times. Interpolated to the integration grid at runtime.
nstep (int or None, optional) – Number of Euler integration steps between consecutive observations. Mutually exclusive with
dt.dt (float or None, optional) – Fixed integration step size. Mutually exclusive with
nstep.accumvars (list of str or None, optional) – Names of accumulator state variables (e.g. incidence counters) that are reset to zero at the start of each observation interval.
validate_logic (bool, optional) – Whether to validate model component function signatures and logic at construction time. Defaults to
True.order (str, optional) – Covariate interpolation method:
"linear"(default) or"constant"(left-step).
Examples
Build a minimal SIR-like POMP model:
>>> import pandas as pd >>> import jax >>> import pypomp as pp >>> from pypomp.types import StateDict, ParamDict, TimeFloat, StepSizeFloat, RNGKey, ObservationDict >>> >>> def my_rinit(theta_: ParamDict, t0: TimeFloat, key: RNGKey) -> StateDict: ... return {"S": 990.0, "I": 10.0, "R": 0.0} >>> >>> def my_rproc(X_: StateDict, theta_: ParamDict, t: TimeFloat, dt: StepSizeFloat, key: RNGKey) -> StateDict: ... return X_ # identity placeholder >>> >>> def my_dmeas(Y_: ObservationDict, X_: StateDict, theta_: ParamDict, t: TimeFloat) -> float: ... import jax.numpy as jnp ... return jnp.array(0.0) >>> >>> ys = pd.DataFrame({"cases": [10, 12, 15]}, index=[1.0, 2.0, 3.0]) >>> theta = pp.PompParameters({"beta": 0.5, "gamma": 0.1}) >>> model = pp.Pomp( ... ys=ys, theta=theta, statenames=["S", "I", "R"], t0=0.0, ... rinit=my_rinit, rproc=my_rproc, dmeas=my_dmeas, dt=0.1, ... )
See also
pypomp.panel.PanelPompMulti-unit panel extension of this class.
pypomp.core.parameters.PompParametersParameter container for single-unit models.
Attributes
- Pomp.theta¶
The current parameter set for the model.
- Returns:
The active
PompParametersobject.- Return type:
- Raises:
ValueError – If
thetahas not been set.
- Pomp.rinit: _RInit¶
Simulator for the initial state distribution.
- Pomp.rproc: _RProc¶
Process model simulator handling state transitions between observation times.
- Pomp.par_trans: ParTrans¶
Parameter transformation object mapping between natural and estimation spaces.
- Pomp.accumvars: list[str] | None¶
Names of accumulator state variables that are reset at each observation time.
- Pomp.results_history: ResultsHistory¶
A
ResultsHistoryobject storing the history of results frompfilter(),mif(), andtrain()calls.
- Pomp.fresh_key: Array | None¶
Running a method that accepts a JAX PRNG key will store a fresh, unused key here.
- Pomp.metadata: ModelMetadata¶
Environment and version metadata initialized when this instance was built.
Core Algorithmic Methods
|
Simulate latent states and observations from the POMP model. |
|
Evaluate the log-likelihood via the bootstrap particle filter. |
|
Estimate parameters via the Iterated Filtering 2 (IF2) algorithm. |
|
Optimize parameters via a differentiable particle filter (MOP). |
|
Optimizes model parameters using the DPOP differentiable particle filter and gradient-based methods. |
|
Particle Markov chain Monte Carlo (PMMH) for Bayesian parameter inference. |
|
Approximate Bayesian Computation with a Metropolis-Hastings outer loop. |
Results
|
Return a summary DataFrame for one run from the results history. |
|
Return the full trace of log-likelihoods and parameters over all runs. |
|
Return conditional log-likelihoods from a particle filter run. |
|
Return effective sample sizes from a particle filter run. |
Other Supporting Methods
|
Sample |
Export the model to a lightweight JAX-compatible struct. |
|
|
Keep the top |
|
Return a summary of wall-clock execution times for all runs. |
|
Fit an ARIMA benchmark model and return its log-likelihood. |
|
Fit a Negative Binomial benchmark model and return its log-likelihood. |
|
Assess goodness-of-fit by comparing data probes to simulated probes. |
|
Print a high-level summary of the model and its estimation history. |
Display environment and version metadata for this model instance. |
|
|
Merge multiple |
Visualization
|
Plot parameter and log-likelihood traces from the results history. |
|
Plot simulated trajectories alongside the observed data. |