Enrico M. Malatesta

Could be worse - Random topics in statistical physics, spin glasses, optimization and average case hardness

The Random Energy Model – Part I

28 December 2025 | E. Malatesta

Main definitions

The Random Energy Model (REM) is probably the easiest disordered system model with a non-trivial (spin glass) behaviour. It has been introduced and solved by B. Derrida (Derrida (1980)). It consists in having 2N2^N random independent energy levels EiE_i each one being extracted from a Gaussian distribution, which I take for simplicity to be having zero mean and variance NJN J

ρN(E)=eE22NJ2πNJ . \rho_N(E) = \frac{e^{-\frac{E^2}{2NJ}}}{\sqrt{2\pi N J}} \,.

In the following I will call by ''disorder'' the realization of the energy level samples.

Boltzmann-Gibbs distribution and thermodynamic quantities

Given an instance of the energy levels {Ei}i=12N\{E_i\}_{i=1}^{2^N} we assign to each of them a weight given by the Boltzmann-Gibbs distribution

μβ(Ei)=eβEiZN(β) \mu_{\beta}(E_i) = \frac{e^{- \beta E_i}}{Z_N(\beta)}

where β=1/T\beta = 1/T is the inverse temperature and the normalization constant ZN(β)Z_N(\beta) is the so-called partition function

ZN(β)=i=12NeβEi . Z_N(\beta) = \sum_{i=1}^{2^N} e^{- \beta E_i} \,.

From the knowledge of ZN(β)Z_N(\beta) we can compute the (intensive[1]) free energy of the model

fN(β)=1βNlnZN(β) f_N(\beta) = - \frac{1}{\beta N} \ln Z_{N}(\beta)

The free energy in turn gives access to all thermodynamic quantities of interest. Denoting by \langle \bullet \rangle the average with respect to the Boltzmann-Gibbs distribution (2) we can compute the energy

eN(β)EN=1NZN(β)i=12NEi eβEi=(βfN(β))β e_N(\beta) \equiv \frac{\langle E \rangle}{N} = \frac{1}{N Z_{N}(\beta)} \sum_{i=1}^{2^N} E_i \, e^{-\beta E_i} = \frac{\partial (\beta f_N(\beta))}{\partial \beta}

and the entropy by

sN(β)=β(eN(β)fN(β))=β2fN(β)β s_N(\beta) = \beta (e_N(\beta) - f_N(\beta)) = \beta^2 \frac{\partial f_N(\beta)}{\partial \beta}

Large NN limit and self-averageness

Computing the partition function of the REM is not an easy task. Indeed, at variance with standard non-disordered models of statistical mechanics, the Boltzmann-Gibbs distribution μβ(Ei)\mu_{\beta}(E_i), and therefore also ZN(β)Z_N(\beta) and fN(β)f_N(\beta) are themselves random variables as they all depend on the realization of the 2N2^N energy levels.

Luckily, when we perform the thermodynamic limit NN\to \infty, usually many simplifications arise, as the properties of intensive observables become independent of the disorder or the sample realization. In other words, the probability distribution of the free energy fN(β)f_N(\beta) becomes peaked around its expected value. Formally, for any ϵ>0\epsilon>0 it holds that

limNPr[fNEfN>ϵ]=0 \lim_{N\to \infty} \mathrm{Pr} \left[ \left| f_N - \mathbb{E} f_N \right| > \epsilon \right] = 0

where I have denoted by E[]\mathbb{E}[\bullet] the average over disorder given in (1). An observable satisfying such property is called self-averaging in statistical physics; this is equivalent to the concept of concentration of a random variable in math. This means that fNf_N does not appreciably fluctuate from sample to sample when NN is large.

We are interested in studying the properties of the Boltzmann-Gibbs distribution in the limit NN\to\infty.

Solving the REM using the microcanonical ensemble

Instead of working out with the temperature fixed (i.e. in the canonical ensemble), it is much easier to solve the REM by fixing the energy ee, which in statistical mechanics is the so-called microcanonical ensemble. In this ensemble one aims to compute the entropy at fixed energy ee which is given by

sN(e)=1NlnΩN(e) s_N(e) = \frac{1}{N} \ln \Omega_N(e)

where ΩN(e)\Omega_N(e) is the the number of configurations with energies in the interval [Ne,Ne+ΔE][N e, Ne+\Delta E]. It can be written as

