Monte Carlo simulation is a set of algorithms used to predict the probabilistic outcomes of a process when its inputs vary randomly. Also referred to as the Monte Carlo method, Monte Carlo analysis, or Monte Carlo experiments, the algorithms are a type of stochastic simulation.
To understand the distribution of possible outcomes, Monte Carlo simulations run a large number of trials, each with a different set of random inputs. The simulation results from each trial are then analyzed to determine the probability distribution of uncertain variables.
The concept of Monte Carlo simulation emerged from the Manhattan Project and subsequent nuclear weapons development programs. In 1946, Stanislaw Ulam and John Von Neumann sought to determine the probability distribution of energy released when a neutron collided with an atomic nucleus. A colleague suggested the name "Monte Carlo" because his uncle gambled at the Monte Carlo Casino in Monaco, and the random selection of input variables reminded them of roulette's randomness.
Most processes are deterministic because the outputs are known for any given set of inputs. As an example, if you add a known amount of heat to a known amount of water at a known temperature, you can calculate how much the temperature rises. But it is difficult to predict outcomes in a more complex system where inputs are random, and the process itself is complex. Engineers, scientists, mathematicians, and economists use Monte Carlo simulations to incorporate randomness into forecasts of outcomes in such systems.
A good way to understand this powerful simulation tool is to look at a simple example. A classic problem is predicting how many times flipping four coins will result in zero, one, two, three, or four heads showing.
The input variable is the number of coins, and the output variable we want to predict is the probability of each combination of heads. A simple Excel Monte Carlo simulation uses the random number function, rand(), to predict heads or tails by setting a cell to one (heads) if the random number is less than 0.5 and zero (tails) if it is more than 0.5. The model consists of a table with one column per coin, one row per trial, and a sum column to compute the number of coins that showed heads. To calculate probabilities, the model uses countif() to count the number of times each possibility occurred, then divides that by the number of trials.
A simple four-coin Monte Carlo simulation in Microsoft Excel. The results are shown at the top of the image and the formulas used at the bottom. A new result is calculated every time the spreadsheet is refreshed.
Monte Carlo simulations use algorithms to solve problems by sampling from a large set of random inputs. Anyone using this tool must define the process he or she is simulating, identify the inputs and outputs, run the simulation, and review the results.
Here are the specific steps:
Start the simulation by defining the process to model. This can be a physics problem, a stock market, the weather in a specific region, or a biological process.
The next step is to capture all the independent variables. These are characteristics of the process that variables can represent. They should also be characteristics that change the process's behavior when they change. Independent variables are also called input variables, input values, or simply inputs.
In this step, investigators must also define the minimum and maximum values for each independent variable and the distribution, or variability, within that range of values. There are many types of distributions. Here are the most common:
The third step is to define the process's dependent variables. These are measurable characteristics that change when the input variables change. Dependent variables should also be metrics that matter to people. Minimizing or maximizing a dependent variable is the typical goal of an optimization study. Or teams use the possible results to inform decision-making. Dependent variables are also called output variables, output values, or result values.
The critical step is to create an accurate representation of the process as a computer algorithm. This can be a simple equation, a lookup table, or a more complex representation as a numerical model. The simulation should run as quickly and efficiently as possible.
The Monte Carlo simulation itself consists of running a large number of trials using the simulation model. The algorithm uses the range of values and distribution for each input to create random values for each input variable. The tool then captures the different outcomes from each trial.
The process under study determines the number of simulations required to obtain an accurate distribution of output values. Some problems require 1,000 to 10,000 runs. But certain processes may need 100,000 or more trials.
Once all output values are collected, the next step is to apply statistical methods to estimate the probability of each outcome. If the output variable has a normal distribution, the mean and standard deviation values represent the probability distribution. In simple cases, the probability of a given value is the count for a given outcome divided by the number of trials.
For more complex systems and applications, especially the training of machine learning models, investigators use a Bayesian analysis.
People use Monte Carlo simulations for probabilistic modeling across a wide range of industries. Here is a look at some of the most common applications:
Engineers use Monte Carlo methods across applications because they often need to design complex systems with no historical data or simple, deterministic models. Outside of design, they also use it for project management to conduct sensitivity analyses and risk management for their project planning. The most common usage is in numerical simulations for complicated systems to understand the statistical behavior of a product and the relationship between input and output variables. One of the best examples is neutron transport, in which engineers calculate how neutrons pass through and interact with the structural components in a nuclear reactor.
Extracting natural resources from the earth involves predicting a project's economic viability amid numerous unknowns. The industry uses Monte Carlo simulations to help predict reservoir sizes, porosity, the quality of the resources they are extracting, and even the price of that commodity in the future. One of the more common uses is to model the geology in a potential oil field using probabilistic distributions for the composition, porosity, and thickness of different layers of rock, in addition to what the oil distribution is for each combination. People then run a Monte Carlo simulation to get a distribution of potential oil concentrations. Instead of predicting the exact amount of oil in a given location, they calculate the probabilistic distribution of the oil.
Few things in the world have more complexity and randomness than financial markets. Economists and financial analysts use Monte Carlo methods to predict stock prices, volatility, interest rates, consumer prices, and other key economic variables. Commodity traders use the Monte Carlo method to stress-test the price of a commodity they own over time. They model the sensitivity of price to dozens of different market-impacting changes and then use a random selection of events over time to get a distribution of possible prices for each day. The result is a value at risk (VAR) for their portfolio.
The Monte Carlo method was initially developed for nuclear physics and remains a key part of modeling radiation in systems such as reactors, radiation therapy, and detectors. Chemists use it as a foundation for computational chemistry and statistical mechanics when modeling chemical reactions or developing new molecules because the mechanisms they study are impossible to calculate analytically. The same is true for biotechnology, where researchers use the method to interpret drug trial results, assess patient response rates, and design new drugs.
A common use of Monte Carlo for drug discovery is for molecular docking simulation. Chemists want to find a small molecule (a key) that fits into a protein (a lock). If the molecule fits into the protein, it can suppress unwanted chemical reactions. Instead of modeling every shape and rotation for the small molecule, a random distribution of both finds the lowest energy combinations that researchers can then focus on.
People use Monte Carlo simulations across many applications because of their advantages. But the approach also has some disadvantages worth consideration before applying it to a real-world problem.
Here is a list of the most common advantages and disadvantages:
There are generally three types of tools used to conduct Monte Carlo simulations: math software, custom programs, and simulation software.
Each has its own advantages and challenges, as outlined below.
Software tools such as Microsoft Excel, Google Sheets, Mathematica, and MATLAB are powerful for performing calculations and handling statistical distributions of input and output variables. The spreadsheet tools lack dedicated Monte Carlo capabilities, so users must build their simulations from the ground up. Math-specific tools, especially those with strong statistics modules, make creating random variables easier, automate the trial runs, and perform probabilistic analysis on the results. The biggest challenge for this class of tools is creating an accurate model of the process.
Custom programs are good when subroutines in a programming language can represent the process. Libraries exist in most languages to support tasks such as creating the input distributions for the random variables and for processing the dependent variables that result. The downside of this approach is that the user must create a custom program for each application, including the model for the process being studied. Programming platforms like Python make this easier, but it can still take some time to set up and debut the simulation.
The most powerful tool set — and the most common for real-world applications — is simulation software. These programs model the process under study and often include built-in tools that simplify Monte Carlo setup and automate trial-case execution.
A great example of this is the Ansys Optics suite: Ansys Zemax OpticStudio optical system design and analysis software for Monte Carlo simulations of optical systems and Ansys Lumerical software for the highly stochastic behavior found in photonics. Both tools help users build parametric models that support Monte Carlo simulation.
The optimization interface for Ansys Lumerical software
The same is true for the flagship Ansys simulation software tools: Ansys Mechanical structural finite element analysis software, Ansys LS-DYNA/LS-Opt nonlinear dynamics structural simulation software, Ansys Fluent fluid simulation software, the Ansys Maxwell advanced electromagnetic field solver, and Ansys HFSS high-frequency electromagnetic simulation software. Each of these tools focuses on simulating a specific subset of physics. Still, they all support parameterization of input and output variables, provide Monte Carlo simulation tools, and support statistical post-processing.
If the built-in tools for a given simulation platform are insufficient, users can integrate them with optimization tools such as Ansys optiSLang process integration and design optimization software. This general-purpose optimization and process integration tool has inherent strengths for Monte Carlo simulation runs and integrates with both Ansys, part of Synopsys, and non-Ansys simulation tools, providing a single, automated platform. It also leverages a robust Python interface that connects the program to other software or Python routines.
The Monte Carlo tolerance interface for Ansys Zemax OpticStudio optical system design and analysis software
Researchers and mathematicians have used Monte Carlo simulations for many different AI applications for some time. Here are a few examples:
The Ansys SimAI cloud-enabled AI platform for simulation is a strong example of a modern AI tool that leverages Monte Carlo simulation to generate training data for models.
如果您面臨工程挑戰,我們的團隊將隨時為您提供協助。憑藉豐富的經驗和對創新的承諾,我們邀請您與我們聯絡。讓我們共同合作,將您的工程障礙轉化為成長和成功的機會。立即與我們聯絡,開始對話。