bayesplain.core.grid.normalize_log_density

bayesplain.core.grid.normalize_log_density(log_density, grid)[source]

Turn an unnormalised log density on a grid into a proper density.

Subtracts the maximum before exponentiating, so densities that would otherwise underflow to zero are handled without loss of precision, then divides by the trapezoidal integral.

Parameters:
log_density : array_like

Unnormalised log density evaluated at each grid point.

grid : array_like

Strictly increasing grid points.

Returns:

Normalised density values, integrating to 1 over the grid.

Return type:

ndarray