archimedes.sysid.PEMObjectiveยถ

class archimedes.sysid.PEMObjective(
predictor: KalmanFilterBase,
data: Timeseries,
P0: np.ndarray | None,
x0: np.ndarray | None = None,
)ยถ

Prediction Error Minimization objective function for system identification.

Low-level interface for PEM optimization that provides both residual and cost function evaluations. This class encapsulates the Kalman filter forward pass and automatic differentiation for gradient computation.

This is typically used internally by pem(). For most applications, use the higher-level pem() function directly. This can be useful mainly for constructing custom optimization workflows.

Parameters:
  • predictor (KalmanFilterBase) โ€“ Kalman filter implementing the system model with step(t, x, y, P, args) method.

  • data (Timeseries) โ€“ Input-output data with ts, us, and ys arrays.

  • P0 (array_like) โ€“ Initial state covariance matrix of shape (nx, nx).

  • x0 (array_like, optional) โ€“ Initial state estimate of shape (nx,). If None, the optimization variables should include both initial state and parameters.

Notes

The objective implements the prediction error formulation:

J = (1/N) ฮฃ[k=1 to N] e[k]แต€ e[k]

where e[k] are the Kalman filter innovations (prediction errors).

See also

pem

High-level parameter estimation interface

Methods

forward(x0, params)

Run Kalman filter forward pass and compute prediction errors.

replace(**updates)

Returns a new object replacing the specified fields with new values.

residuals(decision_variables)

Evaluate prediction error residuals for least-squares optimization.

Attributes

x0

predictor

data

P0

__init__(
predictor: KalmanFilterBase,
data: Timeseries,
P0: np.ndarray | None,
x0: np.ndarray | None = None,
) → Noneยถ
forward(x0: np.ndarray, params: Tree) → dictยถ

Run Kalman filter forward pass and compute prediction errors.

Parameters:
  • x0 (array_like) โ€“ Initial state estimate of shape (nx,).

  • params (Tree) โ€“ Model parameters with arbitrary nested structure.

Returns:

Results dictionary with keys:

  • "x_hat" : State estimates of shape (nx, N)

  • "e" : Prediction errors of shape (ny, N)

  • "V" : Average cost function value (scalar)

Return type:

dict

replace(**updates) → Tยถ

Returns a new object replacing the specified fields with new values.

residuals(decision_variables: Tree | tuple[np.ndarray, Tree]) → np.ndarrayยถ

Evaluate prediction error residuals for least-squares optimization.

Parameters:

decision_variables (Tree or tuple[np.ndarray, Tree]) โ€“ Optimization parameters. If x0 is provided during construction, this contains only model parameters. Otherwise, it contains both initial state and parameters as a flattened array.

Returns:

residuals โ€“ Flattened prediction errors of shape (ny * N,) suitable for least-squares optimization methods like Levenberg-Marquardt.

Return type:

ndarray