Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
PRNGDistribution.hpp
1// INFINITY_API_PUBLIC
2
3#pragma once
4
5#include <Infinity/api.h>
6#include <Infinity/Types/Math/Math.hpp>
7
8#include <cstdint>
9#include <limits>
10#include <type_traits>
11#include <cmath>
12#include <vector>
13#include <algorithm>
14#include <initializer_list>
15
16namespace Infinity::Engine {
17
53 template<typename RealType = double>
54 class INFINITY_API_TEMPLATE UniformRealDistribution
55 {
56 static_assert(std::is_floating_point<RealType>::value,
57 "RealType must be a floating point type");
58
59 public:
60 using result_type = RealType;
61
69 {
71
73 param_type() : param_type(RealType(0)) { }
74
80 explicit param_type(RealType a, RealType b = RealType(1))
81 : m_a(a), m_b(b) {
82 #ifdef _DEBUG
83 assert(a <= b);
84 #endif
85 }
86
88 RealType a() const { return m_a; }
89
91 RealType b() const { return m_b; }
92
93 friend bool operator==(const param_type& lhs, const param_type& rhs)
94 {
95 return lhs.m_a == rhs.m_a && lhs.m_b == rhs.m_b;
96 }
97
98 friend bool operator!=(const param_type& lhs, const param_type& rhs)
99 {
100 return !(lhs == rhs);
101 }
102
103 private:
104 RealType m_a;
105 RealType m_b;
106 };
107
108 // Constructors
109
112
118 explicit UniformRealDistribution(RealType a, RealType b = RealType(1))
119 : m_param(a, b) { }
120
125 explicit UniformRealDistribution(const param_type& param)
126 : m_param(param) { }
127
128 // Reset (no-op for uniform distribution)
129
136 void reset() { }
137
138 // Parameter access
139
141 RealType a() const { return m_param.a(); }
142
144 RealType b() const { return m_param.b(); }
145
147 param_type param() const { return m_param; }
148
150 void param(const param_type& param) { m_param = param; }
151
153 result_type min() const { return a(); }
154
156 result_type max() const { return b(); }
157
158 // Generation
159
166 template<typename Generator>
168 {
169 return (*this)(g, m_param);
170 }
171
184 template<typename Generator>
185 result_type operator()(Generator& g, const param_type& param)
186 {
187 uint32_t random_bits;
188 using generator_result = typename Generator::result_type;
189
190 if constexpr (sizeof(generator_result) >= sizeof(uint32_t))
191 {
192 random_bits = static_cast<uint32_t>(g());
193 } else {
194 constexpr int bits_per_call = sizeof(generator_result) * 8;
195 constexpr int calls_needed = (32 + bits_per_call - 1) / bits_per_call;
196 random_bits = 0;
197 for (int i = 0; i < calls_needed; ++i)
198 {
199 random_bits = (random_bits << bits_per_call) | static_cast<uint32_t>(g());
200 }
201 }
202
203 RealType unit = uint32_to_real(random_bits);
204 return param.a() + unit * (param.b() - param.a());
205 }
206
207 // Comparison
208
209 friend bool operator==(const UniformRealDistribution& lhs,
210 const UniformRealDistribution& rhs)
211 {
212 return lhs.m_param == rhs.m_param;
213 }
214
215 friend bool operator!=(const UniformRealDistribution& lhs,
216 const UniformRealDistribution& rhs)
217 {
218 return !(lhs == rhs);
219 }
220
221 private:
222 param_type m_param;
223
235 static result_type uint32_to_real(uint32_t value)
236 {
237 constexpr RealType scale = RealType(1.0) / RealType(4294967296.0);
238 return static_cast<RealType>(value) * scale;
239 }
240 };
241
278 template<typename IntType = int>
279 class INFINITY_API_TEMPLATE UniformIntDistribution
280 {
281 static_assert(std::is_integral<IntType>::value,
282 "IntType must be an integral type");
283
284 public:
285 using result_type = IntType;
286
293 {
295
298
304 explicit param_type(IntType a, IntType b = std::numeric_limits<IntType>::max())
305 : m_a(a), m_b(b) {
306 #ifdef _DEBUG
307 assert(a <= b);
308 #endif
309 }
310
312 IntType a() const { return m_a; }
313
315 IntType b() const { return m_b; }
316
317 friend bool operator==(const param_type& lhs, const param_type& rhs)
318 {
319 return lhs.m_a == rhs.m_a && lhs.m_b == rhs.m_b;
320 }
321
322 friend bool operator!=(const param_type& lhs, const param_type& rhs)
323 {
324 return !(lhs == rhs);
325 }
326
327 private:
328 IntType m_a;
329 IntType m_b;
330 };
331
332 // Constructors
333
336
342 explicit UniformIntDistribution(IntType a, IntType b = std::numeric_limits<IntType>::max())
343 : m_param(a, b) { }
344
349 explicit UniformIntDistribution(const param_type& param)
350 : m_param(param) { }
351
352 // Reset (no-op for uniform distribution)
353
360 void reset() { }
361
362 // Parameter access
363
365 IntType a() const { return m_param.a(); }
366
368 IntType b() const { return m_param.b(); }
369
371 param_type param() const { return m_param; }
372
374 void param(const param_type& param) { m_param = param; }
375
377 result_type min() const { return a(); }
378
380 result_type max() const { return b(); }
381
382 // Generation
383
390 template<typename Generator>
392 {
393 return (*this)(g, m_param);
394 }
395
412 template<typename Generator>
413 result_type operator()(Generator& g, const param_type& param)
414 {
415 using UIntType = typename std::make_unsigned<IntType>::type;
416
417 const IntType a = param.a();
418 const IntType b = param.b();
419
420 if (a == b) return a;
421
422 const UIntType range = static_cast<UIntType>(b) - static_cast<UIntType>(a);
423
424 using generator_result = typename Generator::result_type;
425 uint32_t x;
426 if constexpr (sizeof(generator_result) >= sizeof(uint32_t))
427 {
428 x = static_cast<uint32_t>(g());
429 } else {
430 constexpr int bits_per_call = sizeof(generator_result) * 8;
431 constexpr int calls_needed = (32 + bits_per_call - 1) / bits_per_call;
432 x = 0;
433 for (int i = 0; i < calls_needed; ++i)
434 {
435 x = (x << bits_per_call) | static_cast<uint32_t>(g());
436 }
437 }
438
439 const UIntType range_plus_one = range + 1;
440 // Fast path for power-of-2 ranges
441 if ((range_plus_one & range) == 0)
442 {
443 return static_cast<IntType>(static_cast<UIntType>(a) + (x & range));
444 }
445
446 // Lemire's algorithm for general ranges
447 uint64_t m = static_cast<uint64_t>(x) * static_cast<uint64_t>(range_plus_one);
448 uint32_t l = static_cast<uint32_t>(m);
449
450 if (l < range_plus_one)
451 {
452 uint32_t t = -range_plus_one % range_plus_one;
453 while (l < t)
454 {
455 x = static_cast<uint32_t>(g());
456 m = static_cast<uint64_t>(x) * static_cast<uint64_t>(range_plus_one);
457 l = static_cast<uint32_t>(m);
458 }
459 }
460
461 return static_cast<IntType>(static_cast<UIntType>(a) + (m >> 32));
462 }
463
464 // Comparison
465
466 friend bool operator==(const UniformIntDistribution& lhs,
467 const UniformIntDistribution& rhs)
468 {
469 return lhs.m_param == rhs.m_param;
470 }
471
472 friend bool operator!=(const UniformIntDistribution& lhs,
473 const UniformIntDistribution& rhs)
474 {
475 return !(lhs == rhs);
476 }
477
478 private:
479 param_type m_param;
480 };
481
522 template<typename RealType = double>
523 class INFINITY_API_TEMPLATE NormalDistribution
524 {
525 static_assert(std::is_floating_point<RealType>::value,
526 "RealType must be a floating point type");
527
528 public:
529 using result_type = RealType;
530
536 struct param_type {
538
540 param_type() : param_type(RealType(0)) { }
541
547 explicit param_type(RealType mean, RealType stddev = RealType(1))
548 : m_mean(mean), m_stddev(stddev) { }
549
551 RealType mean() const { return m_mean; }
552
554 RealType stddev() const { return m_stddev; }
555
556 friend bool operator==(const param_type& lhs, const param_type& rhs)
557 {
558 return lhs.m_mean == rhs.m_mean && lhs.m_stddev == rhs.m_stddev;
559 }
560
561 friend bool operator!=(const param_type& lhs, const param_type& rhs)
562 {
563 return !(lhs == rhs);
564 }
565
566 private:
567 RealType m_mean;
568 RealType m_stddev;
569 };
570
571 // Constructors
572
575
581 explicit NormalDistribution(RealType mean, RealType stddev = RealType(1))
582 : m_param(mean, stddev), m_saved_available(false) {}
583
588 explicit NormalDistribution(const param_type& param)
589 : m_param(param), m_saved_available(false) {}
590
597 void reset() { m_saved_available = false; }
598
599 // Parameter access
600
602 RealType mean() const { return m_param.mean(); }
603
605 RealType stddev() const { return m_param.stddev(); }
606
608 param_type param() const { return m_param; }
609
617 void param(const param_type& param) { m_param = param; m_saved_available = false; }
618
620 result_type min() const { return std::numeric_limits<result_type>::lowest(); }
621
623 result_type max() const { return std::numeric_limits<result_type>::max(); }
624
625 // Generation
626
633 template<typename Generator>
634 result_type operator()(Generator& g) { return (*this)(g, m_param); }
635
655 template<typename Generator>
656 result_type operator()(Generator& g, const param_type& param)
657 {
658 // Use cached value if available
659 if (m_saved_available)
660 {
661 m_saved_available = false;
662 return param.mean() + m_saved * param.stddev();
663 }
664
665 UniformRealDistribution<RealType> uniform(RealType(0), RealType(1));
666
667 // Generate two uniform random values
668 RealType u1, u2;
669 do {
670 u1 = uniform(g);
671 } while (u1 == RealType(0)); // Avoid log(0)
672
673 u2 = uniform(g);
674
675 // Box-Muller transform
676 const RealType magnitude = std::sqrt(-RealType(2) * std::log(u1));
677 const RealType z0 = magnitude * std::cos(RealType(2) * RealType(Infinity::Types::Math::PI) * u2);
678 const RealType z1 = magnitude * std::sin(RealType(2) * RealType(Infinity::Types::Math::PI) * u2);
679
680 // Cache second value for next call
681 m_saved = z1;
682 m_saved_available = true;
683
684 // Return first value scaled to desired mean and stddev
685 return param.mean() + z0 * param.stddev();
686 }
687
688 // Comparison
689
690 friend bool operator==(const NormalDistribution& lhs, const NormalDistribution& rhs)
691 {
692 return lhs.m_param == rhs.m_param && lhs.m_saved_available == rhs.m_saved_available &&
693 (!lhs.m_saved_available || lhs.m_saved == rhs.m_saved);
694 }
695
696 friend bool operator!=(const NormalDistribution& lhs, const NormalDistribution& rhs)
697 {
698 return !(lhs == rhs);
699 }
700
701 private:
702 param_type m_param;
703 result_type m_saved = RealType(0);
704 bool m_saved_available = false;
705 };
706
743 template<typename RealType = double>
744 class INFINITY_API_TEMPLATE LognormalDistribution {
745 static_assert(std::is_floating_point<RealType>::value,
746 "RealType must be a floating point type");
747
748 public:
749 using result_type = RealType;
750
757 {
759
761 param_type() : param_type(RealType(0)) { }
762
768 explicit param_type(RealType m, RealType s = RealType(1)) : m_m(m), m_s(s) { }
769
771 RealType m() const { return m_m; }
772
774 RealType s() const { return m_s; }
775
776 friend bool operator==(const param_type& lhs, const param_type& rhs)
777 {
778 return lhs.m_m == rhs.m_m && lhs.m_s == rhs.m_s;
779 }
780 friend bool operator!=(const param_type& lhs, const param_type& rhs)
781 {
782 return !(lhs == rhs);
783 }
784
785 private:
786 RealType m_m, m_s;
787 };
788
789 // Constructors
790
793
799 explicit LognormalDistribution(RealType m, RealType s = RealType(1))
800 : m_param(m, s), m_nd(m, s) { }
801
806 explicit LognormalDistribution(const param_type& param)
807 : m_param(param), m_nd(param.m(), param.s()) { }
808
814 void reset() { m_nd.reset(); }
815
816 // Parameter access
817
819 RealType m() const { return m_param.m(); }
820
822 RealType s() const { return m_param.s(); }
823
825 param_type param() const { return m_param; }
826
828 void param(const param_type& param) { m_param = param; }
829
831 result_type min() const { return RealType(0); }
832
834 result_type max() const { return std::numeric_limits<result_type>::max(); }
835
836 // Generation
837
844 template<typename Generator>
845 result_type operator()(Generator& g) { return std::exp(m_nd(g)); }
846
858 template<typename Generator>
859 result_type operator()(Generator& g, const param_type& p)
860 {
861 NormalDistribution<RealType> nd(p.m(), p.s());
862 return std::exp(nd(g));
863 }
864
865 // Comparison
866
867 friend bool operator==(const LognormalDistribution& lhs, const LognormalDistribution& rhs)
868 {
869 return lhs.m_param == rhs.m_param && lhs.m_nd == rhs.m_nd;
870 }
871 friend bool operator!=(const LognormalDistribution& lhs, const LognormalDistribution& rhs)
872 {
873 return !(lhs == rhs);
874 }
875
876 private:
877 param_type m_param;
879 };
880
921 template<typename RealType = double>
922 class INFINITY_API_TEMPLATE CauchyDistribution
923 {
924 static_assert(std::is_floating_point<RealType>::value,
925 "RealType must be a floating point type");
926
927 public:
928 using result_type = RealType;
929
935 struct param_type {
937
939 param_type() : param_type(RealType(0)) {}
940
946 explicit param_type(RealType a, RealType b = RealType(1)) : m_a(a), m_b(b) { }
947
949 RealType a() const { return m_a; }
950
952 RealType b() const { return m_b; }
953
954 friend bool operator==(const param_type& lhs, const param_type& rhs)
955 {
956 return lhs.m_a == rhs.m_a && lhs.m_b == rhs.m_b;
957 }
958 friend bool operator!=(const param_type& lhs, const param_type& rhs)
959 {
960 return !(lhs == rhs);
961 }
962
963 private:
964 RealType m_a, m_b;
965 };
966
967 // Constructors
968
971
977 explicit CauchyDistribution(RealType a, RealType b = RealType(1)) : m_param(a, b) { }
978
983 explicit CauchyDistribution(const param_type& param) : m_param(param) { }
984
990 void reset() { }
991
992 // Parameter access
993
995 RealType a() const { return m_param.a(); }
996
998 RealType b() const { return m_param.b(); }
999
1001 param_type param() const { return m_param; }
1002
1004 void param(const param_type& param) { m_param = param; }
1005
1007 result_type min() const { return std::numeric_limits<result_type>::lowest(); }
1008
1010 result_type max() const { return std::numeric_limits<result_type>::max(); }
1011
1012 // Generation
1013
1020 template<typename Generator>
1021 result_type operator()(Generator& g) { return (*this)(g, m_param); }
1022
1034 template<typename Generator>
1035 result_type operator()(Generator& g, const param_type& param)
1036 {
1037 UniformRealDistribution<RealType> uniform(RealType(0), RealType(1));
1038 const RealType u = uniform(g);
1039 return param.a() + param.b() * std::tan(RealType(Infinity::Types::Math::PI) * (u - RealType(0.5)));
1040 }
1041
1042 // Comparison
1043
1044 friend bool operator==(const CauchyDistribution& lhs, const CauchyDistribution& rhs)
1045 {
1046 return lhs.m_param == rhs.m_param;
1047 }
1048 friend bool operator!=(const CauchyDistribution& lhs, const CauchyDistribution& rhs)
1049 {
1050 return !(lhs == rhs);
1051 }
1052
1053 private:
1054 param_type m_param;
1055 };
1056
1096 template<typename RealType = double>
1097 class INFINITY_API_TEMPLATE GammaDistribution
1098 {
1099 static_assert(std::is_floating_point<RealType>::value,
1100 "RealType must be a floating point type");
1101
1102 public:
1103 using result_type = RealType;
1104
1111 {
1113
1115 param_type() : param_type(RealType(1)) {}
1116
1122 explicit param_type(RealType alpha, RealType beta = RealType(1))
1123 : m_alpha(alpha), m_beta(beta) {}
1124
1126 RealType alpha() const { return m_alpha; }
1127
1129 RealType beta() const { return m_beta; }
1130
1131 friend bool operator==(const param_type& lhs, const param_type& rhs)
1132 {
1133 return lhs.m_alpha == rhs.m_alpha && lhs.m_beta == rhs.m_beta;
1134 }
1135 friend bool operator!=(const param_type& lhs, const param_type& rhs)
1136 {
1137 return !(lhs == rhs);
1138 }
1139
1140 private:
1141 RealType m_alpha, m_beta;
1142 };
1143
1144 // Constructors
1145
1148
1154 explicit GammaDistribution(RealType alpha, RealType beta = RealType(1))
1155 : m_param(alpha, beta), m_nd() { }
1156
1161 explicit GammaDistribution(const param_type& param)
1162 : m_param(param), m_nd() { }
1163
1169 void reset() { m_nd.reset(); }
1170
1171 // Parameter access
1172
1174 RealType alpha() const { return m_param.alpha(); }
1175
1177 RealType beta() const { return m_param.beta(); }
1178
1180 param_type param() const { return m_param; }
1181
1183 void param(const param_type& param) { m_param = param; }
1184
1186 result_type min() const { return RealType(0); }
1187
1189 result_type max() const { return std::numeric_limits<result_type>::max(); }
1190
1191 // Generation
1192
1199 template<typename Generator>
1200 result_type operator()(Generator& g) { return (*this)(g, m_param); }
1201
1226 template<typename Generator>
1227 result_type operator()(Generator& g, const param_type& param)
1228 {
1229 const RealType alpha = param.alpha();
1230 const RealType beta = param.beta();
1231
1232 if (alpha < RealType(1))
1233 {
1234 // Transformation method for alpha < 1
1235 // Generate Gamma(alpha+1) and scale by U^(1/alpha)
1236 RealType result = (*this)(g, param_type(alpha + RealType(1), RealType(1)));
1237 UniformRealDistribution<RealType> uniform(RealType(0), RealType(1));
1238 return result * std::pow(uniform(g), RealType(1) / alpha) * beta;
1239 }
1240
1241 // Marsaglia & Tsang (2000) method for alpha >= 1
1242 const RealType d = alpha - RealType(1) / RealType(3);
1243 const RealType c = RealType(1) / std::sqrt(RealType(9) * d);
1244
1245 UniformRealDistribution<RealType> uniform(RealType(0), RealType(1));
1246
1247 while (true)
1248 {
1249 RealType x, v;
1250 // Generate candidate from transformed normal
1251 do {
1252 x = m_nd(g);
1253 v = RealType(1) + c * x;
1254 } while (v <= RealType(0)); // Ensure v > 0
1255
1256 v = v * v * v;
1257 const RealType u = uniform(g);
1258 const RealType x_sq = x * x;
1259
1260 // Squeeze test (fast acceptance)
1261 if (u < RealType(1) - RealType(0.0331) * x_sq * x_sq)
1262 {
1263 return d * v * beta;
1264 }
1265
1266 // Log test (slower but exact)
1267 if (std::log(u) < RealType(0.5) * x_sq + d * (RealType(1) - v + std::log(v)))
1268 {
1269 return d * v * beta;
1270 }
1271
1272 // Rejection - loop continues
1273 }
1274 }
1275
1276 // Comparison
1277
1278 friend bool operator==(const GammaDistribution& lhs, const GammaDistribution& rhs)
1279 {
1280 return lhs.m_param == rhs.m_param && lhs.m_nd == rhs.m_nd;
1281 }
1282 friend bool operator!=(const GammaDistribution& lhs, const GammaDistribution& rhs)
1283 {
1284 return !(lhs == rhs);
1285 }
1286
1287 private:
1288 param_type m_param;
1290 };
1291
1330 template<typename RealType = double>
1331 class INFINITY_API_TEMPLATE ChiSquaredDistribution
1332 {
1333 static_assert(std::is_floating_point<RealType>::value,
1334 "RealType must be a floating point type");
1335
1336 public:
1337 using result_type = RealType;
1338
1344 struct param_type {
1346
1348 param_type() : param_type(RealType(1)) { }
1349
1354 explicit param_type(RealType n) : m_n(n) { }
1355
1357 RealType n() const { return m_n; }
1358
1359 friend bool operator==(const param_type& lhs, const param_type& rhs)
1360 {
1361 return lhs.m_n == rhs.m_n;
1362 }
1363 friend bool operator!=(const param_type& lhs, const param_type& rhs)
1364 {
1365 return !(lhs == rhs);
1366 }
1367
1368 private:
1369 RealType m_n;
1370 };
1371
1372 // Constructors
1373
1376
1381 explicit ChiSquaredDistribution(RealType n)
1382 : m_param(n)
1383 {
1384 m_gd = new GammaDistribution<result_type>(n / RealType(2), RealType(2));
1385 }
1386
1391 explicit ChiSquaredDistribution(const param_type& param)
1392 : m_param(param)
1393 {
1394 m_gd = new GammaDistribution<result_type>(param.n() / RealType(2), RealType(2));
1395 }
1396
1402 void reset()
1403 {
1404 if (m_gd) m_gd->reset();
1405 }
1406
1407 // Parameter access
1408
1410 RealType n() const { return m_param.n(); }
1411
1413 param_type param() const { return m_param; }
1414
1422 void param(const param_type& param)
1423 {
1424 m_param = param;
1425 delete m_gd;
1426 m_gd = new GammaDistribution<result_type>(param.n() / RealType(2), RealType(2));
1427 }
1428
1430 result_type min() const { return RealType(0); }
1431
1433 result_type max() const { return std::numeric_limits<result_type>::max(); }
1434
1435 // Generation
1436
1447 template<typename Generator>
1449 {
1450 return RealType(2) * (*m_gd)(g);
1451 }
1452
1463 template<typename Generator>
1464 result_type operator()(Generator& g, const param_type& param)
1465 {
1466 GammaDistribution<result_type> gd(param.n() / RealType(2), RealType(2));
1467 return RealType(2) * gd(g);
1468 }
1469
1470 // Comparison
1471
1473 {
1474 if (lhs.m_param != rhs.m_param) return false;
1475 if ((lhs.m_gd == nullptr) != (rhs.m_gd == nullptr)) return false;
1476 if (lhs.m_gd && rhs.m_gd && *lhs.m_gd != *rhs.m_gd) return false;
1477 return true;
1478 }
1480 {
1481 return !(lhs == rhs);
1482 }
1483
1484 private:
1485 param_type m_param;
1486 class GammaDistribution<result_type>* m_gd;
1487 };
1488
1523 template<typename RealType = double>
1524 class INFINITY_API_TEMPLATE FisherFDistribution
1525 {
1526 static_assert(std::is_floating_point<RealType>::value,
1527 "RealType must be a floating point type");
1528
1529 public:
1530 using result_type = RealType;
1531
1538 {
1540
1542 param_type() : param_type(RealType(1)) { }
1543
1549 explicit param_type(RealType m, RealType n = RealType(1)) : m_m(m), m_n(n) { }
1550
1552 RealType m() const { return m_m; }
1553
1555 RealType n() const { return m_n; }
1556
1557 friend bool operator==(const param_type& lhs, const param_type& rhs)
1558 {
1559 return lhs.m_m == rhs.m_m && lhs.m_n == rhs.m_n;
1560 }
1561 friend bool operator!=(const param_type& lhs, const param_type& rhs)
1562 {
1563 return !(lhs == rhs);
1564 }
1565
1566 private:
1567 RealType m_m, m_n;
1568 };
1569
1570 // Constructors
1571
1574
1580 explicit FisherFDistribution(RealType m, RealType n = RealType(1))
1581 : m_param(m, n)
1582 {
1583 m_gd_x = new GammaDistribution<result_type>(m / RealType(2), RealType(2));
1584 m_gd_y = new GammaDistribution<result_type>(n / RealType(2), RealType(2));
1585 }
1586
1591 explicit FisherFDistribution(const param_type& param)
1592 : m_param(param)
1593 {
1594 m_gd_x = new GammaDistribution<result_type>(param.m() / RealType(2), RealType(2));
1595 m_gd_y = new GammaDistribution<result_type>(param.n() / RealType(2), RealType(2));
1596 }
1597
1603 void reset()
1604 {
1605 if (m_gd_x) m_gd_x->reset();
1606 if (m_gd_y) m_gd_y->reset();
1607 }
1608
1609 // Parameter access
1610
1612 RealType m() const { return m_param.m(); }
1613
1615 RealType n() const { return m_param.n(); }
1616
1618 param_type param() const { return m_param; }
1619
1627 void param(const param_type& param)
1628 {
1629 m_param = param;
1630 delete m_gd_x;
1631 delete m_gd_y;
1632 m_gd_x = new GammaDistribution<result_type>(param.m() / RealType(2), RealType(2));
1633 m_gd_y = new GammaDistribution<result_type>(param.n() / RealType(2), RealType(2));
1634 }
1635
1637 result_type min() const { return RealType(0); }
1638
1640 result_type max() const { return std::numeric_limits<result_type>::max(); }
1641
1642 // Generation
1643
1654 template<typename Generator>
1656 {
1657 const RealType x = (*m_gd_x)(g);
1658 const RealType y = (*m_gd_y)(g);
1659 return (x * m_param.n()) / (y * m_param.m());
1660 }
1661
1670 template<typename Generator>
1671 result_type operator()(Generator& g, const param_type& param)
1672 {
1673 GammaDistribution<result_type> gd_x(param.m() / RealType(2), RealType(2));
1674 GammaDistribution<result_type> gd_y(param.n() / RealType(2), RealType(2));
1675 const RealType x = gd_x(g);
1676 const RealType y = gd_y(g);
1677 return (x * param.n()) / (y * param.m());
1678 }
1679
1680 // Comparison
1681
1682 friend bool operator==(const FisherFDistribution& lhs, const FisherFDistribution& rhs)
1683 {
1684 if (lhs.m_param != rhs.m_param) return false;
1685 if ((lhs.m_gd_x == nullptr) != (rhs.m_gd_x == nullptr)) return false;
1686 if ((lhs.m_gd_y == nullptr) != (rhs.m_gd_y == nullptr)) return false;
1687 if (lhs.m_gd_x && rhs.m_gd_x && *lhs.m_gd_x != *rhs.m_gd_x) return false;
1688 if (lhs.m_gd_y && rhs.m_gd_y && *lhs.m_gd_y != *rhs.m_gd_y) return false;
1689 return true;
1690 }
1691 friend bool operator!=(const FisherFDistribution& lhs, const FisherFDistribution& rhs)
1692 {
1693 return !(lhs == rhs);
1694 }
1695
1696 private:
1697 param_type m_param;
1698 class GammaDistribution<result_type>* m_gd_x;
1699 class GammaDistribution<result_type>* m_gd_y;
1700 };
1701
1740 template<typename RealType = double>
1741 class INFINITY_API_TEMPLATE StudentTDistribution
1742 {
1743 static_assert(std::is_floating_point<RealType>::value,
1744 "RealType must be a floating point type");
1745
1746 public:
1747 using result_type = RealType;
1748
1755 {
1757
1759 param_type() : param_type(RealType(1)) { }
1760
1765 explicit param_type(RealType n) : m_n(n) { }
1766
1768 RealType n() const { return m_n; }
1769
1770 friend bool operator==(const param_type& lhs, const param_type& rhs)
1771 {
1772 return lhs.m_n == rhs.m_n;
1773 }
1774 friend bool operator!=(const param_type& lhs, const param_type& rhs)
1775 {
1776 return !(lhs == rhs);
1777 }
1778
1779 private:
1780 RealType m_n;
1781 };
1782
1783 // Constructors
1784
1787
1792 explicit StudentTDistribution(RealType n)
1793 : m_param(n), m_nd()
1794 {
1795 m_gd = new GammaDistribution<result_type>(n / RealType(2), RealType(2));
1796 }
1797
1802 explicit StudentTDistribution(const param_type& param)
1803 : m_param(param), m_nd()
1804 {
1805 m_gd = new GammaDistribution<result_type>(param.n() / RealType(2), RealType(2));
1806 }
1807
1813 void reset()
1814 {
1815 m_nd.reset();
1816 if (m_gd) m_gd->reset();
1817 }
1818
1819 // Parameter access
1820
1822 RealType n() const { return m_param.n(); }
1823
1825 param_type param() const { return m_param; }
1826
1834 void param(const param_type& param)
1835 {
1836 m_param = param;
1837 delete m_gd;
1838 m_gd = new GammaDistribution<result_type>(param.n() / RealType(2), RealType(2));
1839 }
1840
1842 result_type min() const { return std::numeric_limits<result_type>::lowest(); }
1843
1845 result_type max() const { return std::numeric_limits<result_type>::max(); }
1846
1847 // Generation
1848
1859 template<typename Generator>
1861 {
1862 const RealType z = m_nd(g);
1863 const RealType v = (*m_gd)(g);
1864 return z * std::sqrt(m_param.n() / v);
1865 }
1866
1875 template<typename Generator>
1876 result_type operator()(Generator& g, const param_type& param)
1877 {
1879 GammaDistribution<result_type> gd(param.n() / RealType(2), RealType(2));
1880 const RealType z = nd(g);
1881 const RealType v = gd(g);
1882 return z * std::sqrt(param.n() / v);
1883 }
1884
1885 // Comparison
1886
1887 friend bool operator==(const StudentTDistribution& lhs, const StudentTDistribution& rhs)
1888 {
1889 if (lhs.m_param != rhs.m_param) return false;
1890 if (lhs.m_nd != rhs.m_nd) return false;
1891 if ((lhs.m_gd == nullptr) != (rhs.m_gd == nullptr)) return false;
1892 if (lhs.m_gd && rhs.m_gd && *lhs.m_gd != *rhs.m_gd) return false;
1893 return true;
1894 }
1895 friend bool operator!=(const StudentTDistribution& lhs, const StudentTDistribution& rhs)
1896 {
1897 return !(lhs == rhs);
1898 }
1899
1900 private:
1901 param_type m_param;
1903 class GammaDistribution<result_type>* m_gd;
1904 };
1905
1947 template<typename RealType = double>
1948 class INFINITY_API_TEMPLATE ExponentialDistribution
1949 {
1950 static_assert(std::is_floating_point<RealType>::value,
1951 "RealType must be a floating point type");
1952
1953 public:
1954 using result_type = RealType;
1955
1962 {
1964
1966 param_type() : param_type(RealType(1)) { }
1967
1972 explicit param_type(RealType lambda) : m_lambda(lambda) { }
1973
1975 RealType lambda() const { return m_lambda; }
1976
1977 friend bool operator==(const param_type& lhs, const param_type& rhs)
1978 {
1979 return lhs.m_lambda == rhs.m_lambda;
1980 }
1981 friend bool operator!=(const param_type& lhs, const param_type& rhs)
1982 {
1983 return !(lhs == rhs);
1984 }
1985
1986 private:
1987 RealType m_lambda;
1988 };
1989
1990 // Constructors
1991
1994
1999 explicit ExponentialDistribution(RealType lambda) : m_param(lambda) { }
2000
2005 explicit ExponentialDistribution(const param_type& param) : m_param(param) { }
2006
2012 void reset() { }
2013
2014 // Parameter access
2015
2017 RealType lambda() const { return m_param.lambda(); }
2018
2020 param_type param() const { return m_param; }
2021
2023 void param(const param_type& param) { m_param = param; }
2024
2026 result_type min() const { return RealType(0); }
2027
2029 result_type max() const { return std::numeric_limits<result_type>::max(); }
2030
2031 // Generation
2032
2039 template<typename Generator>
2040 result_type operator()(Generator& g) { return (*this)(g, m_param); }
2041
2055 template<typename Generator>
2056 result_type operator()(Generator& g, const param_type& param)
2057 {
2058 UniformRealDistribution<RealType> uniform(RealType(0), RealType(1));
2059 RealType u;
2060 do {
2061 u = uniform(g);
2062 } while (u == RealType(0) || u == RealType(1));
2063
2064 return -std::log(RealType(1) - u) / param.lambda();
2065 }
2066
2067 // Comparison
2068
2070 {
2071 return lhs.m_param == rhs.m_param;
2072 }
2074 {
2075 return !(lhs == rhs);
2076 }
2077
2078 private:
2079 param_type m_param;
2080 };
2081
2122 template<typename RealType = double>
2123 class INFINITY_API_TEMPLATE WeibullDistribution
2124 {
2125 static_assert(std::is_floating_point<RealType>::value,
2126 "RealType must be a floating point type");
2127
2128 public:
2129 using result_type = RealType;
2130
2137 {
2139
2141 param_type() : param_type(RealType(1)) {}
2142
2148 explicit param_type(RealType a, RealType b = RealType(1)) : m_a(a), m_b(b) { }
2149
2151 RealType a() const { return m_a; }
2152
2154 RealType b() const { return m_b; }
2155
2156 friend bool operator==(const param_type& lhs, const param_type& rhs)
2157 {
2158 return lhs.m_a == rhs.m_a && lhs.m_b == rhs.m_b;
2159 }
2160 friend bool operator!=(const param_type& lhs, const param_type& rhs)
2161 {
2162 return !(lhs == rhs);
2163 }
2164
2165 private:
2166 RealType m_a, m_b;
2167 };
2168
2169 // Constructors
2170
2173
2179 explicit WeibullDistribution(RealType a, RealType b = RealType(1)) : m_param(a, b) { }
2180
2185 explicit WeibullDistribution(const param_type& param) : m_param(param) { }
2186
2192 void reset() { }
2193
2194 // Parameter access
2195
2197 RealType a() const { return m_param.a(); }
2198
2200 RealType b() const { return m_param.b(); }
2201
2203 param_type param() const { return m_param; }
2204
2206 void param(const param_type& param) { m_param = param; }
2207
2209 result_type min() const { return RealType(0); }
2210
2212 result_type max() const { return std::numeric_limits<result_type>::max(); }
2213
2214 // Generation
2215
2222 template<typename Generator>
2223 result_type operator()(Generator& g) { return (*this)(g, m_param); }
2224
2236 template<typename Generator>
2237 result_type operator()(Generator& g, const param_type& param)
2238 {
2239 ExponentialDistribution<RealType> exp(RealType(1));
2240 return param.b() * std::pow(exp(g), RealType(1) / param.a());
2241 }
2242
2243 // Comparison
2244
2245 friend bool operator==(const WeibullDistribution& lhs, const WeibullDistribution& rhs)
2246 {
2247 return lhs.m_param == rhs.m_param;
2248 }
2249 friend bool operator!=(const WeibullDistribution& lhs, const WeibullDistribution& rhs)
2250 {
2251 return !(lhs == rhs);
2252 }
2253
2254 private:
2255 param_type m_param;
2256 };
2257
2298 template<typename RealType = double>
2299 class INFINITY_API_TEMPLATE ExtremeValueDistribution
2300 {
2301 static_assert(std::is_floating_point<RealType>::value,
2302 "RealType must be a floating point type");
2303
2304 public:
2305 using result_type = RealType;
2306
2313 {
2315
2317 param_type() : param_type(RealType(0)) { }
2318
2324 explicit param_type(RealType a, RealType b = RealType(1)) : m_a(a), m_b(b) { }
2325
2327 RealType a() const { return m_a; }
2328
2330 RealType b() const { return m_b; }
2331
2332 friend bool operator==(const param_type& lhs, const param_type& rhs)
2333 {
2334 return lhs.m_a == rhs.m_a && lhs.m_b == rhs.m_b;
2335 }
2336 friend bool operator!=(const param_type& lhs, const param_type& rhs)
2337 {
2338 return !(lhs == rhs);
2339 }
2340
2341 private:
2342 RealType m_a, m_b;
2343 };
2344
2345 // Constructors
2346
2349
2355 explicit ExtremeValueDistribution(RealType a, RealType b = RealType(1)) : m_param(a, b) { }
2356
2361 explicit ExtremeValueDistribution(const param_type& param) : m_param(param) { }
2362
2368 void reset() { }
2369
2370 // Parameter access
2371
2373 RealType a() const { return m_param.a(); }
2374
2376 RealType b() const { return m_param.b(); }
2377
2379 param_type param() const { return m_param; }
2380
2382 void param(const param_type& param) { m_param = param; }
2383
2385 result_type min() const { return std::numeric_limits<result_type>::lowest(); }
2386
2388 result_type max() const { return std::numeric_limits<result_type>::max(); }
2389
2390 // Generation
2391
2398 template<typename Generator>
2399 result_type operator()(Generator& g) { return (*this)(g, m_param); }
2400
2415 template<typename Generator>
2416 result_type operator()(Generator& g, const param_type& param)
2417 {
2418 UniformRealDistribution<RealType> uniform(RealType(0), RealType(1));
2419 RealType u;
2420 do {
2421 u = uniform(g);
2422 } while (u == RealType(0) || u == RealType(1));
2423
2424 return param.a() - param.b() * std::log(-std::log(u));
2425 }
2426
2427 // Comparison
2428
2430 {
2431 return lhs.m_param == rhs.m_param;
2432 }
2434 {
2435 return !(lhs == rhs);
2436 }
2437
2438 private:
2439 param_type m_param;
2440 };
2441
2485 class INFINITY_API_TEMPLATE BernoulliDistribution
2486 {
2487 public:
2488 using result_type = bool;
2489
2495 struct param_type {
2497
2500
2505 explicit param_type(double p) : m_p(p) { }
2506
2508 double p() const { return m_p; }
2509
2510 friend bool operator==(const param_type& lhs, const param_type& rhs)
2511 {
2512 return lhs.m_p == rhs.m_p;
2513 }
2514 friend bool operator!=(const param_type& lhs, const param_type& rhs)
2515 {
2516 return !(lhs == rhs);
2517 }
2518
2519 private:
2520 double m_p;
2521 };
2522
2523 // Constructors
2524
2527
2532 explicit BernoulliDistribution(double p) : m_param(p) { }
2533
2538 explicit BernoulliDistribution(const param_type& param) : m_param(param) { }
2539
2545 void reset() { }
2546
2547 // Parameter access
2548
2550 double p() const { return m_param.p(); }
2551
2553 param_type param() const { return m_param; }
2554
2556 void param(const param_type& param) { m_param = param; }
2557
2559 result_type min() const { return false; }
2560
2562 result_type max() const { return true; }
2563
2564 // Generation
2565
2572 template<typename Generator>
2573 result_type operator()(Generator& g) { return (*this)(g, m_param); }
2574
2586 template<typename Generator>
2587 result_type operator()(Generator& g, const param_type& param)
2588 {
2589 UniformRealDistribution<double> uniform(0.0, 1.0);
2590 return uniform(g) < param.p();
2591 }
2592
2593 // Comparison
2594
2595 friend bool operator==(const BernoulliDistribution& lhs, const BernoulliDistribution& rhs)
2596 {
2597 return lhs.m_param == rhs.m_param;
2598 }
2599 friend bool operator!=(const BernoulliDistribution& lhs, const BernoulliDistribution& rhs)
2600 {
2601 return !(lhs == rhs);
2602 }
2603
2604 private:
2605 param_type m_param;
2606 };
2607
2649 template<typename IntType = int>
2650 class INFINITY_API_TEMPLATE BinomialDistribution
2651 {
2652 static_assert(std::is_integral<IntType>::value,
2653 "IntType must be an integral type");
2654
2655 public:
2656 using result_type = IntType;
2657
2663 struct param_type {
2665
2668
2674 explicit param_type(IntType t, double p = 0.5) : m_t(t), m_p(p) { }
2675
2677 IntType t() const { return m_t; }
2678
2680 double p() const { return m_p; }
2681
2682 friend bool operator==(const param_type& lhs, const param_type& rhs)
2683 {
2684 return lhs.m_t == rhs.m_t && lhs.m_p == rhs.m_p;
2685 }
2686 friend bool operator!=(const param_type& lhs, const param_type& rhs)
2687 {
2688 return !(lhs == rhs);
2689 }
2690
2691 private:
2692 IntType m_t;
2693 double m_p;
2694 };
2695
2696 // Constructors
2697
2700
2706 explicit BinomialDistribution(IntType t, double p = 0.5)
2707 : m_param(t, p), m_nd(nullptr)
2708 {
2709 if (t * p >= 5.0 && t * (1.0 - p) >= 5.0)
2710 {
2711 double mean = t * p;
2712 double stddev = std::sqrt(t * p * (1.0 - p));
2713 m_nd = new NormalDistribution<double>(mean, stddev);
2714 }
2715 }
2716
2721 explicit BinomialDistribution(const param_type& param)
2722 : m_param(param), m_nd(nullptr)
2723 {
2724 IntType t = param.t();
2725 double p = param.p();
2726 if (t * p >= 5.0 && t * (1.0 - p) >= 5.0)
2727 {
2728 double mean = t * p;
2729 double stddev = std::sqrt(t * p * (1.0 - p));
2730 m_nd = new NormalDistribution<double>(mean, stddev);
2731 }
2732 }
2733
2739 void reset()
2740 {
2741 if (m_nd) m_nd->reset();
2742 }
2743
2744 // Parameter access
2745
2747 IntType t() const { return m_param.t(); }
2748
2750 double p() const { return m_param.p(); }
2751
2753 param_type param() const { return m_param; }
2754
2762 void param(const param_type& param)
2763 {
2764 m_param = param;
2765 delete m_nd;
2766 m_nd = nullptr;
2767 IntType t = param.t();
2768 double p = param.p();
2769 if (t * p >= 5.0 && t * (1.0 - p) >= 5.0)
2770 {
2771 double mean = t * p;
2772 double stddev = std::sqrt(t * p * (1.0 - p));
2773 m_nd = new NormalDistribution<double>(mean, stddev);
2774 }
2775 }
2776
2778 result_type min() const { return 0; }
2779
2781 result_type max() const { return m_param.t(); }
2782
2783 // Generation
2784
2791 template<typename Generator>
2793 {
2794 return (*this)(g, m_param);
2795 }
2796
2815 template<typename Generator>
2816 result_type operator()(Generator& g, const param_type& param)
2817 {
2818 const IntType t = param.t();
2819 const double p = param.p();
2820
2821 if (t * p >= 5.0 && t * (1.0 - p) >= 5.0)
2822 {
2823 // Normal approximation with continuity correction
2824 double mean = t * p;
2825 double stddev = std::sqrt(t * p * (1.0 - p));
2826 NormalDistribution<double> nd(mean, stddev);
2827 IntType result;
2828 do {
2829 result = static_cast<IntType>(std::floor(nd(g) + 0.5));
2830 } while (result < 0 || result > t);
2831 return result;
2832 } else {
2833 // Direct method: simulate each trial
2834 BernoulliDistribution bern(p);
2835 IntType sum = 0;
2836 for (IntType i = 0; i < t; ++i)
2837 {
2838 if (bern(g)) ++sum;
2839 }
2840 return sum;
2841 }
2842 }
2843
2844 // Comparison
2845
2846 friend bool operator==(const BinomialDistribution& lhs, const BinomialDistribution& rhs)
2847 {
2848 if (lhs.m_param != rhs.m_param) return false;
2849 if ((lhs.m_nd == nullptr) != (rhs.m_nd == nullptr)) return false;
2850 if (lhs.m_nd && rhs.m_nd && *lhs.m_nd != *rhs.m_nd) return false;
2851 return true;
2852 }
2853 friend bool operator!=(const BinomialDistribution& lhs, const BinomialDistribution& rhs)
2854 {
2855 return !(lhs == rhs);
2856 }
2857
2858 private:
2859 param_type m_param;
2860 class NormalDistribution<double>* m_nd;
2861 };
2862
2903 template<typename IntType = int>
2904 class INFINITY_API_TEMPLATE GeometricDistribution
2905 {
2906 static_assert(std::is_integral<IntType>::value,
2907 "IntType must be an integral type");
2908
2909 public:
2910 using result_type = IntType;
2911
2917 struct param_type {
2919
2922
2927 explicit param_type(double p) : m_p(p) { }
2928
2930 double p() const { return m_p; }
2931
2932 friend bool operator==(const param_type& lhs, const param_type& rhs)
2933 {
2934 return lhs.m_p == rhs.m_p;
2935 }
2936 friend bool operator!=(const param_type& lhs, const param_type& rhs)
2937 {
2938 return !(lhs == rhs);
2939 }
2940
2941 private:
2942 double m_p;
2943 };
2944
2945 // Constructors
2946
2949
2954 explicit GeometricDistribution(double p) : m_param(p) { }
2955
2960 explicit GeometricDistribution(const param_type& param) : m_param(param) { }
2961
2967 void reset() { }
2968
2969 // Parameter access
2970
2972 double p() const { return m_param.p(); }
2973
2975 param_type param() const { return m_param; }
2976
2978 void param(const param_type& param) { m_param = param; }
2979
2981 result_type min() const { return 0; }
2982
2984 result_type max() const { return std::numeric_limits<result_type>::max(); }
2985
2986 // Generation
2987
2994 template<typename Generator>
2995 result_type operator()(Generator& g) { return (*this)(g, m_param); }
2996
3012 template<typename Generator>
3013 result_type operator()(Generator& g, const param_type& param)
3014 {
3015 UniformRealDistribution<double> uniform(0.0, 1.0);
3016 double u;
3017 do {
3018 u = uniform(g);
3019 } while (u == 0.0 || u == 1.0);
3020
3021 const double log_1_p = std::log(1.0 - param.p());
3022 return static_cast<IntType>(std::ceil(std::log(u) / log_1_p) - 1.0);
3023 }
3024
3025 // Comparison
3026
3027 friend bool operator==(const GeometricDistribution& lhs, const GeometricDistribution& rhs)
3028 {
3029 return lhs.m_param == rhs.m_param;
3030 }
3031 friend bool operator!=(const GeometricDistribution& lhs, const GeometricDistribution& rhs)
3032 {
3033 return !(lhs == rhs);
3034 }
3035
3036 private:
3037 param_type m_param;
3038 };
3039
3081 template<typename IntType = int>
3082 class INFINITY_API_TEMPLATE PoissonDistribution
3083 {
3084 static_assert(std::is_integral<IntType>::value,
3085 "IntType must be an integral type");
3086
3087 public:
3088 using result_type = IntType;
3089
3095 struct param_type {
3097
3100
3105 explicit param_type(double mean) : m_mean(mean) { }
3106
3108 double mean() const { return m_mean; }
3109
3110 friend bool operator==(const param_type& lhs, const param_type& rhs)
3111 {
3112 return lhs.m_mean == rhs.m_mean;
3113 }
3114 friend bool operator!=(const param_type& lhs, const param_type& rhs)
3115 {
3116 return !(lhs == rhs);
3117 }
3118
3119 private:
3120 double m_mean;
3121 };
3122
3123 // Constructors
3124
3127
3132 explicit PoissonDistribution(double mean)
3133 : m_param(mean), m_nd(nullptr)
3134 {
3135 if (mean >= 10.0)
3136 {
3137 m_nd = new NormalDistribution<double>(mean, std::sqrt(mean));
3138 }
3139 }
3140
3145 explicit PoissonDistribution(const param_type& param)
3146 : m_param(param), m_nd(nullptr)
3147 {
3148 if (param.mean() >= 10.0)
3149 {
3150 m_nd = new NormalDistribution<double>(param.mean(), std::sqrt(param.mean()));
3151 }
3152 }
3153
3159 void reset()
3160 {
3161 if (m_nd) m_nd->reset();
3162 }
3163
3164 // Parameter access
3165
3167 double mean() const { return m_param.mean(); }
3168
3170 param_type param() const { return m_param; }
3171
3179 void param(const param_type& param)
3180 {
3181 m_param = param;
3182 delete m_nd;
3183 m_nd = nullptr;
3184 if (param.mean() >= 10.0)
3185 {
3186 m_nd = new NormalDistribution<double>(param.mean(), std::sqrt(param.mean()));
3187 }
3188 }
3189
3191 result_type min() const { return 0; }
3192
3194 result_type max() const { return std::numeric_limits<result_type>::max(); }
3195
3196 // Generation
3197
3204 template<typename Generator>
3206 {
3207 return (*this)(g, m_param);
3208 }
3209
3233 template<typename Generator>
3234 result_type operator()(Generator& g, const param_type& param)
3235 {
3236 const double mean = param.mean();
3237
3238 if (mean >= 10.0)
3239 {
3240 // Normal approximation for large mean
3241 NormalDistribution<double> nd(mean, std::sqrt(mean));
3242 IntType result;
3243 do {
3244 result = static_cast<IntType>(std::floor(nd(g) + 0.5));
3245 } while (result < 0);
3246 return result;
3247 } else {
3248 // Knuth method for small mean
3249 UniformRealDistribution<double> uniform(0.0, 1.0);
3250 const double l = std::exp(-mean);
3251 IntType k = 0;
3252 double p = 1.0;
3253
3254 do {
3255 ++k;
3256 p *= uniform(g);
3257 } while (p > l);
3258
3259 return k - 1;
3260 }
3261 }
3262
3263 // Comparison
3264
3265 friend bool operator==(const PoissonDistribution& lhs, const PoissonDistribution& rhs)
3266 {
3267 if (lhs.m_param != rhs.m_param) return false;
3268 if ((lhs.m_nd == nullptr) != (rhs.m_nd == nullptr)) return false;
3269 if (lhs.m_nd && rhs.m_nd && *lhs.m_nd != *rhs.m_nd) return false;
3270 return true;
3271 }
3272 friend bool operator!=(const PoissonDistribution& lhs, const PoissonDistribution& rhs)
3273 {
3274 return !(lhs == rhs);
3275 }
3276
3277 private:
3278 param_type m_param;
3279 class NormalDistribution<double>* m_nd;
3280 };
3281
3323 template<typename IntType = int>
3324 class INFINITY_API_TEMPLATE NegativeBinomialDistribution
3325 {
3326 static_assert(std::is_integral<IntType>::value,
3327 "IntType must be an integral type");
3328
3329 public:
3330 using result_type = IntType;
3331
3337 struct param_type {
3339
3342
3348 explicit param_type(IntType k, double p = 0.5) : m_k(k), m_p(p) {}
3349
3351 IntType k() const { return m_k; }
3352
3354 double p() const { return m_p; }
3355
3356 friend bool operator==(const param_type& lhs, const param_type& rhs)
3357 {
3358 return lhs.m_k == rhs.m_k && lhs.m_p == rhs.m_p;
3359 }
3360 friend bool operator!=(const param_type& lhs, const param_type& rhs)
3361 {
3362 return !(lhs == rhs);
3363 }
3364
3365 private:
3366 IntType m_k;
3367 double m_p;
3368 };
3369
3370 // Constructors
3371
3374
3380 explicit NegativeBinomialDistribution(IntType k, double p = 0.5)
3381 : m_param(k, p)
3382 {
3383 m_gd = new GammaDistribution<double>(k, (1.0 - p) / p);
3384 }
3385
3391 : m_param(param)
3392 {
3393 m_gd = new GammaDistribution<double>(param.k(), (1.0 - param.p()) / param.p());
3394 }
3395
3401 void reset()
3402 {
3403 if (m_gd) m_gd->reset();
3404 }
3405
3406 // Parameter access
3407
3409 IntType k() const { return m_param.k(); }
3410
3412 double p() const { return m_param.p(); }
3413
3415 param_type param() const { return m_param; }
3416
3424 void param(const param_type& param)
3425 {
3426 m_param = param;
3427 delete m_gd;
3428 m_gd = new GammaDistribution<double>(param.k(), (1.0 - param.p()) / param.p());
3429 }
3430
3432 result_type min() const { return 0; }
3433
3435 result_type max() const { return std::numeric_limits<result_type>::max(); }
3436
3437 // Generation
3438
3445 template<typename Generator>
3447 {
3448 return (*this)(g, m_param);
3449 }
3450
3469 template<typename Generator>
3470 result_type operator()(Generator& g, const param_type& param)
3471 {
3472 GammaDistribution<double> gd(param.k(), (1.0 - param.p()) / param.p());
3473 double gamma_variate = gd(g);
3474 PoissonDistribution<IntType> pd(gamma_variate);
3475 return pd(g);
3476 }
3477
3478 // Comparison
3479
3481 {
3482 if (lhs.m_param != rhs.m_param) return false;
3483 if ((lhs.m_gd == nullptr) != (rhs.m_gd == nullptr)) return false;
3484 if (lhs.m_gd && rhs.m_gd && *lhs.m_gd != *rhs.m_gd) return false;
3485 return true;
3486 }
3488 {
3489 return !(lhs == rhs);
3490 }
3491
3492 private:
3493 param_type m_param;
3494 class GammaDistribution<double>* m_gd;
3495 };
3496
3540 template<typename IntType = int>
3541 class INFINITY_API_TEMPLATE DiscreteDistribution
3542 {
3543 static_assert(std::is_integral<IntType>::value,
3544 "IntType must be an integral type");
3545
3546 public:
3547 using result_type = IntType;
3548
3556 {
3558
3560 param_type() : m_prob(1, 1.0), m_cp(1, 1.0) {}
3561
3571 template<typename InputIterator>
3572 param_type(InputIterator first, InputIterator last)
3573 : m_prob(first, last), m_cp()
3574 {
3575 normalize();
3576 }
3577
3585 param_type(std::initializer_list<double> wl)
3586 : m_prob(wl.begin(), wl.end()), m_cp()
3587 {
3588 normalize();
3589 }
3590
3603 template<typename UnaryOperation>
3604 param_type(size_t count, double xmin, double xmax, UnaryOperation fw)
3605 : m_prob(count), m_cp()
3606 {
3607 const double delta = (xmax - xmin) / count;
3608 for (size_t i = 0; i < count; ++i)
3609 {
3610 m_prob[i] = fw(xmin + (i + 0.5) * delta);
3611 }
3612 normalize();
3613 }
3614
3619 std::vector<double> probabilities() const
3620 {
3621 return m_prob.empty() ? std::vector<double>(1, 1.0) : m_prob;
3622 }
3623
3624 friend bool operator==(const param_type& lhs, const param_type& rhs)
3625 {
3626 return lhs.m_prob == rhs.m_prob;
3627 }
3628 friend bool operator!=(const param_type& lhs, const param_type& rhs)
3629 {
3630 return !(lhs == rhs);
3631 }
3632
3633 std::vector<double> m_prob;
3634 std::vector<double> m_cp;
3635
3636 private:
3643 void normalize()
3644 {
3645 if (m_prob.empty())
3646 {
3647 m_prob.push_back(1.0);
3648 m_cp.push_back(1.0);
3649 return;
3650 }
3651
3652 // Normalize probabilities
3653 double sum = 0.0;
3654 for (double p : m_prob)
3655 {
3656 sum += p;
3657 }
3658
3659 if (sum == 0.0)
3660 {
3661 // All weights are zero, use uniform distribution
3662 const double uniform = 1.0 / m_prob.size();
3663 for (auto& p : m_prob)
3664 {
3665 p = uniform;
3666 }
3667 } else {
3668 for (auto& p : m_prob)
3669 {
3670 p /= sum;
3671 }
3672 }
3673
3674 // Build cumulative probability table
3675 m_cp.resize(m_prob.size());
3676 m_cp[0] = m_prob[0];
3677 for (size_t i = 1; i < m_prob.size(); ++i)
3678 {
3679 m_cp[i] = m_cp[i - 1] + m_prob[i];
3680 }
3681 m_cp.back() = 1.0; // Ensure last element is exactly 1.0
3682 }
3683 friend class DiscreteDistribution<IntType>;
3684 };
3685
3686 // Constructors
3687
3689 DiscreteDistribution() : m_param() { }
3690
3697 template<typename InputIterator>
3698 DiscreteDistribution(InputIterator first, InputIterator last)
3699 : m_param(first, last) { }
3700
3705 DiscreteDistribution(std::initializer_list<double> wl)
3706 : m_param(wl) { }
3707
3716 template<typename UnaryOperation>
3717 DiscreteDistribution(size_t count, double xmin, double xmax, UnaryOperation fw)
3718 : m_param(count, xmin, xmax, fw) { }
3719
3724 explicit DiscreteDistribution(const param_type& param) : m_param(param) { }
3725
3731 void reset() { }
3732
3733 // Parameter access
3734
3739 std::vector<double> probabilities() const { return m_param.probabilities(); }
3740
3742 param_type param() const { return m_param; }
3743
3745 void param(const param_type& param) { m_param = param; }
3746
3748 result_type min() const { return 0; }
3749
3755 return m_param.m_prob.empty() ? 0 :
3756 static_cast<result_type>(m_param.m_prob.size() - 1);
3757 }
3758
3759 // Generation
3760
3767 template<typename Generator>
3768 result_type operator()(Generator& g) { return (*this)(g, m_param); }
3769
3785 template<typename Generator>
3786 result_type operator()(Generator& g, const param_type& param)
3787 {
3788 UniformRealDistribution<double> uniform(0.0, 1.0);
3789 const double u = uniform(g);
3790
3791 // Binary search in cumulative probability table
3792 auto it = std::lower_bound(param.m_cp.begin(), param.m_cp.end(), u);
3793 return static_cast<IntType>(it - param.m_cp.begin());
3794 }
3795
3796 // Comparison
3797
3798 friend bool operator==(const DiscreteDistribution& lhs, const DiscreteDistribution& rhs)
3799 {
3800 return lhs.m_param == rhs.m_param;
3801 }
3802 friend bool operator!=(const DiscreteDistribution& lhs, const DiscreteDistribution& rhs)
3803 {
3804 return !(lhs == rhs);
3805 }
3806
3807 private:
3808 param_type m_param;
3809 };
3810
3857 template<typename RealType = double>
3858 class INFINITY_API_TEMPLATE PiecewiseConstantDistribution
3859 {
3860 static_assert(std::is_floating_point<RealType>::value,
3861 "RealType must be a floating point type");
3862
3863 public:
3864 using result_type = RealType;
3865
3873 {
3875
3878 : m_int{RealType(0), RealType(1)}, m_den{1.0}, m_cp{1.0}
3879 { }
3880
3893 template<typename InputIteratorB, typename InputIteratorW>
3894 param_type(InputIteratorB first_b, InputIteratorB last_b,
3895 InputIteratorW first_w)
3896 : m_int(first_b, last_b), m_den(), m_cp()
3897 {
3898
3899 if (m_int.size() < 2)
3900 {
3901 m_int = {RealType(0), RealType(1)};
3902 m_den = {1.0};
3903 m_cp = {1.0};
3904 return;
3905 }
3906
3907 m_den.resize(m_int.size() - 1);
3908 for (size_t i = 0; i < m_den.size(); ++i, ++first_w)
3909 {
3910 m_den[i] = *first_w;
3911 }
3912
3913 initialize();
3914 }
3915
3925 template<typename UnaryOperation>
3926 param_type(std::initializer_list<RealType> bl, UnaryOperation fw)
3927 : m_int(bl.begin(), bl.end()), m_den(), m_cp()
3928 {
3929
3930 if (m_int.size() < 2)
3931 {
3932 m_int = {RealType(0), RealType(1)};
3933 m_den = {1.0};
3934 m_cp = {1.0};
3935 return;
3936 }
3937
3938 m_den.resize(m_int.size() - 1);
3939 for (size_t i = 0; i < m_den.size(); ++i)
3940 {
3941 const RealType x = (m_int[i] + m_int[i + 1]) / RealType(2);
3942 m_den[i] = fw(x);
3943 }
3944
3945 initialize();
3946 }
3947
3960 template<typename UnaryOperation>
3961 param_type(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
3962 : m_int(nw + 1), m_den(nw), m_cp()
3963 {
3964
3965 const RealType delta = (xmax - xmin) / nw;
3966 for (size_t i = 0; i <= nw; ++i)
3967 {
3968 m_int[i] = xmin + i * delta;
3969 }
3970
3971 for (size_t i = 0; i < nw; ++i)
3972 {
3973 const RealType x = (m_int[i] + m_int[i + 1]) / RealType(2);
3974 m_den[i] = fw(x);
3975 }
3976
3977 initialize();
3978 }
3979
3984 std::vector<RealType> intervals() const
3985 {
3986 if (m_int.empty()) {
3987 std::vector<RealType> result(2);
3988 result[0] = RealType(0);
3989 result[1] = RealType(1);
3990 return result;
3991 }
3992 return m_int;
3993 }
3994
3999 std::vector<double> densities() const
4000 {
4001 return m_den.empty() ? std::vector<double>(1, 1.0) : m_den;
4002 }
4003
4004 friend bool operator==(const param_type& lhs, const param_type& rhs)
4005 {
4006 return lhs.m_int == rhs.m_int && lhs.m_den == rhs.m_den;
4007 }
4008 friend bool operator!=(const param_type& lhs, const param_type& rhs)
4009 {
4010 return !(lhs == rhs);
4011 }
4012
4013 std::vector<RealType> m_int;
4014 std::vector<double> m_den;
4015 std::vector<double> m_cp;
4016
4017 private:
4024 void initialize()
4025 {
4026 // Calculate area under each piece
4027 std::vector<double> areas(m_den.size());
4028 double total_area = 0.0;
4029
4030 for (size_t i = 0; i < m_den.size(); ++i)
4031 {
4032 const double width = static_cast<double>(m_int[i + 1] - m_int[i]);
4033 areas[i] = m_den[i] * width;
4034 total_area += areas[i];
4035 }
4036
4037 // Normalize densities
4038 if (total_area == 0.0)
4039 {
4040 for (auto& d : m_den)
4041 {
4042 d = 1.0;
4043 }
4044 total_area = static_cast<double>(m_int.back() - m_int.front());
4045 }
4046
4047 for (auto& d : m_den)
4048 {
4049 d /= total_area;
4050 }
4051
4052 // Build cumulative probability table
4053 m_cp.resize(m_den.size());
4054 m_cp[0] = m_den[0] * static_cast<double>(m_int[1] - m_int[0]);
4055 for (size_t i = 1; i < m_den.size(); ++i)
4056 {
4057 const double width = static_cast<double>(m_int[i + 1] - m_int[i]);
4058 m_cp[i] = m_cp[i - 1] + m_den[i] * width;
4059 }
4060 m_cp.back() = 1.0;
4061 }
4062 friend class PiecewiseConstantDistribution<RealType>;
4063 };
4064
4065 // Constructors
4066
4069
4078 template<typename InputIteratorB, typename InputIteratorW>
4079 PiecewiseConstantDistribution(InputIteratorB first_b, InputIteratorB last_b,
4080 InputIteratorW first_w)
4081 : m_param(first_b, last_b, first_w) { }
4082
4089 template<typename UnaryOperation>
4090 PiecewiseConstantDistribution(std::initializer_list<RealType> bl, UnaryOperation fw)
4091 : m_param(bl, fw) { }
4092
4101 template<typename UnaryOperation>
4102 PiecewiseConstantDistribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
4103 : m_param(nw, xmin, xmax, fw) { }
4104
4109 explicit PiecewiseConstantDistribution(const param_type& param) : m_param(param) { }
4110
4116 void reset() { }
4117
4118 // Parameter access
4119
4121 std::vector<RealType> intervals() const { return m_param.intervals(); }
4122
4124 std::vector<double> densities() const { return m_param.densities(); }
4125
4127 param_type param() const { return m_param; }
4128
4130 void param(const param_type& param) { m_param = param; }
4131
4134 {
4135 return m_param.m_int.empty() ? RealType(0) : m_param.m_int.front();
4136 }
4137
4140 {
4141 return m_param.m_int.empty() ? RealType(1) : m_param.m_int.back();
4142 }
4143
4144 // Generation
4145
4152 template<typename Generator>
4153 result_type operator()(Generator& g) { return (*this)(g, m_param); }
4154
4170 template<typename Generator>
4171 result_type operator()(Generator& g, const param_type& param)
4172 {
4173 UniformRealDistribution<double> uniform(0.0, 1.0);
4174 const double u = uniform(g);
4175
4176 // Find which interval using binary search
4177 auto it = std::lower_bound(param.m_cp.begin(), param.m_cp.end(), u);
4178 const size_t idx = it - param.m_cp.begin();
4179
4180 // Generate uniform within that interval
4181 UniformRealDistribution<RealType> interval_uniform(param.m_int[idx], param.m_int[idx + 1]);
4182 return interval_uniform(g);
4183 }
4184
4185 // Comparison
4186
4189 {
4190 return lhs.m_param == rhs.m_param;
4191 }
4194 {
4195 return !(lhs == rhs);
4196 }
4197
4198 private:
4199 param_type m_param;
4200 };
4201
4252 template<typename RealType = double>
4253 class INFINITY_API_TEMPLATE PiecewiseLinearDistribution
4254 {
4255 static_assert(std::is_floating_point<RealType>::value,
4256 "RealType must be a floating point type");
4257
4258 public:
4259 using result_type = RealType;
4260
4268 {
4270
4273 : m_int{RealType(0), RealType(1)}, m_den{1.0, 1.0}, m_cp{1.0}, m_m{0.0}
4274 { }
4275
4288 template<typename InputIteratorB, typename InputIteratorW>
4289 param_type(InputIteratorB first_b, InputIteratorB last_b,
4290 InputIteratorW first_w)
4291 : m_int(first_b, last_b), m_den(), m_cp(), m_m()
4292 {
4293
4294 if (m_int.size() < 2)
4295 {
4296 m_int = {RealType(0), RealType(1)};
4297 m_den = {1.0, 1.0};
4298 m_cp = {1.0};
4299 m_m = {0.0};
4300 return;
4301 }
4302
4303 m_den.resize(m_int.size());
4304 for (size_t i = 0; i < m_den.size(); ++i, ++first_w)
4305 {
4306 m_den[i] = *first_w;
4307 }
4308
4309 initialize();
4310 }
4311
4321 template<typename UnaryOperation>
4322 param_type(std::initializer_list<RealType> bl, UnaryOperation fw)
4323 : m_int(bl.begin(), bl.end()), m_den(), m_cp(), m_m()
4324 {
4325
4326 if (m_int.size() < 2)
4327 {
4328 m_int = {RealType(0), RealType(1)};
4329 m_den = {1.0, 1.0};
4330 m_cp = {1.0};
4331 m_m = {0.0};
4332 return;
4333 }
4334
4335 m_den.resize(m_int.size());
4336 for (size_t i = 0; i < m_den.size(); ++i)
4337 {
4338 m_den[i] = fw(m_int[i]);
4339 }
4340
4341 initialize();
4342 }
4343
4356 template<typename UnaryOperation>
4357 param_type(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
4358 : m_int(nw + 1), m_den(nw + 1), m_cp(), m_m()
4359 {
4360
4361 const RealType delta = (xmax - xmin) / nw;
4362 for (size_t i = 0; i <= nw; ++i)
4363 {
4364 m_int[i] = xmin + i * delta;
4365 m_den[i] = fw(m_int[i]);
4366 }
4367
4368 initialize();
4369 }
4370
4375 std::vector<RealType> intervals() const
4376 {
4377 if (m_int.empty())
4378 {
4379 std::vector<RealType> result(2);
4380 result[0] = RealType(0);
4381 result[1] = RealType(1);
4382 return result;
4383 }
4384 return m_int;
4385 }
4386
4391 std::vector<double> densities() const
4392 {
4393 return m_den.empty() ? std::vector<double>(2, 1.0) : m_den;
4394 }
4395
4396 friend bool operator==(const param_type& lhs, const param_type& rhs)
4397 {
4398 return lhs.m_int == rhs.m_int && lhs.m_den == rhs.m_den;
4399 }
4400 friend bool operator!=(const param_type& lhs, const param_type& rhs)
4401 {
4402 return !(lhs == rhs);
4403 }
4404
4405 std::vector<RealType> m_int;
4406 std::vector<double> m_den;
4407 std::vector<double> m_cp;
4408 std::vector<double> m_m;
4409
4410 private:
4418 void initialize()
4419 {
4420 const size_t n = m_int.size() - 1;
4421
4422 // Calculate area under each trapezoid
4423 std::vector<double> areas(n);
4424 double total_area = 0.0;
4425
4426 for (size_t i = 0; i < n; ++i)
4427 {
4428 const double width = static_cast<double>(m_int[i + 1] - m_int[i]);
4429 areas[i] = 0.5 * width * (m_den[i] + m_den[i + 1]);
4430 total_area += areas[i];
4431 }
4432
4433 // Normalize densities
4434 if (total_area == 0.0)
4435 {
4436 for (auto& d : m_den)
4437 {
4438 d = 1.0;
4439 }
4440 for (size_t i = 0; i < n; ++i)
4441 {
4442 const double width = static_cast<double>(m_int[i + 1] - m_int[i]);
4443 areas[i] = width;
4444 total_area += areas[i];
4445 }
4446 }
4447
4448 for (auto& d : m_den)
4449 {
4450 d /= total_area;
4451 }
4452 for (auto& a : areas)
4453 {
4454 a /= total_area;
4455 }
4456
4457 // Build cumulative probability table and slopes
4458 m_cp.resize(n);
4459 m_m.resize(n);
4460
4461 m_cp[0] = areas[0];
4462 for (size_t i = 1; i < n; ++i)
4463 {
4464 m_cp[i] = m_cp[i - 1] + areas[i];
4465 }
4466 m_cp.back() = 1.0;
4467
4468 // Calculate slopes for each piece
4469 for (size_t i = 0; i < n; ++i)
4470 {
4471 const double width = static_cast<double>(m_int[i + 1] - m_int[i]);
4472 m_m[i] = (m_den[i + 1] - m_den[i]) / width;
4473 }
4474 }
4475
4476 friend class PiecewiseLinearDistribution<RealType>;
4477 };
4478
4479 // Constructors
4480
4483
4492 template<typename InputIteratorB, typename InputIteratorW>
4493 PiecewiseLinearDistribution(InputIteratorB first_b, InputIteratorB last_b,
4494 InputIteratorW first_w)
4495 : m_param(first_b, last_b, first_w) { }
4496
4503 template<typename UnaryOperation>
4504 PiecewiseLinearDistribution(std::initializer_list<RealType> bl, UnaryOperation fw)
4505 : m_param(bl, fw) { }
4506
4515 template<typename UnaryOperation>
4516 PiecewiseLinearDistribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
4517 : m_param(nw, xmin, xmax, fw) { }
4518
4523 explicit PiecewiseLinearDistribution(const param_type& param) : m_param(param) { }
4524
4530 void reset() { }
4531
4532 // Parameter access
4533
4535 std::vector<RealType> intervals() const { return m_param.intervals(); }
4536
4538 std::vector<double> densities() const { return m_param.densities(); }
4539
4541 param_type param() const { return m_param; }
4542
4544 void param(const param_type& param) { m_param = param; }
4545
4548 {
4549 return m_param.m_int.empty() ? RealType(0) : m_param.m_int.front();
4550 }
4551
4554 {
4555 return m_param.m_int.empty() ? RealType(1) : m_param.m_int.back();
4556 }
4557
4558 // Generation
4559
4566 template<typename Generator>
4567 result_type operator()(Generator& g) { return (*this)(g, m_param); }
4568
4588 template<typename Generator>
4589 result_type operator()(Generator& g, const param_type& param)
4590 {
4591 UniformRealDistribution<double> uniform(0.0, 1.0);
4592 const double u = uniform(g);
4593
4594 // Find which interval using binary search
4595 auto it = std::lower_bound(param.m_cp.begin(), param.m_cp.end(), u);
4596 const size_t idx = it - param.m_cp.begin();
4597
4598 // Calculate cumulative probability at start of this interval
4599 const double cp_start = (idx == 0) ? 0.0 : param.m_cp[idx - 1];
4600 const double u_local = u - cp_start;
4601
4602 // Solve for x in the linear piece using quadratic formula
4603 // For linear density d(x) = d0 + m*(x-x0), the CDF is:
4604 // F(x) = d0*(x-x0) + 0.5*m*(x-x0)^2
4605 // Solving F(x) = u_local for x
4606
4607 const double x0 = static_cast<double>(param.m_int[idx]);
4608 const double d0 = param.m_den[idx];
4609 const double m = param.m_m[idx];
4610
4611 if (std::abs(m) < 1e-10)
4612 {
4613 // Nearly constant density in this interval
4614 return static_cast<RealType>(x0 + u_local / d0);
4615 } else {
4616 // Quadratic formula: 0.5*m*dx^2 + d0*dx - u_local = 0
4617 const double discriminant = d0 * d0 + 2.0 * m * u_local;
4618 const double dx = (-d0 + std::sqrt(discriminant)) / m;
4619 return static_cast<RealType>(x0 + dx);
4620 }
4621 }
4622
4623 // Comparison
4624
4626 const PiecewiseLinearDistribution& rhs)
4627 {
4628 return lhs.m_param == rhs.m_param;
4629 }
4631 const PiecewiseLinearDistribution& rhs)
4632 {
4633 return !(lhs == rhs);
4634 }
4635
4636 private:
4637 param_type m_param;
4638 };
4639
4653 extern template class UniformRealDistribution<float>;
4654 extern template class UniformRealDistribution<double>;
4655
4656 extern template class UniformIntDistribution<int>;
4657 extern template class UniformIntDistribution<unsigned int>;
4658 extern template class UniformIntDistribution<long>;
4659 extern template class UniformIntDistribution<unsigned long>;
4660 extern template class UniformIntDistribution<long long>;
4661 extern template class UniformIntDistribution<unsigned long long>;
4662
4663 extern template class NormalDistribution<float>;
4664 extern template class NormalDistribution<double>;
4665
4666 extern template class GammaDistribution<float>;
4667 extern template class GammaDistribution<double>;
4668
4669 extern template class ExponentialDistribution<float>;
4670 extern template class ExponentialDistribution<double>;
4671
4672 extern template class WeibullDistribution<float>;
4673 extern template class WeibullDistribution<double>;
4674
4675 extern template class ExtremeValueDistribution<float>;
4676 extern template class ExtremeValueDistribution<double>;
4677
4678 extern template class CauchyDistribution<float>;
4679 extern template class CauchyDistribution<double>;
4680
4681 extern template class LognormalDistribution<float>;
4682 extern template class LognormalDistribution<double>;
4683
4684 extern template class GeometricDistribution<int>;
4685 extern template class GeometricDistribution<unsigned int>;
4686 extern template class GeometricDistribution<long>;
4687 extern template class GeometricDistribution<unsigned long>;
4688
4689 extern template class PoissonDistribution<int>;
4690 extern template class PoissonDistribution<unsigned int>;
4691 extern template class PoissonDistribution<long>;
4692
4693 extern template class BinomialDistribution<int>;
4694 extern template class BinomialDistribution<unsigned int>;
4695
4696 extern template class NegativeBinomialDistribution<int>;
4697 extern template class NegativeBinomialDistribution<unsigned int>;
4698
4699 extern template class ChiSquaredDistribution<float>;
4700 extern template class ChiSquaredDistribution<double>;
4701
4702 extern template class FisherFDistribution<float>;
4703 extern template class FisherFDistribution<double>;
4704
4705 extern template class StudentTDistribution<float>;
4706 extern template class StudentTDistribution<double>;
4707
4708 extern template class DiscreteDistribution<int>;
4709 extern template class DiscreteDistribution<unsigned int>;
4710 extern template class DiscreteDistribution<long>;
4711
4712 extern template class PiecewiseConstantDistribution<float>;
4713 extern template class PiecewiseConstantDistribution<double>;
4714
4715 extern template class PiecewiseLinearDistribution<float>;
4716 extern template class PiecewiseLinearDistribution<double>;
4717
4718}
Platform-independent Bernoulli distribution.
Definition PRNGDistribution.hpp:2486
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:2556
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:2573
result_type max() const
Gets the maximum value that can be generated (true).
Definition PRNGDistribution.hpp:2562
friend bool operator!=(const BernoulliDistribution &lhs, const BernoulliDistribution &rhs)
Definition PRNGDistribution.hpp:2599
friend bool operator==(const BernoulliDistribution &lhs, const BernoulliDistribution &rhs)
Definition PRNGDistribution.hpp:2595
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:2553
result_type min() const
Gets the minimum value that can be generated (false).
Definition PRNGDistribution.hpp:2559
bool result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:2488
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:2587
BernoulliDistribution(double p)
Constructs a Bernoulli distribution with specified success probability.
Definition PRNGDistribution.hpp:2532
BernoulliDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:2538
BernoulliDistribution()
Default constructor. Creates fair Bernoulli distribution (p=0.5).
Definition PRNGDistribution.hpp:2526
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:2550
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:2545
Platform-independent binomial distribution.
Definition PRNGDistribution.hpp:2651
IntType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:2656
IntType t() const
Gets the number of trials.
Definition PRNGDistribution.hpp:2747
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:2739
result_type min() const
Gets the minimum value that can be generated (0).
Definition PRNGDistribution.hpp:2778
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:2753
BinomialDistribution()
Default constructor. Creates single trial distribution (t=1, p=0.5).
Definition PRNGDistribution.hpp:2699
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:2816
result_type max() const
Gets the maximum value that can be generated (t).
Definition PRNGDistribution.hpp:2781
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:2750
BinomialDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:2721
friend bool operator!=(const BinomialDistribution &lhs, const BinomialDistribution &rhs)
Definition PRNGDistribution.hpp:2853
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:2792
friend bool operator==(const BinomialDistribution &lhs, const BinomialDistribution &rhs)
Definition PRNGDistribution.hpp:2846
BinomialDistribution(IntType t, double p=0.5)
Constructs a binomial distribution with specified parameters.
Definition PRNGDistribution.hpp:2706
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:2762
Platform-independent Cauchy (Lorentz) distribution.
Definition PRNGDistribution.hpp:923
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:1010
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:1001
friend bool operator!=(const CauchyDistribution &lhs, const CauchyDistribution &rhs)
Definition PRNGDistribution.hpp:1048
RealType a() const
Gets the location parameter.
Definition PRNGDistribution.hpp:995
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:990
CauchyDistribution(RealType a, RealType b=RealType(1))
Constructs a Cauchy distribution with specified parameters.
Definition PRNGDistribution.hpp:977
CauchyDistribution()
Default constructor. Creates standard Cauchy distribution (a=0, b=1).
Definition PRNGDistribution.hpp:970
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:1021
result_type min() const
Gets the theoretical minimum value (negative infinity).
Definition PRNGDistribution.hpp:1007
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:1004
RealType b() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:998
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:928
CauchyDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:983
friend bool operator==(const CauchyDistribution &lhs, const CauchyDistribution &rhs)
Definition PRNGDistribution.hpp:1044
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:1035
Platform-independent chi-squared distribution.
Definition PRNGDistribution.hpp:1332
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:1402
ChiSquaredDistribution()
Default constructor. Creates ChiSquared(1) distribution.
Definition PRNGDistribution.hpp:1375
friend bool operator!=(const ChiSquaredDistribution &lhs, const ChiSquaredDistribution &rhs)
Definition PRNGDistribution.hpp:1479
ChiSquaredDistribution(RealType n)
Constructs a chi-squared distribution with specified degrees of freedom.
Definition PRNGDistribution.hpp:1381
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:1448
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:1464
ChiSquaredDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:1391
friend bool operator==(const ChiSquaredDistribution &lhs, const ChiSquaredDistribution &rhs)
Definition PRNGDistribution.hpp:1472
result_type min() const
Gets the minimum value that can be generated (approaches 0).
Definition PRNGDistribution.hpp:1430
RealType n() const
Gets the degrees of freedom.
Definition PRNGDistribution.hpp:1410
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:1433
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:1422
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:1413
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:1337
Platform-independent discrete distribution with arbitrary probabilities.
Definition PRNGDistribution.hpp:3542
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:3768
std::vector< double > probabilities() const
Returns the probability vector.
Definition PRNGDistribution.hpp:3739
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:3731
DiscreteDistribution(InputIterator first, InputIterator last)
Constructs from iterator range of weights.
Definition PRNGDistribution.hpp:3698
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:3742
DiscreteDistribution(std::initializer_list< double > wl)
Constructs from initializer list of weights.
Definition PRNGDistribution.hpp:3705
result_type min() const
Gets the minimum value that can be generated (0).
Definition PRNGDistribution.hpp:3748
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:3745
result_type max() const
Gets the maximum value that can be generated.
Definition PRNGDistribution.hpp:3754
DiscreteDistribution(size_t count, double xmin, double xmax, UnaryOperation fw)
Constructs from function evaluated at intervals.
Definition PRNGDistribution.hpp:3717
DiscreteDistribution()
Default constructor. Creates uniform distribution over {0}.
Definition PRNGDistribution.hpp:3689
friend bool operator==(const DiscreteDistribution &lhs, const DiscreteDistribution &rhs)
Definition PRNGDistribution.hpp:3798
DiscreteDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:3724
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:3786
IntType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:3547
friend bool operator!=(const DiscreteDistribution &lhs, const DiscreteDistribution &rhs)
Definition PRNGDistribution.hpp:3802
Platform-independent exponential distribution.
Definition PRNGDistribution.hpp:1949
result_type min() const
Gets the minimum value that can be generated (approaches 0).
Definition PRNGDistribution.hpp:2026
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:1954
ExponentialDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:2005
ExponentialDistribution()
Default constructor. Creates Exponential(1) distribution.
Definition PRNGDistribution.hpp:1993
ExponentialDistribution(RealType lambda)
Constructs an exponential distribution with specified rate.
Definition PRNGDistribution.hpp:1999
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:2040
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:2012
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:2023
friend bool operator!=(const ExponentialDistribution &lhs, const ExponentialDistribution &rhs)
Definition PRNGDistribution.hpp:2073
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:2056
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:2029
friend bool operator==(const ExponentialDistribution &lhs, const ExponentialDistribution &rhs)
Definition PRNGDistribution.hpp:2069
RealType lambda() const
Gets the rate parameter.
Definition PRNGDistribution.hpp:2017
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:2020
Platform-independent extreme value (Gumbel) distribution.
Definition PRNGDistribution.hpp:2300
RealType a() const
Gets the location parameter.
Definition PRNGDistribution.hpp:2373
friend bool operator!=(const ExtremeValueDistribution &lhs, const ExtremeValueDistribution &rhs)
Definition PRNGDistribution.hpp:2433
RealType b() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:2376
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:2382
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:2416
ExtremeValueDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:2361
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:2305
friend bool operator==(const ExtremeValueDistribution &lhs, const ExtremeValueDistribution &rhs)
Definition PRNGDistribution.hpp:2429
ExtremeValueDistribution()
Default constructor. Creates standard Gumbel distribution (a=0, b=1).
Definition PRNGDistribution.hpp:2348
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:2379
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:2368
ExtremeValueDistribution(RealType a, RealType b=RealType(1))
Constructs an extreme value distribution with specified parameters.
Definition PRNGDistribution.hpp:2355
result_type min() const
Gets the theoretical minimum value (negative infinity).
Definition PRNGDistribution.hpp:2385
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:2399
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:2388
Platform-independent Fisher F-distribution.
Definition PRNGDistribution.hpp:1525
RealType n() const
Gets the denominator degrees of freedom.
Definition PRNGDistribution.hpp:1615
friend bool operator==(const FisherFDistribution &lhs, const FisherFDistribution &rhs)
Definition PRNGDistribution.hpp:1682
result_type min() const
Gets the minimum value that can be generated (approaches 0).
Definition PRNGDistribution.hpp:1637
RealType m() const
Gets the numerator degrees of freedom.
Definition PRNGDistribution.hpp:1612
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:1671
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:1618
FisherFDistribution(RealType m, RealType n=RealType(1))
Constructs an F-distribution with specified degrees of freedom.
Definition PRNGDistribution.hpp:1580
FisherFDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:1591
friend bool operator!=(const FisherFDistribution &lhs, const FisherFDistribution &rhs)
Definition PRNGDistribution.hpp:1691
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:1530
FisherFDistribution()
Default constructor. Creates F(1, 1) distribution.
Definition PRNGDistribution.hpp:1573
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:1655
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:1627
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:1603
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:1640
Platform-independent gamma distribution.
Definition PRNGDistribution.hpp:1098
GammaDistribution(RealType alpha, RealType beta=RealType(1))
Constructs a gamma distribution with specified parameters.
Definition PRNGDistribution.hpp:1154
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:1183
RealType alpha() const
Gets the shape parameter.
Definition PRNGDistribution.hpp:1174
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:1180
GammaDistribution()
Default constructor. Creates Gamma(1, 1) distribution.
Definition PRNGDistribution.hpp:1147
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:1169
friend bool operator!=(const GammaDistribution &lhs, const GammaDistribution &rhs)
Definition PRNGDistribution.hpp:1282
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:1200
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:1103
result_type min() const
Gets the minimum value that can be generated (approaches 0).
Definition PRNGDistribution.hpp:1186
GammaDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:1161
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:1227
friend bool operator==(const GammaDistribution &lhs, const GammaDistribution &rhs)
Definition PRNGDistribution.hpp:1278
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:1189
RealType beta() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:1177
Platform-independent geometric distribution.
Definition PRNGDistribution.hpp:2905
friend bool operator==(const GeometricDistribution &lhs, const GeometricDistribution &rhs)
Definition PRNGDistribution.hpp:3027
result_type min() const
Gets the minimum value that can be generated (0).
Definition PRNGDistribution.hpp:2981
IntType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:2910
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:2967
GeometricDistribution()
Default constructor. Creates geometric distribution with p=0.5.
Definition PRNGDistribution.hpp:2948
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:2978
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:2995
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:2972
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:3013
GeometricDistribution(double p)
Constructs a geometric distribution with specified success probability.
Definition PRNGDistribution.hpp:2954
GeometricDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:2960
result_type max() const
Gets the theoretical maximum value (unbounded).
Definition PRNGDistribution.hpp:2984
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:2975
friend bool operator!=(const GeometricDistribution &lhs, const GeometricDistribution &rhs)
Definition PRNGDistribution.hpp:3031
Platform-independent lognormal distribution.
Definition PRNGDistribution.hpp:744
result_type min() const
Gets the minimum value that can be generated (approaches 0).
Definition PRNGDistribution.hpp:831
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:749
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:825
friend bool operator!=(const LognormalDistribution &lhs, const LognormalDistribution &rhs)
Definition PRNGDistribution.hpp:871
RealType s() const
Gets the standard deviation parameter of underlying normal distribution.
Definition PRNGDistribution.hpp:822
RealType m() const
Gets the mean parameter of underlying normal distribution.
Definition PRNGDistribution.hpp:819
LognormalDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:806
LognormalDistribution()
Default constructor. Creates Lognormal(0, 1) distribution.
Definition PRNGDistribution.hpp:792
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:814
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:845
friend bool operator==(const LognormalDistribution &lhs, const LognormalDistribution &rhs)
Definition PRNGDistribution.hpp:867
result_type operator()(Generator &g, const param_type &p)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:859
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:828
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:834
LognormalDistribution(RealType m, RealType s=RealType(1))
Constructs a lognormal distribution with specified parameters.
Definition PRNGDistribution.hpp:799
Platform-independent negative binomial distribution.
Definition PRNGDistribution.hpp:3325
result_type max() const
Gets the theoretical maximum value (unbounded).
Definition PRNGDistribution.hpp:3435
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:3415
result_type min() const
Gets the minimum value that can be generated (0).
Definition PRNGDistribution.hpp:3432
IntType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:3330
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:3470
friend bool operator==(const NegativeBinomialDistribution &lhs, const NegativeBinomialDistribution &rhs)
Definition PRNGDistribution.hpp:3480
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:3424
friend bool operator!=(const NegativeBinomialDistribution &lhs, const NegativeBinomialDistribution &rhs)
Definition PRNGDistribution.hpp:3487
NegativeBinomialDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:3390
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:3401
IntType k() const
Gets the number of successes required.
Definition PRNGDistribution.hpp:3409
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:3446
NegativeBinomialDistribution()
Default constructor. Creates distribution with k=1, p=0.5 (geometric).
Definition PRNGDistribution.hpp:3373
NegativeBinomialDistribution(IntType k, double p=0.5)
Constructs a negative binomial distribution with specified parameters.
Definition PRNGDistribution.hpp:3380
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:3412
Platform-independent normal (Gaussian) distribution.
Definition PRNGDistribution.hpp:524
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:529
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:608
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:597
NormalDistribution()
Default constructor. Creates standard normal distribution (mean=0, stddev=1).
Definition PRNGDistribution.hpp:574
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:617
RealType mean() const
Gets the mean of the distribution.
Definition PRNGDistribution.hpp:602
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:634
result_type min() const
Gets the theoretical minimum value (negative infinity).
Definition PRNGDistribution.hpp:620
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:623
NormalDistribution(RealType mean, RealType stddev=RealType(1))
Constructs a normal distribution with specified parameters.
Definition PRNGDistribution.hpp:581
NormalDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:588
friend bool operator!=(const NormalDistribution &lhs, const NormalDistribution &rhs)
Definition PRNGDistribution.hpp:696
RealType stddev() const
Gets the standard deviation of the distribution.
Definition PRNGDistribution.hpp:605
friend bool operator==(const NormalDistribution &lhs, const NormalDistribution &rhs)
Definition PRNGDistribution.hpp:690
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:656
Platform-independent piecewise constant distribution.
Definition PRNGDistribution.hpp:3859
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:3864
PiecewiseConstantDistribution(std::initializer_list< RealType > bl, UnaryOperation fw)
Constructs from interval boundaries and weight function.
Definition PRNGDistribution.hpp:4090
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:4130
friend bool operator!=(const PiecewiseConstantDistribution &lhs, const PiecewiseConstantDistribution &rhs)
Definition PRNGDistribution.hpp:4192
PiecewiseConstantDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:4109
std::vector< double > densities() const
Returns the density values.
Definition PRNGDistribution.hpp:4124
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:4127
friend bool operator==(const PiecewiseConstantDistribution &lhs, const PiecewiseConstantDistribution &rhs)
Definition PRNGDistribution.hpp:4187
PiecewiseConstantDistribution(InputIteratorB first_b, InputIteratorB last_b, InputIteratorW first_w)
Constructs from interval boundaries and density weights.
Definition PRNGDistribution.hpp:4079
std::vector< RealType > intervals() const
Returns the interval boundaries.
Definition PRNGDistribution.hpp:4121
PiecewiseConstantDistribution()
Default constructor. Creates uniform distribution over [0, 1).
Definition PRNGDistribution.hpp:4068
result_type max() const
Gets the maximum value that can be generated.
Definition PRNGDistribution.hpp:4139
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:4153
PiecewiseConstantDistribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
Constructs with evenly-spaced intervals and weight function.
Definition PRNGDistribution.hpp:4102
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:4171
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:4116
result_type min() const
Gets the minimum value that can be generated.
Definition PRNGDistribution.hpp:4133
Platform-independent piecewise linear distribution.
Definition PRNGDistribution.hpp:4254
PiecewiseLinearDistribution(std::initializer_list< RealType > bl, UnaryOperation fw)
Constructs from interval boundaries and density function.
Definition PRNGDistribution.hpp:4504
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:4541
result_type min() const
Gets the minimum value that can be generated.
Definition PRNGDistribution.hpp:4547
std::vector< double > densities() const
Returns the density values at boundaries.
Definition PRNGDistribution.hpp:4538
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:4589
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:4567
friend bool operator==(const PiecewiseLinearDistribution &lhs, const PiecewiseLinearDistribution &rhs)
Definition PRNGDistribution.hpp:4625
PiecewiseLinearDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:4523
PiecewiseLinearDistribution(InputIteratorB first_b, InputIteratorB last_b, InputIteratorW first_w)
Constructs from interval boundaries and density values.
Definition PRNGDistribution.hpp:4493
PiecewiseLinearDistribution()
Default constructor. Creates uniform distribution over [0, 1).
Definition PRNGDistribution.hpp:4482
result_type max() const
Gets the maximum value that can be generated.
Definition PRNGDistribution.hpp:4553
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:4530
PiecewiseLinearDistribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
Constructs with evenly-spaced intervals and density function.
Definition PRNGDistribution.hpp:4516
friend bool operator!=(const PiecewiseLinearDistribution &lhs, const PiecewiseLinearDistribution &rhs)
Definition PRNGDistribution.hpp:4630
std::vector< RealType > intervals() const
Returns the interval boundaries.
Definition PRNGDistribution.hpp:4535
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:4544
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:4259
Platform-independent Poisson distribution.
Definition PRNGDistribution.hpp:3083
friend bool operator!=(const PoissonDistribution &lhs, const PoissonDistribution &rhs)
Definition PRNGDistribution.hpp:3272
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:3234
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:3179
PoissonDistribution(double mean)
Constructs a Poisson distribution with specified mean.
Definition PRNGDistribution.hpp:3132
double mean() const
Gets the mean (rate) parameter.
Definition PRNGDistribution.hpp:3167
friend bool operator==(const PoissonDistribution &lhs, const PoissonDistribution &rhs)
Definition PRNGDistribution.hpp:3265
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:3159
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:3170
PoissonDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:3145
IntType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:3088
result_type min() const
Gets the minimum value that can be generated (0).
Definition PRNGDistribution.hpp:3191
PoissonDistribution()
Default constructor. Creates Poisson distribution with mean=1.0.
Definition PRNGDistribution.hpp:3126
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:3205
result_type max() const
Gets the theoretical maximum value (unbounded).
Definition PRNGDistribution.hpp:3194
Platform-independent Student's t-distribution.
Definition PRNGDistribution.hpp:1742
StudentTDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:1802
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:1747
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:1813
StudentTDistribution(RealType n)
Constructs a t-distribution with specified degrees of freedom.
Definition PRNGDistribution.hpp:1792
StudentTDistribution()
Default constructor. Creates t(1) distribution (Cauchy).
Definition PRNGDistribution.hpp:1786
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:1825
friend bool operator!=(const StudentTDistribution &lhs, const StudentTDistribution &rhs)
Definition PRNGDistribution.hpp:1895
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:1860
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:1845
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:1834
result_type min() const
Gets the theoretical minimum value (negative infinity).
Definition PRNGDistribution.hpp:1842
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:1876
friend bool operator==(const StudentTDistribution &lhs, const StudentTDistribution &rhs)
Definition PRNGDistribution.hpp:1887
RealType n() const
Gets the degrees of freedom.
Definition PRNGDistribution.hpp:1822
Platform-independent uniform integer distribution.
Definition PRNGDistribution.hpp:280
IntType a() const
Gets the lower bound of the distribution range.
Definition PRNGDistribution.hpp:365
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:391
friend bool operator==(const UniformIntDistribution &lhs, const UniformIntDistribution &rhs)
Definition PRNGDistribution.hpp:466
UniformIntDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:349
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:360
IntType b() const
Gets the upper bound of the distribution range.
Definition PRNGDistribution.hpp:368
result_type max() const
Gets the maximum value that can be generated (inclusive).
Definition PRNGDistribution.hpp:380
friend bool operator!=(const UniformIntDistribution &lhs, const UniformIntDistribution &rhs)
Definition PRNGDistribution.hpp:472
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:371
UniformIntDistribution()
Default constructor. Creates a uniform distribution over [0, IntType::max()].
Definition PRNGDistribution.hpp:335
UniformIntDistribution(IntType a, IntType b=std::numeric_limits< IntType >::max())
Constructs a uniform distribution with specified bounds.
Definition PRNGDistribution.hpp:342
IntType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:285
result_type min() const
Gets the minimum value that can be generated (inclusive).
Definition PRNGDistribution.hpp:377
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:374
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:413
Platform-independent uniform real distribution.
Definition PRNGDistribution.hpp:55
result_type max() const
Gets the maximum value that can be generated (exclusive).
Definition PRNGDistribution.hpp:156
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:147
UniformRealDistribution()
Default constructor. Creates a uniform distribution over [0, 1).
Definition PRNGDistribution.hpp:111
friend bool operator!=(const UniformRealDistribution &lhs, const UniformRealDistribution &rhs)
Definition PRNGDistribution.hpp:215
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:136
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:185
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:60
result_type min() const
Gets the minimum value that can be generated (inclusive).
Definition PRNGDistribution.hpp:153
UniformRealDistribution(RealType a, RealType b=RealType(1))
Constructs a uniform distribution with specified bounds.
Definition PRNGDistribution.hpp:118
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:150
RealType a() const
Gets the lower bound of the distribution range.
Definition PRNGDistribution.hpp:141
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:167
friend bool operator==(const UniformRealDistribution &lhs, const UniformRealDistribution &rhs)
Definition PRNGDistribution.hpp:209
UniformRealDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:125
RealType b() const
Gets the upper bound of the distribution range.
Definition PRNGDistribution.hpp:144
Platform-independent Weibull distribution.
Definition PRNGDistribution.hpp:2124
friend bool operator==(const WeibullDistribution &lhs, const WeibullDistribution &rhs)
Definition PRNGDistribution.hpp:2245
RealType a() const
Gets the shape parameter.
Definition PRNGDistribution.hpp:2197
result_type min() const
Gets the minimum value that can be generated (approaches 0).
Definition PRNGDistribution.hpp:2209
WeibullDistribution()
Default constructor. Creates Weibull(1, 1) distribution.
Definition PRNGDistribution.hpp:2172
result_type max() const
Gets the theoretical maximum value (positive infinity).
Definition PRNGDistribution.hpp:2212
RealType b() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:2200
result_type operator()(Generator &g)
Generates the next random value using stored parameters.
Definition PRNGDistribution.hpp:2223
void param(const param_type &param)
Sets new parameters for the distribution.
Definition PRNGDistribution.hpp:2206
friend bool operator!=(const WeibullDistribution &lhs, const WeibullDistribution &rhs)
Definition PRNGDistribution.hpp:2249
RealType result_type
The type of values produced by the distribution.
Definition PRNGDistribution.hpp:2129
result_type operator()(Generator &g, const param_type &param)
Generates the next random value using provided parameters.
Definition PRNGDistribution.hpp:2237
param_type param() const
Gets the current parameter set.
Definition PRNGDistribution.hpp:2203
WeibullDistribution(RealType a, RealType b=RealType(1))
Constructs a Weibull distribution with specified parameters.
Definition PRNGDistribution.hpp:2179
void reset()
Resets the distribution state.
Definition PRNGDistribution.hpp:2192
WeibullDistribution(const param_type &param)
Constructs from a parameter set.
Definition PRNGDistribution.hpp:2185
Definition BaseException.hpp:9
template class INFINITY_API_PUBLIC ExponentialDistribution< double >
Definition PRNGDistribution.cpp:23
template class INFINITY_API_PUBLIC UniformIntDistribution< unsigned int >
Definition PRNGDistribution.cpp:10
template class INFINITY_API_PUBLIC StudentTDistribution< float >
Definition PRNGDistribution.cpp:58
template class INFINITY_API_PUBLIC WeibullDistribution< double >
Definition PRNGDistribution.cpp:26
template class INFINITY_API_PUBLIC UniformIntDistribution< long long >
Definition PRNGDistribution.cpp:13
template class INFINITY_API_PUBLIC NegativeBinomialDistribution< unsigned int >
Definition PRNGDistribution.cpp:50
template class INFINITY_API_PUBLIC ExtremeValueDistribution< double >
Definition PRNGDistribution.cpp:29
template class INFINITY_API_PUBLIC PiecewiseLinearDistribution< float >
Definition PRNGDistribution.cpp:68
template class INFINITY_API_PUBLIC CauchyDistribution< double >
Definition PRNGDistribution.cpp:32
template class INFINITY_API_PUBLIC UniformIntDistribution< unsigned long long >
Definition PRNGDistribution.cpp:14
template class INFINITY_API_PUBLIC WeibullDistribution< float >
Definition PRNGDistribution.cpp:25
template class INFINITY_API_PUBLIC NegativeBinomialDistribution< int >
Definition PRNGDistribution.cpp:49
template class INFINITY_API_PUBLIC PoissonDistribution< unsigned int >
Definition PRNGDistribution.cpp:43
template class INFINITY_API_PUBLIC PoissonDistribution< long >
Definition PRNGDistribution.cpp:44
template class INFINITY_API_PUBLIC LognormalDistribution< float >
Definition PRNGDistribution.cpp:34
template class INFINITY_API_PUBLIC UniformIntDistribution< unsigned long >
Definition PRNGDistribution.cpp:12
template class INFINITY_API_PUBLIC GeometricDistribution< int >
Definition PRNGDistribution.cpp:37
template class INFINITY_API_PUBLIC DiscreteDistribution< unsigned int >
Definition PRNGDistribution.cpp:62
template class INFINITY_API_PUBLIC ChiSquaredDistribution< float >
Definition PRNGDistribution.cpp:52
template class INFINITY_API_PUBLIC FisherFDistribution< float >
Definition PRNGDistribution.cpp:55
template class INFINITY_API_PUBLIC PiecewiseLinearDistribution< double >
Definition PRNGDistribution.cpp:69
template class INFINITY_API_PUBLIC DiscreteDistribution< int >
Definition PRNGDistribution.cpp:61
template class INFINITY_API_PUBLIC BinomialDistribution< int >
Definition PRNGDistribution.cpp:46
template class INFINITY_API_PUBLIC UniformRealDistribution< double >
Definition PRNGDistribution.cpp:7
template class INFINITY_API_PUBLIC PiecewiseConstantDistribution< float >
Definition PRNGDistribution.cpp:65
template class INFINITY_API_PUBLIC CauchyDistribution< float >
Definition PRNGDistribution.cpp:31
template class INFINITY_API_PUBLIC NormalDistribution< float >
Definition PRNGDistribution.cpp:16
template class INFINITY_API_PUBLIC PoissonDistribution< int >
Definition PRNGDistribution.cpp:42
template class INFINITY_API_PUBLIC LognormalDistribution< double >
Definition PRNGDistribution.cpp:35
template class INFINITY_API_PUBLIC GeometricDistribution< unsigned int >
Definition PRNGDistribution.cpp:38
template class INFINITY_API_PUBLIC GammaDistribution< float >
Definition PRNGDistribution.cpp:19
template class INFINITY_API_PUBLIC NormalDistribution< double >
Definition PRNGDistribution.cpp:17
template class INFINITY_API_PUBLIC GammaDistribution< double >
Definition PRNGDistribution.cpp:20
template class INFINITY_API_PUBLIC DiscreteDistribution< long >
Definition PRNGDistribution.cpp:63
template class INFINITY_API_PUBLIC UniformIntDistribution< long >
Definition PRNGDistribution.cpp:11
template class INFINITY_API_PUBLIC UniformRealDistribution< float >
Definition PRNGDistribution.cpp:6
template class INFINITY_API_PUBLIC ExtremeValueDistribution< float >
Definition PRNGDistribution.cpp:28
template class INFINITY_API_PUBLIC GeometricDistribution< unsigned long >
Definition PRNGDistribution.cpp:40
template class INFINITY_API_PUBLIC UniformIntDistribution< int >
Definition PRNGDistribution.cpp:9
template class INFINITY_API_PUBLIC FisherFDistribution< double >
Definition PRNGDistribution.cpp:56
template class INFINITY_API_PUBLIC GeometricDistribution< long >
Definition PRNGDistribution.cpp:39
template class INFINITY_API_PUBLIC BinomialDistribution< unsigned int >
Definition PRNGDistribution.cpp:47
template class INFINITY_API_PUBLIC ChiSquaredDistribution< double >
Definition PRNGDistribution.cpp:53
template class INFINITY_API_PUBLIC PiecewiseConstantDistribution< double >
Definition PRNGDistribution.cpp:66
template class INFINITY_API_PUBLIC StudentTDistribution< double >
Definition PRNGDistribution.cpp:59
template class INFINITY_API_PUBLIC ExponentialDistribution< float >
Definition PRNGDistribution.cpp:22
constexpr float PI
Mathematical constants.
Definition Math.hpp:11
Parameter set for the distribution.
Definition PRNGDistribution.hpp:2495
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2514
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:2508
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2510
param_type(double p)
Constructs parameters.
Definition PRNGDistribution.hpp:2505
param_type()
Default constructor. Creates parameters for fair coin (p=0.5).
Definition PRNGDistribution.hpp:2499
Parameter set for the distribution.
Definition PRNGDistribution.hpp:2663
param_type(IntType t, double p=0.5)
Constructs parameters.
Definition PRNGDistribution.hpp:2674
IntType t() const
Gets the number of trials.
Definition PRNGDistribution.hpp:2677
param_type()
Default constructor. Creates parameters for single trial (t=1, p=0.5).
Definition PRNGDistribution.hpp:2667
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2686
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:2680
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2682
Parameter set for the distribution.
Definition PRNGDistribution.hpp:935
param_type()
Default constructor. Creates parameters for standard Cauchy (a=0, b=1).
Definition PRNGDistribution.hpp:939
param_type(RealType a, RealType b=RealType(1))
Constructs parameters.
Definition PRNGDistribution.hpp:946
RealType a() const
Gets the location parameter.
Definition PRNGDistribution.hpp:949
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:958
RealType b() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:952
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:954
Parameter set for the distribution.
Definition PRNGDistribution.hpp:1344
RealType n() const
Gets the degrees of freedom.
Definition PRNGDistribution.hpp:1357
param_type()
Default constructor. Creates parameters for ChiSquared(1).
Definition PRNGDistribution.hpp:1348
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1363
param_type(RealType n)
Constructs parameters.
Definition PRNGDistribution.hpp:1354
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1359
Parameter set for the distribution.
Definition PRNGDistribution.hpp:3556
std::vector< double > m_cp
Cumulative probabilities for efficient sampling.
Definition PRNGDistribution.hpp:3634
param_type(std::initializer_list< double > wl)
Constructs from initializer list of weights.
Definition PRNGDistribution.hpp:3585
param_type(InputIterator first, InputIterator last)
Constructs from iterator range of weights.
Definition PRNGDistribution.hpp:3572
param_type(size_t count, double xmin, double xmax, UnaryOperation fw)
Constructs from function evaluated at intervals.
Definition PRNGDistribution.hpp:3604
std::vector< double > probabilities() const
Returns the probability vector.
Definition PRNGDistribution.hpp:3619
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:3628
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:3624
param_type()
Default constructor. Creates uniform distribution over {0}.
Definition PRNGDistribution.hpp:3560
std::vector< double > m_prob
Individual probabilities.
Definition PRNGDistribution.hpp:3633
Parameter set for the distribution.
Definition PRNGDistribution.hpp:1962
RealType lambda() const
Gets the rate parameter.
Definition PRNGDistribution.hpp:1975
param_type()
Default constructor. Creates parameters for Exponential(1).
Definition PRNGDistribution.hpp:1966
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1981
param_type(RealType lambda)
Constructs parameters.
Definition PRNGDistribution.hpp:1972
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1977
Parameter set for the distribution.
Definition PRNGDistribution.hpp:2313
RealType b() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:2330
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2336
param_type(RealType a, RealType b=RealType(1))
Constructs parameters.
Definition PRNGDistribution.hpp:2324
RealType a() const
Gets the location parameter.
Definition PRNGDistribution.hpp:2327
param_type()
Default constructor. Creates parameters for standard Gumbel (a=0, b=1).
Definition PRNGDistribution.hpp:2317
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2332
Parameter set for the distribution.
Definition PRNGDistribution.hpp:1538
RealType m() const
Gets the numerator degrees of freedom.
Definition PRNGDistribution.hpp:1552
param_type(RealType m, RealType n=RealType(1))
Constructs parameters.
Definition PRNGDistribution.hpp:1549
RealType n() const
Gets the denominator degrees of freedom.
Definition PRNGDistribution.hpp:1555
param_type()
Default constructor. Creates parameters for F(1, 1).
Definition PRNGDistribution.hpp:1542
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1561
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1557
Parameter set for the distribution.
Definition PRNGDistribution.hpp:1111
param_type(RealType alpha, RealType beta=RealType(1))
Constructs parameters.
Definition PRNGDistribution.hpp:1122
RealType beta() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:1129
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1135
RealType alpha() const
Gets the shape parameter.
Definition PRNGDistribution.hpp:1126
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1131
param_type()
Default constructor. Creates parameters for Gamma(1, 1).
Definition PRNGDistribution.hpp:1115
Parameter set for the distribution.
Definition PRNGDistribution.hpp:2917
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:2930
param_type(double p)
Constructs parameters.
Definition PRNGDistribution.hpp:2927
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2936
param_type()
Default constructor. Creates parameters for p=0.5.
Definition PRNGDistribution.hpp:2921
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2932
Parameter set for the distribution.
Definition PRNGDistribution.hpp:757
param_type()
Default constructor. Creates parameters for Lognormal(0, 1).
Definition PRNGDistribution.hpp:761
RealType m() const
Gets the mean parameter of underlying normal distribution.
Definition PRNGDistribution.hpp:771
RealType s() const
Gets the standard deviation parameter of underlying normal distribution.
Definition PRNGDistribution.hpp:774
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:780
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:776
param_type(RealType m, RealType s=RealType(1))
Constructs parameters for underlying normal distribution.
Definition PRNGDistribution.hpp:768
Parameter set for the distribution.
Definition PRNGDistribution.hpp:3337
IntType k() const
Gets the number of successes required.
Definition PRNGDistribution.hpp:3351
param_type(IntType k, double p=0.5)
Constructs parameters.
Definition PRNGDistribution.hpp:3348
double p() const
Gets the success probability.
Definition PRNGDistribution.hpp:3354
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:3360
param_type()
Default constructor. Creates parameters for k=1, p=0.5.
Definition PRNGDistribution.hpp:3341
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:3356
Parameter set for the distribution.
Definition PRNGDistribution.hpp:536
param_type()
Default constructor. Creates parameters for standard normal (mean=0, stddev=1).
Definition PRNGDistribution.hpp:540
RealType stddev() const
Gets the standard deviation of the distribution.
Definition PRNGDistribution.hpp:554
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:561
param_type(RealType mean, RealType stddev=RealType(1))
Constructs parameters with specified mean and standard deviation.
Definition PRNGDistribution.hpp:547
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:556
RealType mean() const
Gets the mean of the distribution.
Definition PRNGDistribution.hpp:551
Parameter set for the distribution.
Definition PRNGDistribution.hpp:3873
std::vector< double > m_den
Normalized densities for each interval.
Definition PRNGDistribution.hpp:4014
std::vector< RealType > m_int
Interval boundaries.
Definition PRNGDistribution.hpp:4013
param_type(std::initializer_list< RealType > bl, UnaryOperation fw)
Constructs from interval boundaries and weight function.
Definition PRNGDistribution.hpp:3926
std::vector< double > m_cp
Cumulative probabilities for sampling.
Definition PRNGDistribution.hpp:4015
param_type(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
Constructs with evenly-spaced intervals and weight function.
Definition PRNGDistribution.hpp:3961
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:4008
std::vector< RealType > intervals() const
Returns the interval boundaries.
Definition PRNGDistribution.hpp:3984
param_type(InputIteratorB first_b, InputIteratorB last_b, InputIteratorW first_w)
Constructs from interval boundaries and density weights.
Definition PRNGDistribution.hpp:3894
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:4004
param_type()
Default constructor. Creates uniform distribution over [0, 1).
Definition PRNGDistribution.hpp:3877
std::vector< double > densities() const
Returns the density values for each interval.
Definition PRNGDistribution.hpp:3999
Parameter set for the distribution.
Definition PRNGDistribution.hpp:4268
std::vector< RealType > intervals() const
Returns the interval boundaries.
Definition PRNGDistribution.hpp:4375
param_type(InputIteratorB first_b, InputIteratorB last_b, InputIteratorW first_w)
Constructs from interval boundaries and density values.
Definition PRNGDistribution.hpp:4289
param_type(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw)
Constructs with evenly-spaced intervals and density function.
Definition PRNGDistribution.hpp:4357
std::vector< RealType > m_int
Interval boundaries.
Definition PRNGDistribution.hpp:4405
std::vector< double > densities() const
Returns the density values at boundaries.
Definition PRNGDistribution.hpp:4391
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:4400
std::vector< double > m_cp
Cumulative probabilities.
Definition PRNGDistribution.hpp:4407
param_type(std::initializer_list< RealType > bl, UnaryOperation fw)
Constructs from interval boundaries and density function.
Definition PRNGDistribution.hpp:4322
std::vector< double > m_den
Normalized densities at boundaries.
Definition PRNGDistribution.hpp:4406
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:4396
param_type()
Default constructor. Creates uniform distribution over [0, 1).
Definition PRNGDistribution.hpp:4272
std::vector< double > m_m
Slopes for each interval.
Definition PRNGDistribution.hpp:4408
Parameter set for the distribution.
Definition PRNGDistribution.hpp:3095
param_type(double mean)
Constructs parameters.
Definition PRNGDistribution.hpp:3105
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:3114
param_type()
Default constructor. Creates parameters for mean=1.0.
Definition PRNGDistribution.hpp:3099
double mean() const
Gets the mean (rate) parameter.
Definition PRNGDistribution.hpp:3108
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:3110
Parameter set for the distribution.
Definition PRNGDistribution.hpp:1755
RealType n() const
Gets the degrees of freedom.
Definition PRNGDistribution.hpp:1768
param_type()
Default constructor. Creates parameters for t(1).
Definition PRNGDistribution.hpp:1759
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1774
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:1770
param_type(RealType n)
Constructs parameters.
Definition PRNGDistribution.hpp:1765
Parameter set for the distribution.
Definition PRNGDistribution.hpp:293
IntType a() const
Gets the lower bound.
Definition PRNGDistribution.hpp:312
param_type(IntType a, IntType b=std::numeric_limits< IntType >::max())
Constructs parameters with specified bounds.
Definition PRNGDistribution.hpp:304
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:322
IntType b() const
Gets the upper bound.
Definition PRNGDistribution.hpp:315
param_type()
Default constructor. Creates parameters for uniform distribution over [0, max].
Definition PRNGDistribution.hpp:297
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:317
Parameter set for the distribution.
Definition PRNGDistribution.hpp:69
RealType b() const
Gets the upper bound.
Definition PRNGDistribution.hpp:91
RealType a() const
Gets the lower bound.
Definition PRNGDistribution.hpp:88
param_type()
Default constructor. Creates parameters for uniform distribution over [0, 1).
Definition PRNGDistribution.hpp:73
param_type(RealType a, RealType b=RealType(1))
Constructs parameters with specified bounds.
Definition PRNGDistribution.hpp:80
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:98
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:93
Parameter set for the distribution.
Definition PRNGDistribution.hpp:2137
RealType a() const
Gets the shape parameter.
Definition PRNGDistribution.hpp:2151
RealType b() const
Gets the scale parameter.
Definition PRNGDistribution.hpp:2154
param_type()
Default constructor. Creates parameters for Weibull(1, 1) (exponential).
Definition PRNGDistribution.hpp:2141
friend bool operator!=(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2160
param_type(RealType a, RealType b=RealType(1))
Constructs parameters.
Definition PRNGDistribution.hpp:2148
friend bool operator==(const param_type &lhs, const param_type &rhs)
Definition PRNGDistribution.hpp:2156