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
Instead of spreading a grid of sdreport returns.
This is cheaper than a grid: one optimisation and one Hessian, with no integration over
p(θ|y)p(xᵢ|y)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@lattemodels with recognised GMRF latents, and for the broad class of custom-logpdflikelihoods.FiniteDiffStrategy(): a plain finite-difference fallback. The narrow case that needs it is a hyperparameter-derived value hoisted into the observation payload by the@latteprelude-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.
tmb(model, y; diff_strategy = FiniteDiffStrategy())Reference
Latte.tmb Function
tmb(model::LatentGaussianModel, y; diff_strategy=ADStrategy()) -> TMBResultTMB-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 tofind_hyperparameter_modeand used for the outer-objective Hessian. DefaultADStrategy()usesForwardDiffgradients- 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 toFiniteDiff.finite_difference_hessian. The defaultADStrategy()works for@lattemodels with recognized GMRF latents (verified to agree with FiniteDiff on IID / RW1 / RW2 / AR1 / Besag) and for the broad class of custom-logpdflikelihoods. The narrow case that needsFiniteDiffStrategy()is a hyperparameter-derived value hoisted into the observation payload by the@latteprelude-lift (e.g.φ = exp(log_φ)in the Tweedie tutorial): the buried value can't stayDual-typed through the outer Hessian, so default AD errors. Tracked intasks/dppl-adapter-outer-ad-closure.org.
Limits
Skewed hyperparameter posteriors. The Gaussian at the mode is symmetric, so it misses any skew in
. 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
The TMB R package: fast Laplace approximation of the marginal likelihood for latent-variable models, with automatic differentiation for the gradients and Hessians.
The Laplace approximation for random-effect models that TMB builds on, combined with automatic differentiation.
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.