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


I=∫abf(x) dx.I=\int_a^b f(x)\,dx.


Draw NN independent values X1,…,XNX_1,\ldots,X_N uniformly from [a,b][a,b]. Uniform sampling gives equal probabilities to subintervals of equal width. Evaluate the integrand at each sampled value and average the results:


f‾=1N∑i=1Nf(Xi),I^=(b−a)f‾.\overline f=\frac{1}{N}\sum_{i=1}^N f(X_i), \qquad \widehat I=(b-a)\overline f.


This works because the expected sampled function value is its average over the interval:


E[f(X)]=1b−a∫abf(x) dx.\mathbb E[f(X)]=\frac{1}{b-a}\int_a^b f(x)\,dx.


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 11 when an event occurs and 00 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≥2N\geq2, calculate the sample standard deviation sfs_f and estimate the integral's standard error using


sf2=1N−1∑i=1N[f(Xi)−f‾]2,SE⁡^(I^)=(b−a)sfN.s_f^2=\frac{1}{N-1}\sum_{i=1}^N\left[f(X_i)-\overline f\right]^2, \qquad \widehat{\operatorname{SE}}(\widehat I)=\frac{(b-a)s_f}{\sqrt N}.


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/2N^{-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.


A decreasing curve shows relative standard error falling as the number of independent samples grows.


For a hit fraction p^\widehat p, a common estimated standard error is p^(1−p^)/N\sqrt{\widehat p(1-\widehat 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 XiX_i from a known density p(x)p(x) over the integration domain and use


I^=1N∑i=1Nf(Xi)p(Xi).\widehat I=\frac{1}{N}\sum_{i=1}^N\frac{f(X_i)}{p(X_i)}.


Division by p(Xi)p(X_i) 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)q(t) delivered to a surface during a 10.0 s10.0\ \text{s} pulse. Heat flux is power delivered per unit area, measured in W/m2\text{W/m}^2. The energy delivered per unit area is


H=∫010.0 sq(t) dt.H=\int_0^{10.0\ \text{s}}q(t)\,dt.


The program evaluates qq at 144 independent, uniformly distributed times over the pulse. The sampled mean is 35.0 W/m235.0\ \text{W/m}^2, and the sample standard deviation is 12.0 W/m212.0\ \text{W/m}^2. 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:


H^=(10.0 s)(35.0 W/m2)=350 J/m2.\widehat H=(10.0\ \text{s})(35.0\ \text{W/m}^2)=350\ \text{J/m}^2.


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 ________:


SE⁡^(q‾)=sqN=12.0 W/m2144=1.00 W/m2.\widehat{\operatorname{SE}}(\overline q)=\frac{s_q}{\sqrt N}=\frac{12.0\ \text{W/m}^2}{\sqrt{144}}=1.00\ \text{W/m}^2.


Next multiply by the interval width, using the same scale factor as for the integral estimate:


SE⁡^(H^)=(10.0 s)(1.00 W/m2)=10.0 J/m2.\widehat{\operatorname{SE}}(\widehat H)=(10.0\ \text{s})(1.00\ \text{W/m}^2)=10.0\ \text{J/m}^2.


The estimated standard error is 10.0 J/m². The sample standard deviation of 12.0 W/m212.0\ \text{W/m}^2 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/m25.00\ \text{J/m}^2. 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:


Nnew=Nold(SE⁡oldSE⁡target)2=144(10.05.00)2=576.N_{\text{new}}=N_{\text{old}}\left(\frac{\operatorname{SE}_{\text{old}}}{\operatorname{SE}_{\text{target}}}\right)^2=144\left(\frac{10.0}{5.00}\right)^2=576.


Retaining the original evaluations means the additional requirement is


Nadditional=576−144=432.N_{\text{additional}}=576-144=432.


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.

An analyst estimates an integral using 1,000 independently generated uniform sample points. Restarting the same pseudorandom generator with the saved seed reproduces exactly the same estimate. What does this repeated result establish?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A pump's flow rate Q(t)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.21.2, 1.81.8, 2.42.4, 1.61.6, and 2.0 L/min2.0\ \text{L/min}. Use these values to estimate the total volume delivered during the cycle. Give your answer in litres, to one decimal place.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A pond lies entirely inside a rectangular sampling region measuring 4.0 m4.0\ \text{m} by 3.0 m3.0\ \text{m}. A simulation generates 500 independent points uniformly over the rectangle; 320 fall inside the pond.


An irregular pond lies entirely inside a rectangle measuring four metres by three metres.


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^\widehat p, use


SE⁡^(p^)=p^(1−p^)500.\widehat{\operatorname{SE}}(\widehat p)=\sqrt{\frac{\widehat p(1-\widehat p)}{500}}.
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors