Honeycomb  0.1
Component-Model Framework
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
honey::Vegas< Dim, DimRes, Real__, BinCount > Class Template Reference

Monte Carlo (random-based) method to approximate the integral of a function over any number of dimensions. More...

#include <Vegas.h>

Public Types

typedef Real__ Real
 
typedef Vec< dimRes, RealVecRes
 
typedef Vec< dim, RealVec
 
typedef function< VecRes(const Vec &)> Func
 

Public Member Functions

 Vegas (const Func &func, RandomGen &gen, const Vec &lower, const Vec &upper, sdt sampleCount=1000, Real warmUp=0.1, sdt iterCount=5, Real alpha=1.5)
 Constructor, set up constants for all integration calls. More...
 
 ~Vegas ()
 
const VecResintegrate (Real progressDelta=1)
 Perform integral calculation. The calculation can be split up over multiple calls. More...
 
Real progress () const
 Current progress of calculation, from 0 (start) to 1 (complete). More...
 
const VecResresult () const
 Get current result of integration (same value returned by Integrate) More...
 
const VecReschiSqr () const
 Get chi-square statistic for integral. A value that differs significantly from 1 (eg. diff > 0.5) indicates an unreliable result and more samples or iterations are required. More...
 
const VecResstdDev () const
 Estimate of standard deviation of integral result. Indicative of +- error range in result. More...
 

Static Public Attributes

static const sdt dim = Dim
 
static const sdt dimRes = DimRes
 

Detailed Description

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
class honey::Vegas< Dim, DimRes, Real__, BinCount >

Monte Carlo (random-based) method to approximate the integral of a function over any number of dimensions.

Example: Find the mass of a sphere with radius 2 and density 0.5

//Functor takes a 3D coordinate and returns a 1D density sample
typedef Vegas<3, 1> Vegas;
struct Func { Vegas::VecRes operator()(const Vegas::Vec& coord)   { return coord.length() <= 2 ? 0.5 : 0; }  };

//Integrate over 3D bounding box [-2, 2]
Real mass = Vegas(Func(), Chacha(), Vegas::Vec(-2), Vegas::Vec(2)).integrate();
//mass =~ 16.7
Template Parameters
DimThe dimension of the function input, number of variables that func operates on
DimResThe dimension of the function result, each dimension of the result will be averaged separately over the integration region
BinCountTunable param, each dimension of the input (Dim) will be divided into BinCount separate bins. Higher bin counts provide more accuracy. At the default bin count of 100 a Vegas instance can fit on the stack, providing better performance.

Algorithm from: "VEGAS: An Adaptive Multi-dimensional Integration Program", G.P. Lepage, 1980.
Code adapted from C implementation by Richard Kreckel.

Member Typedef Documentation

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
typedef function<VecRes (const Vec&)> honey::Vegas< Dim, DimRes, Real__, BinCount >::Func
template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
typedef Real__ honey::Vegas< Dim, DimRes, Real__, BinCount >::Real
template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
typedef Vec<dim,Real> honey::Vegas< Dim, DimRes, Real__, BinCount >::Vec
template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
typedef Vec<dimRes,Real> honey::Vegas< Dim, DimRes, Real__, BinCount >::VecRes

Constructor & Destructor Documentation

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
honey::Vegas< Dim, DimRes, Real__, BinCount >::Vegas ( const Func func,
RandomGen gen,
const Vec lower,
const Vec upper,
sdt  sampleCount = 1000,
Real  warmUp = 0.1,
sdt  iterCount = 5,
Real  alpha = 1.5 
)
inline

Constructor, set up constants for all integration calls.

Parameters
funcFunction to integrate
genRandom generator
lowerLower bound of the region over which to integrate (has dimension Dim)
upperUpper bound of the region over which to integrate (has dimension Dim)
sampleCountNumber of functor calls per iteration. If results are not reliable then increase the sample count (check stdDev() or chiSqr())
warmUpTunable param, percentage of samples (range >= 0) to use for warming up the grid. These are extra samples, results are discarded.
iterCountTunable param, number of iterations, functor will be called roughly sampleCount times per iteration.
alphaTunable param, represents stiffness of the grid rebinning algorithm. Range is usually [1,2], no rebinning will occur at 0.
template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
honey::Vegas< Dim, DimRes, Real__, BinCount >::~Vegas ( )
inline

Member Function Documentation

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
const VecRes& honey::Vegas< Dim, DimRes, Real__, BinCount >::chiSqr ( ) const
inline

Get chi-square statistic for integral. A value that differs significantly from 1 (eg. diff > 0.5) indicates an unreliable result and more samples or iterations are required.

template<sdt Dim, sdt DimRes, class Real , sdt BinCount>
const Vegas< Dim, DimRes, Real, BinCount >::VecRes & honey::Vegas< Dim, DimRes, Real, BinCount >::integrate ( Real  progressDelta = 1)

Perform integral calculation. The calculation can be split up over multiple calls.

Parameters
progressDeltaPercentage of progress to complete in this call. Range [0,1]
Returns
Result of integration so far. Accuracy increases with progress.
template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
Real honey::Vegas< Dim, DimRes, Real__, BinCount >::progress ( ) const
inline

Current progress of calculation, from 0 (start) to 1 (complete).

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
const VecRes& honey::Vegas< Dim, DimRes, Real__, BinCount >::result ( ) const
inline

Get current result of integration (same value returned by Integrate)

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
const VecRes& honey::Vegas< Dim, DimRes, Real__, BinCount >::stdDev ( ) const
inline

Estimate of standard deviation of integral result. Indicative of +- error range in result.

Member Data Documentation

template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
const sdt honey::Vegas< Dim, DimRes, Real__, BinCount >::dim = Dim
static
template<sdt Dim = 1, sdt DimRes = 1, class Real__ = Real, sdt BinCount = 100>
const sdt honey::Vegas< Dim, DimRes, Real__, BinCount >::dimRes = DimRes
static

The documentation for this class was generated from the following file: