1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: long_tests
13 // template<class IntType = int>
14 // class poisson_distribution
16 // template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
23 #include "test_macros.h"
36 typedef std::poisson_distribution
<> D
;
37 typedef D::param_type P
;
38 typedef std::minstd_rand G
;
43 std::vector
<double> u
;
44 for (int i
= 0; i
< N
; ++i
)
46 D::result_type v
= d(g
, p
);
47 assert(d
.min() <= v
&& v
<= d
.max());
50 double mean
= std::accumulate(u
.begin(), u
.end(), 0.0) / u
.size();
54 for (unsigned i
= 0; i
< u
.size(); ++i
)
56 double dbl
= (u
[i
] - mean
);
63 double dev
= std::sqrt(var
);
64 skew
/= u
.size() * dev
* var
;
65 kurtosis
/= u
.size() * var
* var
;
67 double x_mean
= p
.mean();
68 double x_var
= p
.mean();
69 double x_skew
= 1 / std::sqrt(x_var
);
70 double x_kurtosis
= 1 / x_var
;
71 assert(std::abs((mean
- x_mean
) / x_mean
) < 0.01);
72 assert(std::abs((var
- x_var
) / x_var
) < 0.01);
73 assert(std::abs((skew
- x_skew
) / x_skew
) < 0.01);
74 assert(std::abs((kurtosis
- x_kurtosis
) / x_kurtosis
) < 0.03);
77 typedef std::poisson_distribution
<> D
;
78 typedef D::param_type P
;
79 typedef std::minstd_rand G
;
84 std::vector
<double> u
;
85 for (int i
= 0; i
< N
; ++i
)
87 D::result_type v
= d(g
, p
);
88 assert(d
.min() <= v
&& v
<= d
.max());
91 double mean
= std::accumulate(u
.begin(), u
.end(), 0.0) / u
.size();
95 for (unsigned i
= 0; i
< u
.size(); ++i
)
97 double dbl
= (u
[i
] - mean
);
104 double dev
= std::sqrt(var
);
105 skew
/= u
.size() * dev
* var
;
106 kurtosis
/= u
.size() * var
* var
;
108 double x_mean
= p
.mean();
109 double x_var
= p
.mean();
110 double x_skew
= 1 / std::sqrt(x_var
);
111 double x_kurtosis
= 1 / x_var
;
112 assert(std::abs((mean
- x_mean
) / x_mean
) < 0.01);
113 assert(std::abs((var
- x_var
) / x_var
) < 0.01);
114 assert(std::abs((skew
- x_skew
) / x_skew
) < 0.01);
115 assert(std::abs((kurtosis
- x_kurtosis
) / x_kurtosis
) < 0.04);
118 typedef std::poisson_distribution
<> D
;
119 typedef D::param_type P
;
120 typedef std::mt19937 G
;
124 const int N
= 1000000;
125 std::vector
<double> u
;
126 for (int i
= 0; i
< N
; ++i
)
128 D::result_type v
= d(g
, p
);
129 assert(d
.min() <= v
&& v
<= d
.max());
132 double mean
= std::accumulate(u
.begin(), u
.end(), 0.0) / u
.size();
136 for (unsigned i
= 0; i
< u
.size(); ++i
)
138 double dbl
= (u
[i
] - mean
);
139 double d2
= sqr(dbl
);
145 double dev
= std::sqrt(var
);
146 skew
/= u
.size() * dev
* var
;
147 kurtosis
/= u
.size() * var
* var
;
149 double x_mean
= p
.mean();
150 double x_var
= p
.mean();
151 double x_skew
= 1 / std::sqrt(x_var
);
152 double x_kurtosis
= 1 / x_var
;
153 assert(std::abs((mean
- x_mean
) / x_mean
) < 0.01);
154 assert(std::abs((var
- x_var
) / x_var
) < 0.01);
155 assert(std::abs((skew
- x_skew
) / x_skew
) < 0.01);
156 assert(std::abs((kurtosis
- x_kurtosis
) / x_kurtosis
) < 0.01);