Qu

particle_filter_init

Builtin index · Statistics & ML

result = particle_filter_init(x0, n, [spread=1.0], [seed=])

Input: x0, n, spread, seed · Output: result

What it is

Generic particle filter state: x0 a length-D centre vector, n (integer) the particle count scattered around it with spread spread (a number, default 1.0), and an optional integer seed=.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = particle_filter_init(x0, n, [spread=1.0], [seed=])
x0 vector or numbernot documented yet
n vector or numbernot documented yet
spread vector or number, optional (default 1.0)not documented yet
seed vector or number, optionalnot documented yet
result Record or vector
Returns a kind="particle_filter" state Record with (n, D) particles and a length-n uniform weights vector; you supply the transition and likelihood functions by name on predict/update.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

process(p) := p + 0.05*randn()                       # process_fn injects its

                                                        # own noise, like monte_carlo

likelihood(p, z) := exp(-(p[0]-z[0])^2 / (2*0.25))    # Gaussian likelihood, sigma=0.5


pf = particle_filter_init([0], 200, spread=2.0, seed=1)   # 200 particles around x0=0

for i = 1 to 10
    pf = pf.predict("process")
    pf = pf.update("likelihood", [2])    # repeatedly measuring z=2

end for
est = pf.estimate()   # weighted-mean point estimate, converges toward 2

from numerics-dsp

How it works

The shared predict/update/estimate dispatch for this whole family (linear Kalman, EKF, UKF, particle filter) lives with the rest of the "model protocol" near model_predict/ model_score, and is reached through the "predict"/ "update"/"estimate" arms below — callable as state.predict(...) / state.update(...) / state.estimate() via the existing recv.method(args) sugar, not as a family of separately-named kalman_predict/ekf_update/... builtins. A particle filter (sequential Monte Carlo): unlike the linear Kalman filter above, the process and observation models can be arbitrary nonlinear/non-Gaussian user-defined Qu functions — the same "function by name" convention minimize/curve_fit already use, since a particle filter has no closed form to fall back to. Model kind "particle_filter", fields particles (an n x d matrix, one particle per row) and weights (length n, sums to 1). The purely numerical parts (systematic resampling, effective sample size) live in qu_core::estimation; this glue only calls back into the interpreter for the two problem-specific steps. particle_filter_init(x0, n, [spread=1.0], [seed=]) — scatters n particles around the initial estimate x0 with Gaussian noise (std spread per dimension), uniform weights 1/n.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.