random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType, double), [...]): Tweak construction of _M_gd.
2011-03-25 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType, double), negative_binomial_distribution<>:: negative_binomial_distribution(const param_type&)): Tweak construction of _M_gd. * include/bits/random.tcc (negative_binomial_distribution<>:: operator()): Adjust. From-SVN: r171443
This commit is contained in:
parent
ec6165f852
commit
ff2e697a03
3 changed files with 17 additions and 8 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2011-03-25 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
* include/bits/random.h (negative_binomial_distribution<>::
|
||||||
|
negative_binomial_distribution(_IntType, double),
|
||||||
|
negative_binomial_distribution<>::
|
||||||
|
negative_binomial_distribution(const param_type&)): Tweak
|
||||||
|
construction of _M_gd.
|
||||||
|
* include/bits/random.tcc (negative_binomial_distribution<>::
|
||||||
|
operator()): Adjust.
|
||||||
|
|
||||||
2011-03-24 Paolo Carlini <paolo.carlini@oracle.com>
|
2011-03-24 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
* include/bits/random.h (negative_binomial_distribution<>::
|
* include/bits/random.h (negative_binomial_distribution<>::
|
||||||
|
|
|
@ -3804,12 +3804,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
|
negative_binomial_distribution(_IntType __k = 1, double __p = 0.5)
|
||||||
: _M_param(__k, __p), _M_gd(__k, 1.0)
|
: _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
negative_binomial_distribution(const param_type& __p)
|
negative_binomial_distribution(const param_type& __p)
|
||||||
: _M_param(__p), _M_gd(__p.k(), 1.0)
|
: _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
return __is;
|
return __is;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is Leger's algorithm.
|
// This is Leger's algorithm, also in Devroye, Ch. X, Example 1.5.
|
||||||
template<typename _IntType>
|
template<typename _IntType>
|
||||||
template<typename _UniformRandomNumberGenerator>
|
template<typename _UniformRandomNumberGenerator>
|
||||||
typename negative_binomial_distribution<_IntType>::result_type
|
typename negative_binomial_distribution<_IntType>::result_type
|
||||||
|
@ -1085,8 +1085,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
const double __y = _M_gd(__urng);
|
const double __y = _M_gd(__urng);
|
||||||
|
|
||||||
// XXX Is the constructor too slow?
|
// XXX Is the constructor too slow?
|
||||||
std::poisson_distribution<result_type> __poisson(__y * (1.0 - p())
|
std::poisson_distribution<result_type> __poisson(__y);
|
||||||
/ p());
|
|
||||||
return __poisson(__urng);
|
return __poisson(__urng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1100,10 +1099,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
typedef typename std::gamma_distribution<result_type>::param_type
|
typedef typename std::gamma_distribution<result_type>::param_type
|
||||||
param_type;
|
param_type;
|
||||||
|
|
||||||
const double __y = _M_gd(__urng, param_type(__p.k(), 1.0));
|
const double __y =
|
||||||
|
_M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
|
||||||
|
|
||||||
std::poisson_distribution<result_type> __poisson(__y * (1.0 - __p.p())
|
std::poisson_distribution<result_type> __poisson(__y);
|
||||||
/ __p.p() );
|
|
||||||
return __poisson(__urng);
|
return __poisson(__urng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue