Skip to content

TMB

TMB is Latte's fast engine. It fits a latent Gaussian model the way the TMB R package does: find the most likely hyperparameters, then describe the uncertainty around them with a single Gaussian. The entry point is tmb.

How it works

Like INLA, TMB approximates the latent field at a fixed value of the hyperparameters θ by a Gaussian (the inner Laplace step). The difference is what it does with the hyperparameters themselves.

Instead of spreading a grid of θ points, TMB finds the mode of p(θy) (the MAP) and fits one Gaussian right there, taking its width from the curvature at the mode (the Hessian of the log posterior). That gives a MAP estimate, a standard error for each hyperparameter, and Gaussian-propagated marginals for the latent field. It is the same information TMB's sdreport returns.

This is cheaper than a grid: one optimisation and one Hessian, with no integration over θ. It is also exact when p(θy) really is Gaussian, which it often nearly is in working (log or logit) space for well-identified models. The cost shows up when that posterior is skewed. A single Gaussian at the mode cannot bend to follow the skew, so the marginals drift. The picture below shows it: with no skew the Gaussian and the true posterior sit on top of each other, and as the skew grows they come apart.

the hyperparameter posterior p(θ|y)
θ = log τ
the resulting latent marginal p(xᵢ|y)
xᵢ
truthTMB (Gaussian at the mode)

Tuning

TMB has far fewer knobs than INLA. The one that matters is how the Hessian is computed.

Hessian computation (diff_strategy)

  • ADStrategy(), the default: ForwardDiff gradients with central differences for the Hessian. Accurate and robust for @latte models with recognised GMRF latents, and for the broad class of custom-logpdf likelihoods.

  • FiniteDiffStrategy(): a plain finite-difference fallback. The narrow case that needs it is a hyperparameter-derived value hoisted into the observation payload by the @latte prelude-lift (φ = exp(log_φ) in the Tweedie tutorial), which the outer Hessian can't keep dual-typed. It is not required for custom likelihoods in general.

julia
tmb(model, y; diff_strategy = FiniteDiffStrategy())

Reference

Latte.tmb Function
julia
tmb(model::LatentGaussianModel, y; diff_strategy=ADStrategy()) -> TMBResult

TMB-style inference: finds the hyperparameter MAP, computes its Gaussian covariance from the Hessian of the negative log posterior, and attaches the inner Laplace approximation for the latent field at that MAP.

Output matches TMB's sdreport shape: MAP θ̂ with standard errors, inner Laplace random-effect posterior means and marginal standard deviations, and a Laplace estimate of log p(y).

Arguments

  • diff_strategy: forwarded to find_hyperparameter_mode and used for the outer-objective Hessian. Default ADStrategy() uses ForwardDiff gradients

    • central differences of those gradients for the Hessian — noise-robust and

    correct on augmented LGMs (where finite-differencing the objective directly can catch catastrophic cancellation from the η-coupling penalty). FiniteDiffStrategy() falls back to FiniteDiff.finite_difference_hessian. The default ADStrategy() works for @latte models with recognized GMRF latents (verified to agree with FiniteDiff on IID / RW1 / RW2 / AR1 / Besag) and for the broad class of custom-logpdf likelihoods. The narrow case that needs FiniteDiffStrategy() is a hyperparameter-derived value hoisted into the observation payload by the @latte prelude-lift (e.g. φ = exp(log_φ) in the Tweedie tutorial): the buried value can't stay Dual-typed through the outer Hessian, so default AD errors. Tracked in tasks/dppl-adapter-outer-ad-closure.org.

source

Limits

  • Skewed hyperparameter posteriors. The Gaussian at the mode is symmetric, so it misses any skew in p(θy). The Validation page shows this plainly: TMB is well calibrated when the hyperparameter posterior is close to Gaussian (the Normal models), and off when it is skewed (count and binary models with little data). When you need the skew, reach for INLA or HMC-Laplace.

  • It reports a mode, not a full marginal. The credible intervals come from the Gaussian standard errors, so they are only as good as that Gaussian assumption.

References

See also

  • INLA: the grid-based engine, for when you need the hyperparameter skew TMB misses.

  • Benchmarks: where TMB's speed pays off.

  • Validation: where its Gaussian assumption holds and where it doesn't.

  • API reference: defining models and working with results.