cyjax.util.mc_integrate#

cyjax.util.mc_integrate(key, count, fn, sample, var=False)#

Monte Carlo integration.

This function approximates

..math::

int mathrm{fn}(z) approx sum_{z, w sim mathrm{sample}} mathrm{fn}(z) cdot w ,.

The function sample is expected to return points \(zs\) and corresponding weights \(w\). The latter are the ratios of the target integration measure and the probability measure corresponding to the used sampling process.

Parameters:
  • key (Union[PRNGKeyArray, Array]) – PRNG random key.

  • count (int) – Number of samples used in the MC approximation.

  • fn (Callable[[Union[Array, ndarray, bool_, number]], Union[Array, ndarray, bool_, number]]) – Integrand, taking an array of points as input.

  • sample (Callable[[Union[PRNGKeyArray, Array], int], Union[Array, ndarray, bool_, number]]) – Sampling function, taking a random key and an integer indicating the number of desired samples as input. Must return a tuple of samples and corresponding weights.

  • var (bool) – Whether to return an MC approximation of the variance of the integration result. This assumes generated samples are i.i.d.

Return type:

Union[Array, ndarray, bool_, number, float, int, tuple[Union[Array, ndarray, bool_, number, float, int], Union[Array, ndarray, bool_, number, float, int]]]

Returns:

Either the integration result, or the integration result and the estimated variance.