Monte Carlo Integration
Monte Carlo Methods: Estimating with Random Samples
Monte Carlo methods use random samples to estimate numerical quantities. You can apply them when evaluating a function is practical but calculating its integral directly is difficult. The same idea estimates probabilities: simulate many outcomes and count how often an event occurs. The result is an estimate whose sampling uncertainty you should report alongside its value.
Turn an integral into an average
Suppose you want to calculate
Draw N independent values X1,…,XN uniformly from [a,b]. Uniform sampling gives equal probabilities to subintervals of equal width. Evaluate the integrand at each sampled value and average the results:
This works because the expected sampled function value is its average over the interval:
Multiplying by the interval width therefore gives an unbiased estimate. Unbiasedness describes repeated sampling; an individual estimate can still be above or below the true integral.
Several common versions share this averaging principle:
Approach | What you sample | Estimate | Essential condition |
|---|---|---|---|
Sample mean | Uniform points in an interval | Interval width times mean function value | Sample the entire integration interval |
Hit or miss | Uniform points in a bounding rectangle | Rectangle area times fraction inside the region | The rectangle contains the entire region |
Weighted sampling | Points from a chosen probability density | Mean of function value divided by sampling density | Density is positive wherever the integrand is nonzero, apart from sets of zero width |
For probabilities, assign the value 1 when an event occurs and 0 otherwise. The average of these values is the observed event fraction.
Quantify sampling uncertainty
The standard error measures the spread of an estimate across repeated independent samples. It differs from the spread of individual function values. For N≥2, calculate the sample standard deviation sf and estimate the integral's standard error using
These uncertainty calculations require independent samples and finite variance. The interval width supplies the same units to the estimate and its standard error. If function values are in litres per minute and the interval is in minutes, both quantities are in litres.
Holding the sampled variance fixed, standard error decreases as N−1/2. You need four times as many samples to halve the standard error. Increasing the sample count tenfold does not reduce the error tenfold.
For a hit fraction p, a common estimated standard error is p(1−p)/N. Multiply this by the rectangle area when estimating an area. With sufficiently large, well-behaved samples, an interval extending about two standard errors on either side of an estimate gives an approximate 95% uncertainty interval. It is not a guaranteed error bound.
Choose samples and check the estimate
Uniform sampling is convenient, but other distributions can be useful. With importance sampling, draw Xi from a known density p(x) over the integration domain and use
Division by p(Xi) compensates for how frequently different locations are sampled. An unweighted average generally targets a different quantity. A sampler that entirely misses a region where the integrand contributes cannot recover that contribution through weighting alone. Choosing a different density also changes variance; improvement is not automatic.
What to remember
- Express the target as an average under a specified sampling distribution.
- Use the correct interval factor or probability-density weight.
- Report sampling uncertainty and plan sample counts using inverse-square-root scaling.
Example: Estimating Heat Delivered During a Pulse
A thermal simulation returns the heat flux q(t) delivered to a surface during a 10.0 s pulse. Heat flux is power delivered per unit area, measured in W/m2. The energy delivered per unit area is
The program evaluates q at 144 independent, uniformly distributed times over the pulse. The sampled mean is 35.0 W/m2, and the sample standard deviation is 12.0 W/m2. Treat model evaluations as exact; assess only uncertainty from sampling the times.
a) Calculate the Monte Carlo estimate of energy delivered per unit area.
The Monte Carlo estimate is the interval width multiplied by the sampled mean function value. Here, the interval width is ________, and the sampled mean heat flux is ________.
Multiply these quantities, keeping their units:
A watt is a joule per second, so multiplying by seconds gives energy per unit area. The estimated energy delivered is 350 J/m².
b) Estimate the standard error of this result.
First calculate the standard error of the sampled mean. The square root of the sample count is ________, so the mean heat flux has estimated standard error ________:
Next multiply by the interval width, using the same scale factor as for the integral estimate:
The estimated standard error is 10.0 J/m². The sample standard deviation of 12.0 W/m2 describes individual heat-flux evaluations, rather than uncertainty in the estimated integral.
c) Plan the total sample count needed for a target standard error of 5.00 J/m2. How many additional evaluations are needed if the original samples are retained? Assume the sampled variance remains unchanged.
The desired reduction factor in standard error is ________. Because standard error scales as the inverse square root of the sample count, square this factor when planning the new total:
Retaining the original evaluations means the additional requirement is
Plan for 576 total evaluations, requiring 432 additional evaluations. This is a planning estimate under the fixed-variance assumption. Recalculate the standard error after extending the sample because the observed sample standard deviation can change.
A pump's flow rate Q(t) varies during an 8.0-minute cycle. A computer model evaluates the rate at five independently sampled times drawn uniformly over the entire cycle. The returned rates are 1.2, 1.8, 2.4, 1.6, and 2.0 L/min. Use these values to estimate the total volume delivered during the cycle. Give your answer in litres, to one decimal place.
A pond lies entirely inside a rectangular sampling region measuring 4.0 m by 3.0 m. A simulation generates 500 independent points uniformly over the rectangle; 320 fall inside the pond.
Find the estimated pond area in square metres, to two decimal places, and its estimated standard error in square metres, to three decimal places. For the hit fraction p, use