File indexing completed on 2025-08-06 08:09:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Fatras/Kernel/detail/LandauQuantile.hpp"
0012 #include <random>
0013
0014 namespace Fatras {
0015
0016
0017
0018 using GaussDist = std::normal_distribution<double>;
0019 using UniformDist = std::uniform_real_distribution<double>;
0020 using GammaDist = std::gamma_distribution<double>;
0021 using PoissonDist = std::poisson_distribution<int>;
0022
0023
0024
0025 class LandauDist {
0026 public:
0027
0028 struct param_type {
0029 double mean = 0.;
0030 double scale = 1.;
0031
0032
0033 param_type() = default;
0034 param_type(double mean, double scale);
0035
0036
0037 param_type(const param_type &) = default;
0038 param_type &operator=(const param_type &) = default;
0039
0040
0041 bool operator==(const param_type &other) const;
0042 bool operator!=(const param_type &other) const { return !(*this == other); }
0043
0044
0045 using distribution_type = LandauDist;
0046 };
0047
0048
0049
0050 LandauDist() = default;
0051 LandauDist(double mean, double scale);
0052 LandauDist(const param_type &cfg);
0053
0054
0055 LandauDist(const LandauDist &) = default;
0056 LandauDist &operator=(const LandauDist &) = default;
0057
0058
0059 void reset() {
0060 }
0061 param_type param() const { return m_cfg; }
0062 void param(const param_type &p) { m_cfg = p; }
0063
0064
0065
0066 using result_type = double;
0067 result_type min() const;
0068 result_type max() const;
0069
0070
0071 template <typename Generator> result_type operator()(Generator &engine) {
0072 return (*this)(engine, m_cfg);
0073 }
0074
0075
0076 template <typename Generator>
0077 result_type operator()(Generator &engine, const param_type ¶ms) {
0078 double x = std::generate_canonical<float, 10>(engine);
0079 double res = params.mean + landau_quantile(x, params.scale);
0080 return res;
0081 }
0082
0083
0084 bool operator==(const LandauDist &other) const;
0085 bool operator!=(const LandauDist &other) const { return !(*this == other); }
0086
0087 private:
0088 param_type m_cfg;
0089 };
0090 }