Skip to content

Simulations

Monte Carlo

The Monte-Carlo (MC) method is a method of sampling random numbers that dates back to 1777. The name was suggested by Nick Metropolis when MC was used while working on the Manhattan Project. It is used in Random Number Generators which generally produce pseudo random numbers. Extensive information on the Monte-Carlo method can be found in [33].

Quasi Monte Carlo

For a comprehensive introduction to Quasi Monte Carlo, view [34]. The following provides an essential overview.

Quasi Monte Carlo (QMC), is a method of producing samples similar to those generated via Monte Carlo (MC). The difference being that QMC samples are generated deterministically in a way to ensure they are evenly distributed across the sampling space, not forming clutters or voids as MC samples might. This makes QMC more efficient than MC for lots of applications, since fewer samples are needed in order to produce a sufficient density of samples throughout. There are multiple ways of QMC sampling methods which can be classified as either digital nets/sequences or lattices [35]. Since the samples are not random, they are not suitable for many tasks. However, it is possible to randomize QMC samples by randomly shifting or scrambling each sample.

While the disjunction of a deterministic sampling and a randomization method that can be applied to the samples later is most common for QMC, there are also some sampling methods that directly produce quasi random samples.

Dependency QuasiMonteCarlo.jl

This package relies on QuasiMonteCarlo.jl which offers various QMC sampling methods as well as corresponding randomization methods. An example on how to use them is shown below.

The package provides the following deterministic sampling algorithms:

  • Lattices:

    • GridSample

    • LatticeRuleSample

    • GoldenSample

    • KroneckerSample

  • Digital nets:

    • SobolSample

    • FaureSample

    • HaltonSample

Note

KroneckerSample should not be used with bases > 3. GoldenSample is a special version of a KroneckerSample and should be used with base 1 only. Otherwise, LatticeRuleSample is the preferred method. For more information on this and on the implementation of the other sampling algorithms, please consult the corresponding documentation of QuasiMonteCarlo.jl.

Note

The number of samples for digital nets should always be a power of the base, while lattices work best with large prime numbers as sample-sizes. Straying from these rules may worsen results significantly, since the samples will be imbalanced [36].

The samples can be randomized by shifting using these methods:

  • Shift (Cranley-Patterson rotation [37])

  • Scrambles:

    • MatousekScramble[38]

    • OwenScramble[39] or

    • DigitalShift(functions similarly to Shift, but takes the base that was used during sampling into account)

Note

For randomizing lattice-samples, Shift is recommended. The mentioned scrambling methods work well with samples from digital nets.

Further, these are the available randomized sampling algorithms: * LatinHypercubeSample[40] * RandomizedHaltonSample[41]

Example

To facilitate QMC-sampling in UncertaintyQuantification.jl one needs to first create one or more random variables to sample from as well as an instance of QuasiMonteCarloSampling, which takes the number of samples and the desired sampling algorithm from QuasiMonteCarlo.jl. Using the sample-function, the defined number of samples is created from the given variable(s).

julia
    using QuasiMonteCarlo
    x = RandomVariable(Uniform(), :x)
    qmc = QuasiMonteCarloSampling(128, LatinHypercubeSample())
    samples = UncertaintyQuantification.sample(x, qmc)

It is of course possible to directly create the QuasiMonteCarloSampling-instance inside the sample-call, enabling a more efficient version of the example above which looks like this:

julia
    x = RandomVariable(Uniform(), :x)
    samples = UncertaintyQuantification.sample(x, QuasiMonteCarloSampling(128, LatinHypercubeSample()))

Note

When chosing n, be reminded that, for digital nets, n must be a power of the base that is used for creating the respective sequence. For SobolSample the base is always equal to 2 while for FaureSample, it depends on the number of input-variables, being the smallest prime number that is greater or equal to the number of variables.

julia
    x = RandomVariable(Uniform(), :x)
    samples = UncertaintyQuantification.sample(x, QuasiMonteCarloSampling(128, QuasiMonteCarlo.SobolSample()))
128×1 DataFrame
Rowx
Float64
10.0117187
20.511719
30.761719
40.261719
50.386719
60.886719
70.636719
80.136719
90.199219
100.699219
110.949219
120.449219
130.324219
140.824219
150.574219
160.0742188
170.105469
180.605469
190.855469
200.355469
210.480469
220.980469
230.730469
240.230469
250.167969
260.667969
270.917969
280.417969
290.292969
300.792969
310.542969
320.0429687
330.0585938
340.558594
350.808594
360.308594
370.433594
380.933594
390.683594
400.183594
410.246094
420.746094
430.996094
440.496094
450.371094
460.871094
470.621094
480.121094
490.0898437
500.589844
510.839844
520.339844
530.464844
540.964844
550.714844
560.214844
570.152344
580.652344
590.902344
600.402344
610.277344
620.777344
630.527344
640.0273437
650.0195312
660.519531
670.769531
680.269531
690.394531
700.894531
710.644531
720.144531
730.207031
740.707031
750.957031
760.457031
770.332031
780.832031
790.582031
800.0820313
810.113281
820.613281
830.863281
840.363281
850.488281
860.988281
870.738281
880.238281
890.175781
900.675781
910.925781
920.425781
930.300781
940.800781
950.550781
960.0507812
970.0351562
980.535156
990.785156
1000.285156
1010.410156
1020.910156
1030.660156
1040.160156
1050.222656
1060.722656
1070.972656
1080.472656
1090.347656
1100.847656
1110.597656
1120.0976562
1130.0664063
1140.566406
1150.816406
1160.316406
1170.441406
1180.941406
1190.691406
1200.191406
1210.128906
1220.628906
1230.878906
1240.378906
1250.253906
1260.753906
1270.503906
1280.00390625

To emphasize the importance of randomization, consider the correlations that might occur using unrandomized QMC and how they are fixed by randomizing. For instance, this is the 7th dimension plotted against the 8th in Faure Sampling, unrandomized vs. randomized via Owen Scramble: