# Hamiltonian monte carlo sampling : Energy Histogram vs Sample Histogram

I'm using HMC to sample from an N-d Gaussian. So the PDF is that of a multivariate normal distribution. HMC requires an energy function and its gradient. The library I'm using, maximizes the log(density) . So if density is the PDF of a multi-variate normal, my energy function is simply log(density). For my experiments, I used a standard multi-variate gaussian (mean = 0, covariance = I) . So in this case, $$energy=(-k/2)log(2\pi) - 0.5 x^Tx$$I used a 5D distribution as an experiment, and the HMC is initialized with a 5D zero-vector (for x)

After running the HMC iterations, I can draw my samples. From the drawn samples, I plot two histograms: Sample Histogram and Energy Histogram.

For every sample drawn, I compute the mean across the 5 dimensions. The resulting values are split across 100 bins and I get the sample histogram as below:

As you can see, my samples seem to be drawn from a Gaussian, as expected.

However, my energy histogram has a bit of a problem that I'm unable to explain. As mentioned before, energy is simply log(density). For every sample drawn, I compute it's energy and plot the corresponding histogram. According to my energy definition, low energy values should have high probability of being sampled, and the probability should monotonically decrease as the energy value increases. However, what I observe, is this

There's a steep rise to a peak, after which I see the monotonic drop. The above is for a 5D standard normal. As I increase the number of dimensions, the peak in the energy histogram shifts more towards the right. The sample histogram shows clear 0 mean. So I should observe a monotonic decrease. I don't understand why that early steep rise exists. Is it related to the size of the bins? As in, I could have sampled low energy samples, yet the "area" occupied by them is too small to show up in the energy histogram? I don't get what's going on here and would like to get some insights.

Thanks!

• Can you elaborate on what exactly happens when I compute the mean across the 5 dimensions? – Lee David Chung Lin Mar 15 at 0:39