# Monte Carlo and probabilistic simulation

(Redirected from Monte Carlo)

Probabilistic simulation means simulating probabilistic variables by selecting a random sample from each distribution. Analytica offers four sampling methods, Monte Carlo simulation, Median Latin hypercube (the default), Random Latin hypercube, and Sobol sampling (new to Analytica 5.0). We describe each of them, and then explain how to select among them.

### Monte Carlo sampling

The most widely used sampling method is known as Monte Carlo, named after the randomness in games of chance, such as at the famous casino in Monte Carlo. In this method, each of the m sample points for each uncertainty quantity, X, is generated at random from X with probability proportional to the probability density (or probability mass for discrete quantities) for X. Analytica generates m uniform random values, ui, for i = 1, 2,...m, between 0 and 1, using the specified random number method (see below). It then uses the inverse of the cumulative probability distribution to generate the corresponding values of X,

Xi where P() = ui for i = 1, 2,...m

With the simple Monte Carlo method, each value of every random variable X in the model, including those computed from other random quantities, is a sample of m independent random values from the true probability distribution for X. You can therefore use standard statistical methods to estimate the accuracy of statistics, such as the estimated mean or fractile (percentile) of a distribution, as described in Selecting the Sample Size.

### Median Latin hypercube

Median Latin hypercube sampling is the default method: It divides each uncertain quantity X into m equiprobable intervals, where m is the sample size. The sample points are the medians of the m intervals, that is, the fractiles:

Xi where P() = (i - 0.5)/m, for i = 1, 2,...m.

These points are then randomly shuffled so that they are no longer in ascending order, to avoid nonrandom correlations among different quantities.

### Random Latin hypercube

The random Latin hypercube method is similar to the median Latin hypercube method except that, instead of using the median of each of the m equiprobable intervals, it samples at random from each interval. With random Latin hypercube sampling, each sample is a true random sample from the distribution, as in simple Monte Carlo. However, the samples are not totally independent because they are constrained to have one sample from each of the n intervals.

### Sobol sampling

(New to Analytica 5.0)

The Sobol Sampling method is a quasi-Monte Carlo method that attempts to spread sample points out more evenly in probability space across multiple dimensions than Monte Carlo or Latin hypercube methods. Latin hypercube methods spread samples out uniformly for each scalar quantity separately, but since it samples from each quantity (dimension) independently, the coverage of the multidimensional space may not be very uniform. Sobol samples in a way that coordinates across multiple dimensions, creating a more even sampling than Latin hypercube. It does this by applying Sobol sequences to each scalar quantity.

Sobol sampling comes with a much stronger convergence guarantee than pure Monte Carlo sampling. Monte Carlo sampling error converges as $\displaystyle{ O(1/\sqrt{n}) }$ whereas Sobol converges as $\displaystyle{ O(\log(n)^d / n) }$, where d is the number of uncertain scalar quantities. For a fixed d, Sobol's convergence rate at extremely large n approaches $\displaystyle{ O(1/n) }$, often seen as the holy grail of simulation. However, since $\displaystyle{ \log(n)^d }$ is a very large number when d is even of moderate size, the guaranteed bound is not as useful as you might think.

### Choosing a sampling method

The advantage of Latin hypercube methods is that they provide more uniform distributions of samples for each distribution than simple Monte Carlo sampling. Median Latin hypercube, since it uses the median of each equiprobable interval is even more uniformly distributed than random Latin hypercube. If you display the PDF of a variable that is defined as a single continuous distribution, or is a function of just one continuous uncertain variable, the distribution usually looks fairly smooth even with a small sample size (such as 20) with median Latin hypercube sampling -- where simple Monte Carlo results looks quite noisy.

The advantage of Latin hypercube in reducing noise reduces when the result depends on two or more uncertain quantities that have comparable effects on the result, with the noise increasing with the number of uncertain quantities performance of the Latin hypercube. For more than 5 or so uncertain quantities, Latin hypercube methods might not be discernibly better than simple Monte Carlo. Since the median Latin hypercube method is sometimes much better, and almost never worse than the others, Analytica uses it as the default method.

### When not to use Latin hypercube sampling

In very rare situations, median Latin hypercube can produce poor results -- when the model includes a periodic function (like a Sin function) and the period is similar to the size of the equiprobable intervals on the uncertain parameter. For example:

X := Uniform(1, Samplesize)
Y := Sin(2*Pi*X)

In this case, median Latin hypercube sampling gives bad results --- so you should use random Latin hypercube or simple Monte Carlo, which avoids this problem. But, the vast majority of models have no periodic function of this kind, so you do not need to worry about the reliability of median Latin hypercube sampling.
{"ft_lang_label":"__label__en","ft_lang_prob":0.86531013,"math_prob":0.992832,"size":5900,"snap":"2023-40-2023-50","text_gpt3_token_len":1228,"char_repetition_ratio":0.17282903,"word_repetition_ratio":0.0064794817,"special_character_ratio":0.19830509,"punctuation_ratio":0.10229445,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99759924,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-11T12:24:42Z\",\"WARC-Record-ID\":\"<urn:uuid:4441b81c-5178-4931-9108-4f03268e6689>\",\"Content-Length\":\"26005\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3455b651-60cf-4e3a-880f-18bafcccbcbc>\",\"WARC-Concurrent-To\":\"<urn:uuid:8f0ab66b-a847-421f-b3dd-4ef35e19b0f6>\",\"WARC-IP-Address\":\"35.212.139.245\",\"WARC-Target-URI\":\"https://docs.analytica.com/index.php/Monte_Carlo\",\"WARC-Payload-Digest\":\"sha1:QV6RMXSZRGSAMTBMWZRJ5ZQU7HX3PNUP\",\"WARC-Block-Digest\":\"sha1:4LBYGELJLHJMDCB5I5IW2AMFNTKJVVTQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679511159.96_warc_CC-MAIN-20231211112008-20231211142008-00451.warc.gz\"}"}