Monte Carlo (random-based) method to approximate the integral of a function over any number of dimensions.
More...
|
| 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 VecRes & | integrate (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 VecRes & | result () const |
| Get current result of integration (same value returned by Integrate) More...
|
|
const VecRes & | chiSqr () 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 VecRes & | stdDev () const |
| Estimate of standard deviation of integral result. Indicative of +- error range in result. More...
|
|
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
-
Dim | The dimension of the function input, number of variables that func operates on |
DimRes | The dimension of the function result, each dimension of the result will be averaged separately over the integration region |
BinCount | Tunable 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.