numerics 0.1.0
Loading...
Searching...
No Matches
Boltzmann Acceptance Table

include/stochastic/boltzmann_table.hpp provides two small utilities in num::markov for computing Metropolis acceptance probabilities.

Definition

Every Metropolis sweep must decide whether to accept a proposed spin flip. The acceptance probability is \(\min(1,\, e^{-\beta \Delta E})\).

In a typical Ising sweep over \(N^2 = 90\,000\) sites this is evaluated millions of times per second. Calling std::exp at runtime is avoidable because \(\Delta E\) is discrete: for the 2D Ising model,

\[ \Delta E = 2J s \cdot \sum_{\text{nbrs}} s_j - 2F s, \qquad s,\,s_j \in \{-1,+1\},\; \sum_{\text{nbrs}} \in \{-4,-2,0,2,4\} \]

so only 10 distinct values of \(\Delta E\) occur. Pre-computing a \(2 \times 5\) lookup table eliminates exp from the hot path entirely.

Routine Reference

namespace num::markov {
// Single evaluation: min(1, exp(-beta DeltaE))
double boltzmann_accept(double dE, double beta) noexcept;
// Precompute a table for a discrete DeltaE set
std::vector<double> make_boltzmann_table(const std::vector<double>& dEs, double beta);
}
std::vector< double > make_boltzmann_table(const std::vector< double > &dEs, double beta)
double boltzmann_accept(double dE, double beta) noexcept
real beta(real a, real b)
B(a, b) – beta function.
Definition math.hpp:248

Examples

Single Probability

double p = num::markov::boltzmann_accept(dE, beta);

Flat Lookup Table

std::vector<double> dEs = {-4.0, -2.0, 0.0, 2.0, 4.0};
auto table = num::markov::make_boltzmann_table(dEs, beta);
auto probability = [&](double dE) {
const int slot = static_cast<int>((dE + 4.0) / 2.0);
return table[static_cast<std::size_t>(slot)];
};