# Use of Metropolis-Hasting algorithm for gathering statistics

I understand how MH work, I'm able to use it to simulate e.g. 2D Ising model. What I don't understand is what you actually take average of.

When I run the simulation, it reaches equlibrium after some time: Now each new state is going to be the same, so I see no point in taking the average or variance of the sequence that would follow.

Do I have to run the simulation each time over and over again from the beginning and take averages of the reached equilibrium states? This seems very inefficient to me.

• MH defines a Markov chain that is supposed to converge to a stationary distribution, this distribution and expected values under it are what people are usually after. When you say "equilibrium", that's not really supposed to happen, you could just be observing that consecutive states in MH are highly correlated with each other, so run it for much longer. – Kirill Mar 2 '16 at 21:15

Your post actually contains two questions:

## 1) What should you calculate

This first question will be answered by defining what you are studying. If it is the magnetic properties of your system (usual interest of Ising models) you can calculate the energy of your state by calculating the sum of the energy of each components:

$$U_i = - \sum_i \textbf{m}_i\cdot \textbf{E}$$

Where $$m_i$$ is the magnetic moment of the component $$i$$ and $$E$$ the electric field. Yet this represents only an instantaneous energy of the whole system which you can't observe directly in a real physical system due to his natural fluctuations. Contrarly to your saying, in equilibrium at microscopic level, the energy is not always the same for each configurations at equilibrium. The algorithm has a non-zero probability to accept higher energy configurations and I recommend you to test higher temperature systems Hence we observe the mean of a serie of records (forming your data): $$U = \frac{1}{n} \sum_i^n U_i$$ Where $$n$$ is the number of records you'll keep. Furthermore you can calculate standard deviation and other statistical properties that are useful for any physical calculations (check any good statistical and computational physics textbook like the Shang-Keng Ma or the one of Werner Krauth).

## 2) What data must I use to calculate it?

This second question is a bit more challenging as you have to define if your system has reached equilibrium. For simple Ising models this is not really a problem since you'll just observe the fluctuations of energy in you're last records. If they are small enough it's a win but if you're working in non-micro-canonical ou non-canonical ensembles for systems with highers degrees of freedom, it can become quite tedious to define whether or not your model finally converged. Usually if your data did not converge to an acceptable mean result, you should continue your simulation starting from the configuration you end up with. Else you can (more or less) arbritrary define a starting point for your statistical analysis, depending on the convergence of your data. You also have to take some time between the different records of your values for them to be statistically independent. For example, only record one out of one thousand configuration.