Skip to contents

Results in a finite_dist of n equally weighted draws from dist, converging to dist as n grows. Useful for approximating a mixture that has no closed form, or for approximating a distribution for which it is difficult to compute expectations under.

Usage

discretise(dist, n)

Arguments

dist

A distribution to sample.

n

Number of draws.

Value

A finite_dist on n equally weighted atoms.

Examples

set.seed(1)
fam <- multinomial_family(n_trials = 6L, k = 3L)

W <- dirichlet(alpha = c(4, 3, 2))
approx <- discretise(W, 500L)
n_atoms(approx)
#> [1] 500

x <- enumerate_space(fam@sample_space)
log_density(fam(W), c(2,2,2))
#> [1] -2.81441
log_density(fam(approx), c(2,2,2))
#> [1] -2.802821