Invntr
Source

All instruments

kalman_filter

Linear Kalman filter for a small state-space model x[k] = F x[k-1] + w (cov Q), z[k] = H x[k] + v (cov R): filtered states and covariance (Joseph form), innovation statistics with the NIS χ-square consistency band, log-likelihood, the steady-state gain and covariance (Riccati recursion to its fixed point), and the RMS error against a truth track when given.

Measurements inline (z) or from a csv; a null step is predicted, not updated.

States carry the model's own units (declared 1).

Field
Dynamics and control
Version
0.1.0
Runs as
Compiled (Rust)
Typical run
0.05 s

Compiled from source: run sh packs/install.sh once before admitting it.

Known answers it must pass

Admission replaykalman_filter 0.1.0 · files 474bcdb8aac5…0b5e
  1. r0001scalar random walk q=1, r=2: steady prior P = (q + √(q² + 4qr))/2 = 2, gain P/(P+r) = 0.5, posterior P r/(P+r) = 1 (closed-form Riccati fixed point, rel 10⁻⁶)passed

    steady_converged= truetruelockedexact match
    steady_prior_cov.0.0= 2, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    steady_gain.0.0= 0.5, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    steady_post_cov.0.0= 1, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
  2. r0002scalar random walk q=r=1: steady prior P = (1 + √5)/2 = golden ratio 1.6180339887, gain = 1/φ = 0.6180339887 (closed-form Riccati fixed point, rel 10⁻⁶)passed

    steady_prior_cov.0.0= 1.618034, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    steady_gain.0.0= 0.618034, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
  3. r0003constant state, q=0, diffuse prior, r=4, z=[1,2,3,4,10]: estimate = running mean 4, P_n = r/n = 0.8; truth 4 gives RMS of running means (-3,-2.5,-2,-1.5,0) = √(4.3) (exact; rel 10⁻⁶ covers the 10⁹ prior's ~10⁻⁹ bias)passed

    x_final.0= 4, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    P_final.0.0= 0.8, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    rms_error.0= 2.073644, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    steady_converged= falsefalselockedexact match
  4. r0004noise-free constant-velocity target z = 3 + 2k (k=1..10), F=[[1,1],[0,1]], q=0, r=1, diffuse prior: velocity 2 and position 23 exactly; covariance = least-squares line fit: var v = r/Sxx = 1/82.5, var x10 = r(1/N + (N-tbar)²/Sxx) = 0.345454, cov = 4.5/82.5 (exact; rel 10⁻⁶)passed

    x_final.0= 23, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    x_final.1= 2, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    P_final.1.1= 0.012121, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    P_final.0.0= 0.345455, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    P_final.0.1= 0.054545, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
  5. r0005α-β steady state (Kalata 1984; Bar-Shalom, Li, Kirubarajan 2001, sec. 6.5): white-acceleration CV model, T=1, tracking index λ = sigma_a T²/sigma_z = 1 → α = 0.75, β = 0.5, gain [α, β/T], prior var x = α r/(1-α) = 3 (closed form; rel 10⁻⁶)passed

    steady_converged= truetruelockedexact match
    steady_gain.0.0= 0.75, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    steady_gain.1.0= 0.5, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    steady_prior_cov.0.0= 3, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
  6. r0006two hand-worked scalar steps (F=H=Q=R=P₀=1, x₀=0, z=[3,6]): S=3, v=3, NIS 3; S=8/3, v=4, NIS 6 → x=4.5, P=5/8, mean NIS 4.5, log-lik -(2 ln 2π + ln 3 + ln 8/3 + 9)/2; 2-dof χ-square band from the closed form F⁻¹(p) = -2 ln(1-p): [-ln 0.975, -ln 0.025] (exact; rel 10⁻⁶)passed

    x_final.0= 4.5, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    P_final.0.0= 0.625, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    nis_mean4.5 ± 4.5 × 10⁻⁶4.5lockedunder 0.01 % of the tolerance used
    innovation_mean.0= 3.5, within 1.000000 × 10⁻⁶ relativereading not recorded on this page
    log_likelihood-7.3776 ± 7.4 × 10⁻⁶-7.3776lockedunder 0.01 % of the tolerance used
    nis_band_lo0.0253178 ± 2.5 × 10⁻⁸0.0253178lockedunder 0.01 % of the tolerance used
    nis_band_hi3.68888 ± 3.7 × 10⁻⁶3.68888lockedunder 0.01 % of the tolerance used
    consistent= falsefalselockedexact match
6 of 6 cases passed · sandbox macos-seatbeltrecorded from the kernel in a fresh lab

Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.

Inputs

NameUnitDefaultMeaning
F1State transition matrix, n x n (1 to 12 states), as a list of rows, e.g. [[1, 1], [0, 1]] for constant velocity with a step of 1. Model units.
H1Measurement matrix, m x n (1 to 12 measurements), e.g. [[1, 0]] to measure position only.
Q1Process noise covariance, n x n, symmetric, variances ≥ 0. Left out: zero (a deterministic state).
R1Measurement noise covariance, m x m, symmetric; positive variances keep the gain defined.
P01Prior covariance of x₀, n x n. Left out: a diffuse prior, diffuse_variance on every state.
x01Prior state, n numbers. Left out: zeros (harmless with the diffuse prior).
z1Measurements, one entry per step: a list of m numbers (a bare number when m = 1), or null for a step without a measurement. Leave out z and csv to get the steady state only.
csvMeasurements from a csv with a header row instead of z: columns z (m = 1) or z₁..zm, optional truth columns x1_true..xn_true. Empty cell = no measurement.
z_columnscsv column names holding the m measurements, in the order of the rows of H.
truth_columnscsv column names holding the true states, in state order ("" for a state without truth).
truth1True states inline, one list of n numbers per step (null where unknown); gives the RMS error of the estimates.
diffuse_variance11000000000.0Prior variance on every state when P₀ is left out; far above anything the states can take.
predict_firsttruetrue: x₀, P₀ are at step 0 and the first measurement is at step 1 (predict, then update); false: x₀, P₀ are at the first measurement.
confidence10.95Two-sided probability of the NIS χ-square consistency band.

Readings

NameUnitMeaning
n_states1
n_measurements1
n_steps1
n_updates1
prior"given" or "diffuse"
x_final1Filtered state after the last step (model units).
P_final1Its covariance.
sigma_final1Square roots of the diagonal of P_final.
gain_final1Kalman gain of the last update, n x m.
innovation_mean1
innovation_rms1
innovation_lag1_autocorrelation1Near 0 for a well-tuned filter (white innovations).
nis_mean1Mean normalised innovation squared v' S⁻¹ v; expected value m.
nis_expected1
nis_band_lo1Lower edge of the χ-square band for the mean NIS (dof = updates x m), divided by the number of updates.
nis_band_hi1
consistenttrue when the mean NIS lies inside its band.
log_likelihood1Gaussian log-likelihood of the innovations (nats).
steady_convergedWhether the Riccati recursion reached a fixed point (relative change ≤ 10⁻¹³).
steady_iterations1
steady_gain1Steady-state Kalman gain, n x m.
steady_prior_cov1Steady-state predicted covariance (Riccati fixed point).
steady_post_cov1Steady-state updated covariance.
steady_post_sigma1
rms_error1RMS of estimate - truth per state, over the steps with truth.
rms_measurement_error1RMS of z - H truth per measurement (the raw sensor error), for comparison.
states
warnings

Try the call

Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.

Terminal
MCP call