OptionaladamAdam hyperparameters. Default: b1=0.9, b2=0.9, eps=1e-8.
OptionalalgorithmAlgorithm selection. Default: auto-select from device/dtype.
OptionalarAR coefficients (initial values). In MATLAB DLM, this is arphi.
OptionalcallbacksCallbacks for monitoring optimization progress.
OptionalonInit?: (theta: FloatArray) => voidCalled before iteration 0 with the initial theta.
OptionalonIteration?: (iter: number, theta: FloatArray, deviance: number) => voidCalled after each iteration with updated theta and deviance.
OptionalcheckpointGradient checkpointing for lax.scan backward pass.
true: √N segment checkpointing (O(√N) memory, ~2× compute).false (default): store all N carries (O(N) memory, fastest backward pass).Only affects the sequential scan loss path; ignored for assocScan.
OptionaldtypeComputation precision. Default: 'f64'.
OptionalfitEstimate AR coefficients via MLE. In MATLAB DLM, this is fitar.
OptionalfullFull seasonal component (ns-1 dummy variables). In MATLAB DLM, this is fullseas.
OptionalharmonicsNumber of trigonometric harmonic pairs. In MATLAB DLM, this is trig.
OptionalinitInitial parameter guess.
OptionallossCustom loss function for MAP estimation or other regularised objectives.
Default: 'ml' (standard Kalman prediction-error likelihood).
When a function is provided it receives:
deviance — Kalman −2·logL (scalar np.Array).params — natural-scale parameter vector (1-D np.Array).meta — DlmParamMeta describing the params layout.params layout: [s?, w₀, …, w_{m-1}, φ₁, …, φ_p]
s and wᵢ are positive std devs (not log-transformed).fitAr) are unconstrained.obsStdFixed is set, the leading s slot is absent.The entire chain — Kalman scan + custom penalty + AD backward pass +
optimizer update — is wrapped in a single jit() call.
Tip: use dlmPrior to create a callback with MATLAB DLM-style Inverse-Gamma priors on variances — no manual coding needed.
const result = await dlmMLE(y, {
order: 1,
loss: (deviance, params, meta) => {
// Split params into [obsStd, processStd] using meta
const parts = np.split(params, [meta.nObs], 0);
const processStd = parts[meta.nObs > 0 ? 1 : 0];
const prior = np.multiply(np.array(0.1), np.sum(np.square(processStd)));
return np.add(deviance, prior);
},
});
OptionallrAdam learning rate. Default: 0.05.
OptionalmaxMaximum optimizer iterations. Default: 200.
OptionalnaturalOptions for the 'natural' optimizer. Ignored when optimizer is 'adam'.
OptionalfdStep?: numberFinite-difference step size for hessian='fd'. Default: 1e-5.
Optionalhessian?: "fd" | "exact"How to compute the Hessian. Default: 'fd'.
'fd': central finite differences of the JIT'd gradient
(2·nParams extra gradient evaluations per step, no extra JIT trace).'exact': exact AD Hessian via jit(hessian(lossFn))
(jacfwd(grad)). More accurate and avoids FD step-size tuning,
but the first call incurs a large JIT compilation overhead
(~20 s for nParams=2 on WASM as of jax-js v0.7.8).
May become competitive as jax-js JIT improves.OptionallambdaGrow?: numberλ grow factor on rejected step. Default: 2.
OptionallambdaInit?: numberInitial λ scale: λ₀ = lambdaInit · max(diag(H)). Default: 0.1.
OptionallambdaShrink?: numberλ shrink factor on accepted step. Default: 0.5.
OptionalobsPer-observation σ array (length n). When provided, obsStd is fixed and not estimated. In MATLAB DLM, this is sFixed.
OptionaloptimizerOptimizer selection. Default: 'natural' for f64, 'adam' for f32.
'adam': optax Adam (first-order, diagonal curvature approximation).'natural': Newton / Fisher scoring (second-order, full Hessian).
Solves (H + λI)⁻¹ g with adaptive Levenberg-Marquardt damping.
Converges in far fewer iterations than Adam but each step costs more.
Best for small parameter spaces (nParams ≤ ~10).
Uses lr as step size (default 1.0 for Newton).OptionalorderPolynomial trend order: 0 (level), 1 (level + slope), 2 (level + slope + acceleration). Default: 1.
OptionalseasonSeasons per cycle (period length). In MATLAB DLM, this is ns. Default: 12.
OptionalsplineSpline mode for order=1: modifies W for integrated random walk.
OptionaltolConvergence tolerance on relative deviance change. Default: 1e-6.
OptionalXCovariate matrix: n rows × q columns.
Options for dlmMLE.