Monte Carlo Algorithm (Monte Carlo method)

Source: Internet
Author: User

Overview of Monte Carlo methods

Monte Carlo method, also called statistical simulation method, random sampling technology, is a stochastic simulation method, based on the probability and statistical theory of a method of calculation, is the use of random numbers (or more common pseudo-random numbers) to solve many computational problems. The solved problem is connected with a certain probability model, and statistical simulation or sampling is realized by computer to obtain approximate solution of the problem. In order to indicate the probabilistic statistical characteristics of this method symbolically, it is named by the Monte Carlo of the Las Vegas city.

The basic idea of Monte Carlo method

The "probability" of an event is determined by the "frequency" at which the event occurs. High-speed electronic computers make it possible to simulate such experiments in a large and fast way on a computer using mathematical methods.

The basic principle of Monte Carlo method

With statistical independent random variable XI (i=1,2,3,...,k), its corresponding probability density function is fx1,fx2,...,fxk, function function is z=g (X1,X2,...,XK).

First, according to the corresponding distribution of the random variables, produce N set of random number x1,x2,...,xk value, calculate function function value zi=g (X1,X2,...,XK) (i=1,2,...,n), if there is a function value of the random number of L group Zi≤0, when n→∞, according to The characteristics of Bernoulli large number theorem and normal random variables are: structure failure probability, reliable index.

It can be seen from the method of Monte Carlo that the method avoids the mathematical difficulty in structural reliability analysis, whether the state function is non-linear or not, the random variable is not normal, so long as the number of simulations is enough, a more accurate failure probability and reliability index can be obtained.

The steps of Monte Carlo method for molecular simulation calculation

Monte Carlo method implementation steps:

1, through sensitivity analysis, determine the random variables;

2. Probabilistic distribution model for constructing random variables;

3. Random numbers are extracted for each input random variable;

4. The sampled random number is converted to the sampling value of each input random variable.

5, the sampling value is composed of a set of project evaluation basis data;

6, according to the basic data to calculate the evaluation index value;

7. Arrange the expected value, variance, standard deviation and probability distribution and accumulative probability of the evaluation index of the simulation results, and draw the cumulative probability distribution chart to calculate the probability of feasible or infeasible project.

Monte Carlo method application

1. Ask π

#include <bits/stdc++.h>#defineMax_iters 10000000using namespacestd;DoubleRand (DoubleLDoubleR) {    returnL + (r-l) * RAND () *1.0/Rand_max;}Doublegetpi () {Srand (Time (NULL)); intCNT =0;  for(inti =0; i < max_iters; i++)    {        Doublex = Rand (-1,1); Doubley = Rand (-1,1); if(x * x + y * y <=1) CNT++; }    returnCNT *4.0/max_iters;}intMain () { for(inti =0; I <Ten; i++) cout<<fixed<< Setprecision (Ten) &LT;&LT;GETPI () <<Endl; return 0;
}

2. Ask for E

#include <bits/stdc++.h>#defineMax_iters 10000000using namespacestd;structpoint{Doublex, y;};DoubleRand (DoubleLDoubleR) {    returnL + (r-l) * RAND () *1.0/Rand_max;}    Point GetPoint () {point T; T.x= Rand (1.0,2.0); T.y= Rand (0.0,1.0); returnt;}DoubleGetResult () {intm =0; intn =max_iters;    Srand (Time (NULL));  for(inti =0; I < n; i++) {Point T=GetPoint (); Doubleres = T.x *T.y; if(Res <=1.0) M++; }    returnPow2.0,1.0Nm);}intMain () { for(inti =0; I < -; i++) cout<<fixed<< Setprecision (Ten) << GetResult () <<Endl; return 0;}//Precision () returns the current floating-point precision value//Precision (val) sets Val to the new floating-point precision value and returns the original value//SETF (Flags) adds the format flag flags, which returns the original state of all flags.//Showpos positive front plus + sign//fixed using fractional counting method//scientific using scientific notation//uppercase using uppercase characters//Showbase Displays the number of digits in the system//boolalpha bool value using a character representation, true or false//Noboolalpha BOOL uses 0 and 1 to denote//left aligns//Right Aligns//internal word Fu alignment, digital card right alignment

Reference:

[1]http://blog.csdn.net/acdreamers/article/details/44978591

[2] MBA Think tank: http://wiki.mbalib.com/wiki/%E8%92%99%E7%89%B9%E5%8D%A1%E7%BD%97%E6%96%B9%E6%B3%95

Monte Carlo Algorithm (Monte Carlo method)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.