Comment by shoo
1 day ago
Here's a few related ideas:
1) rejection sampling - this is the name to the general technique used in the first example, to estimate pi by sampling from a uniform distribution over a unit square (easy) and then rejecting the samples that fall outside of the distribution you're actually interested in (unit disk).
Another simple example of rejection sampling is if you want to randomly pick between 5 ordered options and only have a d6. Roll the d6. If you roll a 6, reject the roll & re-roll. If you roll 1-5, that's your choice.
2) the Metropolis-Hastings algorithm -- this is a Markov chain Monte Carlo algorithm. It can be useful in some applications to sample from a distribution that is difficult to sample from.
Suppose you have some system described by a state vector x & you know that the probability of the system being in state x, p(x), is proportional to q(x), where q is some function you can compute. If you could integrate q over x, to give Z := integral_{x in X} q(x) dx then you'd have p(x) = Z^-1 q(x)
For a concrete example, x might be a state vector of a physical system -- say a bunch of molecules in a box, where you can compute the energy of any given state u(x) and know the probability of x, p(x), is proportional to exp(-u(x)).
Metropolis-Hastings is neat as it gives you a way to sample from p even if you cannot compute Z or sample from q --- you just need to have some way to sample a proposed a new candidate state x' from x (this proposal distribution doesn't need to have any relationship to the distributions p & q you're actually interested in). Can often think of the proposed candidate state x' as some kind of local mutation of x. Provided you can compute q(x') / q(x), you can use that ratio as a probability of accepting the move to replace x with candidate x'.
By the algorithm depending on the ratio of probabilities of two different states p(x') / p(x) = q(x') / q(x), it lets you sample from p even if you can't compute Z or have any direct way to sample from p or q. *
Metropolis-Hastings & Markov Chain Monte Carlo methods are definitely in the territory of clever 'what to do if you don't know what to do' methods --- if there's some other more direct & practical way of computing the thing you're trying to compute, use that instead! But if there's not, & you have some gnarly problem, maybe MCMC might be the best option available.
* caveat caveat caveat: provided you let the sampler run long enough for it to 'burn in', & perhaps restart it a few times from different initial states x_0 to reduce the chance of it getting trapped in some unrepresentative local optima
Ironically, there have been studies done in using Monte Carlo methods to predict software delivery timelines (Dan Vacanti and Prateek Singh's work specifically), that found out that the more mature and well-behaved your pipelines and test automation were, the more accurate a naive Monte Carlo simulation was.
The only teams where Markov Chain methods or messing with sampling dates would provide more accurate timelines were the teams whose delivery processes were the most borked and spiky.