A fully-connected ferromagnetic Ising model with uniform coupling strength, described by a Boltzmann distribution
is exactly solvable in polynomial time.
Quantity | Expression | Cost |
---|---|---|
Normalization | ||
Free energy | ||
Sample a configuration | ||
Average energy | ||
Entropy | ||
Distribution of the sum of the N spins | ||
Site magnetizations | ||
Correlations |
]add UniformIsingModels
Construct a UniformIsing
instance
using UniformIsingModels, Random
N = 10
J = 2.0
rng = MersenneTwister(0)
h = randn(rng, N)
β = 0.1
x = UniformIsing(N, J, h, β)
Compute stuff
# normalization and free energy
Z = normalization(x)
F = free_energy(x)
# energy and probability of a configuration
σ = rand(rng, (-1,1), N)
E = energy(x, σ)
prob = pdf(x, σ)
# a sample along with its probability
σ, p = sample(rng, x)
# single-site magnetizations <σᵢ>
m = site_magnetizations(x)
# distribution of the sum Σᵢσᵢ of all variables
ps = sum_distribution(x)
# energy expected value
U = avg_energy(x)
# entropy
S = entropy(x)
# correlations <σᵢσⱼ> and covariances <σᵢσⱼ>-<σᵢ><σⱼ>
p = correlations(x)
c = covariances(x)
The internals rely on dynamic programming.
If you know of any implementation that's more efficient than this one I'd be very happy to learn about it!