numerics 0.1.0
Loading...
Searching...
No Matches
boltzmann_table.hpp
Go to the documentation of this file.
1/// @file stochastic/boltzmann_table.hpp
2/// @brief Boltzmann acceptance probability helpers for Metropolis MCMC.
3///
4/// boltzmann_accept(dE, beta) -- min(1, exp(-beta*dE)) inline, branch-free
5/// exp make_boltzmann_table(dEs, beta) -- precompute table for a discrete dE
6/// set
7///
8/// Typical usage (Ising model):
9/// @code
10/// // Replace: boltz[si][ni] = (dE <= 0) ? 1.0 : exp(-beta*dE)
11/// boltz[si][ni] = num::markov::boltzmann_accept(dE, beta);
12/// @endcode
13#pragma once
14
15#include <cmath>
16#include <vector>
17
18namespace num::markov {
19
20/// Metropolis acceptance probability min(1, exp(-beta*dE)).
21inline double boltzmann_accept(double dE, double beta) noexcept {
22 return (dE <= 0.0) ? 1.0 : std::exp(-beta * dE);
23}
24
25/// Precompute a table of acceptance probabilities for a discrete set of dE
26/// values.
27inline std::vector<double> make_boltzmann_table(const std::vector<double>& dEs,
28 double beta) {
29 std::vector<double> table(dEs.size());
30 for (std::size_t i = 0; i < dEs.size(); ++i)
31 table[i] = boltzmann_accept(dEs[i], beta);
32 return table;
33}
34
35} // namespace num::markov
std::vector< double > make_boltzmann_table(const std::vector< double > &dEs, double beta)
double boltzmann_accept(double dE, double beta) noexcept
Metropolis acceptance probability min(1, exp(-beta*dE)).
real beta(real a, real b)
B(a, b) – beta function.
Definition math.hpp:248