Stefan Bringuier
If we want to evaluate the integral of a function over some domain we can numerically approximate this using the midpoint rule: \[ \int_a^b f(x) dx = \frac{b-a}{N} \sum_{i=1}^N f(x_i) \qquad(1)\]
There is an alternative way to do this using probablity theory to determine the expectation value of a function \(f(x)\) for random variable \(x\): \[ \int_a^b p(x) f(x) dx = \frac{b-a}{N} \sum_{i=1}^N f(x_i) \qquad(2)\] where \(p(x)\) is a uniform probablity distribution over the interval \([a,b]\).
The difference between numerically evaluating Equation 1 and Equation 2, is that Equation 1 is evaluated over a grid of points and Equation 2 is randomly sampled points.
The error of MC integration is \(\propto \frac{1}{\sqrt{N}}\) as a result of central limit theorem
Stefan Bringuier
A more detailed notebook implementing the code can be viewed here
It is required to add the previous configuration \(i\) to the trajectory if the configuration \(i+1\) is rejected in order to ensure the distribution is valid