bayesplain.core.grid.sample_from_grid

bayesplain.core.grid.sample_from_grid(density, grid, size=100000, rng=None)[source]

Sample from a grid-approximated posterior by inverting its CDF.

Draws uniforms and reads them back through the interpolated cumulative distribution. The draws are independent, so the only error is the discretisation of the grid, which a fine grid makes negligible.

Parameters:
density : array_like

Normalised density values.

grid : array_like

Grid points.

size : int, default 100_000

Number of draws.

rng : numpy.random.Generator, optional

Random generator.

Returns:

Array of size draws.

Return type:

ndarray