Normalise outer-grid log-marginals to posterior cell weights
Source:R/nested_laplace.R
tulpa_normalise_weights_safe.RdThe 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.
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();NULLnormalises 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.