Observations (n×1)
Model specification (order, trig, ns, arphi, fitar, etc.)
Optionalinit: { arphi?: number[]; s?: number; w?: number[] }Initial guess for parameters (optional; arphi defaults to options.arphi)
Maximum optimizer iterations (default: 200)
Learning rate for Adam (default: 0.05)
Convergence tolerance on relative lik change (default: 1e-6). Requires 5 consecutive steps below this threshold before stopping, to guard against transient near-zero steps during oscillation (e.g. assocScan path).
Computation precision (default: Float64)
Optionalcallbacks: {OptionalonInit?: (theta: Float64Array<ArrayBufferLike> | Float32Array<ArrayBufferLike>) => voidCalled before iteration 0 with the initial theta.
OptionalonIteration?: (Called after each iteration with the updated theta and lik.
OptionalX: ArrayLike<number>[]Optional covariate matrix (n rows × q cols), passed through to dlmFit
OptionalsFixed: ArrayLike<number>Optional per-timestep σ array (length n). When provided, s is fixed and not estimated; only W is optimized.
OptionaladamOpts: anyOptional Adam hyperparameters (b1, b2, eps). Default: b1=0.9, b2=0.9, eps=1e-8. The b2=0.9 default is much faster to adapt than the canonical 0.999 on DLM likelihoods (measured: reaches same loss in ~3× fewer iterations on Nile and ozone benchmarks).
OptionalforceAssocScan: booleanForce use of makeKalmanLossAssoc (associativeScan-based loss) regardless
of device/dtype. Useful for benchmarking the parallel loss path on
CPU/WASM backends where it would not normally be selected.
MLE result with estimated parameters and full DLM fit
Estimate DLM parameters (s, w, and optionally arphi) by maximum likelihood via autodiff.
The entire optimization step —
valueAndGrad(loss)(Kalman filter forward pass + AD backward pass) and optax Adam moment/parameter updates — is wrapped in a singlejit()call, so every iteration runs from compiled code.The parameterization maps unconstrained reals → positive values: s = exp(θ_s), w[i] = exp(θ_{w,i}) AR coefficients (when
options.fitar = true) are optimized directly (unconstrained — not log-transformed, matching MATLAB DLM behavior).When
sFixedis supplied (a per-timestep σ array, e.g. known measurement uncertainties), the observation noise is not estimated — it is treated as a known constant. Only W (and optionally arphi) are optimized. The returnedsfield will beNaNin this case.