A 1D Ising model with open boundary conditions, described by a Boltzmann distribution
is exactly solvable in polynomial time.
Quantity | Cost |
---|---|
Normalization, Free energy | |
Sample a configuration | |
Average energy, Entropy | |
Single-site distributions | |
Joint distributions of pairs of neighbors |
using Pkg; Pkg.add("https://github.com/stecrotti/IsingChains.jl.git")
Construct a IsingChain
instance
using IsingChains, Random
N = 100000
rng = MersenneTwister(0)
J = 2.0*randn(rng, N-1)
h = randn(rng, N)
β = 0.1
x = IsingChain(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 log-probability
σ, logp = sample(rng, x)
# single-site magnetizations <σᵢ>
m = site_magnetizations(x)
# nearest-neighbor magnetizations <σᵢσᵢ₊₁>
mneigs = neighbor_magnetizations(x)
# energy expected value
U = avg_energy(x)
# entropy
S = entropy(x)