numerics
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(-β ΔE)) inline, branch-free exp
5/// make_boltzmann_table(dEs, β) -- precompute table for a discrete ΔE set
6///
7/// Typical usage (Ising model):
8/// @code
9/// // Replace: boltz[si][ni] = (dE <= 0) ? 1.0 : exp(-beta*dE)
10/// boltz[si][ni] = num::markov::boltzmann_accept(dE, beta);
11/// @endcode
12#pragma once
13
14#include <cmath>
15#include <vector>
16
17namespace num::markov {
18
19/// Metropolis acceptance probability min(1, exp(-β ΔE)).
20inline double boltzmann_accept(double dE, double beta) noexcept {
21 return (dE <= 0.0) ? 1.0 : std::exp(-beta * dE);
22}
23
24/// Precompute a table of acceptance probabilities for a discrete set of dE values.
25inline std::vector<double> make_boltzmann_table(const std::vector<double>& dEs,
26 double beta) {
27 std::vector<double> table(dEs.size());
28 for (std::size_t i = 0; i < dEs.size(); ++i)
30 return table;
31}
32
33} // namespace num::markov
std::vector< double > make_boltzmann_table(const std::vector< double > &dEs, double beta)
Precompute a table of acceptance probabilities for a discrete set of dE values.
double boltzmann_accept(double dE, double beta) noexcept
Metropolis acceptance probability min(1, exp(-β ΔE)).
real beta(real a, real b)
B(a, b) – beta function.
Definition math.hpp:242
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.