pub struct MiserMonteCarlo { /* private fields */ }
Expand description

The MISER algorithm of Press and Farrar is based on recursive stratified sampling. This technique aims to reduce the overall integration error by concentrating integration points in the regions of highest variance.

The idea of stratified sampling begins with the observation that for two disjoint regions a and b with Monte Carlo estimates of the integral E_a(f) and E_b(f) and variances sigma_a^2(f) and sigma_b^2(f), the variance Var(f) of the combined estimate E(f) = (1/2) (E_a(f) + E_b(f)) is given by,

Var(f) = (sigma_a^2(f) / 4 N_a) + (sigma_b^2(f) / 4 N_b).

It can be shown that this variance is minimized by distributing the points such that,

N_a / (N_a + N_b) = sigma_a / (sigma_a + sigma_b).

Hence the smallest error estimate is obtained by allocating sample points in proportion to the standard deviation of the function in each sub-region.

The MISER algorithm proceeds by bisecting the integration region along one coordinate axis to give two sub-regions at each step. The direction is chosen by examining all d possible bisections and selecting the one which will minimize the combined variance of the two sub-regions. The variance in the sub-regions is estimated by sampling with a fraction of the total number of points available to the current step. The same procedure is then repeated recursively for each of the two half-spaces from the best bisection. The remaining sample points are allocated to the sub-regions using the formula for N_a and N_b. This recursive allocation of integration points continues down to a user-specified depth where each sub-region is integrated using a plain Monte Carlo estimate. These individual values and their error estimates are then combined upwards to give an overall result and an estimate of its error.

Implementations§

source§

impl MiserMonteCarlo

source

pub fn new(dim: usize) -> Option<MiserMonteCarlo>

This function allocates and initializes a workspace for Monte Carlo integration in dim dimensions. The workspace is used to maintain the state of the integration.

source

pub fn init(&mut self) -> Result<(), Value>

This function initializes a previously allocated integration state. This allows an existing workspace to be reused for different integrations.

source

pub fn integrate<F: FnMut(&[f64]) -> f64>( &mut self, f: F, xl: &[f64], xu: &[f64], t_calls: usize, r: &mut Rng ) -> Result<(f64, f64), Value>

This routines uses the MISER Monte Carlo algorithm to integrate the function f over the dim-dimensional hypercubic region defined by the lower and upper limits in the arrays xl and xu, each of size dim. The integration uses a fixed number of function calls calls, and obtains random sampling points using the random number generator r. A previously allocated workspace s must be supplied. The result of the integration is returned in result, with an estimated absolute error abserr.

In C, the function takes a gsl_monte_function as first argument. In here, you have to pass the dim argument and the function pointer (which became a closure) directly to the function.

It returns either Ok((result, abserr)) or Err(Value).

source

pub fn get_params(&self) -> MiserParams

This function copies the parameters of the integrator state into the user-supplied params structure.

source

pub fn set_params(&mut self, params: &MiserParams)

This function sets the integrator parameters based on values provided in the params structure.

Trait Implementations§

source§

impl Drop for MiserMonteCarlo

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.