News for hackers. Stuff that matters.
Re:The art of solving problems with Monte Carlo simulations by tragomaskhalos on Tuesday May 04, 2021 @06:35AM (#27035989)
A (minor) point not raised in the article is that the accuracy of these methods is typically bounded unless your RNG is truly random. So for example if you try to calculate pi as shown you will not be able to finesse the answer beyond a certain accuracy if you are using a typical language's pseudo-random number generator, because the true space of possible values is only partially sampled.
Re:The art of solving problems with Monte Carlo simulations by mathrando on Tuesday May 04, 2021 @07:36AM (#27036461)
RNG quality is probably the least of your worries.

The curse of dimensionality means you often need a huge number of samples to guarantee a useful level of precision. Additionally, many quantities you'd like to know come up in Monte Carlo simulations themselves. That creates an intractable O(N^2) problem.

Here's an example that I encountered at work yesterday:

You want to know P(x>=a and y>=b) where (x,y) is a standard bivariate normal with correlation R.

You can:

1. Simulate a bunch of (x,y) and take the mean of the indicator function 1[x>=a, y>=b]. This will take whole seconds to compute.

2. Use an adaptive quadrature method like scipy.integrate.nquad. This will take dozens to hundreds of milliseconds.

3. Write a fixed grid Gauss-Legendre quadrature routine in c. This will take less than a microsecond.

I needed this value inside a Monte Carlo simulation. If I had to simulate the solution, the problem would be intractable.

Re:The art of solving problems with Monte Carlo simulations by gbrown on Tuesday May 04, 2021 @08:39AM (#27036916)
Wouldn’t it be even faster to solve that problem conditionally? P(x >= a)P(y >= a | x >= a), since the conditional distribution is known and normal?
Re:The art of solving problems with Monte Carlo simulations by mathrando on Tuesday May 04, 2021 @08:56AM (#27037044)
You still need to integrate over x. y|x=c is Gaussian for each c, but there are many such c's in [a,inf].

If you're curious:

https://www.ams.org/journals/mcom/1978-32-141/S0025-5718-197...

Re:The art of solving problems with Monte Carlo simulations by gbrown on Tuesday May 04, 2021 @01:24PM (#27040038)
Ah, duh. Not enough coffee.
Re:The art of solving problems with Monte Carlo simulations by jacquesm on Tuesday May 04, 2021 @06:43AM (#27036050)
Ah, this may have been my problem (see other comment in this thread). I will have to try this again now with a better RNG. Thank you!
Re:The art of solving problems with Monte Carlo simulations by cycomanic on Tuesday May 04, 2021 @08:21AM (#27036774)
Does that mean we can use the calculation of e.g. pi and a check what value it converges to as a check of the sampling space of a rng? I guess the sampling space is only a necessary condition for rng "quality"?