ΩN(e)=i=12Nni(e) \Omega_N(e) = \sum_{i=1}^{2^N} n_i(e)

with

ni(e)={1 ,Ei[Ne,Ne+ΔE]0 ,otherwise n_i(e) = \left\{ \begin{align*} &1 \,, & E_i \in \left[N e, N e +\Delta E\right] \\ &0 \,, & \mathrm{otherwise} \end{align*} \right.

Note that sN(e)s_N(e) is itself a random variable, being dependent on the particular realization of the energy levels.

Physical range of energies of the REM

Markov's inequality bounds the probability that the a non-negative random variable is strictly positive by its average value. In our case the random variable ΩN(e)\Omega_N(e) is also integer valued, so one finds

Pr[ΩN(e)>0]=n>0Pr[ΩN(e)=n]n0n Pr[ΩN(e)=n]=E[ΩN(e)] \mathrm{Pr}[\Omega_N(e) > 0] = \sum_{n>0} \mathrm{Pr}[\Omega_N(e) = n] \le \sum_{n\ge 0} n \, \mathrm{Pr}[\Omega_N(e) = n] = \mathbb{E}[\Omega_N(e)]

This is also called first moment bound. Note that ΩN(e)\Omega_N(e) is a Bernoulli random variable ΩN(e)B(2N,pN(e))\Omega_N(e) \sim B(2^N, p_N(e)), where

pN(e)=NeNe+ΔEdEρN(E)ρN(Ne)ΔE p_N(e) = \int_{Ne}^{N e + \Delta E } dE \rho_N(E) \simeq \rho_N(Ne) \Delta E

having assumed a narrow window of energies ΔE\Delta E that does not scale with NN. The average of ΩN(e)\Omega_N(e) over the realization of the energy levels is therefore simple to compute and gives

E[ΩN(e)]=2NpN(e)eN(ln2e22J) \mathbb{E} [\Omega_N(e)] = 2^N p_N(e) \sim e^{N\left(\ln 2 - \frac{e^2}{2J}\right)}

This quantity goes exponentially to zero when NN\to \infty if e>e0|e| > e_0 with

e0=2Jln2 .e_0 = \sqrt{2J \ln 2} \,.

From Markov's inequality one finds therefore that the probability of finding energy levels with e>e0|e| > e_0 is exponentially small in NN. For this reason from now on we will consider as the physical interval of energies to be[2]

e[e0,e0] . e \in [- e_0, e_0] \,.

In this range the average number of energy levels with energy ee, is exponentially large in NN.

Self averaging property of ΩN(e)\Omega_N(e)

I want to now show that in the large NN limit ΩN(e)\Omega_N(e) concentrates around its average value. This can be shown by computing its variance:

Var[ΩN(e)]=2NpN(e)(1pN(e))=E[ΩN(e)]O(eN) \mathrm{Var}[\Omega_N(e)] = 2^N p_N(e) (1-p_N(e)) = \mathbb{E}[\Omega_N(e)] - O(e^{-N})

where in the last step I have neglected exponentially small corrections in NN. A simple application of Chebyshev's inequality gives ϵ>0\forall \epsilon>0

Pr[ΩN(e)E[ΩN(e)]1ϵ]Var[ΩN(e)]ϵ2 E[ΩN(e)]21ϵ2 E[ΩN(e)]N0 \mathrm{Pr}\left[\left| \frac{\Omega_N(e)}{\mathbb{E} [\Omega_N(e)]} - 1 \right| \ge \epsilon \right] \le \frac{\mathrm{Var}[\Omega_N(e)]}{\epsilon^2 \, \mathbb{E}[\Omega_N(e)]^2} \le \frac{1}{\epsilon^2 \, \mathbb{E}[\Omega_N(e)]} \overset{N\to \infty}{\longrightarrow} 0

that the random variable ΩN(e)\Omega_N(e) converges in probability exponentially fast in NN to its expected value.

This implies that average microcanonical entropy is given by

s(e)=limNsN(e)=limN1NlnE[ΩN(e)]={ln2e22J ,ee00 ,e>e0 s(e) = \lim_{N\to \infty} s_N(e) = \lim_{N\to \infty} \frac{1}{N} \ln \mathbb{E} [\Omega_N(e)] = \left\{ \begin{align*} &\ln 2 - \frac{e^2}{2 J}\,, & |e| \le e_0 \\ & 0\,, & |e| > e_0 \end{align*} \right.

Note that this expression does not depend on the coarse-graining of the energy ΔE\Delta E.

The free energy

Having found the microcanonical entropy, I now wish to find the free energy of the model which requires the inverse temperature β\beta to be fixed. This can be obtained by the so called Legendre transform which is the way one passes from one ensemble to another in statistical mechanics. For the reader not familiar with changes of ensemble this is actually obtained by grouping configurations by their energy density ee and then integrating over all possible (allowed) energies ee. Sending the coarse-graining ΔE\Delta E to zero (after the limit NN\to \infty) one finds

ZN(β)=i=12NeβNei=de i=12Nδ(eei)eβNe=e0e0de eN(s(e)βe) . Z_N(\beta) = \sum_{i=1}^{2^N} e^{- \beta N e_i} = \int d e \, \sum_{i=1}^{2^N} \delta(e-e_i) e^{- \beta N e} = \int_{-e_0}^{e_0} d e \, e^{N (s(e) - \beta e)} \,.

For large NN the integral is dominated by the maximum of the argument of the exponential (Laplace's method), that is

f(β)limNfN(β)=1β maxe[e0,e0][s(e)βe] . f(\beta) \equiv \lim_{N\to\infty} f_N(\beta) = -\frac{1}{\beta} \, \max_{e \in [-e_0, e_0]} \left[s(e) - \beta e\right] \,.

The maximization imposes

ds(e)dee=eJ=β e=βJ . \left. \frac{d s(e)}{d e}\right|_{e_\star} = - \frac{e_\star}{J} = \beta \; ⟹ \; e_\star = - \beta J \,.

This is valid only if ee_\star lies in the interval of allowed energy densities [e0,e0][-e_0, e_0]. The corresponding free energy being

f(β)=1β(ln2β2J2+β2J)=ln2ββJ2 f(\beta) = -\frac{1}{\beta} \left( \ln 2 - \frac{\beta^2 J}{2} + \beta^2 J\right) = -\frac{\ln 2 }{\beta} - \frac{\beta J}{2}
Microcanonical entropy of REM
Figure 1: Microcanonical entropy s(e)s(e) of the REM (with J=1J=1). In violet, green and light blue are straight lines tangent to s(e)s(e) such that their slope are equal to respectively β=βc, 0.6, 0.2\beta = \beta_c,\, 0.6,\, 0.2. The corresponding energy ee_\star satisfies equation (21).

If β\beta is too large (i.e. the temperature too low), the maximum of (20) is given by e=e0e_\star = -e_0. This holds when

ββce0J=2ln2J . \beta \ge \beta_c \equiv \frac{e_0}{J} = \sqrt{\frac{2 \ln 2}{J}} \,.

In this regime the free energy is constant. Summarizing the free energy of the REM is

f(β)=limNfN(β)={ln2ββJ2 if β<βc2Jln2 if ββc . f(\beta) = \lim_{N\to\infty} f_N(\beta) = \begin{cases} -\frac{\ln 2 }{\beta} - \frac{\beta J}{2} & \; \mathrm{if} \;\beta< \beta_c \\ - \sqrt{2 J \ln 2} & \; \mathrm{if} \; \beta \ge \beta_c \,. \end{cases}

This shows that at β=βc\beta = \beta_c the model exhibits a second order phase transition as the derivative of f(β)f(\beta) is continuous at β=βc\beta = \beta_c, but its second order is not. This phase transition has different names in the literature: ''freezing'', ''condensation'' and ''random first order'' (RFOT) phase transition. The first two names refers to the fact that the system ''freezes'' or ''condenses'' into the states having lowest available energies, i.e. Eie0NE_i \simeq - e_0 N.

The last name refers to the fact that while the transition is of second order in the classical sense, it discontinuous in terms of the order parameter. We have not introduced the order parameter in the REM model, but we will probably analyze it in a later post. Here I only anticipate the fact that at β=βc\beta = \beta_c the Boltzmann-Gibbs measure in eq. (2) starts being dominated by subexponential number of configurations. This can be indeed verified by computing the entropy of the REM as a function of the temperature

s(β)=β2fβ={ln2β2J2 if β<βc0 if ββc . s(\beta) = \beta^2 \frac{\partial f}{\partial \beta} = \begin{cases} \ln 2 - \frac{\beta^2 J}{2} & \; \mathrm{if} \;\beta< \beta_c \\ 0 & \; \mathrm{if} \; \beta \ge \beta_c \,. \end{cases}

Numerical checks

Below I show a simple code that computes numerically the quenched average of the free energy of the REM by sampling independent Gaussian energy levels (with J=1J=1).

using Random, Statistics, Plots, LaTeXStrings

"""
    Robust implementation of logsumexp
"""
logsumexp(x) = (m = maximum(x); m + log(sum(exp.(x .- m))))

"""
    One-sample REM free energy
"""
function rem_free_energy_sample(N::Int, β::Float64)
    M = 1 << N
    σ = sqrt(N)
    E = σ .* randn(M)
    logZ = logsumexp(- β .* E)
    return - logZ / (β * N)
end


"""
    Averaged REM free energy in the limit N → ∞
"""
function rem_free_energy_theory(β::Float64)
    βc = √(2log(2))
    if β <= βc
        return - log(2) / β - β / 2
    else
        return - √(2log(2))
    end
end

"""
    Computes the average over `nsamples` of the REM free energy
    for the values of β contained in the vector `βs`
"""
function simulate_curve(N::Int, βs::Vector{Float64}; nsamples::Int=30, seed::Int=23)
    if seed > 0
        Random.seed!(seed);
    end
    means = Float64[]
    stderrs = Float64[]
    for β in βs
        vals = [rem_free_energy_sample(N, β) for _ in 1:nsamples]
        push!(means, mean(vals))
        push!(stderrs, std(vals) / √nsamples)
    end
    return means, stderrs
end

"""
    Generates a plot comparing theory vs simulations
"""
function plot_rem_free_energy(; N=18, βmin = 0.25, βmax = 2.25, nβ=25,
                              nsamples=30,
                              seed=-23,
                              outfile="rem_free_energy.png")
    βc = √(2log(2))
    βs = collect(range(βmin, βmax, length=nβ))

    f_sim, f_err = simulate_curve(N, βs; nsamples=nsamples, seed=seed)

    plot(rem_free_energy_theory, xlim=(βmin-0.05, βmax);
        label="Theory (N → ∞)",
        linewidth=3, color=:red,
        xlabel="β", ylabel="free energy f(β)",
    )

    scatter!(βs, f_sim;
        yerror=f_err, color=:blue, markerstrokecolor=:blue,
        label="Simulation",
        markersize=3.5
    )

    vline!([βc]; label=L"\beta=\beta_c", linestyle=:dash, linewidth=3, color=:green)

    savefig(outfile)
end

plot_rem_free_energy(N=18, nsamples=30, outfile="./_assets/images/blog/rem_free_energy.png")

The results are summarized in the figure below. The numerical results reproduce the exact NN\to \infty free-energy curve and its freezing transition at β=2Jln2\beta=\sqrt{2 J \ln 2}.

Free energy of the REM
Figure 2: Theory vs Simulation of the REM (N=18, number of samples=30)

[1] i.e. scaled with 1/N1/N.
[2] Note that the value of the energy e0e_0 can be obtained by asking: given MM normal Gaussian variables XX with mean zero and variance J=1J=1, what is the typical value attained by the maximum among those? This can be obtained by imposing that the probability of observing the random variable XX to be large than a (large) value xMx_M is comparable to 1/M1/M

Pr[XxM]=xMdyey2/22π=12Erfc(xM2)exM2/22πxM=1M .\mathrm{Pr}[X \ge x_M] = \int_{x_M}^{\infty} dy \frac{e^{-y^2/2}}{\sqrt{2\pi}} = \frac{1}{2} \mathrm{Erfc}\left( \frac{x_M}{\sqrt{2}}\right) \simeq \frac{e^{-x_M^2/2}}{\sqrt{2\pi} x_M} = \frac{1}{M}\,.

Taking logs one finds at the leading order in MM

xM2lnM .x_M ≃ \sqrt{2 \ln M} \,.

Using M=2NM = 2^N and rescaling with NN one gets the result. By symmetry and a similar argument one also can get the value e0-e_0 by studying the minimum instead of the maximum.

References

[1] Derrida, Bernard, "Random-energy model: Limit of a family of disordered models", Physical Review Letters 45.2 (1980): 79.

© Enrico M. Malatesta. Last modified: March 22, 2026. Built with Franklin.jl.