tulpa_normalise_weights_safe: Normalise outer-grid log-marginals to posterior cell weights

View source: R/nested_laplace.R

tulpa_normalise_weights_safeR Documentation

Normalise outer-grid log-marginals to posterior cell weights

Description

The single weight normaliser for every outer hyperparameter grid: softmax of lm (optionally plus a per-cell log quadrature weight) into weights summing to 1. Non-finite nodes (an inner Newton diverging in a grid corner) are dropped from the max-shift and zeroed before renormalising over the finite cells; an all-non-finite grid returns all-NA with a warning rather than NaN. Intended for reconstructing a fit's outer-grid posterior weights (with tulpa_theta_matrix() and tulpa_grid_log_quad()) when the fit doesn't already carry fit$weights.

Usage

tulpa_normalise_weights_safe(lm, what = "grids / data", log_quad = NULL)

Arguments

lm

Numeric vector of per-cell log-marginal-likelihood values.

what

Label for the grid, used only in the degenerate-case warning.

log_quad

Optional per-cell log quadrature weight (prior mass) of the outer grid, e.g. from tulpa_grid_log_quad(); NULL normalises the likelihood alone.

Value

Numeric vector of posterior cell weights summing to 1, the same length as lm, or all-NA if no cell carries finite mass.

See Also

tulpa_theta_matrix(), tulpa_grid_log_quad()

Examples

tulpa_normalise_weights_safe(c(-1, 0, -2))
# With per-cell log quadrature weights (cell prior masses):
tulpa_normalise_weights_safe(c(-1, 0, -2), log_quad = log(c(0.2, 0.5, 0.3)))

tulpa documentation built on Oct. 19, 2026, 5:09 p.m.