Monte Carlo integration
In mathematics, Monte Carlo integration is a technique for numerical integration using random numbers. It is a particular Monte Carlo method that numerically computes a definite integral. While other algorithms usually evaluate the integrand at a regular grid, Monte Carlo randomly choose points at which the integrand is evaluated. This method is particularly useful for higher-dimensional integrals.
There are different methods to perform a Monte Carlo integration, such as uniform sampling, stratified sampling, importance sampling, Sequential Monte Carlo (a.k.a. particle filter), and mean field particle methods.
In numerical integration, methods such as the Trapezoidal rule use a deterministic approach. Monte Carlo integration, on the other hand, employs a non-deterministic approaches: each realization provides a different outcome. In Monte Carlo, the final outcome is an approximation of the correct value with respective error bars, and the correct value is within those error bars.
The problem Monte Carlo integration addresses is the computation of a multidimensional definite integral
where Ω, a subset of Rm, has volume
The naive Monte Carlo approach is to sample points uniformly on Ω: given N uniform samples,
I can be approximated by
This is because the law of large numbers ensures that
which leads to
As long as the sequence
is bounded, this variance decreases asymptotically to zero as 1/N. The estimation of the error of QN is thus
which decreases as . This result does not depend on the number of dimensions of the integral, which is the promised advantage of Monte Carlo integration against most deterministic methods that depend exponentially on the dimension. It is important to notice that, like in deterministic methods, the estimate of the error is not a strict error bound; random sampling may not uncover all the important features of the integrand that can result in an underestimate of the error.
While the naive Monte Carlo works for simple examples, this is not the case in most problems. A large part of the Monte Carlo literature is dedicated in developing strategies to improve the error estimates. In particular, stratified sampling - dividing the region in sub-domains -, and importance sampling - sampling from non-uniform distributions - are two of such techniques.
A paradigmatic example of a Monte Carlo integration is the estimation of π. Consider the function
and the set Ω = [−1,1] × [−1,1] with V = 4. Notice that
Thus, a crude way of calculating the value of π with Monte Carlo integration is to pick N random numbers on Ω and compute
In the figure on the right, the relative error is measured as a function of N, confirming the .
Wolfram Mathematica Example
The code below describes a process of integrating the function
from using the Monte-Carlo method in Mathematica:
Recursive stratified sampling
Recursive stratified sampling is a generalization of one-dimensional adaptive quadratures to multi-dimensional integrals. On each recursion step the integral and the error are estimated using a plain Monte Carlo algorithm. If the error estimate is larger than the required accuracy the integration volume is divided into sub-volumes and the procedure is recursively applied to sub-volumes.
The ordinary 'dividing by two' strategy does not work for multi-dimensions as the number of sub-volumes grows far too quickly to keep track. Instead one estimates along which dimension a subdivision should bring the most dividends and only subdivides the volume along this dimension.
The stratified sampling algorithm concentrates the sampling points in the regions where the variance of the function is largest thus reducing the grand variance and making the sampling more effective, as shown on the illustration.
The popular MISER routine implements a similar algorithm.
MISER Monte Carlo
The idea of stratified sampling begins with the observation that for two disjoint regions a and b with Monte Carlo estimates of the integral and and variances and , the variance Var(f) of the combined estimate
is given by,
It can be shown that this variance is minimized by distributing the points such that,
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 Na and Nb. 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.
VEGAS Monte Carlo
The VEGAS algorithm takes advantage of the information stored during the sampling, and uses it and importance sampling to efficiently estimate the integral I. It samples points from the probability distribution described by the function |f| so that the points are concentrated in the regions that make the largest contribution to the integral.
In general, if the Monte Carlo integral of f is sampled with points distributed according to a probability distribution described by the function g, we obtain an estimate:
with a corresponding variance,
If the probability distribution is chosen as
then it can be shown that the variance vanishes, and the error in the estimate will be zero. In practice it is not possible to sample from the exact distribution g for an arbitrary function, so importance sampling algorithms aim to produce efficient approximations to the desired distribution.
The VEGAS algorithm approximates the exact distribution by making a number of passes over the integration region which creates the histogram of the function f. Each histogram is used to define a sampling distribution for the next pass. Asymptotically this procedure converges to the desired distribution. In order to avoid the number of histogram bins growing like Kd, the probability distribution is approximated by a separable function:
so that the number of bins required is only Kd. This is equivalent to locating the peaks of the function from the projections of the integrand onto the coordinate axes. The efficiency of VEGAS depends on the validity of this assumption. It is most efficient when the peaks of the integrand are well-localized. If an integrand can be rewritten in a form which is approximately separable this will increase the efficiency of integration with VEGAS.
VEGAS incorporates a number of additional features, and combines both stratified sampling and importance sampling. The integration region is divided into a number of "boxes", with each box getting a fixed number of points (the goal is 2). Each box can then have a fractional number of bins, but if bins/box is less than two, Vegas switches to a kind variance reduction (rather than importance sampling).
This routines uses the VEGAS 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. The result and its error estimate are based on a weighted average of independent samples.
The VEGAS algorithm computes a number of independent estimates of the integral internally, according to the iterations parameter described below, and returns their weighted average. Random sampling of the integrand can occasionally produce an estimate where the error is zero, particularly if the function is constant in some regions. An estimate with zero error causes the weighted average to break down and must be handled separately.
Importance sampling algorithm
Importance sampling provides a very important tool to perform Monte-Carlo integration. The main result of importance sampling to this method is that the uniform sampling of is a particular case of a more generic choice, on which the samples are drawn from any distribution . The idea is that can be chosen to decrease the variance of the measurement QN.
Consider the following example where one would like to numerically integrate a gaussian function, centered at 0, with σ = 1, from −1000 to 1000. Naturally, if the samples are drawn uniformly on the interval [−1000, 1000], only a very small part of them would be significant to the integral. This can be improved by choosing a different distribution from where the samples are chosen, for instance by sampling according to a gaussian distribution centered at 0, with σ = 1. Of course the "right" choice strongly depends on the integrand.
Formally, given a set of samples chosen from a distribution
the estimator for I is given by
Intuitively, this says that if we pick a particular sample twice as much as other samples, we weight it half as much as the other samples. This estimator is naturally valid for uniform sampling, the case where is constant.
Multiple and Adaptive Importance Sampling
When different proposal distributions, , are jointly used for drawing the samples different proper weighting functions can be employed (e.g., see ). In an adaptive setting, the proposal distributions, , and are updated each iteration of the adaptive importance sampling algorithm. Hence, since a population of proposal densities is used, several suitable combinations of sampling and weighting schemes can be employed.
- Press et al, 2007, Chap. 4.
- Press et al, 2007, Chap. 7.
- Newman, 1999, Chap. 2.
- Newman, 1999, Chap. 1.
- Press et al, 2007
- Press, 1990, pp 190-195.
- Lepage, 1978
- Kroese, D. P.; Taimre, T.; Botev, Z. I. (2011). Handbook of Monte Carlo Methods. John Wiley & Sons.
- Veach, Eric; Guibas, Leonidas J. (1995-01-01). "Optimally Combining Sampling Techniques for Monte Carlo Rendering". Proceedings of the 22Nd Annual Conference on Computer Graphics and Interactive Techniques. SIGGRAPH '95 (New York, NY, USA: ACM): 419–428. doi:10.1145/218380.218498. ISBN 0-89791-701-4.
- Owen, Art; Associate, Yi Zhou (2000-03-01). "Safe and Effective Importance Sampling". Journal of the American Statistical Association 95 (449): 135–143. doi:10.1080/01621459.2000.10473909. ISSN 0162-1459.
- Elvira, V.; Martino, L.; Luengo, D.; Bugallo, M.F. (2015-10-01). "Efficient Multiple Importance Sampling Estimators". IEEE Signal Processing Letters 22 (10): 1757–1761. doi:10.1109/LSP.2015.2432078. ISSN 1070-9908.
- Cappé, O.; Guillin, A.; Marin, J. M.; Robert, C. P. (2004-12-01). "Population Monte Carlo". Journal of Computational and Graphical Statistics 13 (4): 907–929. doi:10.1198/106186004X12803. ISSN 1061-8600.
- Cappé, Olivier; Douc, Randal; Guillin, Arnaud; Marin, Jean-Michel; Robert, Christian P. (2008-04-25). "Adaptive importance sampling in general mixture classes". Statistics and Computing 18 (4): 447–459. doi:10.1007/s11222-008-9059-x. ISSN 0960-3174.
- Cornuet, Jean-Marie; Marin, Jean-Michel; Mira, Antonietta; Robert, Christian P. (2012-12-01). "Adaptive Multiple Importance Sampling". Scandinavian Journal of Statistics 39 (4): 798–812. doi:10.1111/j.1467-9469.2011.00756.x. ISSN 1467-9469.
- Martino, L.; Elvira, V.; Luengo, D.; Corander, J. (2015-08-01). "An Adaptive Population Importance Sampler: Learning From Uncertainty". IEEE Transactions on Signal Processing 63 (16): 4422–4437. doi:10.1109/TSP.2015.2440215. ISSN 1053-587X.
- Bugallo, Mónica F.; Martino, Luca; Corander, Jukka (2015-12-01). "Adaptive importance sampling in signal processing". Digital Signal Processing. Special Issue in Honour of William J. (Bill) Fitzgerald 47: 36–49. doi:10.1016/j.dsp.2015.05.014.
- R. E. Caflisch, Monte Carlo and quasi-Monte Carlo methods, Acta Numerica vol. 7, Cambridge University Press, 1998, pp. 1–49.
- S. Weinzierl, Introduction to Monte Carlo methods,
- W.H. Press, G.R. Farrar, Recursive Stratified Sampling for Multidimensional Monte Carlo Integration, Computers in Physics, v4 (1990).
- G.P. Lepage, A New Algorithm for Adaptive Multidimensional Integration, Journal of Computational Physics 27, 192-203, (1978)
- G.P. Lepage, VEGAS: An Adaptive Multi-dimensional Integration Program, Cornell preprint CLNS 80-447, March 1980
- J. M. Hammersley, D.C. Handscomb (1964) Monte Carlo Methods. Methuen. ISBN 0-416-52340-4
- Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007). Numerical Recipes: The Art of Scientific Computing (3rd ed.). New York: Cambridge University Press. ISBN 978-0-521-88068-8.
- Newman, MEJ; Barkema, GT (1999). Monte Carlo Methods in Statistical Physics. Clarendon Press.
- Robert, CP; Casella, G (2004). Monte Carlo Statistical Methods (2nd ed.). Springer. ISBN 978-1-4419-1939-7.