mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-11-27 13:50:23 +00:00
[rand.dist.norm.f]
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@104035 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ed9b2aa21d
commit
d8bc09b616
@ -264,7 +264,7 @@ namespace chrono
|
||||
|
||||
template <class _Rep, class _Period = ratio<1> > class duration;
|
||||
|
||||
template <class T>
|
||||
template <class _Tp>
|
||||
struct __is_duration : false_type {};
|
||||
|
||||
template <class _Rep, class _Period>
|
||||
|
@ -57,13 +57,13 @@ struct nullptr_t
|
||||
|
||||
_LIBCPP_ALWAYS_INLINE operator int __nat::*() const {return 0;}
|
||||
|
||||
template <class T>
|
||||
template <class _Tp>
|
||||
_LIBCPP_ALWAYS_INLINE
|
||||
operator T* () const {return 0;}
|
||||
operator _Tp* () const {return 0;}
|
||||
|
||||
template <class T, class U>
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_ALWAYS_INLINE
|
||||
operator T U::* () const {return 0;}
|
||||
operator _Tp _Up::* () const {return 0;}
|
||||
|
||||
friend _LIBCPP_ALWAYS_INLINE bool operator==(nullptr_t, nullptr_t) {return true;}
|
||||
friend _LIBCPP_ALWAYS_INLINE bool operator!=(nullptr_t, nullptr_t) {return false;}
|
||||
|
172
include/random
172
include/random
@ -1296,7 +1296,62 @@ public:
|
||||
};
|
||||
|
||||
template<class RealType = double>
|
||||
class fisher_f_distribution;
|
||||
class fisher_f_distribution
|
||||
{
|
||||
public:
|
||||
// types
|
||||
typedef RealType result_type;
|
||||
|
||||
class param_type
|
||||
{
|
||||
public:
|
||||
typedef result_type distribution_type;
|
||||
|
||||
explicit param_type(result_type m = 1, result_type n = 1);
|
||||
|
||||
result_type m() const;
|
||||
result_type n() const;
|
||||
|
||||
friend bool operator==(const param_type& x, const param_type& y);
|
||||
friend bool operator!=(const param_type& x, const param_type& y);
|
||||
};
|
||||
|
||||
// constructor and reset functions
|
||||
explicit fisher_f_distribution(result_type m = 1, result_type n = 1);
|
||||
explicit fisher_f_distribution(const param_type& parm);
|
||||
void reset();
|
||||
|
||||
// generating functions
|
||||
template<class URNG> result_type operator()(URNG& g);
|
||||
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
|
||||
|
||||
// property functions
|
||||
result_type m() const;
|
||||
result_type n() const;
|
||||
|
||||
param_type param() const;
|
||||
void param(const param_type& parm);
|
||||
|
||||
result_type min() const;
|
||||
result_type max() const;
|
||||
|
||||
friend bool operator==(const fisher_f_distribution& x,
|
||||
const fisher_f_distribution& y);
|
||||
friend bool operator!=(const fisher_f_distribution& x,
|
||||
const fisher_f_distribution& y);
|
||||
|
||||
template <class charT, class traits>
|
||||
friend
|
||||
basic_ostream<charT, traits>&
|
||||
operator<<(basic_ostream<charT, traits>& os,
|
||||
const fisher_f_distribution& x);
|
||||
|
||||
template <class charT, class traits>
|
||||
friend
|
||||
basic_istream<charT, traits>&
|
||||
operator>>(basic_istream<charT, traits>& is,
|
||||
fisher_f_distribution& x);
|
||||
};
|
||||
|
||||
template<class RealType = double>
|
||||
class student_t_distribution;
|
||||
@ -4921,18 +4976,6 @@ public:
|
||||
friend bool operator!=(const cauchy_distribution& __x,
|
||||
const cauchy_distribution& __y)
|
||||
{return !(__x == __y);}
|
||||
|
||||
template <class _CharT, class _Traits, class _RT>
|
||||
friend
|
||||
basic_ostream<_CharT, _Traits>&
|
||||
operator<<(basic_ostream<_CharT, _Traits>& __os,
|
||||
const cauchy_distribution<_RT>& __x);
|
||||
|
||||
template <class _CharT, class _Traits, class _RT>
|
||||
friend
|
||||
basic_istream<_CharT, _Traits>&
|
||||
operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
cauchy_distribution<_RT>& __x);
|
||||
};
|
||||
|
||||
template <class _RealType>
|
||||
@ -4977,6 +5020,109 @@ operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
return __is;
|
||||
}
|
||||
|
||||
// fisher_f_distribution
|
||||
|
||||
template<class _RealType = double>
|
||||
class fisher_f_distribution
|
||||
{
|
||||
public:
|
||||
// types
|
||||
typedef _RealType result_type;
|
||||
|
||||
class param_type
|
||||
{
|
||||
result_type __m_;
|
||||
result_type __n_;
|
||||
public:
|
||||
typedef fisher_f_distribution distribution_type;
|
||||
|
||||
explicit param_type(result_type __m = 1, result_type __n = 1)
|
||||
: __m_(__m), __n_(__n) {}
|
||||
|
||||
result_type m() const {return __m_;}
|
||||
result_type n() const {return __n_;}
|
||||
|
||||
friend bool operator==(const param_type& __x, const param_type& __y)
|
||||
{return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;}
|
||||
friend bool operator!=(const param_type& __x, const param_type& __y)
|
||||
{return !(__x == __y);}
|
||||
};
|
||||
|
||||
private:
|
||||
param_type __p_;
|
||||
|
||||
public:
|
||||
// constructor and reset functions
|
||||
explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
|
||||
: __p_(param_type(__m, __n)) {}
|
||||
explicit fisher_f_distribution(const param_type& __p)
|
||||
: __p_(__p) {}
|
||||
void reset() {}
|
||||
|
||||
// generating functions
|
||||
template<class _URNG> result_type operator()(_URNG& __g)
|
||||
{return (*this)(__g, __p_);}
|
||||
template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
|
||||
|
||||
// property functions
|
||||
result_type m() const {return __p_.m();}
|
||||
result_type n() const {return __p_.n();}
|
||||
|
||||
param_type param() const {return __p_;}
|
||||
void param(const param_type& __p) {__p_ = __p;}
|
||||
|
||||
result_type min() const {return 0;}
|
||||
result_type max() const {return numeric_limits<result_type>::infinity();}
|
||||
|
||||
friend bool operator==(const fisher_f_distribution& __x,
|
||||
const fisher_f_distribution& __y)
|
||||
{return __x.__p_ == __y.__p_;}
|
||||
friend bool operator!=(const fisher_f_distribution& __x,
|
||||
const fisher_f_distribution& __y)
|
||||
{return !(__x == __y);}
|
||||
};
|
||||
|
||||
template <class _RealType>
|
||||
template<class _URNG>
|
||||
_RealType
|
||||
fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
|
||||
{
|
||||
gamma_distribution<result_type> __gdm(__p.m() * result_type(.5));
|
||||
gamma_distribution<result_type> __gdn(__p.n() * result_type(.5));
|
||||
return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g));
|
||||
}
|
||||
|
||||
template <class _CharT, class _Traits, class _RT>
|
||||
basic_ostream<_CharT, _Traits>&
|
||||
operator<<(basic_ostream<_CharT, _Traits>& __os,
|
||||
const fisher_f_distribution<_RT>& __x)
|
||||
{
|
||||
__save_flags<_CharT, _Traits> _(__os);
|
||||
__os.flags(ios_base::dec | ios_base::left);
|
||||
_CharT __sp = __os.widen(' ');
|
||||
__os.fill(__sp);
|
||||
__os << __x.m() << __sp << __x.n();
|
||||
return __os;
|
||||
}
|
||||
|
||||
template <class _CharT, class _Traits, class _RT>
|
||||
basic_istream<_CharT, _Traits>&
|
||||
operator>>(basic_istream<_CharT, _Traits>& __is,
|
||||
fisher_f_distribution<_RT>& __x)
|
||||
{
|
||||
typedef fisher_f_distribution<_RT> _Eng;
|
||||
typedef typename _Eng::result_type result_type;
|
||||
typedef typename _Eng::param_type param_type;
|
||||
__save_flags<_CharT, _Traits> _(__is);
|
||||
__is.flags(ios_base::dec | ios_base::skipws);
|
||||
result_type __m;
|
||||
result_type __n;
|
||||
__is >> __m >> __n;
|
||||
if (!__is.fail())
|
||||
__x.param(param_type(__m, __n));
|
||||
return __is;
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_RANDOM
|
||||
|
@ -239,7 +239,7 @@ public:
|
||||
template <intmax_t _Num, intmax_t _Den> const intmax_t ratio<_Num, _Den>::num;
|
||||
template <intmax_t _Num, intmax_t _Den> const intmax_t ratio<_Num, _Den>::den;
|
||||
|
||||
template <class T> struct __is_ratio : false_type {};
|
||||
template <class _Tp> struct __is_ratio : false_type {};
|
||||
template <intmax_t _Num, intmax_t _Den> struct __is_ratio<ratio<_Num, _Den> > : true_type {};
|
||||
|
||||
typedef ratio<1LL, 1000000000000000000LL> atto;
|
||||
|
@ -395,7 +395,7 @@ template <class _Tp> struct add_volatile {typedef typename __add_volatile<_Tp>::
|
||||
|
||||
// add_cv
|
||||
|
||||
template <class T> struct add_cv {typedef typename add_const<typename add_volatile<T>::type>::type type;};
|
||||
template <class _Tp> struct add_cv {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
|
||||
|
||||
// remove_reference
|
||||
|
||||
@ -1154,86 +1154,86 @@ forward(_Up&& __t)
|
||||
|
||||
#else // _LIBCPP_MOVE
|
||||
|
||||
template <class T>
|
||||
template <class _Tp>
|
||||
class __rv
|
||||
{
|
||||
typedef typename remove_reference<T>::type Trr;
|
||||
Trr& t_;
|
||||
typedef typename remove_reference<_Tp>::type _Trr;
|
||||
_Trr& t_;
|
||||
public:
|
||||
Trr* operator->() {return &t_;}
|
||||
explicit __rv(Trr& t) : t_(t) {}
|
||||
_Trr* operator->() {return &t_;}
|
||||
explicit __rv(_Trr& __t) : t_(__t) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
template <class _Tp>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
!is_convertible<T, __rv<T> >::value,
|
||||
T&
|
||||
!is_convertible<_Tp, __rv<_Tp> >::value,
|
||||
_Tp&
|
||||
>::type
|
||||
move(T& t)
|
||||
move(_Tp& __t)
|
||||
{
|
||||
return t;
|
||||
return __t;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
template <class _Tp>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
is_convertible<T, __rv<T> >::value,
|
||||
T
|
||||
is_convertible<_Tp, __rv<_Tp> >::value,
|
||||
_Tp
|
||||
>::type
|
||||
move(T& t)
|
||||
move(_Tp& __t)
|
||||
{
|
||||
return T(__rv<T>(t));
|
||||
return _Tp(__rv<_Tp>(__t));
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
template <class _Tp, class _Up>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
!is_convertible<T, __rv<T> >::value,
|
||||
typename add_lvalue_reference<T>::type
|
||||
!is_convertible<_Tp, __rv<_Tp> >::value,
|
||||
typename add_lvalue_reference<_Tp>::type
|
||||
>::type
|
||||
forward(U& t)
|
||||
forward(_Up& __t)
|
||||
{
|
||||
return t;
|
||||
return __t;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
template <class _Tp, class _Up>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
!is_convertible<T, __rv<T> >::value,
|
||||
typename add_lvalue_reference<T>::type
|
||||
!is_convertible<_Tp, __rv<_Tp> >::value,
|
||||
typename add_lvalue_reference<_Tp>::type
|
||||
>::type
|
||||
forward(const U& t)
|
||||
forward(const _Up& __t)
|
||||
{
|
||||
return t;
|
||||
return __t;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
template <class _Tp, class _Up>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
is_convertible<T, __rv<T> >::value,
|
||||
T
|
||||
is_convertible<_Tp, __rv<_Tp> >::value,
|
||||
_Tp
|
||||
>::type
|
||||
forward(U& t)
|
||||
forward(_Up& __t)
|
||||
{
|
||||
return T(__rv<T>(t));
|
||||
return _Tp(__rv<_Tp>(__t));
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
template <class _Tp, class _Up>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
is_convertible<T, __rv<T> >::value,
|
||||
T
|
||||
is_convertible<_Tp, __rv<_Tp> >::value,
|
||||
_Tp
|
||||
>::type
|
||||
forward(const U& t)
|
||||
forward(const _Up& __t)
|
||||
{
|
||||
return T(__rv<T>(t));
|
||||
return _Tp(__rv<_Tp>(__t));
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_MOVE
|
||||
|
@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// fisher_f_distribution& operator=(const fisher_f_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d1(20, 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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// fisher_f_distribution(const fisher_f_distribution&);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d1(20, 1.75);
|
||||
D d2 = d1;
|
||||
assert(d1 == d2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// explicit fisher_f_distribution(result_type alpha = 0, result_type beta = 1);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d;
|
||||
assert(d.m() == 1);
|
||||
assert(d.n() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d(14.5);
|
||||
assert(d.m() == 14.5);
|
||||
assert(d.n() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d(14.5, 5.25);
|
||||
assert(d.m() == 14.5);
|
||||
assert(d.n() == 5.25);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// explicit fisher_f_distribution(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
P p(0.25, 10);
|
||||
D d(p);
|
||||
assert(d.m() == 0.25);
|
||||
assert(d.n() == 10);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// bool operator=(const fisher_f_distribution& x,
|
||||
// const fisher_f_distribution& y);
|
||||
// bool operator!(const fisher_f_distribution& x,
|
||||
// const fisher_f_distribution& y);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d1(2.5, 4);
|
||||
D d2(2.5, 4);
|
||||
assert(d1 == d2);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d1(2.5, 4);
|
||||
D d2(2.5, 4.5);
|
||||
assert(d1 != d2);
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
double fac(double x)
|
||||
{
|
||||
double r = 1;
|
||||
for (; x > 1; --x)
|
||||
r *= x;
|
||||
return r;
|
||||
}
|
||||
|
||||
double
|
||||
I(double x, unsigned a, unsigned b)
|
||||
{
|
||||
double r = 0;
|
||||
for (int j = a; j <= a+b-1; ++j)
|
||||
r += fac(a+b-1)/(fac(j) * fac(a + b - 1 - j)) * std::pow(x, j) *
|
||||
std::pow(1-x, a+b-1-j);
|
||||
return r;
|
||||
}
|
||||
|
||||
double
|
||||
f(double x, double m, double n)
|
||||
{
|
||||
return I(m * x / (m*x + n), static_cast<unsigned>(m/2), static_cast<unsigned>(n/2));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Purposefully only testing even integral values of m and n (for now)
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(2, 4);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(v >= 0);
|
||||
u.push_back(v);
|
||||
}
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], d.m(), d.n()) - double(i)/N) < .01);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(4, 2);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(v >= 0);
|
||||
u.push_back(v);
|
||||
}
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], d.m(), d.n()) - double(i)/N) < .01);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(18, 20);
|
||||
const int N = 100000;
|
||||
std::vector<D::result_type> u;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
D::result_type v = d(g);
|
||||
assert(v >= 0);
|
||||
u.push_back(v);
|
||||
}
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], d.m(), d.n()) - double(i)/N) < .01);
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
double fac(double x)
|
||||
{
|
||||
double r = 1;
|
||||
for (; x > 1; --x)
|
||||
r *= x;
|
||||
return r;
|
||||
}
|
||||
|
||||
double
|
||||
I(double x, unsigned a, unsigned b)
|
||||
{
|
||||
double r = 0;
|
||||
for (int j = a; j <= a+b-1; ++j)
|
||||
r += fac(a+b-1)/(fac(j) * fac(a + b - 1 - j)) * std::pow(x, j) *
|
||||
std::pow(1-x, a+b-1-j);
|
||||
return r;
|
||||
}
|
||||
|
||||
double
|
||||
f(double x, double m, double n)
|
||||
{
|
||||
return I(m * x / (m*x + n), static_cast<unsigned>(m/2), static_cast<unsigned>(n/2));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Purposefully only testing even integral values of m and n (for now)
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(2, 4);
|
||||
P p(4, 2);
|
||||
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(v >= 0);
|
||||
u.push_back(v);
|
||||
}
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], p.m(), p.n()) - double(i)/N) < .01);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(4, 2);
|
||||
P p(6, 8);
|
||||
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(v >= 0);
|
||||
u.push_back(v);
|
||||
}
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], p.m(), p.n()) - double(i)/N) < .01);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type P;
|
||||
typedef std::mt19937 G;
|
||||
G g;
|
||||
D d(18, 20);
|
||||
P p(16, 14);
|
||||
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(v >= 0);
|
||||
u.push_back(v);
|
||||
}
|
||||
std::sort(u.begin(), u.end());
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(std::abs(f(u[i], p.m(), p.n()) - double(i)/N) < .01);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// param_type param() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// template <class CharT, class Traits, class RealType>
|
||||
// basic_ostream<CharT, Traits>&
|
||||
// operator<<(basic_ostream<CharT, Traits>& os,
|
||||
// const fisher_f_distribution<RealType>& x);
|
||||
|
||||
// template <class CharT, class Traits, class RealType>
|
||||
// basic_istream<CharT, Traits>&
|
||||
// operator>>(basic_istream<CharT, Traits>& is,
|
||||
// fisher_f_distribution<RealType>& x);
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d1(7, 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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// result_type max() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
|
||||
// result_type min() const;
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
D d(.5, .5);
|
||||
assert(d.min() == 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(.75, 6);
|
||||
param_type p;
|
||||
p = p0;
|
||||
assert(p.m() == .75);
|
||||
assert(p.n() == 6);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p0(10, .125);
|
||||
param_type p = p0;
|
||||
assert(p.m() == 10);
|
||||
assert(p.n() == .125);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p;
|
||||
assert(p.m() == 1);
|
||||
assert(p.n() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10);
|
||||
assert(p.m() == 10);
|
||||
assert(p.n() == 1);
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::param_type param_type;
|
||||
param_type p(10, 5);
|
||||
assert(p.m() == 10);
|
||||
assert(p.n() == 5);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_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::fisher_f_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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
// {
|
||||
// class param_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution;
|
||||
|
||||
// void param(const param_type& parm);
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_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 distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class RealType = double>
|
||||
// class fisher_f_distribution
|
||||
// {
|
||||
// public:
|
||||
// // types
|
||||
// typedef RealType result_type;
|
||||
|
||||
#include <random>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::fisher_f_distribution<> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, double>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::fisher_f_distribution<float> D;
|
||||
typedef D::result_type result_type;
|
||||
static_assert((std::is_same<result_type, float>::value), "");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user