How to | Perform a Monte Carlo Simulation
Monte Carlo methods use randomly generated numbers or events to simulate random processes and estimate complicated results. For example, they are used to model financial systems, to simulate telecommunication networks, and to compute results for high-dimensional integrals in physics. Monte Carlo simulations can be constructed directly by using the Wolfram Language's built‐in random number generation functions.
A sequence of random numbers can be a very simple Monte Carlo simulation. For instance, a list of random numbers generated independently from a normal distribution with mean 0 can simulate a white noise process.
Use ListPlot to visualize the data:
Use [[ ]] (the short form of the Part function) to get the final data point of each random walk:
Monte Carlo methods can also be used to approximate values such as constants or numeric integrals. For instance, the following approximates the value of by generating random points in a square around a circle of radius 1, and then using the relationship between the area of the square and the circle.
Monte Carlo simulations are most useful in cases where the nature of the system of interest is complicated. In Bayesian analysis, you often want to mix distributions, with the parameters of two distributions following each other to generate a bivariate distribution. Because the individual distributions are interrelated, points must be iteratively generated and inserted into the other distribution to sample from the bivariate distribution.
As an example, you might have a normal distribution where the mean is known, but the standard deviation is not. However, you know that the standard deviation follows a beta distribution that has one known shape parameter, and another shape parameter that is related to the normal distribution where the mean is known.
You can simulate a point from the bivariate distribution by choosing a starting value for the normal standard deviation, and then sequentially generating random numbers from the normal and beta distributions. A normal variate is generated using the starting value for the normal standard deviation. A beta variate is then generated by using that normal variate as the unknown shape parameter for the beta distribution. This beta variate is then used as the unknown standard deviation for a new normal distribution, and so on. This process is carried out for some number of iterations, and the final normal and beta variates are the coordinates of the simulated point.
Visualize the resulting points using ListPlot:
Visualize the density of the points using Histogram3D:
Other examples of Monte Carlo methods for estimation include optimization and high-dimensional integration. NMinimize and NIntegrate have methods for optimization and numeric integration using these techniques.