# Computing the partition function from a Metropolis Monte Carlo sample

I must be missing something. I could not find an answer in similar posts.

Suppose I have an energy $$E(x)$$ and have sampled many points, $$\{x_1, x_2, ..., x_N\}$$ through a Metropolis Monte Carlo simulation. If the space is high enough dimension such that numerically integrating over the space is impossible, what are my options for estimating the partition function (or free energy)?

P.S. I don't really care about the accuracy of the estimate. This question is more for didactic reasons than for practical ones.

• Sampled according to which distribution? -- Note that from a normalized sample of the Gibbs distribution, you cannot reconstruct the normalization (unless you use the sample to estimate the entropy and compute the free energy). Jul 8 at 9:40
• What is each individual point $x_i$? Jul 8 at 9:55
• Correct, I was assuming the canonical ensemble. And $x \in \mathbb{R}^N$ where $N$ is the dimension of the space. $x_i$ is a single point in $\mathbb{R}^N$ and is the $i$th point in the sample. Jul 9 at 10:19

The aim of the Metropolis Monte Carlo method is to evaluate the main macroscopic thermodynamic quantities of a system. These quantities are evaluated through an ensemble average. The idea of the Metropolis algorithm is to replace ensemble averages with time averages on a sufficiently large number $$M$$ of steps. The partition function $$Q$$ does not represent a quantity of interest for this method since it is not required for the calculation of the acceptance probability and it is not even involved in the calculation of time averages. Moreover, $$Q$$ is not a function of the coordinates and depends only on the parameters $$N, V, T$$. I see from your question that you also refer to free energy $$A=U-TS$$. The evaluation of the energy average is quite straightforward: $$U=\frac{1}{M}\sum_{i=0}^{M}U(\vec{R}_{i})$$ with $$\vec{R}_{i}=(\vec{r}_1...\vec{r}_N)$$ is the set of all the coordinates at time $$i$$. On the other hand we need to be very careful in the entropy calculation: first of all, we cannot calculate the "real" thermodynamic entropy but a "coarse grained" function which not necessarily approximates the fine-grained entropy. The entropy and the free energy do not admit an explicit expression in time when the system is evolving, but we can compute the differences of these quantities between equilibrium states. Here I want to give a sort of recipe for the evaluation of $$S$$: one divides the phase space into $$R$$ cells (all with the same size) and calculates the "weights" $$w_j$$, i.e., the number of particles placed in the $$j$$-th cell divided by the number of particles $$N$$. Then the coarse-grained entropy is given by $$S=-\sum_{j=1}^{R}w_j\ln(w_j)$$ P.S.: when we run a computer simulation starting from everywhere in the state space, then we expect the distribution to be approximately stationary after a large number of steps, therefore one can discard the non-equilibrium values of the quantities in order to get a more precise evaluation of the integrals.
• But your expression for the partition function does not seem correct now either. I have the sense that if my sample was uniformly distributed in $\mathbb{R}^N$ your method might work. But the sample is distributed $p(x)=e^{-\beta E(x)}$ since it comes from a Metropolis Monte Carlo simulation (I'm assuming the simulation is long enough to converge to equilibrium). Jul 9 at 13:12