Types¶
Result bundles expose named fields for solver, simulation, and estimator outputs. The public result types are:
SimResultforsimulate(),lsim(),step_response(),impulse_response(), andinitial_response()SampleResultfor a discrete nonlinear model'sstep()method, including sampled integration diagnosticsLyapunovResultforlyap(),dlyap()and controllability/observability GramiansPlaceResultforplace()LQRResultfordare(),care(),lqr(), andlqi()KalmanGainResultforkalman_gain()KalmanResultforkalman()andekf()UKFResultforukf()RTSResultforrts()anduks()MHEResultformhe()PHSStructureDiagnosticsforphs_diagnostics()InnovationDiagnosticsandLikelihoodDiagnosticsfor filter-health helpersSmootherDiagnosticsfor RTS/UKS covariance-reduction health checks
Why Result Bundles Exist¶
The result bundles provide stable field names and remain JAX pytrees:
- they make multi-output solver contracts explicit
- they keep field names stable across tutorials, examples, and compiled code
- they remain pytrees, so downstream JAX code can return or differentiate
through fields such as
LQRResult.Kwithout conversion to ad hoc dicts
Important Fields¶
Some fields are especially worth knowing about:
Simulation, filtering, smoothing and MHE all expose the state trajectory as
.xs and its last state as .final_state. Filtering and smoothing covariances
are .Ps. A single covariance, such as kalman_gain(...).P, remains .P.
An empty trajectory has no final state: accessing .final_state raises
ValueError. Apply vmap to individual solves when working with batches.
Online prediction helpers return FilterPredictionResult with .x and .P;
updates and combined steps return FilterUpdateResult, which also exposes
.innovation. Both include .status and .successful.
Batch filter and smoother bundles expose the same status properties. Their
covariance validation checks symmetry and positive semidefiniteness.
Simulation exposes .state_times aligned with .xs and .output_times
aligned with .ys; .ts aliases .output_times.
LQRResult.closed_loop and KalmanGainResult.closed_loop retain the designed
error/feedback transition matrices. Their .poles properties evaluate
eigenvalues on access, so unused pole diagnostics do not restrict higher-order
derivatives of gain/covariance objectives. Pole objectives follow JAX's
nonsymmetric eigenvalue differentiation limits; higher derivatives of those
eigenvalues are not provided by JAX.
LQRResult.residual_norm: a JAX scalar Riccati residual diagnosticKalmanResult.innovations: the measurement residual sequenceUKFResult.log_likelihood_terms: per-step innovation-form Gaussian log-likelihood termsKalmanGainResult.K: the steady-state measurement-update gainMHEResult.final_state: the terminal state estimate from the optimized windowPHSStructureDiagnostics.power_balance_residual: the local port-Hamiltonian power-balance residualInnovationDiagnostics.mean_nis: the mean normalized innovation squared summarySmootherDiagnostics.min_covariance_reduction: the worst-case smoother covariance-reduction health flag; negative means the smoother increased variance in some direction
Related Pages¶
- Control for
LQRResult - Estimation for the Kalman-family and MHE result bundles
- Systems for structured-system diagnostics
contrax.types
¶
Public result-bundle types.
FilterPredictionResult
¶
Bases: Module
Mean, covariance, and status from one Kalman prediction step.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Array
|
Predicted mean. Shape: |
P |
Array
|
Predicted covariance. Shape: |
solver_status |
Array
|
Input or backend status code. |
status |
Array
|
Status after checking the mean and covariance. |
successful |
Array
|
Whether the prediction passed validation. |
Source code in contrax/_filter_types.py
FilterUpdateResult
¶
Bases: Module
Mean, covariance, innovation, and status from one Kalman update.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Array
|
Updated mean. Shape: |
P |
Array
|
Updated covariance. Shape: |
innovation |
Array
|
Measurement residual. Shape: |
solver_status |
Array
|
Input or backend status code. |
status |
Array
|
Status after checking the mean, covariance, and innovation. |
successful |
Array
|
Whether the update passed validation. |
Source code in contrax/_filter_types.py
InnovationDiagnostics
¶
Bases: Module
Diagnostics derived from an innovation sequence and covariance model.
Source code in contrax/types.py
KalmanGainResult
¶
Bases: Module
Result bundle for steady-state Kalman estimator design.
Attributes:
| Name | Type | Description |
|---|---|---|
K |
Array
|
Steady-state measurement-update gain. Shape: |
P |
Array
|
Steady-state predicted covariance. Shape: |
poles |
Array
|
Estimator error-dynamics eigenvalues. Shape: |
closed_loop |
Array
|
Predicted-error transition matrix A(I-KC). Shape: |
status |
Array
|
Integer Riccati design status. Shape: scalar. |
residual_norm |
Array
|
Maximum absolute dual Riccati residual. |
num_steps |
Array
|
Iterations used by the dual Riccati design. |
successful |
Array
|
Whether the validated Riccati design succeeded. |
Source code in contrax/types.py
KalmanResult
¶
Bases: Module
Result bundle for Kalman filter and EKF passes.
Attributes:
| Name | Type | Description |
|---|---|---|
xs |
Array
|
Filtered state estimates over time. Shape: |
Ps |
Array
|
Filtered covariance matrices over time. Shape: |
innovations |
Array
|
Measurement residual sequence. Shape: |
has_measurement |
Array
|
Availability mask. Shape: |
final_state |
Array
|
Last filtered state; raises ValueError for an empty pass. |
solver_status |
Array
|
Input or backend status, zero on success. |
status |
Array
|
Input/backend failure or invalid numerical output status. |
successful |
Array
|
Whether finite means and valid covariances were returned. |
Source code in contrax/_filter_types.py
LQRResult
¶
Bases: Module
Result bundle for LQR, DARE, and CARE computations.
Attributes:
| Name | Type | Description |
|---|---|---|
K |
Array
|
Optimal state-feedback gain. Shape: |
S |
Array
|
Riccati solution matrix. Shape: |
poles |
Array
|
Closed-loop eigenvalues of the designed system. Shape: |
closed_loop |
Array
|
Closed-loop state matrix A-BK. Shape: |
residual_norm |
Array
|
Maximum absolute Riccati residual. Shape: scalar. |
status |
Array
|
Integer |
num_steps |
Array
|
Doubling iterations or accepted CARE refinement corrections. |
successful |
Array
|
Whether the residual, cost and stability checks passed. |
Source code in contrax/types.py
LikelihoodDiagnostics
¶
Bases: Module
Summary diagnostics for innovation-form log-likelihood terms.
Source code in contrax/types.py
LyapunovResult
¶
Bases: Module
Solution and diagnostics for a Lyapunov equation or LTI Gramian.
Attributes:
| Name | Type | Description |
|---|---|---|
X |
Array
|
Equation solution. Shape: |
status |
Array
|
Integer |
num_steps |
Array
|
Doubling iterations, or the term count for a finite discrete Gramian. Zero for an explicit dense solve or finite continuous integral. |
residual_norm |
Array
|
Frobenius norm of the equation residual. |
successful |
Array
|
Whether the validated equation residual meets tolerance. |
Source code in contrax/types.py
MHEResult
¶
Bases: Module
Result bundle for a fixed-window moving-horizon-estimation solve.
Attributes:
| Name | Type | Description |
|---|---|---|
xs |
Array
|
Estimated state trajectory over the window. Shape: |
final_state |
Array
|
Terminal state estimate, equal to |
final_cost |
Array
|
Final MHE objective value. Shape: scalar. |
solver_converged |
Array
|
Whether the underlying optimizer reported convergence. Shape: scalar bool. False means convergence was not established; inspect status, cost reduction and gradient_norm before use. |
status |
Array
|
Integer |
num_steps |
Array
|
Optimizer iterations attempted. |
gradient_norm |
Array
|
Objective gradient norm at the returned trajectory. |
initial_cost |
Array
|
Objective value at the initial trajectory guess. |
successful |
Array
|
Whether convergence succeeded with a finite trajectory/cost. |
Source code in contrax/types.py
PHSStructureDiagnostics
¶
Bases: Module
Structure-oriented diagnostics for a port-Hamiltonian state.
Attributes:
| Name | Type | Description |
|---|---|---|
skew_symmetry_error |
Array
|
Maximum absolute residual in |
dissipation_symmetry_error |
Array
|
Maximum absolute residual in |
min_dissipation_eigenvalue |
Array
|
Smallest eigenvalue of the symmetrized dissipation matrix. Shape: scalar. |
storage_rate |
Array
|
Instantaneous Hamiltonian rate |
dissipation_power |
Array
|
Dissipated power |
supplied_power |
Array
|
Port power |
power_balance_residual |
Array
|
Residual in the standard PHS energy balance
|
Source code in contrax/types.py
PlaceResult
¶
Bases: Module
Result bundle for pole placement.
Attributes:
| Name | Type | Description |
|---|---|---|
K |
Array
|
State-feedback gain. Shape: |
poles |
Array
|
Achieved closed-loop eigenvalues. Shape: |
status |
Array
|
JAX scalar SolverStatus code. |
successful |
Array
|
Whether assignment, conditioning and convergence passed. |
assignment_error |
Array
|
Smallest maximum matching distance to requested poles. |
controllability_condition |
Array
|
Condition estimate of the controllability matrix. |
eigenvector_condition |
Array
|
Condition estimate of the achieved eigenvector basis. |
num_steps |
Array
|
Update sweeps performed; zero for direct or fallback solves. |
relative_improvement |
Array
|
Last relative determinant-improvement measure. |
used_fallback |
Array
|
Whether K came from the bounded Ackermann fallback. |
method |
str
|
Selected KNV0, YT or ackermann method, as static metadata. |
Source code in contrax/types.py
RTSResult
¶
Bases: Module
Result bundle for Rauch-Tung-Striebel smoothing.
Attributes:
| Name | Type | Description |
|---|---|---|
xs |
Array
|
Smoothed state estimates over time. Shape: |
Ps |
Array
|
Smoothed covariance matrices over time. Shape: |
final_state |
Array
|
Last smoothed state; raises ValueError for an empty pass. |
solver_status |
Array
|
Forward-pass or process-noise status, zero on success. |
status |
Array
|
Forward failure or invalid smoothed mean/covariance status. |
successful |
Array
|
Whether the forward and smoothing passes succeeded. |
Source code in contrax/types.py
SampleResult
¶
Bases: Module
One discrete transition, including numerical integration diagnostics.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Array
|
Terminal state. Shape: |
status |
Array
|
Integer |
num_steps |
Array
|
Integration steps, or one for an ordinary discrete model. |
successful |
Array
|
Whether the transition finished with finite output. |
Source code in contrax/types.py
SimResult
¶
Bases: Module
Result bundle for simulation functions.
Attributes:
| Name | Type | Description |
|---|---|---|
ts |
Array
|
Output sample times, also exposed as output_times. Shape: |
state_times |
Array
|
Times aligned with xs. Shape: |
xs |
Array
|
State trajectory including the initial state. Shape: |
ys |
Array
|
Output trajectory. Shape: |
solver_status |
Array
|
Backend status code; zero when no backend failure occurred. |
status |
Array
|
Backend failure code, or numerical_failure for nonfinite output. |
successful |
Array
|
Whether the backend and output finiteness checks succeeded. |
num_steps |
Array
|
State advances or adaptive integration steps performed. |
final_state |
Array
|
Last state, shape |
Source code in contrax/types.py
SmootherDiagnostics
¶
Bases: Module
Health diagnostics for RTS/UKS smoother output.
A well-behaved smoother strictly reduces uncertainty: P_smooth ≤ P_filtered
in the positive-semidefinite sense. These diagnostics surface numerical
breakdown before it affects downstream analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
covariance_reduction |
Array
|
Per-step minimum eigenvalue of
|
min_covariance_reduction |
Array
|
Scalar minimum over time. The primary health flag: negative means the smoother violated its own uncertainty-reduction guarantee. |
state_corrections |
Array
|
Per-step L2 norm of |
max_state_correction |
Array
|
Scalar maximum correction over time. |
smoothed_min_eigenvalue |
Array
|
Per-step minimum eigenvalue of |
nonfinite |
Array
|
True if any smoothed mean or covariance contains NaN/Inf. |
Source code in contrax/types.py
UKFResult
¶
Bases: Module
Result bundle for unscented Kalman filtering.
Attributes:
| Name | Type | Description |
|---|---|---|
xs |
Array
|
Filtered state estimates over time. Shape: |
Ps |
Array
|
Filtered covariance matrices over time. Shape: |
final_state |
Array
|
Last filtered state; raises ValueError for an empty pass. |
innovations |
Array
|
Measurement residual sequence. Shape: |
has_measurement |
Array
|
Availability mask. Shape: |
predicted_measurements |
Array
|
Predicted measurement means before each update.
Shape: |
innovation_covariances |
Array
|
Innovation covariance matrices for each update.
Shape: |
log_likelihood_terms |
Array
|
Per-step Gaussian innovation log-likelihood
terms. Shape: |
predicted_state_means |
Array
|
One-step predicted state means after each
update. Shape: |
predicted_state_covariances |
Array
|
One-step predicted state covariances after
each update. Shape: |
transition_cross_covariances |
Array
|
Cross-covariances between filtered
states and one-step predictions. Shape: |
solver_status |
Array
|
Input or backend status, zero on success. |
status |
Array
|
Input/backend failure or invalid output/prediction status. |
successful |
Array
|
Whether the validated filtering/prediction pass succeeded. |