Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
12
test/std/numerics/rand/rand.dis/nothing_to_do.pass.cpp
Normal file
12
test/std/numerics/rand/rand.dis/nothing_to_do.pass.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// bernoulli_distribution& operator=(const bernoulli_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d1(0.75);
|
||||
D d2;
|
||||
assert(d1 != d2);
|
||||
d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// bernoulli_distribution(const bernoulli_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d1(0.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// explicit bernoulli_distribution(double p = 0.5);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d;
|
||||
assert(d.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d(0);
|
||||
assert(d.p() == 0);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d(0.75);
|
||||
assert(d.p() == 0.75);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// explicit bernoulli_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25);
|
||||
D d(p);
|
||||
assert(d.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// bool operator=(const bernoulli_distribution& x,
|
||||
// const bernoulli_distribution& y);
|
||||
// bool operator!(const bernoulli_distribution& x,
|
||||
// const bernoulli_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d1(.25);
|
||||
D d2(.25);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d1(.28);
|
||||
D d2(.25);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(.75);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g));
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.p();
|
||||
double x_var = d.p()*(1-d.p());
|
||||
double x_skew = (1 - 2 * d.p())/std::sqrt(x_var);
|
||||
double x_kurtosis = (6 * sqr(d.p()) - 6 * d.p() + 1)/x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(.25);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g));
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.p();
|
||||
double x_var = d.p()*(1-d.p());
|
||||
double x_skew = (1 - 2 * d.p())/std::sqrt(x_var);
|
||||
double x_kurtosis = (6 * sqr(d.p()) - 6 * d.p() + 1)/x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(.75);
|
||||
P p(.25);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g, p));
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.p();
|
||||
double x_var = p.p()*(1-p.p());
|
||||
double x_skew = (1 - 2 * p.p())/std::sqrt(x_var);
|
||||
double x_kurtosis = (6 * sqr(p.p()) - 6 * p.p() + 1)/x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(.25);
|
||||
P p(.75);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g, p));
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.p();
|
||||
double x_var = p.p()*(1-p.p());
|
||||
double x_skew = (1 - 2 * p.p())/std::sqrt(x_var);
|
||||
double x_kurtosis = (6 * sqr(p.p()) - 6 * p.p() + 1)/x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// param_type param() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type P;
|
||||
P p(.125);
|
||||
D d(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// template <class charT, class traits>
|
||||
// basic_ostream<charT, traits>&
|
||||
// operator<<(basic_ostream<charT, traits>& os,
|
||||
// const bernoulli_distribution& x);
|
||||
//
|
||||
// template <class charT, class traits>
|
||||
// basic_istream<charT, traits>&
|
||||
// operator>>(basic_istream<charT, traits>& is,
|
||||
// bernoulli_distribution& x);
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d1(.25);
|
||||
std::ostringstream os;
|
||||
os << d1;
|
||||
std::istringstream is(os.str());
|
||||
D d2;
|
||||
is >> d2;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// result_type max() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d(.25);
|
||||
assert(d.max() == true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// result_type min() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
D d(.5);
|
||||
assert(d.min() == false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(.7);
|
||||
param_type p;
|
||||
p = p0;
|
||||
assert(p.p() == .7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(.125);
|
||||
param_type p = p0;
|
||||
assert(p.p() == .125);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p;
|
||||
assert(p.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(0.25);
|
||||
assert(p.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(0.75);
|
||||
param_type p2(0.75);
|
||||
assert(p1 == p2);
|
||||
}
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(0.75);
|
||||
param_type p2(0.5);
|
||||
assert(p1 != p2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type param_type;
|
||||
typedef param_type::distribution_type distribution_type;
|
||||
static_assert((std::is_same<D, distribution_type>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
|
||||
// void param(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25);
|
||||
D d(0.75);
|
||||
d.param(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// class bernoulli_distribution
|
||||
// {
|
||||
// typedef bool result_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::bernoulli_distribution D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, bool>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// binomial_distribution& operator=(const binomial_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d1(2, 0.75);
|
||||
D d2;
|
||||
assert(d1 != d2);
|
||||
d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// binomial_distribution(const binomial_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d1(2, 0.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// explicit binomial_distribution(IntType t = 1, double p = 0.5);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d;
|
||||
assert(d.t() == 1);
|
||||
assert(d.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d(3);
|
||||
assert(d.t() == 3);
|
||||
assert(d.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d(3, 0.75);
|
||||
assert(d.t() == 3);
|
||||
assert(d.p() == 0.75);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// explicit binomial_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(5, 0.25);
|
||||
D d(p);
|
||||
assert(d.t() == 5);
|
||||
assert(d.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// bool operator=(const binomial_distribution& x,
|
||||
// const binomial_distribution& y);
|
||||
// bool operator!(const binomial_distribution& x,
|
||||
// const binomial_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d1(3, .25);
|
||||
D d2(3, .25);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d1(3, .28);
|
||||
D d2(3, .25);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d1(3, .25);
|
||||
D d2(4, .25);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937_64 G;
|
||||
G g;
|
||||
D d(5, .75);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(30, .03125);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(40, .25);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.03);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.3);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(40, 0);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
// In this case:
|
||||
// skew computes to 0./0. == nan
|
||||
// kurtosis computes to 0./0. == nan
|
||||
// x_skew == inf
|
||||
// x_kurtosis == inf
|
||||
// These tests are commented out because UBSan warns about division by 0
|
||||
// skew /= u.size() * dev * var;
|
||||
// kurtosis /= u.size() * var * var;
|
||||
// kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(mean == x_mean);
|
||||
assert(var == x_var);
|
||||
// assert(skew == x_skew);
|
||||
// assert(kurtosis == x_kurtosis);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(40, 1);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
// In this case:
|
||||
// skew computes to 0./0. == nan
|
||||
// kurtosis computes to 0./0. == nan
|
||||
// x_skew == -inf
|
||||
// x_kurtosis == inf
|
||||
// These tests are commented out because UBSan warns about division by 0
|
||||
// skew /= u.size() * dev * var;
|
||||
// kurtosis /= u.size() * var * var;
|
||||
// kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(mean == x_mean);
|
||||
assert(var == x_var);
|
||||
// assert(skew == x_skew);
|
||||
// assert(kurtosis == x_kurtosis);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(400, 0.5);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs(skew - x_skew) < 0.01);
|
||||
assert(std::abs(kurtosis - x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(1, 0.5);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs(skew - x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
const int N = 100000;
|
||||
std::mt19937 gen1;
|
||||
std::mt19937 gen2;
|
||||
|
||||
std::binomial_distribution<> dist1(5, 0.1);
|
||||
std::binomial_distribution<unsigned> dist2(5, 0.1);
|
||||
|
||||
for(int i = 0; i < N; ++i)
|
||||
assert(dist1(gen1) == dist2(gen2));
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0, 0.005);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
// In this case:
|
||||
// skew computes to 0./0. == nan
|
||||
// kurtosis computes to 0./0. == nan
|
||||
// x_skew == inf
|
||||
// x_kurtosis == inf
|
||||
// These tests are commented out because UBSan warns about division by 0
|
||||
// skew /= u.size() * dev * var;
|
||||
// kurtosis /= u.size() * var * var;
|
||||
// kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(mean == x_mean);
|
||||
assert(var == x_var);
|
||||
// assert(skew == x_skew);
|
||||
// assert(kurtosis == x_kurtosis);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0, 0);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
// In this case:
|
||||
// skew computes to 0./0. == nan
|
||||
// kurtosis computes to 0./0. == nan
|
||||
// x_skew == inf
|
||||
// x_kurtosis == inf
|
||||
// These tests are commented out because UBSan warns about division by 0
|
||||
// skew /= u.size() * dev * var;
|
||||
// kurtosis /= u.size() * var * var;
|
||||
// kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(mean == x_mean);
|
||||
assert(var == x_var);
|
||||
// assert(skew == x_skew);
|
||||
// assert(kurtosis == x_kurtosis);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0, 1);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
// In this case:
|
||||
// skew computes to 0./0. == nan
|
||||
// kurtosis computes to 0./0. == nan
|
||||
// x_skew == -inf
|
||||
// x_kurtosis == inf
|
||||
// These tests are commented out because UBSan warns about division by 0
|
||||
// skew /= u.size() * dev * var;
|
||||
// kurtosis /= u.size() * var * var;
|
||||
// kurtosis -= 3;
|
||||
double x_mean = d.t() * d.p();
|
||||
double x_var = x_mean*(1-d.p());
|
||||
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
|
||||
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
|
||||
assert(mean == x_mean);
|
||||
assert(var == x_var);
|
||||
// assert(skew == x_skew);
|
||||
// assert(kurtosis == x_kurtosis);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937_64 G;
|
||||
G g;
|
||||
D d(16, .75);
|
||||
P p(5, .75);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(0 <= v && v <= p.t());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.t() * p.p();
|
||||
double x_var = x_mean*(1-p.p());
|
||||
double x_skew = (1-2*p.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(16, .75);
|
||||
P p(30, .03125);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(0 <= v && v <= p.t());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.t() * p.p();
|
||||
double x_var = x_mean*(1-p.p());
|
||||
double x_skew = (1-2*p.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(16, .75);
|
||||
P p(40, .25);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(0 <= v && v <= p.t());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.t() * p.p();
|
||||
double x_var = x_mean*(1-p.p());
|
||||
double x_skew = (1-2*p.p()) / std::sqrt(x_var);
|
||||
double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var;
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.04);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// param_type param() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(5, .125);
|
||||
D d(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// template <class charT, class traits>
|
||||
// basic_ostream<charT, traits>&
|
||||
// operator<<(basic_ostream<charT, traits>& os,
|
||||
// const binomial_distribution& x);
|
||||
//
|
||||
// template <class charT, class traits>
|
||||
// basic_istream<charT, traits>&
|
||||
// operator>>(basic_istream<charT, traits>& is,
|
||||
// binomial_distribution& x);
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d1(7, .25);
|
||||
std::ostringstream os;
|
||||
os << d1;
|
||||
std::istringstream is(os.str());
|
||||
D d2;
|
||||
is >> d2;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// result_type max() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d(4, .25);
|
||||
assert(d.max() == 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// result_type min() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
D d(4, .5);
|
||||
assert(d.min() == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(6, .7);
|
||||
param_type p;
|
||||
p = p0;
|
||||
assert(p.t() == 6);
|
||||
assert(p.p() == .7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(10, .125);
|
||||
param_type p = p0;
|
||||
assert(p.t() == 10);
|
||||
assert(p.p() == .125);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p;
|
||||
assert(p.t() == 1);
|
||||
assert(p.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10);
|
||||
assert(p.t() == 10);
|
||||
assert(p.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10, 0.25);
|
||||
assert(p.t() == 10);
|
||||
assert(p.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(3, 0.75);
|
||||
param_type p2(3, 0.75);
|
||||
assert(p1 == p2);
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(3, 0.75);
|
||||
param_type p2(3, 0.5);
|
||||
assert(p1 != p2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
typedef param_type::distribution_type distribution_type;
|
||||
static_assert((std::is_same<D, distribution_type>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
|
||||
// void param(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(10, 0.25);
|
||||
D d(8, 0.75);
|
||||
d.param(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class binomial_distribution
|
||||
// {
|
||||
// typedef bool result_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::binomial_distribution<> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, int>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::binomial_distribution<long> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, long>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// geometric_distribution& operator=(const geometric_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d1(0.75);
|
||||
D d2;
|
||||
assert(d1 != d2);
|
||||
d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// geometric_distribution(const geometric_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d1(0.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// explicit geometric_distribution(double p = 0.5);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d;
|
||||
assert(d.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d(0.75);
|
||||
assert(d.p() == 0.75);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// explicit geometric_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25);
|
||||
D d(p);
|
||||
assert(d.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// bool operator=(const geometric_distribution& x,
|
||||
// const geometric_distribution& y);
|
||||
// bool operator!(const geometric_distribution& x,
|
||||
// const geometric_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d1(.25);
|
||||
D d2(.25);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d1(.28);
|
||||
D d2(.25);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(.03125);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
|
||||
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0.05);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
|
||||
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(.25);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
|
||||
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0.5);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
|
||||
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0.75);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
|
||||
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(0.96875);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
|
||||
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(.75);
|
||||
P p(.03125);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - p.p()) / p.p();
|
||||
double x_var = x_mean / p.p();
|
||||
double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
|
||||
double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(.75);
|
||||
P p(.25);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - p.p()) / p.p();
|
||||
double x_var = x_mean / p.p();
|
||||
double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
|
||||
double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(.5);
|
||||
P p(.75);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = (1 - p.p()) / p.p();
|
||||
double x_var = x_mean / p.p();
|
||||
double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
|
||||
double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// param_type param() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(.125);
|
||||
D d(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// template <class charT, class traits>
|
||||
// basic_ostream<charT, traits>&
|
||||
// operator<<(basic_ostream<charT, traits>& os,
|
||||
// const geometric_distribution& x);
|
||||
//
|
||||
// template <class charT, class traits>
|
||||
// basic_istream<charT, traits>&
|
||||
// operator>>(basic_istream<charT, traits>& is,
|
||||
// geometric_distribution& x);
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d1(.25);
|
||||
std::ostringstream os;
|
||||
os << d1;
|
||||
std::istringstream is(os.str());
|
||||
D d2;
|
||||
is >> d2;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// result_type max() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d(.25);
|
||||
assert(d.max() == std::numeric_limits<int>::max());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// result_type min() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
D d(.5);
|
||||
assert(d.min() == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(.7);
|
||||
param_type p;
|
||||
p = p0;
|
||||
assert(p.p() == .7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(.125);
|
||||
param_type p = p0;
|
||||
assert(p.p() == .125);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p;
|
||||
assert(p.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(0.25);
|
||||
assert(p.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(0.75);
|
||||
param_type p2(0.75);
|
||||
assert(p1 == p2);
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(0.75);
|
||||
param_type p2(0.5);
|
||||
assert(p1 != p2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
typedef param_type::distribution_type distribution_type;
|
||||
static_assert((std::is_same<D, distribution_type>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
|
||||
// void param(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25);
|
||||
D d(0.75);
|
||||
d.param(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class geometric_distribution
|
||||
// {
|
||||
// typedef bool result_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::geometric_distribution<> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, int>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::geometric_distribution<long> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, long>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// negative_binomial_distribution& operator=(const negative_binomial_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d1(2, 0.75);
|
||||
D d2;
|
||||
assert(d1 != d2);
|
||||
d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// negative_binomial_distribution(const negative_binomial_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d1(2, 0.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// explicit negative_binomial_distribution(IntType t = 1, double p = 0.5);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d;
|
||||
assert(d.k() == 1);
|
||||
assert(d.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d(3);
|
||||
assert(d.k() == 3);
|
||||
assert(d.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d(3, 0.75);
|
||||
assert(d.k() == 3);
|
||||
assert(d.p() == 0.75);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// explicit negative_binomial_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(5, 0.25);
|
||||
D d(p);
|
||||
assert(d.k() == 5);
|
||||
assert(d.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// bool operator=(const negative_binomial_distribution& x,
|
||||
// const negative_binomial_distribution& y);
|
||||
// bool operator!(const negative_binomial_distribution& x,
|
||||
// const negative_binomial_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d1(3, .25);
|
||||
D d2(3, .25);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d1(3, .28);
|
||||
D d2(3, .25);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d1(3, .25);
|
||||
D d2(4, .25);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(5, .25);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.k() * (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p()));
|
||||
double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(30, .03125);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.k() * (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p()));
|
||||
double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(40, .25);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.k() * (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p()));
|
||||
double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(40, 1);
|
||||
const int N = 1000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.k() * (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p()));
|
||||
double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p()));
|
||||
assert(mean == x_mean);
|
||||
assert(var == x_var);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(400, 0.5);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.k() * (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p()));
|
||||
double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.04);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.05);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(1, 0.05);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.k() * (1 - d.p()) / d.p();
|
||||
double x_var = x_mean / d.p();
|
||||
double x_skew = (2 - d.p()) / std::sqrt(d.k() * (1 - d.p()));
|
||||
double x_kurtosis = 6. / d.k() + sqr(d.p()) / (d.k() * (1 - d.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(16, .75);
|
||||
P p(5, .75);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.k() * (1 - p.p()) / p.p();
|
||||
double x_var = x_mean / p.p();
|
||||
double x_skew = (2 - p.p()) / std::sqrt(p.k() * (1 - p.p()));
|
||||
double x_kurtosis = 6. / p.k() + sqr(p.p()) / (p.k() * (1 - p.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(16, .75);
|
||||
P p(30, .03125);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.k() * (1 - p.p()) / p.p();
|
||||
double x_var = x_mean / p.p();
|
||||
double x_skew = (2 - p.p()) / std::sqrt(p.k() * (1 - p.p()));
|
||||
double x_kurtosis = 6. / p.k() + sqr(p.p()) / (p.k() * (1 - p.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(16, .75);
|
||||
P p(40, .25);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() <= v && v <= d.max());
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(),
|
||||
double(0)) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.k() * (1 - p.p()) / p.p();
|
||||
double x_var = x_mean / p.p();
|
||||
double x_skew = (2 - p.p()) / std::sqrt(p.k() * (1 - p.p()));
|
||||
double x_kurtosis = 6. / p.k() + sqr(p.p()) / (p.k() * (1 - p.p()));
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// param_type param() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(5, .125);
|
||||
D d(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// template <class charT, class traits>
|
||||
// basic_ostream<charT, traits>&
|
||||
// operator<<(basic_ostream<charT, traits>& os,
|
||||
// const negative_binomial_distribution& x);
|
||||
//
|
||||
// template <class charT, class traits>
|
||||
// basic_istream<charT, traits>&
|
||||
// operator>>(basic_istream<charT, traits>& is,
|
||||
// negative_binomial_distribution& x);
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d1(7, .25);
|
||||
std::ostringstream os;
|
||||
os << d1;
|
||||
std::istringstream is(os.str());
|
||||
D d2;
|
||||
is >> d2;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// result_type max() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d(4, .25);
|
||||
assert(d.max() == std::numeric_limits<int>::max());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// result_type min() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
D d(4, .5);
|
||||
assert(d.min() == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(6, .7);
|
||||
param_type p;
|
||||
p = p0;
|
||||
assert(p.k() == 6);
|
||||
assert(p.p() == .7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(10, .125);
|
||||
param_type p = p0;
|
||||
assert(p.k() == 10);
|
||||
assert(p.p() == .125);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p;
|
||||
assert(p.k() == 1);
|
||||
assert(p.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10);
|
||||
assert(p.k() == 10);
|
||||
assert(p.p() == 0.5);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10, 0.25);
|
||||
assert(p.k() == 10);
|
||||
assert(p.p() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(3, 0.75);
|
||||
param_type p2(3, 0.75);
|
||||
assert(p1 == p2);
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(3, 0.75);
|
||||
param_type p2(3, 0.5);
|
||||
assert(p1 != p2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
typedef param_type::distribution_type distribution_type;
|
||||
static_assert((std::is_same<D, distribution_type>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
|
||||
// void param(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(10, 0.25);
|
||||
D d(8, 0.75);
|
||||
d.param(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class IntType = int>
|
||||
// class negative_binomial_distribution
|
||||
// {
|
||||
// typedef bool result_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::negative_binomial_distribution<> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, int>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::negative_binomial_distribution<long> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, long>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// cauchy_distribution& operator=(const cauchy_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d1(.5, 2);
|
||||
D d2;
|
||||
assert(d1 != d2);
|
||||
d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// cauchy_distribution(const cauchy_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d1(.5, 1.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// explicit cauchy_distribution(result_type a = 0, result_type b = 1);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d;
|
||||
assert(d.a() == 0);
|
||||
assert(d.b() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d(14.5);
|
||||
assert(d.a() == 14.5);
|
||||
assert(d.b() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d(14.5, 5.25);
|
||||
assert(d.a() == 14.5);
|
||||
assert(d.b() == 5.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// explicit cauchy_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25, 10);
|
||||
D d(p);
|
||||
assert(d.a() == 0.25);
|
||||
assert(d.b() == 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// bool operator=(const cauchy_distribution& x,
|
||||
// const cauchy_distribution& y);
|
||||
// bool operator!(const cauchy_distribution& x,
|
||||
// const cauchy_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d1(2.5, 4);
|
||||
D d2(2.5, 4);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d1(2.5, 4);
|
||||
D d2(2.5, 4.5);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
double
|
||||
f(double x, double a, double b)
|
||||
{
|
||||
return 1/3.1415926535897932 * std::atan((x - a)/b) + .5;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
const double a = 10;
|
||||
const double b = .5;
|
||||
D d(a, b);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g));
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
const double a = -1.5;
|
||||
const double b = 1;
|
||||
D d(a, b);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g));
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
const double a = .5;
|
||||
const double b = 2;
|
||||
D d(a, b);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g));
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
double
|
||||
f(double x, double a, double b)
|
||||
{
|
||||
return 1/3.1415926535897932 * std::atan((x - a)/b) + .5;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
const double a = 10;
|
||||
const double b = .5;
|
||||
D d;
|
||||
P p(a, b);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g, p));
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
const double a = -1.5;
|
||||
const double b = 1;
|
||||
D d;
|
||||
P p(a, b);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g, p));
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
const double a = .5;
|
||||
const double b = 2;
|
||||
D d;
|
||||
P p(a, b);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
u.push_back(d(g, p));
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], a, b) - double(i)/N) < .001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// param_type param() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(.125, .5);
|
||||
D d(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// template <class CharT, class Traits, class RealType>
|
||||
// basic_ostream<CharT, Traits>&
|
||||
// operator<<(basic_ostream<CharT, Traits>& os,
|
||||
// const cauchy_distribution<RealType>& x);
|
||||
|
||||
// template <class CharT, class Traits, class RealType>
|
||||
// basic_istream<CharT, Traits>&
|
||||
// operator>>(basic_istream<CharT, Traits>& is,
|
||||
// cauchy_distribution<RealType>& x);
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d1(7.5, 5.5);
|
||||
std::ostringstream os;
|
||||
os << d1;
|
||||
std::istringstream is(os.str());
|
||||
D d2;
|
||||
is >> d2;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// result_type max() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d(5, .25);
|
||||
D::result_type m = d.max();
|
||||
assert(m == INFINITY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
|
||||
// result_type min() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
D d(.5, .5);
|
||||
assert(d.min() == -INFINITY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(.75, 6);
|
||||
param_type p;
|
||||
p = p0;
|
||||
assert(p.a() == .75);
|
||||
assert(p.b() == 6);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(10, .125);
|
||||
param_type p = p0;
|
||||
assert(p.a() == 10);
|
||||
assert(p.b() == .125);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p;
|
||||
assert(p.a() == 0);
|
||||
assert(p.b() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10);
|
||||
assert(p.a() == 10);
|
||||
assert(p.b() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10, 5);
|
||||
assert(p.a() == 10);
|
||||
assert(p.b() == 5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(0.75, .5);
|
||||
param_type p2(0.75, .5);
|
||||
assert(p1 == p2);
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p1(0.75, .5);
|
||||
param_type p2(0.5, .5);
|
||||
assert(p1 != p2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
typedef param_type::distribution_type distribution_type;
|
||||
static_assert((std::is_same<D, distribution_type>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution;
|
||||
|
||||
// void param(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25, 5.5);
|
||||
D d(0.75, 4);
|
||||
d.param(p);
|
||||
assert(d.param() == p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class cauchy_distribution
|
||||
// {
|
||||
// public:
|
||||
// // types
|
||||
// typedef RealType result_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::cauchy_distribution<> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, double>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::cauchy_distribution<float> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, float>::value), "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// chi_squared_distribution& operator=(const chi_squared_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
D d1(20.75);
|
||||
D d2;
|
||||
assert(d1 != d2);
|
||||
d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// chi_squared_distribution(const chi_squared_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
D d1(21.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// explicit chi_squared_distribution(result_type alpha = 0, result_type beta = 1);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
D d;
|
||||
assert(d.n() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
D d(14.5);
|
||||
assert(d.n() == 14.5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// explicit chi_squared_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25);
|
||||
D d(p);
|
||||
assert(d.n() == 0.25);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// bool operator=(const chi_squared_distribution& x,
|
||||
// const chi_squared_distribution& y);
|
||||
// bool operator!(const chi_squared_distribution& x,
|
||||
// const chi_squared_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
D d1(2.5);
|
||||
D d2(2.5);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
D d1(4);
|
||||
D d2(4.5);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(0.5);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() < v);
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.n();
|
||||
double x_var = 2 * d.n();
|
||||
double x_skew = std::sqrt(8 / d.n());
|
||||
double x_kurtosis = 12 / d.n();
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(1);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() < v);
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.n();
|
||||
double x_var = 2 * d.n();
|
||||
double x_skew = std::sqrt(8 / d.n());
|
||||
double x_kurtosis = 12 / d.n();
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(2);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(d.min() < v);
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = d.n();
|
||||
double x_var = 2 * d.n();
|
||||
double x_skew = std::sqrt(8 / d.n());
|
||||
double x_kurtosis = 12 / d.n();
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// REQUIRES: long_tests
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class chi_squared_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
T
|
||||
sqr(T x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(0.5);
|
||||
P p(1);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() < v);
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.n();
|
||||
double x_var = 2 * p.n();
|
||||
double x_skew = std::sqrt(8 / p.n());
|
||||
double x_kurtosis = 12 / p.n();
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(1);
|
||||
P p(2);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() < v);
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.n();
|
||||
double x_var = 2 * p.n();
|
||||
double x_skew = std::sqrt(8 / p.n());
|
||||
double x_kurtosis = 12 / p.n();
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
{
|
||||
typedef std::chi_squared_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::minstd_rand G;
|
||||
G g;
|
||||
D d(2);
|
||||
P p(.5);
|
||||
const int N = 1000000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g, p);
|
||||
assert(d.min() < v);
|
||||
u.push_back(v);
|
||||
}
|
||||
double mean = std::accumulate(u.begin(), u.end(), 0.0) / u.size();
|
||||
double var = 0;
|
||||
double skew = 0;
|
||||
double kurtosis = 0;
|
||||
for (int i = 0; i < u.size(); ++i)
|
||||
{
|
||||
double d = (u[i] - mean);
|
||||
double d2 = sqr(d);
|
||||
var += d2;
|
||||
skew += d * d2;
|
||||
kurtosis += d2 * d2;
|
||||
}
|
||||
var /= u.size();
|
||||
double dev = std::sqrt(var);
|
||||
skew /= u.size() * dev * var;
|
||||
kurtosis /= u.size() * var * var;
|
||||
kurtosis -= 3;
|
||||
double x_mean = p.n();
|
||||
double x_var = 2 * p.n();
|
||||
double x_skew = std::sqrt(8 / p.n());
|
||||
double x_kurtosis = 12 / p.n();
|
||||
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
|
||||
assert(std::abs((var - x_var) / x_var) < 0.01);
|
||||
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
|
||||
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user