21 std::random_device rd;
22 static_assert(std::is_same<decltype(rd()), uint32_t>::value,
23 "random_device is assumed to generate uint32_t");
24 uint64_t unsigned_seed =
25 (
static_cast<uint64_t
>(rd()) << 32) |
static_cast<uint64_t
>(rd());
27 const int64_t seed =
static_cast<int64_t
>(unsigned_seed >> 1);
32 const double poisson_mean2,
33 const int fixed_difference)
34 : a_(2.0 * std::sqrt(poisson_mean1 * poisson_mean2)),
35 N_(std::abs(fixed_difference)),
36 N_is_positive_(fixed_difference >= 0) {
37 assert(poisson_mean1 >= 0.0);
38 assert(poisson_mean2 >= 0.0);
40 ": Poisson mean N1 = ", poisson_mean1,
41 ", Poisson mean N2 = ", poisson_mean2,
42 ", N1 - N2 fixed to ", fixed_difference);
46 const double mean_sqr =
mu_ * (1.0 + 0.5 *
a_ *
r_(
N_ + 1,
a_));
49 "m = ",
m_,
" -> using gaussian sampling with mean = ",
mu_,
53 " -> using direct sampling method");
54 std::vector<double> probabilities;
55 double wi = 1.0, sum = 0.0;
59 probabilities.push_back(wi);
60 wi *= 0.25 *
a_ *
a_ / (i + 1) / (
N_ + i + 1);
64 for (
double p : probabilities) {
74 const int N_smaller = (m_ >= m_switch_method_)
77 return N_is_positive_ ? std::make_pair(N_smaller + N_, N_smaller)
78 : std::make_pair(N_smaller, N_smaller + N_);
82 const double a_inv = 1.0 / a;
90 res = 1.0 / (a_inv * 2 * (
n + i) + res);
93 assert(a / (std::sqrt(a * a + (
n + 1) * (
n + 1)) +
n + 1) <= res);
94 assert(res <= a / (std::sqrt(a * a +
n *
n) +
n));
double mu_
Mean of the Bessel distribution.
double sigma_
Standard deviation of the Bessel distribution.
std::pair< int, int > sample()
Sample two numbers from given Poissonians with a fixed difference.
static double r_(int n, double a)
Compute the ratio of two Bessel functions r(n,a) = bessel_I(n+1,a)/bessel_I(n,a) using the continued ...
static constexpr double negligible_probability_
Probabilities smaller than negligibly_probability are neglected.
double m_
Mode of the Bessel function, see for details.
static constexpr double m_switch_method_
Switching mode to normal approximation.
random::discrete_dist< double > dist_
Vector to store tabulated values of probabilities for small m case (m <6).
BesselSampler(const double poisson_mean1, const double poisson_mean2, const int fixed_difference)
Construct a BesselSampler.
const int N_
First parameter of Bessel distribution (= in ).
const double a_
Second parameter of Bessel distribution, see for details.
void reset_weights(const std::vector< T > &plist)
Reset the discrete distribution from a new probability list.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Engine engine
The engine that is used commonly by all distributions.
int64_t generate_63bit_seed()
Generates a seed with a truly random 63-bit value, if possible.
std::mt19937_64 Engine
The random number engine used is the Mersenne Twister.
double normal(const T &mean, const T &sigma)
Returns a random number drawn from a normal distribution.
static constexpr int LGrandcanThermalizer