kalman_init
Builtin index · Statistics & ML
result = kalman_init(x0, P0)
Input: x0, P0 · Output: result
What it is
Initial linear-Kalman state: x0 a length-D initial state estimate vector, P0 a (D, D) initial covariance matrix.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = kalman_init(x0, P0) | x0 vector or matrixnot documented yetP0 vector or matrixnot documented yet | x —length-DP —(D, D) | Returns a kind="kalman" state Record with fields x (length-D) and P ((D, D)). No control input. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
state = kalman_init([0], [1]) # initial estimate x0, covariance P0
state = state.predict([1], [0]) # time update: F, Q
state = state.update([1], [2], [1]) # measurement update: H, z, R
print("estimate {state.x}, covariance {state.P}")
estimate [1], covariance [0.5]
from specialized
s0 = kalman_init([0.0, 0.0], [1.0, 0, 0, 1.0] as matrix(2, 2))
F = [1, 0, 1, 1] as matrix(2, 2)
Q = [0.01, 0, 0, 0.01] as matrix(2, 2)
s1 = s0.predict(F, Q)
print("filter .predict returns a new state Record; its x field: {round(s1.x, 3)}")
filter .predict returns a new state Record; its x field: [0, 0]
from statistics-ml
s = kalman_init([0], [10]) # 1-D state, initial uncertainty 10
for i = 1 to 8
s = s.predict([1], [0.01]) # static state: F=1, small process noise Q
s = s.update([1], [2], [1]) # repeatedly measuring z=2, H=1, R=1
end for
print("x = {s.x}, P = {s.P}") # x converges toward 2, P shrinks as evidence accumulates
x = [1.977787], P = [0.144572]
from numerics-dsp
s = kalman_init([2], [10])
for i = 1 to 10
s = s.predict("proc", [0.001], method="ukf")
s = s.update("obs", [9], [0.5], method="ukf")
end for
print("x = {s.x}") # converges toward 3, same as the EKF version above
x = [2.994821]
from numerics-dsp
How it works
The estimation-theory family: a linear Kalman filter, built on the same Value::Model handle as the fit/predict/score protocol (kind "kalman", fields x/P) — a script threads the returned state through successive kalman_predict/ kalman_update calls rather than mutating anything in place, matching this whole family's "return a new value" convention. No control input (B*u) in this first cut — flagged in BACKLOG.md, not silently assumed away. kalman_init(x0, P0) — the initial state estimate and its covariance.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.