Remove Activ libs and includes

This commit is contained in:
John Colvin committed 2023-12-15 13:15:08 -05:00
1 parent 28ed30c944
commit 4b718994be
10967 files changed
-2306716

No files matched your search

@@ -1,283 +0,0 @@
/* boost random/additive_combine.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_ADDITIVE_COMBINE_HPP
#define ACTIV_BOOST_RANDOM_ADDITIVE_COMBINE_HPP
#include <istream>
#include <iosfwd>
#include <algorithm> // for std::min and std::max
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/linear_congruential.hpp>
namespace Boost {
namespace random {
/**
* An instantiation of class template @c additive_combine_engine models a
* \pseudo_random_number_generator. It combines two multiplicative
* \linear_congruential_engine number generators, i.e. those with @c c = 0.
* It is described in
*
* @blockquote
* "Efficient and Portable Combined Random Number Generators", Pierre L'Ecuyer,
* Communications of the ACM, Vol. 31, No. 6, June 1988, pp. 742-749, 774
* @endblockquote
*
* The template parameters MLCG1 and MLCG2 shall denote two different
* \linear_congruential_engine number generators, each with c = 0. Each
* invocation returns a random number
* X(n) := (MLCG1(n) - MLCG2(n)) mod (m1 - 1),
* where m1 denotes the modulus of MLCG1.
*/
template<class MLCG1, class MLCG2>
class additive_combine_engine
{
public:
typedef MLCG1 first_base;
typedef MLCG2 second_base;
typedef typename MLCG1::result_type result_type;
// Required by old Boost.Random concept
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
/**
* Returns the smallest value that the generator can produce
*/
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 1; }
/**
* Returns the largest value that the generator can produce
*/
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return MLCG1::modulus-1; }
/**
* Constructs an @c additive_combine_engine using the
* default constructors of the two base generators.
*/
additive_combine_engine() : _mlcg1(), _mlcg2() { }
/**
* Constructs an @c additive_combine_engine, using seed as
* the constructor argument for both base generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(additive_combine_engine,
result_type, seed_arg)
{
_mlcg1.seed(seed_arg);
_mlcg2.seed(seed_arg);
}
/**
* Constructs an @c additive_combine_engine, using seq as
* the constructor argument for both base generators.
*
* @xmlwarning
* The semantics of this function are liable to change.
* A @c seed_seq is designed to generate all the seeds
* in one shot, but this seeds the two base engines
* independantly and probably ends up giving the same
* sequence to both.
* @endxmlwarning
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(additive_combine_engine,
SeedSeq, seq)
{
_mlcg1.seed(seq);
_mlcg2.seed(seq);
}
/**
* Constructs an @c additive_combine_engine, using
* @c seed1 and @c seed2 as the constructor argument to
* the first and second base generators, respectively.
*/
additive_combine_engine(typename MLCG1::result_type seed1,
typename MLCG2::result_type seed2)
: _mlcg1(seed1), _mlcg2(seed2) { }
/**
* Contructs an @c additive_combine_engine with
* values from the range defined by the input iterators first
* and last. first will be modified to point to the element
* after the last one used.
*
* Throws: @c std::invalid_argument if the input range is too small.
*
* Exception Safety: Basic
*/
template<class It> additive_combine_engine(It& first, It last)
: _mlcg1(first, last), _mlcg2(first, last) { }
/**
* Seeds an @c additive_combine_engine using the default
* seeds of the two base generators.
*/
void seed()
{
_mlcg1.seed();
_mlcg2.seed();
}
/**
* Seeds an @c additive_combine_engine, using @c seed as the
* seed for both base generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(additive_combine_engine,
result_type, seed_arg)
{
_mlcg1.seed(seed_arg);
_mlcg2.seed(seed_arg);
}
/**
* Seeds an @c additive_combine_engine, using @c seq to
* seed both base generators.
*
* See the warning on the corresponding constructor.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(additive_combine_engine,
SeedSeq, seq)
{
_mlcg1.seed(seq);
_mlcg2.seed(seq);
}
/**
* Seeds an @c additive_combine generator, using @c seed1 and @c seed2 as
* the seeds to the first and second base generators, respectively.
*/
void seed(typename MLCG1::result_type seed1,
typename MLCG2::result_type seed2)
{
_mlcg1.seed(seed1);
_mlcg2.seed(seed2);
}
/**
* Seeds an @c additive_combine_engine with
* values from the range defined by the input iterators first
* and last. first will be modified to point to the element
* after the last one used.
*
* Throws: @c std::invalid_argument if the input range is too small.
*
* Exception Safety: Basic
*/
template<class It> void seed(It& first, It last)
{
_mlcg1.seed(first, last);
_mlcg2.seed(first, last);
}
/** Returns the next value of the generator. */
result_type operator()() {
result_type val1 = _mlcg1();
result_type val2 = _mlcg2();
if(val2 < val1) return val1 - val2;
else return val1 - val2 + MLCG1::modulus - 1;
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
_mlcg1.discard(z);
_mlcg2.discard(z);
}
/**
* Writes the state of an @c additive_combine_engine to a @c
* std::ostream. The textual representation of an @c
* additive_combine_engine is the textual representation of
* the first base generator followed by the textual representation
* of the second base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, additive_combine_engine, r)
{ os << r._mlcg1 << ' ' << r._mlcg2; return os; }
/**
* Reads the state of an @c additive_combine_engine from a
* @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, additive_combine_engine, r)
{ is >> r._mlcg1 >> std::ws >> r._mlcg2; return is; }
/**
* Returns: true iff the two @c additive_combine_engines will
* produce the same sequence of values.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(additive_combine_engine, x, y)
{ return x._mlcg1 == y._mlcg1 && x._mlcg2 == y._mlcg2; }
/**
* Returns: true iff the two @c additive_combine_engines will
* produce different sequences of values.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(additive_combine_engine)
private:
MLCG1 _mlcg1;
MLCG2 _mlcg2;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template<class MLCG1, class MLCG2>
const bool additive_combine_engine<MLCG1, MLCG2>::has_fixed_range;
#endif
/// \cond show_deprecated
/** Provided for backwards compatibility. */
template<class MLCG1, class MLCG2, typename MLCG1::result_type val = 0>
class additive_combine : public additive_combine_engine<MLCG1, MLCG2>
{
typedef additive_combine_engine<MLCG1, MLCG2> base_t;
public:
typedef typename base_t::result_type result_type;
additive_combine() {}
template<class T>
additive_combine(T& arg) : base_t(arg) {}
template<class T>
additive_combine(const T& arg) : base_t(arg) {}
template<class It>
additive_combine(It& first, It last) : base_t(first, last) {}
};
/// \endcond
/**
* The specialization \ecuyer1988 was suggested in
*
* @blockquote
* "Efficient and Portable Combined Random Number Generators", Pierre L'Ecuyer,
* Communications of the ACM, Vol. 31, No. 6, June 1988, pp. 742-749, 774
* @endblockquote
*/
typedef additive_combine_engine<
linear_congruential_engine<uint32_t, 40014, 0, 2147483563>,
linear_congruential_engine<uint32_t, 40692, 0, 2147483399>
> ecuyer1988;
} // namespace random
using random::ecuyer1988;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_ADDITIVE_COMBINE_HPP
@@ -1,197 +0,0 @@
/* boost random/bernoulli_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template \bernoulli_distribution model a
* \random_distribution. Such a random distribution produces bool values
* distributed with probabilities P(true) = p and P(false) = 1-p. p is
* the parameter of the distribution.
*/
template<class RealType = double>
class bernoulli_distribution
{
public:
// In principle, this could work with both integer and floating-point
// types. Generating floating-point random numbers in the first
// place is probably more expensive, so use integer as input.
typedef int input_type;
typedef bool result_type;
class param_type
{
public:
typedef bernoulli_distribution distribution_type;
/**
* Constructs the parameters of the distribution.
*
* Requires: 0 <= p <= 1
*/
explicit param_type(RealType p_arg = RealType(0.5))
: _p(p_arg)
{
ACTIV_BOOST_ASSERT(_p >= 0);
ACTIV_BOOST_ASSERT(_p <= 1);
}
/** Returns the p parameter of the distribution. */
RealType p() const { return _p; }
/** Writes the parameters to a std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._p;
return os;
}
/** Reads the parameters from a std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._p;
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._p == rhs._p; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _p;
};
/**
* Constructs a \bernoulli_distribution object.
* p is the parameter of the distribution.
*
* Requires: 0 <= p <= 1
*/
explicit bernoulli_distribution(const RealType& p_arg = RealType(0.5))
: _p(p_arg)
{
ACTIV_BOOST_ASSERT(_p >= 0);
ACTIV_BOOST_ASSERT(_p <= 1);
}
/**
* Constructs \bernoulli_distribution from its parameters
*/
explicit bernoulli_distribution(const param_type& parm)
: _p(parm.p()) {}
// compiler-generated copy ctor and assignment operator are fine
/**
* Returns: The "p" parameter of the distribution.
*/
RealType p() const { return _p; }
/** Returns the smallest value that the distribution can produce. */
bool min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return false; }
/** Returns the largest value that the distribution can produce. */
bool max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return true; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_p); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm) { _p = parm.p(); }
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/**
* Returns: a random variate distributed according to the
* \bernoulli_distribution.
*/
template<class Engine>
bool operator()(Engine& eng) const
{
if(_p == RealType(0))
return false;
else
return RealType(eng() - (eng.min)()) <= _p * RealType((eng.max)()-(eng.min)());
}
/**
* Returns: a random variate distributed according to the
* \bernoulli_distribution with parameters specified by param.
*/
template<class Engine>
bool operator()(Engine& eng, const param_type& parm) const
{
return bernoulli_distribution(parm)(eng);
}
/**
* Writes the parameters of the distribution to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, bernoulli_distribution, bd)
{
os << bd._p;
return os;
}
/**
* Reads the parameters of the distribution from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, bernoulli_distribution, bd)
{
is >> bd._p;
return is;
}
/**
* Returns true iff the two distributions will produce identical
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(bernoulli_distribution, lhs, rhs)
{ return lhs._p == rhs._p; }
/**
* Returns true iff the two distributions will produce different
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(bernoulli_distribution)
private:
RealType _p;
};
} // namespace random
using random::bernoulli_distribution;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_BERNOULLI_DISTRIBUTION_HPP
@@ -1,184 +0,0 @@
/* boost random/beta_distribution.hpp header file
*
* Copyright Steven Watanabe 2014
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_BETA_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_BETA_DISTRIBUTION_HPP
#include <cassert>
#include <istream>
#include <iosfwd>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/gamma_distribution.hpp>
namespace Boost {
namespace random {
/**
* The beta distribution is a real-valued distribution which produces
* values in the range [0, 1]. It has two parameters, alpha and beta.
*
* It has \f$\displaystyle p(x) = \frac{x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha, \beta)}\f$.
*/
template<class RealType = double>
class beta_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef beta_distribution distribution_type;
/**
* Constructs a @c param_type from the "alpha" and "beta" parameters
* of the distribution.
*
* Requires: alpha > 0, beta > 0
*/
explicit param_type(RealType alpha_arg = RealType(1.0),
RealType beta_arg = RealType(1.0))
: _alpha(alpha_arg), _beta(beta_arg)
{
assert(alpha_arg > 0);
assert(beta_arg > 0);
}
/** Returns the "alpha" parameter of the distribtuion. */
RealType alpha() const { return _alpha; }
/** Returns the "beta" parameter of the distribution. */
RealType beta() const { return _beta; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._alpha << ' ' << parm._beta; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._alpha >> std::ws >> parm._beta; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._alpha == rhs._alpha && lhs._beta == rhs._beta; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _alpha;
RealType _beta;
};
/**
* Constructs an @c beta_distribution from its "alpha" and "beta" parameters.
*
* Requires: alpha > 0, beta > 0
*/
explicit beta_distribution(RealType alpha_arg = RealType(1.0),
RealType beta_arg = RealType(1.0))
: _alpha(alpha_arg), _beta(beta_arg)
{
assert(alpha_arg > 0);
assert(beta_arg > 0);
}
/** Constructs an @c beta_distribution from its parameters. */
explicit beta_distribution(const param_type& parm)
: _alpha(parm.alpha()), _beta(parm.beta())
{}
/**
* Returns a random variate distributed according to the
* beta distribution.
*/
template<class URNG>
RealType operator()(URNG& urng) const
{
RealType a = gamma_distribution<RealType>(_alpha, RealType(1.0))(urng);
RealType b = gamma_distribution<RealType>(_beta, RealType(1.0))(urng);
return a / (a + b);
}
/**
* Returns a random variate distributed accordint to the beta
* distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return beta_distribution(parm)(urng);
}
/** Returns the "alpha" parameter of the distribution. */
RealType alpha() const { return _alpha; }
/** Returns the "beta" parameter of the distribution. */
RealType beta() const { return _beta; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return RealType(0.0); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return RealType(1.0); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_alpha, _beta); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_alpha = parm.alpha();
_beta = parm.beta();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Writes an @c beta_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, beta_distribution, wd)
{
os << wd.param();
return os;
}
/** Reads an @c beta_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, beta_distribution, wd)
{
param_type parm;
if(is >> parm) {
wd.param(parm);
}
return is;
}
/**
* Returns true if the two instances of @c beta_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(beta_distribution, lhs, rhs)
{ return lhs._alpha == rhs._alpha && lhs._beta == rhs._beta; }
/**
* Returns true if the two instances of @c beta_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(beta_distribution)
private:
RealType _alpha;
RealType _beta;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_BETA_DISTRIBUTION_HPP
@@ -1,434 +0,0 @@
/* boost random/binomial_distribution.hpp header file
*
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_BINOMIAL_DISTRIBUTION_HPP_INCLUDED
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <cstdlib>
#include <iosfwd>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class RealType>
struct binomial_table {
static const RealType table[10];
};
template<class RealType>
const RealType binomial_table<RealType>::table[10] = {
0.08106146679532726,
0.04134069595540929,
0.02767792568499834,
0.02079067210376509,
0.01664469118982119,
0.01387612882307075,
0.01189670994589177,
0.01041126526197209,
0.009255462182712733,
0.008330563433362871
};
}
/**
* The binomial distribution is an integer valued distribution with
* two parameters, @c t and @c p. The values of the distribution
* are within the range [0,t].
*
* The distribution function is
* \f$\displaystyle P(k) = {t \choose k}p^k(1-p)^{t-k}\f$.
*
* The algorithm used is the BTRD algorithm described in
*
* @blockquote
* "The generation of binomial random variates", Wolfgang Hormann,
* Journal of Statistical Computation and Simulation, Volume 46,
* Issue 1 & 2 April 1993 , pages 101 - 110
* @endblockquote
*/
template<class IntType = int, class RealType = double>
class binomial_distribution {
public:
typedef IntType result_type;
typedef RealType input_type;
class param_type {
public:
typedef binomial_distribution distribution_type;
/**
* Construct a param_type object. @c t and @c p
* are the parameters of the distribution.
*
* Requires: t >=0 && 0 <= p <= 1
*/
explicit param_type(IntType t_arg = 1, RealType p_arg = RealType (0.5))
: _t(t_arg), _p(p_arg)
{}
/** Returns the @c t parameter of the distribution. */
IntType t() const { return _t; }
/** Returns the @c p parameter of the distribution. */
RealType p() const { return _p; }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const param_type& parm)
{
os << parm._p << " " << parm._t;
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, param_type& parm)
{
is >> parm._p >> std::ws >> parm._t;
return is;
}
#endif
/** Returns true if the parameters have the same values. */
friend bool operator==(const param_type& lhs, const param_type& rhs)
{
return lhs._t == rhs._t && lhs._p == rhs._p;
}
/** Returns true if the parameters have different values. */
friend bool operator!=(const param_type& lhs, const param_type& rhs)
{
return !(lhs == rhs);
}
private:
IntType _t;
RealType _p;
};
/**
* Construct a @c binomial_distribution object. @c t and @c p
* are the parameters of the distribution.
*
* Requires: t >=0 && 0 <= p <= 1
*/
explicit binomial_distribution(IntType t_arg = 1,
RealType p_arg = RealType(0.5))
: _t(t_arg), _p(p_arg)
{
init();
}
/**
* Construct an @c binomial_distribution object from the
* parameters.
*/
explicit binomial_distribution(const param_type& parm)
: _t(parm.t()), _p(parm.p())
{
init();
}
/**
* Returns a random variate distributed according to the
* binomial distribution.
*/
template<class URNG>
IntType operator()(URNG& urng) const
{
if(use_inversion()) {
if(0.5 < _p) {
return _t - invert(_t, 1-_p, urng);
} else {
return invert(_t, _p, urng);
}
} else if(0.5 < _p) {
return _t - generate(urng);
} else {
return generate(urng);
}
}
/**
* Returns a random variate distributed according to the
* binomial distribution with parameters specified by @c param.
*/
template<class URNG>
IntType operator()(URNG& urng, const param_type& parm) const
{
return binomial_distribution(parm)(urng);
}
/** Returns the @c t parameter of the distribution. */
IntType t() const { return _t; }
/** Returns the @c p parameter of the distribution. */
RealType p() const { return _p; }
/** Returns the smallest value that the distribution can produce. */
IntType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const { return 0; }
/** Returns the largest value that the distribution can produce. */
IntType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const { return _t; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_t, _p); }
/** Sets parameters of the distribution. */
void param(const param_type& parm)
{
_t = parm.t();
_p = parm.p();
init();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const binomial_distribution& bd)
{
os << bd.param();
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, binomial_distribution& bd)
{
bd.read(is);
return is;
}
#endif
/** Returns true if the two distributions will produce the same
sequence of values, given equal generators. */
friend bool operator==(const binomial_distribution& lhs,
const binomial_distribution& rhs)
{
return lhs._t == rhs._t && lhs._p == rhs._p;
}
/** Returns true if the two distributions could produce different
sequences of values, given equal generators. */
friend bool operator!=(const binomial_distribution& lhs,
const binomial_distribution& rhs)
{
return !(lhs == rhs);
}
private:
/// @cond show_private
template<class CharT, class Traits>
void read(std::basic_istream<CharT, Traits>& is) {
param_type parm;
if(is >> parm) {
param(parm);
}
}
bool use_inversion() const
{
// BTRD is safe when np >= 10
return m < 11;
}
// computes the correction factor for the Stirling approximation
// for log(k!)
static RealType fc(IntType k)
{
if(k < 10) return detail::binomial_table<RealType>::table[k];
else {
RealType ikp1 = RealType(1) / (k + 1);
return (RealType(1)/12
- (RealType(1)/360
- (RealType(1)/1260)*(ikp1*ikp1))*(ikp1*ikp1))*ikp1;
}
}
void init()
{
using std::sqrt;
using std::pow;
RealType p = (0.5 < _p)? (1 - _p) : _p;
IntType t = _t;
m = static_cast<IntType>((t+1)*p);
if(use_inversion()) {
_u.q_n = pow((1 - p), static_cast<RealType>(t));
} else {
_u.btrd.r = p/(1-p);
_u.btrd.nr = (t+1)*_u.btrd.r;
_u.btrd.npq = t*p*(1-p);
RealType sqrt_npq = sqrt(_u.btrd.npq);
_u.btrd.b = 1.15 + 2.53 * sqrt_npq;
_u.btrd.a = -0.0873 + 0.0248*_u.btrd.b + 0.01*p;
_u.btrd.c = t*p + 0.5;
_u.btrd.alpha = (2.83 + 5.1/_u.btrd.b) * sqrt_npq;
_u.btrd.v_r = 0.92 - 4.2/_u.btrd.b;
_u.btrd.u_rv_r = 0.86*_u.btrd.v_r;
}
}
template<class URNG>
result_type generate(URNG& urng) const
{
using std::floor;
using std::abs;
using std::log;
while(true) {
RealType u;
RealType v = uniform_01<RealType>()(urng);
if(v <= _u.btrd.u_rv_r) {
u = v/_u.btrd.v_r - 0.43;
return static_cast<IntType>(floor(
(2*_u.btrd.a/(0.5 - abs(u)) + _u.btrd.b)*u + _u.btrd.c));
}
if(v >= _u.btrd.v_r) {
u = uniform_01<RealType>()(urng) - 0.5;
} else {
u = v/_u.btrd.v_r - 0.93;
u = ((u < 0)? -0.5 : 0.5) - u;
v = uniform_01<RealType>()(urng) * _u.btrd.v_r;
}
RealType us = 0.5 - abs(u);
IntType k = static_cast<IntType>(floor((2*_u.btrd.a/us + _u.btrd.b)*u + _u.btrd.c));
if(k < 0 || k > _t) continue;
v = v*_u.btrd.alpha/(_u.btrd.a/(us*us) + _u.btrd.b);
RealType km = abs(k - m);
if(km <= 15) {
RealType f = 1;
if(m < k) {
IntType i = m;
do {
++i;
f = f*(_u.btrd.nr/i - _u.btrd.r);
} while(i != k);
} else if(m > k) {
IntType i = k;
do {
++i;
v = v*(_u.btrd.nr/i - _u.btrd.r);
} while(i != m);
}
if(v <= f) return k;
else continue;
} else {
// final acceptance/rejection
v = log(v);
RealType rho =
(km/_u.btrd.npq)*(((km/3. + 0.625)*km + 1./6)/_u.btrd.npq + 0.5);
RealType t = -km*km/(2*_u.btrd.npq);
if(v < t - rho) return k;
if(v > t + rho) continue;
IntType nm = _t - m + 1;
RealType h = (m + 0.5)*log((m + 1)/(_u.btrd.r*nm))
+ fc(m) + fc(_t - m);
IntType nk = _t - k + 1;
if(v <= h + (_t+1)*log(static_cast<RealType>(nm)/nk)
+ (k + 0.5)*log(nk*_u.btrd.r/(k+1))
- fc(k)
- fc(_t - k))
{
return k;
} else {
continue;
}
}
}
}
template<class URNG>
IntType invert(IntType t, RealType p, URNG& urng) const
{
RealType q = 1 - p;
RealType s = p / q;
RealType a = (t + 1) * s;
RealType r = _u.q_n;
RealType u = uniform_01<RealType>()(urng);
IntType x = 0;
while(u > r) {
u = u - r;
++x;
RealType r1 = ((a/x) - s) * r;
// If r gets too small then the round-off error
// becomes a problem. At this point, p(i) is
// decreasing exponentially, so if we just call
// it 0, it's close enough. Note that the
// minimum value of q_n is about 1e-7, so we
// may need to be a little careful to make sure that
// we don't terminate the first time through the loop
// for float. (Hence the test that r is decreasing)
if(r1 < std::numeric_limits<RealType>::epsilon() && r1 < r) {
break;
}
r = r1;
}
return x;
}
// parameters
IntType _t;
RealType _p;
// common data
IntType m;
union {
// for btrd
struct {
RealType r;
RealType nr;
RealType npq;
RealType b;
RealType a;
RealType c;
RealType alpha;
RealType v_r;
RealType u_rv_r;
} btrd;
// for inversion
RealType q_n;
} _u;
/// @endcond
};
}
// backwards compatibility
using random::binomial_distribution;
}
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif
@@ -1,214 +0,0 @@
/* boost random/cauchy_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <istream>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/uniform_01.hpp>
namespace Boost {
namespace random {
// Cauchy distribution:
/**
* The cauchy distribution is a continuous distribution with two
* parameters, median and sigma.
*
* It has \f$\displaystyle p(x) = \frac{\sigma}{\pi(\sigma^2 + (x-m)^2)}\f$
*/
template<class RealType = double>
class cauchy_distribution
{
public:
typedef RealType input_type;
typedef RealType result_type;
class param_type
{
public:
typedef cauchy_distribution distribution_type;
/** Constructs the parameters of the cauchy distribution. */
explicit param_type(RealType median_arg = RealType(0.0),
RealType sigma_arg = RealType(1.0))
: _median(median_arg), _sigma(sigma_arg) {}
// backwards compatibility for Boost.Random
/** Returns the median of the distribution. */
RealType median() const { return _median; }
/** Returns the sigma parameter of the distribution. */
RealType sigma() const { return _sigma; }
// The new names in C++0x.
/** Returns the median of the distribution. */
RealType a() const { return _median; }
/** Returns the sigma parameter of the distribution. */
RealType b() const { return _sigma; }
/** Writes the parameters to a std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._median << " " << parm._sigma;
return os;
}
/** Reads the parameters from a std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._median >> std::ws >> parm._sigma;
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._median == rhs._median && lhs._sigma == rhs._sigma; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _median;
RealType _sigma;
};
/**
* Constructs a \cauchy_distribution with the paramters @c median
* and @c sigma.
*/
explicit cauchy_distribution(RealType median_arg = RealType(0.0),
RealType sigma_arg = RealType(1.0))
: _median(median_arg), _sigma(sigma_arg) { }
/**
* Constructs a \cauchy_distribution from it's parameters.
*/
explicit cauchy_distribution(const param_type& parm)
: _median(parm.median()), _sigma(parm.sigma()) { }
// compiler-generated copy ctor and assignment operator are fine
// backwards compatibility for Boost.Random
/** Returns: the "median" parameter of the distribution */
RealType median() const { return _median; }
/** Returns: the "sigma" parameter of the distribution */
RealType sigma() const { return _sigma; }
// The new names in C++0x
/** Returns: the "median" parameter of the distribution */
RealType a() const { return _median; }
/** Returns: the "sigma" parameter of the distribution */
RealType b() const { return _sigma; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return -(std::numeric_limits<RealType>::infinity)(); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return (std::numeric_limits<RealType>::infinity)(); }
param_type param() const { return param_type(_median, _sigma); }
void param(const param_type& parm)
{
_median = parm.median();
_sigma = parm.sigma();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/**
* Returns: A random variate distributed according to the
* cauchy distribution.
*/
template<class Engine>
result_type operator()(Engine& eng)
{
// Can we have a Boost::mathconst please?
const result_type pi = result_type(3.14159265358979323846);
using std::tan;
RealType val = uniform_01<RealType>()(eng)-result_type(0.5);
return _median + _sigma * tan(pi*val);
}
/**
* Returns: A random variate distributed according to the
* cauchy distribution with parameters specified by param.
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm)
{
return cauchy_distribution(parm)(eng);
}
/**
* Writes the distribution to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, cauchy_distribution, cd)
{
os << cd._median << " " << cd._sigma;
return os;
}
/**
* Reads the distribution from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, cauchy_distribution, cd)
{
is >> cd._median >> std::ws >> cd._sigma;
return is;
}
/**
* Returns true if the two distributions will produce
* identical sequences of values, given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(cauchy_distribution, lhs, rhs)
{ return lhs._median == rhs._median && lhs._sigma == rhs._sigma; }
/**
* Returns true if the two distributions may produce
* different sequences of values, given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(cauchy_distribution)
private:
RealType _median;
RealType _sigma;
};
} // namespace random
using random::cauchy_distribution;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
@@ -1,209 +0,0 @@
/* boost random/chi_squared_distribution.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_CHI_SQUARED_DISTRIBUTION_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_CHI_SQUARED_DISTRIBUTION_HPP_INCLUDED
#include <iosfwd>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/gamma_distribution.hpp>
namespace Boost {
namespace random {
/**
* The chi squared distribution is a real valued distribution with
* one parameter, @c n. The distribution produces values > 0.
*
* The distribution function is
* \f$\displaystyle P(x) = \frac{x^{(n/2)-1}e^{-x/2}}{\Gamma(n/2)2^{n/2}}\f$.
*/
template<class RealType = double>
class chi_squared_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef chi_squared_distribution distribution_type;
/**
* Construct a param_type object. @c n
* is the parameter of the distribution.
*
* Requires: t >=0 && 0 <= p <= 1
*/
explicit param_type(RealType n_arg = RealType(1))
: _n(n_arg)
{}
/** Returns the @c n parameter of the distribution. */
RealType n() const { return _n; }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const param_type& parm)
{
os << parm._n;
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, param_type& parm)
{
is >> parm._n;
return is;
}
#endif
/** Returns true if the parameters have the same values. */
friend bool operator==(const param_type& lhs, const param_type& rhs)
{
return lhs._n == rhs._n;
}
/** Returns true if the parameters have different values. */
friend bool operator!=(const param_type& lhs, const param_type& rhs)
{
return !(lhs == rhs);
}
private:
RealType _n;
};
/**
* Construct a @c chi_squared_distribution object. @c n
* is the parameter of the distribution.
*
* Requires: t >=0 && 0 <= p <= 1
*/
explicit chi_squared_distribution(RealType n_arg = RealType(1))
: _impl(static_cast<RealType>(n_arg / 2))
{
}
/**
* Construct an @c chi_squared_distribution object from the
* parameters.
*/
explicit chi_squared_distribution(const param_type& parm)
: _impl(static_cast<RealType>(parm.n() / 2))
{
}
/**
* Returns a random variate distributed according to the
* chi squared distribution.
*/
template<class URNG>
RealType operator()(URNG& urng)
{
return 2 * _impl(urng);
}
/**
* Returns a random variate distributed according to the
* chi squared distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return chi_squared_distribution(parm)(urng);
}
/** Returns the @c n parameter of the distribution. */
RealType n() const { return 2 * _impl.alpha(); }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const { return 0; }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const
{ return (std::numeric_limits<RealType>::infinity)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(n()); }
/** Sets parameters of the distribution. */
void param(const param_type& parm)
{
typedef gamma_distribution<RealType> impl_type;
typename impl_type::param_type impl_parm(static_cast<RealType>(parm.n() / 2));
_impl.param(impl_parm);
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { _impl.reset(); }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const chi_squared_distribution& c2d)
{
os << c2d.param();
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is,
chi_squared_distribution& c2d)
{
c2d.read(is);
return is;
}
#endif
/** Returns true if the two distributions will produce the same
sequence of values, given equal generators. */
friend bool operator==(const chi_squared_distribution& lhs,
const chi_squared_distribution& rhs)
{
return lhs._impl == rhs._impl;
}
/** Returns true if the two distributions could produce different
sequences of values, given equal generators. */
friend bool operator!=(const chi_squared_distribution& lhs,
const chi_squared_distribution& rhs)
{
return !(lhs == rhs);
}
private:
/// @cond show_private
template<class CharT, class Traits>
void read(std::basic_istream<CharT, Traits>& is) {
param_type parm;
if(is >> parm) {
param(parm);
}
}
gamma_distribution<RealType> _impl;
/// @endcond
};
}
}
#endif
@@ -1,40 +0,0 @@
/* boost random auto_link.hpp header file
*
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_AUTO_LINK_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_AUTO_LINK_HPP
#include <ActivBoost/config.hpp>
#if defined(ACTIV_BOOST_ALL_DYN_LINK) || defined(ACTIV_BOOST_RANDOM_DYN_LINK)
#if defined(ACTIV_BOOST_RANDOM_SOURCE)
#define ACTIV_BOOST_RANDOM_DECL ACTIV_BOOST_SYMBOL_EXPORT
#else
#define ACTIV_BOOST_RANDOM_DECL ACTIV_BOOST_SYMBOL_IMPORT
#endif
#endif
#ifndef ACTIV_BOOST_RANDOM_DECL
#define ACTIV_BOOST_RANDOM_DECL
#endif
#if !defined(ACTIV_BOOST_RANDOM_NO_LIB) && !defined(ACTIV_BOOST_ALL_NO_LIB) && !defined(ACTIV_BOOST_RANDOM_SOURCE)
#define ACTIV_BOOST_LIB_NAME Boost_random
#if defined(ACTIV_BOOST_RANDOM_DYN_LINK) || defined(ACTIV_BOOST_ALL_DYN_LINK)
#define ACTIV_BOOST_DYN_LINK
#endif
#include <ActivBoost/config/auto_link.hpp>
#endif
#endif
@@ -1,18 +0,0 @@
/* boost random/detail/config.hpp header file
*
* Copyright Steven Watanabe 2009
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#include <ActivBoost/config.hpp>
#if (defined(ACTIV_BOOST_NO_OPERATORS_IN_NAMESPACE) || defined(ACTIV_BOOST_NO_MEMBER_TEMPLATE_FRIENDS)) \
&& !defined(ACTIV_BOOST_MSVC)
#define ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
#endif
@@ -1,216 +0,0 @@
/* boost random/detail/const_mod.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_CONST_MOD_HPP
#define ACTIV_BOOST_RANDOM_CONST_MOD_HPP
#include <ActivBoost/assert.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/integer_traits.hpp>
#include <ActivBoost/type_traits/make_unsigned.hpp>
#include <ActivBoost/random/detail/large_arithmetic.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
template<class IntType, IntType m>
class const_mod
{
public:
static IntType apply(IntType x)
{
if(((unsigned_m() - 1) & unsigned_m()) == 0)
return (unsigned_type(x)) & (unsigned_m() - 1);
else {
IntType suppress_warnings = (m == 0);
ACTIV_BOOST_ASSERT(suppress_warnings == 0);
return x % (m + suppress_warnings);
}
}
static IntType add(IntType x, IntType c)
{
if(((unsigned_m() - 1) & unsigned_m()) == 0)
return (unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
else if(c == 0)
return x;
else if(x < m - c)
return x + c;
else
return x - (m - c);
}
static IntType mult(IntType a, IntType x)
{
if(((unsigned_m() - 1) & unsigned_m()) == 0)
return unsigned_type(a) * unsigned_type(x) & (unsigned_m() - 1);
else if(a == 0)
return 0;
else if(a == 1)
return x;
else if(m <= traits::const_max/a) // i.e. a*m <= max
return mult_small(a, x);
else if(traits::is_signed && (m%a < m/a))
return mult_schrage(a, x);
else
return mult_general(a, x);
}
static IntType mult_add(IntType a, IntType x, IntType c)
{
if(((unsigned_m() - 1) & unsigned_m()) == 0)
return (unsigned_type(a) * unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
else if(a == 0)
return c;
else if(m <= (traits::const_max-c)/a) { // i.e. a*m+c <= max
IntType suppress_warnings = (m == 0);
ACTIV_BOOST_ASSERT(suppress_warnings == 0);
return (a*x+c) % (m + suppress_warnings);
} else
return add(mult(a, x), c);
}
static IntType pow(IntType a, Boost::uintmax_t exponent)
{
IntType result = 1;
while(exponent != 0) {
if(exponent % 2 == 1) {
result = mult(result, a);
}
a = mult(a, a);
exponent /= 2;
}
return result;
}
static IntType invert(IntType x)
{ return x == 0 ? 0 : (m == 0? invert_euclidian0(x) : invert_euclidian(x)); }
private:
typedef integer_traits<IntType> traits;
typedef typename make_unsigned<IntType>::type unsigned_type;
const_mod(); // don't instantiate
static IntType mult_small(IntType a, IntType x)
{
IntType suppress_warnings = (m == 0);
ACTIV_BOOST_ASSERT(suppress_warnings == 0);
return a*x % (m + suppress_warnings);
}
static IntType mult_schrage(IntType a, IntType value)
{
const IntType q = m / a;
const IntType r = m % a;
ACTIV_BOOST_ASSERT(r < q); // check that overflow cannot happen
return sub(a*(value%q), r*(value/q));
}
static IntType mult_general(IntType a, IntType b)
{
IntType suppress_warnings = (m == 0);
ACTIV_BOOST_ASSERT(suppress_warnings == 0);
IntType modulus = m + suppress_warnings;
ACTIV_BOOST_ASSERT(modulus == m);
if(::Boost::uintmax_t(modulus) <=
(::std::numeric_limits< ::Boost::uintmax_t>::max)() / modulus)
{
return static_cast<IntType>(Boost::uintmax_t(a) * b % modulus);
} else {
return static_cast<IntType>(detail::mulmod(a, b, modulus));
}
}
static IntType sub(IntType a, IntType b)
{
if(a < b)
return m - (b - a);
else
return a - b;
}
static unsigned_type unsigned_m()
{
if(m == 0) {
return unsigned_type((std::numeric_limits<IntType>::max)()) + 1;
} else {
return unsigned_type(m);
}
}
// invert c in the finite field (mod m) (m must be prime)
static IntType invert_euclidian(IntType c)
{
// we are interested in the gcd factor for c, because this is our inverse
ACTIV_BOOST_ASSERT(c > 0);
IntType l1 = 0;
IntType l2 = 1;
IntType n = c;
IntType p = m;
for(;;) {
IntType q = p / n;
l1 += q * l2;
p -= q * n;
if(p == 0)
return l2;
IntType q2 = n / p;
l2 += q2 * l1;
n -= q2 * p;
if(n == 0)
return m - l1;
}
}
// invert c in the finite field (mod m) (c must be relatively prime to m)
static IntType invert_euclidian0(IntType c)
{
// we are interested in the gcd factor for c, because this is our inverse
ACTIV_BOOST_ASSERT(c > 0);
if(c == 1) return 1;
IntType l1 = 0;
IntType l2 = 1;
IntType n = c;
IntType p = m;
IntType max = (std::numeric_limits<IntType>::max)();
IntType q = max / n;
ACTIV_BOOST_ASSERT(max % n != n - 1 && "c must be relatively prime to m.");
l1 += q * l2;
p = max - q * n + 1;
for(;;) {
if(p == 0)
return l2;
IntType q2 = n / p;
l2 += q2 * l1;
n -= q2 * p;
if(n == 0)
return m - l1;
q = p / n;
l1 += q * l2;
p -= q * n;
}
}
};
} // namespace random
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_CONST_MOD_HPP
@@ -1,29 +0,0 @@
/* boost random/detail/disable_warnings.hpp header file
*
* Copyright Steven Watanabe 2009
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
// No #include guard. This header is intended to be included multiple times.
#include <ActivBoost/config.hpp>
#ifdef ACTIV_BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4512)
#pragma warning(disable:4127)
#pragma warning(disable:4724)
#pragma warning(disable:4800) // 'int' : forcing value to bool 'true' or 'false' (performance warning)
#endif
#if defined(ACTIV_BOOST_GCC) && ACTIV_BOOST_GCC >= 40600
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wlogical-op"
#endif
@@ -1,22 +0,0 @@
/* boost random/detail/enable_warnings.hpp header file
*
* Copyright Steven Watanabe 2009
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
// No #include guard. This header is intended to be included multiple times.
#ifdef ACTIV_BOOST_MSVC
#pragma warning(pop)
#endif
#if defined(ACTIV_BOOST_GCC) && ACTIV_BOOST_GCC >= 40600
#pragma GCC diagnostic pop
#endif
@@ -1,36 +0,0 @@
/* boost random/detail/generator_bits.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
#include <ActivBoost/limits.hpp>
namespace Boost {
namespace random {
namespace detail {
// This is a temporary measure that retains backwards
// compatibility.
template<class URNG>
struct generator_bits {
static std::size_t value() {
return std::numeric_limits<typename URNG::result_type>::digits;
}
};
} // namespace detail
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
@@ -1,40 +0,0 @@
/* boost random/mersenne_twister.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED_SEQ_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED_SEQ_HPP_INCLUDED
namespace Boost {
namespace random {
namespace detail {
template<class Generator>
class generator_seed_seq {
public:
generator_seed_seq(Generator& g) : gen(&g) {}
template<class It>
void generate(It first, It last) {
for(; first != last; ++first) {
*first = (*gen)();
}
}
private:
Generator* gen;
};
}
}
}
#endif
@@ -1,190 +0,0 @@
/* boost random/detail/gray_coded_qrng.hpp header file
*
* Copyright Justinas Vygintas Daugmaudis 2010-2018
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_GRAY_CODED_QRNG_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_GRAY_CODED_QRNG_HPP
#include <ActivBoost/random/detail/qrng_base.hpp>
#include <ActivBoost/core/bit.hpp> // lsb
#include <ActivBoost/throw_exception.hpp>
#include <stdexcept>
#include <functional> // bit_xor
#include <algorithm>
#include <ActivBoost/type_traits/conditional.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
//!\file
//!Describes the gray-coded quasi-random number generator base class template.
namespace Boost {
namespace random {
namespace qrng_detail {
template<class T> static int lsb( T x )
{
if( x == 0 )
{
ACTIV_BOOST_THROW_EXCEPTION( std::range_error( "qrng_detail::lsb: argument is 0" ) );
}
return Boost::core::countr_zero( x );
}
template<class T> static int msb( T x )
{
if( x == 0 )
{
ACTIV_BOOST_THROW_EXCEPTION( std::range_error( "qrng_detail::msb: argument is 0" ) );
}
return std::numeric_limits<T>::digits - 1 - Boost::core::countl_zero( x );
}
template<typename LatticeT>
class gray_coded_qrng
: public qrng_base<
gray_coded_qrng<LatticeT>
, LatticeT
, typename LatticeT::value_type
>
{
public:
typedef typename LatticeT::value_type result_type;
typedef result_type size_type;
private:
typedef gray_coded_qrng<LatticeT> self_t;
typedef qrng_base<self_t, LatticeT, size_type> base_t;
// The base needs to access modifying member f-ns, and we
// don't want these functions to be available for the public use
friend class qrng_base<self_t, LatticeT, size_type>;
// Respect lattice bit_count here
struct check_nothing {
inline static void bit_pos(unsigned) {}
inline static void code_size(size_type) {}
};
struct check_bit_range {
static void raise_bit_count() {
Boost::throw_exception( std::range_error("gray_coded_qrng: bit_count") );
}
inline static void bit_pos(unsigned bit_pos) {
if (bit_pos >= LatticeT::bit_count)
raise_bit_count();
}
inline static void code_size(size_type code) {
if (code > (self_t::max)())
raise_bit_count();
}
};
// We only want to check whether bit pos is outside the range if given bit_count
// is narrower than the size_type, otherwise checks compile to nothing.
ACTIV_BOOST_STATIC_ASSERT(LatticeT::bit_count <= std::numeric_limits<size_type>::digits);
typedef typename conditional<
((LatticeT::bit_count) < std::numeric_limits<size_type>::digits)
, check_bit_range
, check_nothing
>::type check_bit_range_t;
public:
//!Returns: Tight lower bound on the set of values returned by operator().
//!
//!Throws: nothing.
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 0; }
//!Returns: Tight upper bound on the set of values returned by operator().
//!
//!Throws: nothing.
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return low_bits_mask_t<LatticeT::bit_count>::sig_bits; }
explicit gray_coded_qrng(std::size_t dimension)
: base_t(dimension)
{}
// default copy c-tor is fine
// default assignment operator is fine
void seed()
{
set_zero_state();
update_quasi(0);
base_t::reset_seq(0);
}
void seed(const size_type init)
{
if (init != this->curr_seq())
{
// We don't want negative seeds.
check_seed_sign(init);
size_type seq_code = init + 1;
if (ACTIV_BOOST_UNLIKELY(!(init < seq_code)))
Boost::throw_exception( std::range_error("gray_coded_qrng: seed") );
seq_code ^= (seq_code >> 1);
// Fail if we see that seq_code is outside bit range.
// We do that before we even touch engine state.
check_bit_range_t::code_size(seq_code);
set_zero_state();
for (unsigned r = 0; seq_code != 0; ++r, seq_code >>= 1)
{
if (seq_code & static_cast<size_type>(1))
update_quasi(r);
}
}
// Everything went well, set the new seq count
base_t::reset_seq(init);
}
private:
void compute_seq(size_type seq)
{
// Find the position of the least-significant zero in sequence count.
// This is the bit that changes in the Gray-code representation as
// the count is advanced.
// Xor'ing with max() has the effect of flipping all the bits in seq,
// except for the sign bit.
unsigned r = qrng_detail::lsb(static_cast<size_type>(seq ^ (self_t::max)()));
check_bit_range_t::bit_pos(r);
update_quasi(r);
}
void update_quasi(unsigned r)
{
// Calculate the next state.
std::transform(this->state_begin(), this->state_end(),
this->lattice.iter_at(r * this->dimension()), this->state_begin(),
std::bit_xor<result_type>());
}
void set_zero_state()
{
std::fill(this->state_begin(), this->state_end(), result_type /*zero*/ ());
}
};
} // namespace qrng_detail
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DETAIL_GRAY_CODED_QRNG_HPP
@@ -1,120 +0,0 @@
/* boost random/detail/int_float_pair.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2010-2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_INT_FLOAT_PAIR_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_INT_FLOAT_PAIR_HPP
#include <utility>
#include <ActivBoost/integer.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/type_traits/make_unsigned.hpp>
#include <ActivBoost/type_traits/is_integral.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/random/uniform_int_distribution.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/random/detail/integer_log2.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class Engine>
inline typename Boost::make_unsigned<typename Engine::result_type>::type
generate_one_digit(Engine& eng, std::size_t bits)
{
typedef typename Engine::result_type base_result;
typedef typename Boost::make_unsigned<base_result>::type base_unsigned;
base_unsigned range =
detail::subtract<base_result>()((eng.max)(), (eng.min)());
base_unsigned y0_mask = (base_unsigned(2) << (bits - 1)) - 1;
base_unsigned y0 = (range + 1) & ~y0_mask;
base_unsigned u;
do {
u = detail::subtract<base_result>()(eng(), (eng.min)());
} while(y0 != 0 && u > base_unsigned(y0 - 1));
return u & y0_mask;
}
template<class RealType, std::size_t w, class Engine>
std::pair<RealType, int> generate_int_float_pair(Engine& eng, Boost::true_type)
{
typedef typename Engine::result_type base_result;
typedef typename Boost::make_unsigned<base_result>::type base_unsigned;
base_unsigned range =
detail::subtract<base_result>()((eng.max)(), (eng.min)());
std::size_t m =
(range == (std::numeric_limits<base_unsigned>::max)()) ?
std::numeric_limits<base_unsigned>::digits :
detail::integer_log2(range + 1);
int bucket = 0;
// process as many full digits as possible into the int part
for(std::size_t i = 0; i < w/m; ++i) {
base_unsigned u = generate_one_digit(eng, m);
bucket = (bucket << m) | u;
}
RealType r;
const std::size_t digits = std::numeric_limits<RealType>::digits;
{
base_unsigned u = generate_one_digit(eng, m);
base_unsigned mask = (base_unsigned(1) << (w%m)) - 1;
bucket = (bucket << (w%m)) | (mask & u);
const RealType mult = RealType(1)/RealType(base_unsigned(1) << (m - w%m));
// zero out unused bits
if (m - w%m > digits) {
u &= ~(base_unsigned(1) << (m - digits));
}
r = RealType(u >> (w%m)) * mult;
}
for(std::size_t i = m - w%m; i + m < digits; i += m) {
base_unsigned u = generate_one_digit(eng, m);
r += u;
r *= RealType(0.5)/RealType(base_unsigned(1) << (m - 1));
}
if (m - w%m < digits)
{
const std::size_t remaining = (digits - m + w%m) % m;
base_unsigned u = generate_one_digit(eng, m);
r += u & ((base_unsigned(2) << (remaining - 1)) - 1);
const RealType mult = RealType(0.5)/RealType(base_unsigned(1) << (remaining - 1));
r *= mult;
}
return std::make_pair(r, bucket);
}
template<class RealType, std::size_t w, class Engine>
inline std::pair<RealType, int> generate_int_float_pair(Engine& eng, Boost::false_type)
{
int bucket = uniform_int_distribution<>(0, (1 << w) - 1)(eng);
RealType r = uniform_01<RealType>()(eng);
return std::make_pair(r, bucket);
}
template<class RealType, std::size_t w, class Engine>
inline std::pair<RealType, int> generate_int_float_pair(Engine& eng)
{
typedef typename Engine::result_type base_result;
return generate_int_float_pair<RealType, w>(eng,
Boost::is_integral<base_result>());
}
} // namespace detail
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DETAIL_INT_FLOAT_PAIR_HPP
@@ -1,84 +0,0 @@
/* boost random/detail/integer_log2.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/integer/integer_log2.hpp>
namespace Boost {
namespace random {
namespace detail {
#if !defined(ACTIV_BOOST_NO_CXX11_CONSTEXPR)
#define ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR constexpr
#elif defined(ACTIV_BOOST_MSVC)
#define ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR __forceinline
#elif defined(__GNUC__) && __GNUC__ >= 4
#define ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR inline __attribute__((__const__)) __attribute__((__always_inline__))
#else
#define ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR inline
#endif
template<int Shift>
struct integer_log2_impl
{
#if defined(ACTIV_BOOST_NO_CXX11_CONSTEXPR)
template<class T>
ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
{
int update = ((t >> Shift) != 0) * Shift;
return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
}
#else
template<class T>
ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR static int apply2(T t, int accum, int update)
{
return integer_log2_impl<Shift / 2>::apply(t >> update, accum + update);
}
template<class T>
ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
{
return apply2(t, accum, ((t >> Shift) != 0) * Shift);
}
#endif
};
template<>
struct integer_log2_impl<1>
{
template<class T>
ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR static int apply(T t, int accum)
{
return int(t >> 1) + accum;
}
};
template<class T>
ACTIV_BOOST_RANDOM_DETAIL_CONSTEXPR int integer_log2(T t)
{
return integer_log2_impl<
::Boost::detail::max_pow2_less<
::std::numeric_limits<T>::digits, 4
>::value
>::apply(t, 0);
}
} // namespace detail
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DETAIL_INTEGER_LOG2_HPP
@@ -1,45 +0,0 @@
/* boost random/detail/iterator_mixin.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* Revision history
*/
#ifndef ACTIV_BOOST_ITERATOR_MIXIN_HPP
#define ACTIV_BOOST_ITERATOR_MIXIN_HPP
#include <ActivBoost/operators.hpp>
namespace Boost {
// must be in boost namespace, otherwise the inline friend trick fails
template<class Generator, class ResultType>
class generator_iterator_mixin_adapter
: incrementable<Generator>, equality_comparable<Generator>
{
public:
typedef std::input_iterator_tag iterator_category;
typedef ResultType value_type;
typedef std::ptrdiff_t difference_type;
typedef const value_type * pointer;
typedef const value_type & reference;
Generator& operator++() { v = cast()(); return cast(); }
const value_type& operator*() const { return v; }
protected:
// instantiate from derived classes only
generator_iterator_mixin_adapter() { }
void iterator_init() { operator++(); }
private:
Generator & cast() { return static_cast<Generator&>(*this); }
value_type v;
};
} // namespace Boost
#endif // ACTIV_BOOST_ITERATOR_MIXIN_HPP
@@ -1,122 +0,0 @@
/* boost random/detail/large_arithmetic.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/integer.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/integer_log2.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
namespace detail {
struct div_t {
Boost::uintmax_t quotient;
Boost::uintmax_t remainder;
};
inline div_t muldivmod(Boost::uintmax_t a, Boost::uintmax_t b, Boost::uintmax_t m)
{
const int bits =
::std::numeric_limits< ::Boost::uintmax_t>::digits / 2;
const ::Boost::uintmax_t mask = (::Boost::uintmax_t(1) << bits) - 1;
typedef ::Boost::uint_t<bits>::fast digit_t;
int shift = std::numeric_limits< ::Boost::uintmax_t>::digits - 1
- detail::integer_log2(m);
a <<= shift;
m <<= shift;
digit_t product[4] = { 0, 0, 0, 0 };
digit_t a_[2] = { digit_t(a & mask), digit_t((a >> bits) & mask) };
digit_t b_[2] = { digit_t(b & mask), digit_t((b >> bits) & mask) };
digit_t m_[2] = { digit_t(m & mask), digit_t((m >> bits) & mask) };
// multiply a * b
for(int i = 0; i < 2; ++i) {
digit_t carry = 0;
for(int j = 0; j < 2; ++j) {
::Boost::uint64_t temp = ::Boost::uintmax_t(a_[i]) * b_[j] +
carry + product[i + j];
product[i + j] = digit_t(temp & mask);
carry = digit_t(temp >> bits);
}
if(carry != 0) {
product[i + 2] += carry;
}
}
digit_t quotient[2];
if(m == 0) {
div_t result = {
((::Boost::uintmax_t(product[3]) << bits) | product[2]),
((::Boost::uintmax_t(product[1]) << bits) | product[0]) >> shift,
};
return result;
}
// divide product / m
for(int i = 3; i >= 2; --i) {
::Boost::uintmax_t temp =
::Boost::uintmax_t(product[i]) << bits | product[i - 1];
digit_t q = digit_t((product[i] == m_[1]) ? mask : temp / m_[1]);
::Boost::uintmax_t rem =
((temp - ::Boost::uintmax_t(q) * m_[1]) << bits) + product[i - 2];
::Boost::uintmax_t diff = m_[0] * ::Boost::uintmax_t(q);
int error = 0;
if(diff > rem) {
if(diff - rem > m) {
error = 2;
} else {
error = 1;
}
}
q -= error;
rem = rem + error * m - diff;
quotient[i - 2] = q;
product[i] = 0;
product[i-1] = static_cast<digit_t>((rem >> bits) & mask);
product[i-2] = static_cast<digit_t>(rem & mask);
}
div_t result = {
((::Boost::uintmax_t(quotient[1]) << bits) | quotient[0]),
((::Boost::uintmax_t(product[1]) << bits) | product[0]) >> shift,
};
return result;
}
inline Boost::uintmax_t muldiv(Boost::uintmax_t a, Boost::uintmax_t b, Boost::uintmax_t m)
{ return detail::muldivmod(a, b, m).quotient; }
inline Boost::uintmax_t mulmod(Boost::uintmax_t a, Boost::uintmax_t b, Boost::uintmax_t m)
{ return detail::muldivmod(a, b, m).remainder; }
} // namespace detail
} // namespace random
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_DETAIL_LARGE_ARITHMETIC_HPP
@@ -1,287 +0,0 @@
/*
skipping coefficients for N=17
three-parameter generator
* MIXMAX
* A Pseudo-Random Number Generator
*
*
* G.K.Savvidy and N.G.Ter-Arutyunian,
* On the Monte Carlo simulation of physical systems,
* J.Comput.Phys. 97, 566 (1991);
* Preprint EPI-865-16-86, Yerevan, Jan. 1986
*
* K.Savvidy
* The MIXMAX random number generator
* Comp. Phys. Commun. 196 (2015), pp 161–165
* http://dx.doi.org/10.1016/j.cpc.2015.06.003
*
*/
/*
skipping coefficients for N=17, m=2^36+1 and s=0
*/
{
{ 159701761865468764 , 126615459087983936 , 971935980882445987 , 1266425933430727482 , 330954324138038300 , 1494390944182608462 , 985567525599556189 , 1444303754750856766 , 1592836147366511740 , 944566361294427577 , 6336044263941214 , 686240801639476028 , 1446998785307329212 , 2077656654628400897 , 458344447554229916 , 1731527985347537415 , 1856587133043405783 }, // x^2^512
{ 582338566698838802 , 782718157798125637 , 684912925900277712 , 1271246213246651012 , 564133275057152122 , 1254731637174240011 , 899802366531028440 , 203611955528219606 , 2146610763813957982 , 115972700754870533 , 2092933746397577991 , 1136406621159800137 , 1067897330754616454 , 1722611875894083236 , 1630948851615767512 , 989604548662398765 , 421680943972696470 }, // x^2^513
{ 617097029144871694 , 2275108162235384877 , 1363862259022425560 , 153831723325577176 , 1962207167612439146 , 2011895465932033980 , 1007329645826843776 , 1300917526580470528 , 1171539246226411634 , 836665263844149790 , 1026633245683781179 , 32389807716467901 , 2296276234884428109 , 409297319724863974 , 1911430032287806834 , 916469329336553330 , 65677079513594107 }, // x^2^514
{ 1656997175938683235 , 334384582636879447 , 2289018900497662792 , 1053313217223819648 , 2529561867064419 , 2085279416854675588 , 2246944213774249775 , 917902382070457615 , 505594560851411438 , 1748690703652028000 , 1078212339021286156 , 170401217082007747 , 1552855376842911219 , 2209415219208922654 , 1174711397611724375 , 1342069058820567972 , 577671676013094771 }, // x^2^515
{ 200864199029196267 , 647584785983829858 , 449579673559383642 , 2210795481121719067 , 1185405708665067088 , 310118907549337558 , 1112237647478646030 , 907316892605650051 , 1241087052423417724 , 1441515240516850614 , 13684659557896782 , 1932376613205111310 , 60357690290969298 , 403792989584565525 , 102986206885970367 , 1838760170077135151 , 727651972830521938 }, // x^2^516
{ 2112835707304810889 , 583170948234442322 , 504636752552038260 , 1287047182580144501 , 2197579855548731362 , 1121897458052508302 , 1952770053431596080 , 772611988382900586 , 1985521487785539447 , 1011576935509998521 , 367571328103323233 , 1395044686007468872 , 398356602519830546 , 1118155658788636138 , 1242807300672421078 , 783603574838596371 , 2129902332243215295 }, // x^2^517
{ 476494511866938851 , 1225043666051930516 , 965084907571074277 , 48495729686479132 , 668653785847993343 , 1110923567965684699 , 1480594060141743070 , 1780050366926533029 , 1286523699078185217 , 669624786360998719 , 1865875391054214711 , 1887676069452920579 , 9982283268123603 , 1231842656474052119 , 1913212077924560289 , 1062511441187205188 , 698250642012057138 }, // x^2^518
{ 1052793057808933925 , 1488114650898155736 , 1809655216561165737 , 1766730333219340872 , 1142295800552777206 , 1197008472054994109 , 288311604729845194 , 1252198368803793342 , 1700393396484664348 , 1561218011609178732 , 1039496900875671159 , 1199061431134041566 , 217182459685479427 , 1965769716664277780 , 883713133563637492 , 855967538957706448 , 182946949964136989 }, // x^2^519
{ 521221301273005220 , 732177595172654650 , 1177004708676171981 , 491026482834387582 , 1475491185407701571 , 338551745124704898 , 322679017279562868 , 1102042763149957642 , 1781637400817890058 , 2230976132808504329 , 1647749103867940848 , 363540249136304168 , 1060964616691451642 , 856789607085849123 , 470641990892341750 , 1281772529585552540 , 603420272349730830 }, // x^2^520
{ 1803571173151157726 , 1944596483605820771 , 213094595441099858 , 901693591156501692 , 861915355835676099 , 635260099576893571 , 1982413183327998212 , 1120049474254535333 , 1505283430373136398 , 284189413831487026 , 1271922039532043918 , 154314556649628344 , 52549783574158204 , 584612521732421173 , 1901458131142776860 , 1937288889567974526 , 1212147240165209394 }, // x^2^521
{ 2034564475748864204 , 2101470381626210311 , 2288088283864667246 , 1914963188887983022 , 1095385391183929148 , 945106352371129676 , 1400087958043804470 , 1843694373265941018 , 389168898546209530 , 624173071047154320 , 1627380173012800657 , 1094171310315703468 , 1857806715885218084 , 1326770924244540642 , 2245083043975660260 , 807823933843072560 , 2287413039178247285 }, // x^2^522
{ 1438462501157028417 , 1178282907367658045 , 2151871713069448741 , 2216564753928829884 , 1135646926807917971 , 873250056357106251 , 1665621526869344532 , 1732452289298951455 , 1127204916768538887 , 1653631650320969340 , 1992482205762138263 , 1836865404020205588 , 1595463001888299444 , 958431756408955134 , 2110530659740056614 , 215688460376624015 , 1158251593711172802 }, // x^2^523
{ 1733925877085130548 , 2093555366416251473 , 2234101572813223254 , 27150917859587271 , 2120208241420965005 , 1740681603888968422 , 344809595448125388 , 2297225515944255048 , 2259042601422705288 , 872774782224758302 , 1492625124653803821 , 1721307140915414448 , 331124824482108658 , 120601336292842643 , 1057772943542838223 , 904281382213867256 , 2268149550994572836 }, // x^2^524
{ 1308619451049024014 , 362949499662291350 , 507935491259228365 , 1578906684563693579 , 1147252812024062738 , 170426700812984671 , 2292369007840245901 , 2278676904939144735 , 1661943824935578983 , 1151791566444763239 , 244664648985115502 , 788605939290857339 , 185329244981575100 , 2234030485122694225 , 1354886281367682733 , 1172982108216683874 , 1673999648423090090 }, // x^2^525
{ 12148567885654147 , 1372231622618064454 , 1512411127803286398 , 91088917975722538 , 1479647890243287328 , 720784302152223867 , 796410783806366571 , 581618991323966327 , 850700716339425563 , 930903615199005243 , 1411478967795549943 , 1395258853733301256 , 1287449265209562277 , 2138600707136677508 , 1952689678998032749 , 1536157936222739421 , 1365983300736022067 }, // x^2^526
{ 1614268848379872789 , 1977966741412095904 , 1868426217239032474 , 1603841034660414664 , 1538146046227581261 , 686243317632590721 , 1825936888550743483 , 1880896341340126997 , 368542569942961260 , 127908944176116453 , 2240186396348061575 , 1299238346503882153 , 2102660872371583004 , 1938050823525276998 , 1611779572790548487 , 923339421522954197 , 1640317376822349283 }, // x^2^527
{ 1068274751244808317 , 478761882933885805 , 146343578721548466 , 2122787414678627286 , 478616655821124071 , 1223652533398739090 , 1178267270852093552 , 1585682559495334861 , 448375108812347778 , 28390211070681947 , 1690010627725723003 , 1631513459519602506 , 344109887337730484 , 1228367175232395654 , 1245714930611054419 , 2076109931139359104 , 1028725609142702754 }, // x^2^528
{ 922695624671435383 , 1212395461257377598 , 2004462039540699849 , 1640073156934071824 , 2048256174899844882 , 1784439921745628237 , 1181704167380381729 , 1002268784211250265 , 1203700422140227637 , 414802973276697203 , 1506620899880171251 , 1653959500223714911 , 761577027275676953 , 1394862681050805826 , 283665158959068873 , 1674581989169655504 , 2170268137063855658 }, // x^2^529
{ 1531823228490667160 , 655178204437606577 , 1143440975987174633 , 1469225472530244216 , 1459815855107895954 , 169158503015419167 , 896992338984130145 , 2224392167406479582 , 334969241330017474 , 1210934779672254914 , 958852377915238487 , 916143882424925025 , 1228314367757567546 , 576985231081272085 , 69708611488908557 , 419353864719896559 , 2063012113607020176 }, // x^2^530
{ 1561213794756615274 , 1035561623111560834 , 236042828876112400 , 2227997009011010087 , 69191692217035803 , 680016809348368644 , 304720676536884446 , 402216461956911069 , 579355410310536007 , 2067077610395244217 , 850246508783344249 , 1267387033405622409 , 381166642361949681 , 745560785470896920 , 475789434723626541 , 624301081669895306 , 542440096530351799 }, // x^2^531
{ 292947975657821923 , 1975118192564031841 , 1096919547621493467 , 1963319303199452777 , 1497672437671054944 , 587569660431161322 , 1640139998254479090 , 2075259177632397124 , 1660504006066529017 , 2098448192586763026 , 2110557029504033173 , 1649560687483066215 , 1687307417474238546 , 1953341749861443552 , 1238894388766834138 , 1741784409005434700 , 961090363500770371 }, // x^2^532
{ 1383869753498066511 , 1233178641086644718 , 983298541932470614 , 670427917276364832 , 1594590175512954791 , 1215937832423358959 , 1903793454103261000 , 2172773248760515308 , 536919802769335489 , 1192052568730958579 , 1911240856897478532 , 474283681972418461 , 1641036102716815339 , 1411044907503618945 , 1001175747401094733 , 301211985765609746 , 87149012356549448 }, // x^2^533
{ 261502789562703795 , 2039292976033461220 , 1383214847400482168 , 617091957131872918 , 11536068257558752 , 1594678644021354556 , 75861344789992516 , 571299992729856381 , 1893030021771949746 , 955316100521264931 , 1984661955054505780 , 2011703935837291735 , 1088722461445557653 , 1179450192264585869 , 2187858293377977903 , 925337903456050826 , 646310246691765740 }, // x^2^534
{ 1067110047296065055 , 1681438952663914065 , 1912868211773513420 , 157328871056550869 , 1606539524193585050 , 1826960759022391567 , 333004198356937619 , 1654504867491237582 , 1675004459630487926 , 71936368060300 , 1918748055540842111 , 1831638571780226898 , 1740919230167947613 , 1865657023192411640 , 1938852440014266019 , 294008211664586131 , 1233347209473542392 }, // x^2^535
{ 1793671892574625082 , 1130285389461734712 , 2256576488166743893 , 499935214652909272 , 1154848893191704610 , 2081455429764661190 , 132180046418477201 , 2017092125714317442 , 1267352468781603191 , 1320951561119166755 , 1819380377385314624 , 1968657260504504792 , 795175392323167167 , 138949840583543195 , 2205578352394323161 , 2162095450973436967 , 144991897502595141 }, // x^2^536
{ 683024508151477474 , 1048650848431764111 , 222063671742581704 , 1033879240711051787 , 2065492192337124448 , 1040278918101037386 , 1671617116839141169 , 1142933505587090141 , 578155580871550072 , 1397916094430897857 , 1428297170374867004 , 343607952975225879 , 2212099097846398741 , 659520961168888597 , 1099474129656084832 , 163872983722101162 , 469023960460927874 }, // x^2^537
{ 1156093888444545360 , 477156936151507247 , 340730541722292373 , 1631554541005175777 , 186957487417408624 , 926739184035859811 , 1357420454563306968 , 1018117004392525830 , 363668834887049598 , 562598157996426449 , 1477447398167639388 , 570432714234334068 , 797165670329651828 , 927307345530529305 , 1474634744709399927 , 2245157369991218355 , 586948150323806327 }, // x^2^538
{ 267980979185924701 , 1565212575331069567 , 2036070690586106209 , 850842928652802398 , 1084085447966709199 , 53832993778516816 , 2236093215844622791 , 361324823691972021 , 673008249565884673 , 1820092500335360408 , 2155516028757275328 , 1127096462606937572 , 1358543969239663842 , 2250855440900689232 , 1750872323705159361 , 1362418718801185396 , 766489969361488653 }, // x^2^539
{ 259726699384885201 , 1899046140654817590 , 1306363085361051998 , 2081068431945330598 , 85108856372668378 , 1324347710267860858 , 637751183869623188 , 2248344050276940170 , 2150579538601288819 , 1105694420952032875 , 952722029405414348 , 1555403505154017419 , 2124427035047642831 , 2043566203745579024 , 2297745588334532887 , 383567419144690253 , 295720540923262008 }, // x^2^540
{ 1861487178452566675 , 1408373324284705278 , 1763971337054095719 , 830694774025045496 , 1222854782641346372 , 1367429629279521808 , 646871018425974561 , 594901312199197009 , 1347745885562466060 , 1872975180162717691 , 264288217725438485 , 1587326205070728608 , 636368619535248259 , 1345295891447307881 , 147325724921249282 , 451151671184877984 , 369152850758367779 }, // x^2^541
{ 57601454029724418 , 8965969940832902 , 1015753881352776595 , 1272955433813211634 , 1500099915165437510 , 1505908015386217991 , 2200135170747962774 , 898929787588318880 , 94174721104731682 , 2001843482426425606 , 1296185933469804867 , 2067771350105959635 , 244437767883759705 , 115304829559788030 , 1570793303180703663 , 2075829501594571540 , 1142789736568430590 }, // x^2^542
{ 1666339398200583535 , 352498459116081565 , 1296181205638634316 , 943151467845475937 , 1576590058032732201 , 991197898685844101 , 172929644755996237 , 348073447626095407 , 1119639777406826568 , 569438225411593708 , 2284730591697077199 , 62008449878226744 , 237477582274396799 , 284434691435252140 , 1765995421169394732 , 1594311192946755506 , 604156017409724002 }, // x^2^543
{ 495281382117458539 , 205408453347821044 , 1681558300394231421 , 768174766423516475 , 2178619873339022076 , 765997180179026402 , 102658969211254460 , 895017413823772592 , 415845558640901473 , 601933504588026198 , 969782745266307970 , 855044719798584000 , 2201199786666131647 , 1734600819975899129 , 1006570536931532428 , 1130105133424164395 , 1127782802378551477 }, // x^2^544
{ 2279222264094136096 , 918140621636386578 , 764051053229027870 , 284578302438407812 , 18442247946635388 , 31558521455257101 , 2294641003511473164 , 1698376578572281576 , 1937426563738038511 , 809127821329680664 , 1605067175404678954 , 189108927488132646 , 2042036507825496222 , 311247532621290928 , 1403615118897576721 , 1715491077248039654 , 1885408148480015203 }, // x^2^545
{ 1303703719061282226 , 2273657250242045723 , 1357599208936374367 , 635087130862478000 , 1079733394689912801 , 1118552166016645994 , 606420152917155530 , 1461390879031614972 , 104855646611743091 , 1155586802792637483 , 1332607042374593381 , 485954066105103318 , 755622945227398111 , 100703703472763330 , 2104688739715121722 , 884188331727454949 , 634077400952306173 }, // x^2^546
{ 951241189979241574 , 605016052445461627 , 2017048237067736326 , 989577001336697190 , 729360432477738078 , 1891686993869218661 , 1178287733434616934 , 2257768800220793298 , 386183991328298626 , 1256576692082166247 , 1989644154430757909 , 677803830671194177 , 233612802004492344 , 1711459201958972728 , 1493606889466009749 , 2046914649687863407 , 621460642415971297 }, // x^2^547
{ 1751267799283060659 , 2256655950470869985 , 984875549537277532 , 2146590585318069342 , 1539686266680012185 , 25924698613741241 , 633436588936544176 , 1549785231759087109 , 934442226797007335 , 1754392592879566030 , 1106511892592859350 , 2133384541112231515 , 483183511756818991 , 1106565501063528265 , 1107187069130962112 , 2075632961004138802 , 1789791698038574768 }, // x^2^548
{ 2168119975504999102 , 12966540192424488 , 681037686628849373 , 194933206197471208 , 1333929840850796338 , 2213746149905142918 , 1379421507825630221 , 672612248824101656 , 335325159518504203 , 1891726571269569489 , 838501400504296092 , 1301803583046081493 , 1750320150554937404 , 67761357879073926 , 1985524641824792115 , 1623610528663151019 , 1386176498075642165 }, // x^2^549
{ 1725373491573591435 , 1047415675966614123 , 1624486786194930396 , 1270371958501591477 , 915493804007886656 , 2289688909829684654 , 2049603525909314516 , 148613066066958793 , 726433066490138797 , 1727275655898645687 , 1975538226366019203 , 394922847880149584 , 462814805660060890 , 1087564105835469854 , 293119996590319709 , 561334965874644379 , 1159197305565422760 }, // x^2^550
{ 1167941940931666302 , 186514058829683028 , 284351732075544532 , 1512524808600673716 , 43881750227659649 , 1609741131150076188 , 1125658924019416678 , 1011534154384997338 , 732738003772919984 , 277064895441615462 , 1622677204527889015 , 1938173807800443399 , 2063908410477010918 , 48488552879373011 , 1181372505578038205 , 135655409305671122 , 1938059649851535706 }, // x^2^551
{ 337206759525681069 , 1755948102219815566 , 678765415558248151 , 1298324546232590789 , 484850096725079792 , 1257105102233963714 , 1905953290815779223 , 1631095014301272964 , 27718500263208979 , 850594049252190048 , 583977122492931140 , 1805594056761021711 , 1719584503850087741 , 86179004867644487 , 1270985715490800843 , 644779453772114088 , 1760476987252969926 }, // x^2^552
{ 853995884080236938 , 369111089848434712 , 559743835711047174 , 1594116816433474826 , 35842475217144553 , 2171235383636811428 , 765712905092749171 , 941173958645971457 , 608455896272321575 , 560604720551238557 , 1845649540169134916 , 1718920359984151079 , 1401755957661962268 , 1423907959444825866 , 1098311071256242778 , 1528916661846841494 , 1508764511499232241 }, // x^2^553
{ 1508791960279504205 , 258737323991262817 , 2078642398527055752 , 2047350895402792396 , 1386159783711778842 , 2027047763369412816 , 58440814829283402 , 771612188948247815 , 1023214498156083887 , 844220082620919469 , 868367506978956802 , 460654633908296364 , 2166638508094415965 , 2152060517892743275 , 2195460306854592144 , 541094667496643303 , 2293587356561486979 }, // x^2^554
{ 1214656342962583818 , 757702747146927395 , 2189480375257771121 , 1816527465277679192 , 138815664117127512 , 1431350214961325326 , 1187978151676236367 , 1241806570983467832 , 1284450519130025998 , 1613889771871333389 , 1061608822774622375 , 381417471969594147 , 2180713817066758069 , 1573268990076834701 , 905173682016321866 , 1950470428221045886 , 295485711949393017 }, // x^2^555
{ 819753035519543635 , 538715919221404699 , 2219429537481971437 , 752393850271742164 , 77092035906327214 , 1114501521607776562 , 1781083659997559466 , 2154696941256077128 , 1218985834766672241 , 211616781192221457 , 216411965392177616 , 1670594910477530341 , 714505138692032780 , 2103941244229463221 , 2088317230298558512 , 1289168057502589286 , 1125637208200814412 }, // x^2^556
{ 1962227768978994180 , 1690314396114180321 , 375465114688955302 , 1798066679445937030 , 462818969271150710 , 1000261197673181741 , 449380920277416447 , 2291003141210787002 , 1295168501047080160 , 96762399469569918 , 673992173479089483 , 22635411461259319 , 690222719954237584 , 336145523606337534 , 934574030654348792 , 1843383288751365671 , 1895192556383603959 }, // x^2^557
{ 22617970229773822 , 1482887891197581503 , 190614907712811083 , 693572772014158846 , 2013130701640461017 , 2080394974487399438 , 1946114308346089259 , 990495636788197392 , 1782544219386492119 , 661191434765959775 , 2044311906562246966 , 1069940178504200830 , 1955224049483069684 , 2032802635089013840 , 1312150198687724551 , 1790320974584854699 , 1722451636719440405 }, // x^2^558
{ 844270734204704640 , 144569156478286025 , 458434355726727522 , 54107521005723860 , 1370238437704355388 , 635959790870056500 , 580190401330281055 , 1190738125435083361 , 1508034736034112394 , 384356207961213908 , 2225422022608450401 , 1307978291279169425 , 1836303719023016910 , 1688394455914172152 , 1145318805385872977 , 28214091532568837 , 2271521727551942534 }, // x^2^559
{ 707823463534947110 , 1322853985703915624 , 1283965375707685336 , 1235846354925013921 , 2241994185339373382 , 1492018342988994366 , 354756557339909458 , 2038382297798252220 , 1998256038116472547 , 1191608355457210551 , 431624398742182860 , 979989445521359703 , 1874604718333228361 , 863699730728041575 , 303002850561444625 , 351750811939826058 , 2086150517074464097 }, // x^2^560
{ 938650030581340927 , 1484495848437960060 , 906987191271901948 , 602861889366282296 , 829217328598139608 , 1170659179365524445 , 136537691170306827 , 2263710078069587303 , 1916941180571676310 , 601979432897153599 , 2075793575506860756 , 323119178978530887 , 7962577560787577 , 959899426480760280 , 465731965934497666 , 485390457639864074 , 182578072602393068 }, // x^2^561
{ 845056639071703739 , 2022501832369820141 , 1551830514420859659 , 712651911384419505 , 1901754482233053508 , 771255057924942569 , 1624974410054352307 , 1095555020243807180 , 48292506949982043 , 1924628272072369018 , 354506579070195883 , 2074354629523999876 , 481327135146565647 , 1980060303227111264 , 374025770449242754 , 2197437559867642882 , 1347989415958383967 }, // x^2^562
{ 2284531938332082408 , 2081446697857700129 , 407946796335100046 , 2284742117207953792 , 310471079731850760 , 1290351582175218317 , 356273760688651989 , 1910139122966702303 , 380631662657835885 , 2287374039009394440 , 485797501634087358 , 900166727954042323 , 1169554169155638307 , 1802101457472636718 , 474217730229244850 , 1004410789585399243 , 588639270649921383 }, // x^2^563
{ 1502830393741044692 , 502885788914291282 , 1000641636223469702 , 599101320428395707 , 2179406366865940840 , 358024368445093522 , 1564063948136384394 , 2159233836362830609 , 1080529492271670836 , 737489746809287059 , 779539060254650511 , 567680696243734902 , 803303944361973640 , 1778879099887965284 , 2245121666542231208 , 280989822576167540 , 2256030916132704537 }, // x^2^564
{ 1678854909602034917 , 1362544615060522442 , 1338371892984320209 , 1236016995662152262 , 2266586199968442015 , 1429545066557982811 , 1057272578263945968 , 1902362138019567296 , 2027249515853796780 , 1379458255463795129 , 715456741316196206 , 483096191538955481 , 562452275970679447 , 1899368762554121096 , 1095218941132187764 , 1182616069429316286 , 2041204243971349283 }, // x^2^565
{ 1470384206682188393 , 993056282930013636 , 2186884113482342484 , 1568683072711048719 , 2141576651319216540 , 1545634359639056795 , 1451267712100583056 , 583449252763690840 , 743076343569515666 , 880735478838481309 , 1139615309806234587 , 1405631565601779814 , 1162183658026694832 , 758880015783224342 , 186132385266916884 , 299496669995968613 , 2115484609912800200 }, // x^2^566
{ 2269185097674681740 , 368408303414772947 , 2272053720551708375 , 1632770988466577149 , 2005375285078385494 , 1280199055327212680 , 1821048605091132853 , 1567765420710739271 , 1887232479893207919 , 2230675230841783167 , 1361156385383252011 , 87414071150394174 , 611216773833872434 , 1860713875917257321 , 1409775498386462397 , 1690326679721511537 , 83275546754626406 }, // x^2^567
{ 790112276274407445 , 769228027816192054 , 2205289911751012082 , 696806322595942722 , 1027622205316503460 , 1843245508230762915 , 181348331184190272 , 1685443775553823790 , 765291022909566823 , 1159224061954534775 , 1753833798485424233 , 1131135065567349204 , 1004980355827594316 , 1518506610289278726 , 1077654190664918382 , 2049836184231549381 , 186534172155365157 }, // x^2^568
{ 2214978522047075314 , 1523958231722460737 , 940540633818853829 , 1502207690061290977 , 1973166365192858632 , 834167590580214713 , 193198187070116104 , 1200481096199012868 , 1045382432042256669 , 1043046955924667651 , 1764037894194441387 , 326214257353715662 , 847610851336013740 , 821380410810508534 , 118611704753506829 , 212870724809513245 , 1049669518188822039 }, // x^2^569
{ 1186686984731968114 , 492485282093702769 , 2084974668148141701 , 1954670681979820725 , 158025799762360442 , 1546024887967767275 , 321250855908273132 , 1839134851204623669 , 2276195450093740401 , 216550545714992720 , 1147405869335269365 , 1691809800568592195 , 92303605959988217 , 1444340652242832966 , 1276065726666195728 , 324774933653588943 , 1312430778251072843 }, // x^2^570
{ 1914401401876468669 , 1648868062260221854 , 1464059991570664252 , 875976384406088755 , 859422856357056602 , 1864309596721585546 , 516857141291982496 , 464095730580902783 , 934796258134400377 , 1817127289097008540 , 655971001935077689 , 680288930067826216 , 229080197392071732 , 921859076031383827 , 2242366335784005876 , 2231689867120356867 , 102494160827714957 }, // x^2^571
{ 1047877418576672693 , 850258032575291687 , 545055359259387307 , 939787324567586678 , 588678011951547088 , 397057856974487431 , 226066134643513040 , 2082177109290521202 , 866921181848612589 , 1377167370849823007 , 923546628885112186 , 1369468709683575581 , 163347741879505736 , 63898233712570047 , 1837149445977275412 , 81917523037053887 , 1724871657333737359 }, // x^2^572
{ 2302595391708576272 , 160985864775068781 , 764451814383377581 , 277491655221007957 , 2065357052112797123 , 2022995433719782905 , 1992649094929659709 , 534121146273082282 , 2156280075941140984 , 1374921692284132634 , 7490180772772763 , 724537764516397075 , 1458937057231627989 , 2128708058250265224 , 1343524011236415024 , 1632380201084339158 , 218723970886479505 }, // x^2^573
{ 2117760628529948776 , 2132935432038525560 , 768781595656590901 , 1400974401324013175 , 1245919916200029631 , 1432559837530198229 , 1163713351897028899 , 1923146399637847839 , 1213782762495170404 , 541538612171639467 , 1998922401826244596 , 1231856100509046580 , 579861832524317272 , 342657654818204433 , 1849901794740458260 , 2279916971309950571 , 760499761682595396 }, // x^2^574
{ 2133951096918945939 , 245427172150052114 , 981217690063201632 , 2240543031382098229 , 72038350069308602 , 597184866817343336 , 328644676877024543 , 183469578860761428 , 1484808128953021465 , 1223798115302938004 , 622162521478669994 , 1190522948279756621 , 1770221081272204495 , 300642277489993017 , 323299607262829861 , 1121130797903609296 , 1341151672362966624 }, // x^2^575
{ 978460885885818525 , 1015163128148908540 , 1977562332100546610 , 2245843532918136978 , 52755975506265961 , 105385627927894157 , 1072178687697178180 , 2189119972792037580 , 1846365892857759522 , 509344149142820345 , 1764914861664878049 , 1812095995141658018 , 972953132412161570 , 1195708733082367698 , 49856206632166450 , 1968416938611340445 , 2224505860268693924 }, // x^2^576
{ 327862488024780357 , 1457219179227842324 , 2230322439686492524 , 1014759634574897984 , 268418936182947756 , 1502956125465763704 , 61942509184664792 , 1760829907047336797 , 1772759420678440112 , 213631264477227981 , 1260050930099550098 , 1356809535018841668 , 2084415297676571737 , 392165946698433004 , 823317575518425201 , 1619251312183556482 , 1475671506190286260 }, // x^2^577
{ 1056862459352327285 , 650761739286013201 , 711866770850654745 , 995772669095949341 , 638628037366816307 , 319488467144926010 , 146863433379310830 , 1101916435400125848 , 1403815239053246876 , 1038453114803570080 , 467259301797897322 , 1758832454145478316 , 359553557196445664 , 1487375835680896666 , 76291938912745016 , 844090192831690228 , 793442078170731733 }, // x^2^578
{ 1952837235717320563 , 445430339419636400 , 122525557445898274 , 735595189125576324 , 1842210194389261500 , 1795223307042139024 , 751864575701713084 , 1119184159833325999 , 700766534388037595 , 393549636253210822 , 1662606888175396198 , 777088695141990512 , 1949046976963730503 , 659714914447882016 , 1701619511100158747 , 2106648518620441962 , 2230177471130012298 }, // x^2^579
{ 2242830595691081287 , 2153702821027923023 , 2056432480338738486 , 290410908425161907 , 1981631243730724167 , 1568909835655310667 , 1868498486537085636 , 443377197549410236 , 1989171328893245017 , 832914678880127633 , 122754022462592655 , 2074425172477633432 , 450810432342594695 , 1304742577811847983 , 1915105538864887632 , 398240897735172221 , 854257484180168406 }, // x^2^580
{ 2200340348805749851 , 459904691507133993 , 1398407253135138579 , 2223256024161740360 , 605045994980733172 , 1376873737656823533 , 2154922394517147235 , 1733951063198734927 , 972687456101926553 , 901838082782677970 , 786315965699770073 , 220890454000213916 , 1082354731585990169 , 1575625362271244736 , 1934345059883646897 , 610599809596399831 , 342994941095873735 }, // x^2^581
{ 135197059374104208 , 763606053289129943 , 1762314800446038038 , 1958652087897421237 , 1759073139864458242 , 777882068437388702 , 1929274536720142390 , 911476487406644691 , 2214565556314441473 , 52312220897893321 , 1846728531947717379 , 2200466005983704615 , 262302790665678959 , 2226903910074888712 , 2217869614731681025 , 56279709804267946 , 2290324007417928442 }, // x^2^582
{ 2033888752861355042 , 1032905065687727870 , 1228320602981295572 , 507759480115032778 , 2286473996360684281 , 2214758482416116553 , 1809366838165194032 , 1058372692666396235 , 1752374720633908247 , 783225856075389703 , 1873729037970411918 , 515708137390539649 , 1758253278936485521 , 2232321656689971091 , 54123739319322403 , 1645021409194515326 , 128999663975261693 }, // x^2^583
{ 1548696340275626821 , 1058994430734061174 , 975903143090188182 , 1753221425369032354 , 642770173718849415 , 72871801728857389 , 1532366481913853262 , 1685179220297983661 , 221740024932865141 , 572304397314497403 , 1337436598601163606 , 615711199196774965 , 1856428633974911262 , 2091160220746353073 , 1268041182491440797 , 1823672822413606168 , 85882960870940069 }, // x^2^584
{ 1596386067990045239 , 1082049082776347514 , 964167595689777765 , 2196584899289686937 , 1775478739112084197 , 668585706672723348 , 148931594902619061 , 1989674837193253753 , 548537612282770315 , 1196600058755599499 , 40994948219245722 , 585997221548702784 , 1852642327512527056 , 1962368180715517868 , 647388617327737622 , 1259769006990328711 , 760195312392461746 }, // x^2^585
{ 718683317139573302 , 320255468933257119 , 1602065008785819027 , 811539625884985377 , 473380658706433597 , 1912262500486946501 , 470045053505719659 , 2044632105828108925 , 1926951883673524133 , 2227261383404374216 , 486603446225142281 , 663210447975562680 , 939660586393225605 , 285150104962906352 , 1736759590302217217 , 1557356149606075095 , 202888193082920775 }, // x^2^586
{ 1704252131283387210 , 749862216125654467 , 1151691390735685357 , 1645735627001577084 , 1704474438618968650 , 748171802247682061 , 2192661098187053709 , 687285052039352483 , 854812886608086510 , 1254425642986060904 , 1755448133247766409 , 2011170119775364505 , 2238140979402216154 , 430682510031291698 , 1344094596771993123 , 1487316607310729340 , 572027053290063200 }, // x^2^587
{ 490145643447149312 , 139932608980010944 , 655464257025259880 , 394296759589777370 , 505632773723135101 , 1661411471151623719 , 2151487638856430824 , 1405022191175603197 , 1752924822934387289 , 540705285689857192 , 321557534615604425 , 357668350120260760 , 1216461776875955281 , 227959942379372288 , 1843268809411056088 , 1278964120834620296 , 1475031348508152943 }, // x^2^588
{ 77196441284986546 , 2116432279354126192 , 477307664737255679 , 2054284248076058866 , 1902595507518183399 , 892309383355817071 , 632707825296532637 , 2068144493364120654 , 2269464712931165434 , 1869550090717623995 , 1230295724219128689 , 265213902138950946 , 2035223329405422145 , 1942656580078323795 , 1193709919134967859 , 2129017786957860238 , 1381902932849007959 }, // x^2^589
{ 1250515786673063664 , 1170029995563455371 , 1875333685750981198 , 202301072852130868 , 2043478147118479243 , 1430654884019451218 , 1932432698651776626 , 906545901346634684 , 300667563272986237 , 1419422183404003464 , 1991379549654933852 , 647455449394880739 , 694191473419776108 , 276654368069638649 , 327518818778853777 , 776612031552014882 , 754333675021774044 }, // x^2^590
{ 1494337748978015003 , 2195753570178835409 , 1756395833112881603 , 1391513303657053978 , 1469720991718755668 , 1385546023774706695 , 2174495928889154879 , 1845916193012260560 , 1508599521784450080 , 1646177877887412686 , 1600214236327823295 , 481492506494972498 , 607939032270197735 , 1035787083329757142 , 1867038566495963823 , 1327899656420714797 , 120455193991568778 }, // x^2^591
{ 1272270033586499361 , 1355938084262029033 , 1130547642931602057 , 1571210037203668042 , 109838764087692662 , 665089929034619866 , 1477929841071085716 , 354404882207113353 , 485207799804145872 , 295271887824129191 , 1434571796278931709 , 1640884996563085247 , 349639709072954139 , 2048198598052923555 , 524893036895320686 , 2241615913147991183 , 1476041495950183974 }, // x^2^592
{ 1191478803597513079 , 179928617987606724 , 1893767020776627979 , 2279764014883753334 , 2000307147025567411 , 1317337023680470054 , 2103432586600253524 , 72635103884479033 , 2120393133065940248 , 630577942926446005 , 184690001576938472 , 724734720983686380 , 2222559033240707306 , 957823503700662442 , 1530455664164510916 , 1897774219578829063 , 1565275869726572277 }, // x^2^593
{ 802169516563427070 , 2266388954150660250 , 1016109430849964502 , 425155158957108184 , 1509177586061010059 , 735042889547641844 , 435841014763623437 , 552466077216086185 , 1380304476103110982 , 67287297735634201 , 447647206919187346 , 2068383112520459072 , 1700683878491979663 , 876911219219450197 , 1724440678224620967 , 2161646349907542457 , 1646103618347380320 }, // x^2^594
{ 612487302971671307 , 1375201488802854426 , 381927427343438951 , 522937542366715499 , 344542446499511062 , 2207818055791032517 , 1589757712162343309 , 800577551503529820 , 1901158862710281177 , 282526012842555873 , 978266672216571827 , 851384948740770681 , 1847198461333883874 , 1701120025203313330 , 1579726260607682225 , 425398491832428623 , 470525020962949424 }, // x^2^595
{ 2088490725567484178 , 485853289338907617 , 1031877816384950332 , 2204970857389602283 , 1742289513696508421 , 1887097317304814932 , 611739697091118719 , 620524462574164777 , 866744533296715680 , 113249287824674575 , 1094771911813698402 , 1113977650240159227 , 597674782116109822 , 745608676499086192 , 1626698293359327222 , 1428826314680818479 , 2215603110047911506 }, // x^2^596
{ 376585604887633526 , 1048922386135384477 , 2142424598885808255 , 675251024248975850 , 1545330669815065990 , 1857893574217764638 , 2048982207690498307 , 1533653988510679070 , 335130892749828677 , 104131490905494608 , 2194266840041437356 , 683616020969961024 , 2038987316895996656 , 917297429323765875 , 821082630191764403 , 1666057951671669384 , 1130032032943836952 }, // x^2^597
{ 1041829149523127110 , 1951902012535484719 , 2152661804693326326 , 1269908279296181874 , 971953632796866049 , 1266540697681616989 , 2071865642155459708 , 845692533418042777 , 1241457687074422224 , 161412923983560739 , 390632925491962906 , 353948016710720772 , 2026700469979616031 , 96483949026756707 , 1773219759585896547 , 993715984447404907 , 1829150519300709735 }, // x^2^598
{ 877798478622581516 , 942092329022409512 , 1965158005364305044 , 1441028099309753513 , 500071448451573682 , 1840680567469132321 , 1468971950339879193 , 1438547156759802726 , 549595496973813971 , 390734351826704403 , 1073287705054298510 , 48924576386470253 , 1989283157579117827 , 187450184005400512 , 1949224458829795298 , 1951496711030456157 , 2167858042677531808 }, // x^2^599
{ 1996597802411685974 , 114349701898949545 , 1084220018985830117 , 27462757590845683 , 1081095686730339174 , 2059987003957425282 , 1321806358033656174 , 1828830847664378831 , 1455949950124722259 , 477041639297859939 , 2295506231622178555 , 1152831764620264515 , 396805345192155178 , 2211812614000847756 , 1962229985869550296 , 848640427896833485 , 548986687197667440 }, // x^2^600
{ 491594119422354073 , 1742453895833966377 , 1525602929914324406 , 2076597071019376631 , 865550929971279566 , 997883929562138029 , 610577039659314246 , 1003718639233780963 , 1951174507028809908 , 1185710764340213666 , 1693015712372426191 , 317455835845832474 , 1848795541252464763 , 401332635199514101 , 224456822593358236 , 742409296289707819 , 2118807906613325507 }, // x^2^601
{ 1293009127273644989 , 1124274480353253667 , 1810129434176838306 , 259729045897854950 , 1468101939413453436 , 1111947300756487949 , 501989537109533070 , 1388491866061828170 , 1312270603637319867 , 1615629996017192524 , 2134426516814571448 , 548391958129447766 , 1852805539182613949 , 562903002408545356 , 1582149854427086182 , 1136405868045684314 , 679089614531440081 }, // x^2^602
{ 786115001012233217 , 572934901393961574 , 906662352794537253 , 1146052338661137694 , 1717117579480047687 , 2238979311119472866 , 1282072454711511764 , 913074328950615201 , 1508062462715721091 , 585179548016207318 , 2263240538685112497 , 212602680696443031 , 2286609014980268736 , 2160223566289961256 , 457719410118216561 , 892534882541613344 , 1802928045269113919 }, // x^2^603
{ 412244890005542545 , 882317329387396531 , 1194216517008066508 , 2113679728861695547 , 754826510247388584 , 143906396701128982 , 1624499088946075077 , 1517734354505524658 , 1319665375831884375 , 108068462219720639 , 2061550944874121143 , 1387192717449700004 , 1784206536018821508 , 1531349906234275665 , 37851629185782003 , 1964408593925350957 , 675543575437141874 }, // x^2^604
{ 2224871078409190905 , 1109593689354222314 , 2282026642284422235 , 1526142908234895159 , 1185903712917801891 , 2095637833179633450 , 1684061887934064807 , 1459637973270975973 , 2080524575243813761 , 948583036372588019 , 1196499685761340006 , 1838560132753716756 , 1035066941117701308 , 1633636158414982077 , 2082933534230116545 , 161677865488580416 , 936609732430805584 }, // x^2^605
{ 409257345609329461 , 1002655167281875678 , 18470199587775000 , 2184022032975947208 , 148234944683729763 , 2162572938835480438 , 1216127754790813623 , 1303762224282752882 , 2064136757082740176 , 518955562885803190 , 1212819681300030394 , 486562075491162613 , 1283290324562294532 , 285537074615846742 , 321224661976450451 , 2089560323722387545 , 238275251292120492 }, // x^2^606
{ 2214799429964260023 , 694747922604332887 , 312465276764308387 , 314561248153726635 , 1765153767754864756 , 1092506825381016367 , 1475330654269567868 , 1379961995474423138 , 1380037933141733384 , 767686246763038167 , 2008926192530430712 , 304944109134708306 , 261183406799178779 , 326684916374054817 , 1565573428651338229 , 1920871811367768904 , 2089282340964983664 }, // x^2^607
{ 1133198628406257078 , 977759521511265809 , 1677025924443289061 , 1729641585066757341 , 2008693257322528571 , 1421311051680525446 , 2030362323209952329 , 1921889928974731930 , 1093849407549420400 , 1836335521578497369 , 407868381069619222 , 10208083363410986 , 1550647306879485613 , 1032274398117330349 , 889271835949247699 , 508828554264478304 , 313811787637759042 }, // x^2^608
{ 265345699270236054 , 432199859212969150 , 874558322199992458 , 1131965915049654978 , 298519106167257998 , 10561017697598846 , 1036255447357471766 , 990617823928118898 , 183634792806558724 , 123066866696319933 , 1303845119890513396 , 1915539994626985074 , 2074006245341867746 , 442443726074289720 , 1398504520177556356 , 2177822133301482183 , 1618315631184181685 }, // x^2^609
{ 2281731104267965972 , 1565833165249376146 , 2084133230658243672 , 1466077014346623711 , 2100113102745347532 , 1509772133714278653 , 1072220688498313491 , 698970180110383152 , 1702069119117461364 , 786447122909266339 , 1700725262288581680 , 1201605067747742747 , 1285909410275446050 , 465944984489850383 , 1581258227975449663 , 1468892983675794809 , 698369184018114847 }, // x^2^610
{ 721614432883106726 , 1168570529527401436 , 1558741633956623588 , 625821206916677993 , 1729484582639558993 , 202818544256349027 , 942584755749892262 , 384853745237896372 , 1878778990418394018 , 2006136039057883787 , 2000492489726132701 , 1628427185964600209 , 456608645446900334 , 559232459658214239 , 1425457030239632449 , 287429815653732691 , 1537646113987862352 }, // x^2^611
{ 168932144896498705 , 1584765261048819233 , 505170343346470483 , 1661727371938733976 , 58225995502531476 , 1069662977595621678 , 1534921440358104004 , 1665430445118051718 , 1421063952495178964 , 1964407550412120431 , 271153105959670492 , 1303954744475330405 , 1402417619008570585 , 2067748336717081462 , 635378162740815380 , 1966388298672109925 , 2276135507117268900 }, // x^2^612
{ 209516738545946051 , 126364818200849051 , 1934171883678238548 , 964383175854976730 , 1426910927989095855 , 1225737711393069252 , 545817142750996161 , 1941470598322211846 , 1888603351110522964 , 1693849545801590503 , 1145960696683862080 , 1544154409134561092 , 2057079562609173728 , 333449282037994372 , 2138527354092198252 , 1857839034788608299 , 96149649256385712 }, // x^2^613
{ 1680829537551411728 , 2134567358027244766 , 2233241443836144884 , 882397883456946081 , 1272913220199061746 , 7737651019535212 , 554065101789910033 , 1237958145783195446 , 1349598693130928045 , 1212195573003581110 , 1392362203075907328 , 913027022784782751 , 411026031675105306 , 872967435734543202 , 294712992119516029 , 272260211295161762 , 1636719289988127499 }, // x^2^614
{ 1664102028071512887 , 1120090114167125698 , 678215188753805783 , 2138907996085142066 , 1721907479145867302 , 1086048121088426493 , 282597371457515207 , 2252562071097166874 , 880501568810700587 , 1513947683103494818 , 118765667707656670 , 133926112036721838 , 567919878484948061 , 79410381524546935 , 1454226739666450321 , 1554107108291191805 , 1442417286842488623 }, // x^2^615
{ 1332050352400493680 , 1321101334747797025 , 124286076382368784 , 2016174712781756901 , 1731820299459346863 , 545006347537545995 , 1068874777126444609 , 767902913608305873 , 2267594054719694251 , 1590335123866293983 , 868156357394677648 , 2249143243430804218 , 347528411881171670 , 1754162230470399965 , 2070435897818234391 , 1115080034382184583 , 727133352156610422 }, // x^2^616
{ 355843900790907311 , 363191259548386230 , 1247995738147301243 , 1637822561418229980 , 2161312386590710193 , 827479641142168242 , 551490280055656820 , 116433208177525158 , 219743626260276428 , 1031342298455165770 , 956941458946607562 , 1971095287608216767 , 1197895453910374577 , 758722071093994752 , 777125942555276007 , 1415023106509593626 , 318953060159670820 }, // x^2^617
{ 2116009462654498660 , 816261448355929278 , 2272633719403001435 , 573255612065573253 , 968141095699581750 , 1763511366639175689 , 1173137617258455966 , 481749672060198864 , 750918552038818940 , 519539565364235474 , 1926446971667744959 , 313336000413603815 , 515893570456318246 , 1497339799087374476 , 478287049521531475 , 1236625257683288385 , 359335556903155074 }, // x^2^618
{ 284411256262633501 , 1789336543617378723 , 1511246373802383265 , 937616018328420337 , 138227234082520224 , 1667286674451103850 , 693601919163926025 , 13505785652584434 , 720941360686097746 , 958299499540120680 , 2165799682030822154 , 569950597702024056 , 655621404198221825 , 1755168971312171278 , 2043596507506252973 , 723457099999134940 , 542348768717201728 }, // x^2^619
{ 14465848372683520 , 998603764202551247 , 724938950471219595 , 325209651844259777 , 821482747183096187 , 2233461975545399202 , 1931346739821426382 , 2293325179294131554 , 243302969523090162 , 1510343779638164774 , 959965695881709576 , 1831708054543131034 , 883847853251423712 , 1165812877635303160 , 2007671568816070608 , 44906786919162811 , 1277515245984716365 }, // x^2^620
{ 631454168243258384 , 1518494517880443027 , 2287322260213126417 , 73685056254736833 , 942598569327822559 , 1532992770144658039 , 2229403027115926821 , 842743413258963958 , 1865437000699847820 , 369346269649870812 , 1254468168457467223 , 559290945795297932 , 1457535932113599162 , 1926542806880420086 , 437581909774872900 , 1002726378631501533 , 182139319307728305 }, // x^2^621
{ 1539785164984779758 , 2045565025200148915 , 120085588989386291 , 1851688824536244542 , 1980194980609785714 , 1768302648237998273 , 937420755919973678 , 2210791368804399387 , 328708870574712683 , 1007467584698506438 , 928652866696652949 , 2228808519508067530 , 1642940388306822455 , 1618552641970232946 , 108597732587521580 , 1988412225258659433 , 1660448156453751001 }, // x^2^622
{ 131526482323749840 , 503434317381483751 , 1560765838807596555 , 1027232124412255852 , 654779282895217397 , 2273302731188942421 , 1551720915692515402 , 1826828338382462468 , 604485879763220723 , 1057737165588422306 , 106531819221246981 , 425783162197347937 , 489984741847314768 , 523779814301405487 , 1865105780134618992 , 1677103130386412459 , 318671848522267610 }, // x^2^623
{ 1639089103549084783 , 2260330277551218496 , 754892153485552977 , 2047710903557972804 , 2229320667962732246 , 307697180850646681 , 423771572510991367 , 17754501861697173 , 1238910344976760345 , 339140894113319789 , 1445828176546996833 , 2042997377381022070 , 2207437390435628445 , 551144982338719121 , 384944764939825909 , 1474198471229196249 , 1659242296891127810 }, // x^2^624
{ 795309147716951006 , 1452711178054134843 , 1664782861363981358 , 1006405310566793269 , 971226122955741921 , 752466486101956684 , 1168643572163743942 , 1369730711422397346 , 627654132922219702 , 2104230754718381006 , 1588968809641801416 , 440238626377162178 , 732134947635506053 , 1160506871469695759 , 395151165185992129 , 957703098223865589 , 1844022625316455575 }, // x^2^625
{ 1964890520513046164 , 829237203674997277 , 1045128031232022678 , 930832386865989645 , 501678256081635892 , 917829023495631073 , 881831635034313098 , 394230956869842550 , 71895808688446751 , 1874849501133161758 , 645524260474403693 , 301748792077270066 , 1063834409487547589 , 521966335959428443 , 735272076777014321 , 753999758410424987 , 292792781171616060 }, // x^2^626
{ 1976769506118304887 , 328773719961068411 , 538585052711106822 , 2240145575420715174 , 1291008337036982313 , 1034350880207773432 , 1888353090737342761 , 1978548213503129609 , 743903982747501766 , 2240529593386457105 , 229308641102639039 , 1678061221588734337 , 1248567483083113072 , 1768596733943584627 , 1268676342298500384 , 216631313378191648 , 1830565281699080858 }, // x^2^627
{ 222335339024805767 , 146026382943095887 , 1745991091656491682 , 364572344137903996 , 491711339269051713 , 1355802228883764600 , 2287182613212117809 , 1628584733201147266 , 1730760626189599809 , 1568968802576521126 , 311144633575093285 , 1257985237943883059 , 2071814648333720000 , 687885153740420654 , 134464058021476074 , 1159135545218675174 , 1046016356313666266 }, // x^2^628
{ 2218238585802550263 , 1796073488881922547 , 108147160614248440 , 2147497677742828723 , 940377749228338777 , 166702239352185028 , 14837186174842935 , 1881782378259233528 , 442792017566957734 , 1550966771279227259 , 1902483003501989215 , 660158154476503000 , 673105302791153020 , 749237522153030898 , 904762939332248683 , 1085180116177134000 , 32410680807805190 }, // x^2^629
{ 1565357784323540059 , 2004567400386087250 , 563556471193393347 , 2176504294263508416 , 1354931238262729258 , 1868302215996805633 , 1039100426489789297 , 540592058162156675 , 2043699722662531658 , 1444431990121166178 , 931232743518887886 , 2055389098129788451 , 1235540167366576898 , 1090861860232324736 , 1732281293507875925 , 1285969498415451875 , 1757636524168521125 }, // x^2^630
{ 2235287391127506303 , 1401636021589024058 , 2051095569701746947 , 644542369524563085 , 1717409066688580033 , 839878318363782234 , 964338104498650467 , 193111125860611415 , 41226228181058700 , 659802192172642300 , 481644033258717967 , 1649597320109931775 , 1169882823869469374 , 2274302558105332483 , 318951044439334783 , 1790653470898866515 , 1273274762300650850 }, // x^2^631
{ 300315997535491308 , 2172766343039137706 , 1640387745692897945 , 1527918068635484048 , 882433389130238556 , 519571876740982088 , 840810181955840317 , 967721991925117462 , 757987265005423150 , 692837321139327525 , 1347675233763916865 , 1262263002781039893 , 366275012213686434 , 1720518743710286974 , 788123176573078844 , 118677909193430055 , 331168466283501375 }, // x^2^632
{ 2204724021283944336 , 614667311623152683 , 1844295995732490949 , 810904822281747865 , 1057803411491878257 , 2192784617269518738 , 525328525709235908 , 1625675926696707314 , 2219520795837515346 , 1111578739349697071 , 850264822465802254 , 1875225445537474991 , 447934460789202298 , 1577693216054964532 , 2069208581718856575 , 1844971513814599533 , 1100047974003437056 }, // x^2^633
{ 212063919658939349 , 1955050766498331130 , 1016643445611085361 , 310923000117302398 , 1108559594383531725 , 1574096462279058604 , 2058721019806527059 , 1495555971494333315 , 1290148625133033915 , 1726857770258998357 , 839176472902748525 , 1938011636448040623 , 1509176691584187835 , 1684996881754410913 , 339436873350779373 , 1476161426144378753 , 1443502235558451143 }, // x^2^634
{ 2154146131717687018 , 1161290317713326050 , 362912384144320809 , 1110332862415808487 , 716729690755657231 , 1048283751964241153 , 1336749180461386759 , 2280348028206541371 , 1259918326978354156 , 1980538993489881425 , 1333565492277683625 , 514625871678292821 , 1173265787958600132 , 569893472219264300 , 812175666077334991 , 1255701238860433930 , 79993120593823961 }, // x^2^635
{ 409217992666385378 , 728224420299246128 , 1959936179576785895 , 1444295307550571182 , 998063979246407739 , 554682441648959407 , 2073233365208088525 , 1349861235690939694 , 1097281043663983707 , 1649731108960027223 , 2214398868943408274 , 1449553717147663103 , 2196500661345051527 , 2171871885380914429 , 491427195052411299 , 470657045051378516 , 554494320060727622 }, // x^2^636
{ 2211653713656632985 , 1473087100459732074 , 345838890415354412 , 1445623252958685565 , 1041419654691395738 , 2188283266242968331 , 1417777133392604784 , 1154814074996216406 , 1442989098963226134 , 901383116742510681 , 497212216058355345 , 999731586376214828 , 817831951035275271 , 159325628653133022 , 120914548489015393 , 1449314802372642427 , 471104110110980884 }, // x^2^637
{ 323038291515073224 , 265070044955668299 , 1053676807411822176 , 2247226908652601286 , 2083016828474103062 , 273234004102527575 , 11857926472424922 , 2055314572998661967 , 311921811886787132 , 1870415531374949840 , 21265502209057804 , 678112836970959466 , 926490438737525589 , 2027644346888215584 , 495557988374717777 , 1817993454480752541 , 2141242677896973878 }, // x^2^638
{ 1445163042542523231 , 1767410038768111356 , 462427149761798838 , 1007504177155879483 , 1181224656949316486 , 357022206754812124 , 1898271363493710619 , 1339720449183752193 , 883758224923786172 , 36020177946849132 , 461791639260431974 , 1411405712850290498 , 701758173778161093 , 1222887871945629218 , 1174213062638935911 , 326342461405188581 , 2211032895429848005 } // x^2^639
};
@@ -1,514 +0,0 @@
/* boost random/detail/nierderreiter_base2_table.hpp header file
*
* Copyright Justinas Vygintas Daugmaudis 2010-2018
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_NIEDERREITER_BASE2_TABLE_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_NIEDERREITER_BASE2_TABLE_HPP
#include <ActivBoost/config.hpp>
#include <cstddef>
namespace Boost {
namespace random {
namespace detail {
namespace qrng_tables {
// Maximum allowed space dimension. This number of dimensions has been
// chosen because up to 4720th GF(2) prime the values fit to unsigned short,
// which produces a (still) reasonably small table.
#define ACTIV_BOOST_RANDOM_NIEDERREITER_BASE2_MAX_DIMENSION 4720
struct niederreiter_base2
{
ACTIV_BOOST_STATIC_CONSTANT(unsigned, max_dimension = ACTIV_BOOST_RANDOM_NIEDERREITER_BASE2_MAX_DIMENSION);
typedef unsigned short value_type;
// Binary irreducible polynomials (primes in the ring GF(2)[X]), evaluated at X=2.
// Mathematica code:
// Reap[
// Do[If[IrreduciblePolynomialQ[
// IntegerDigits[n, 2].x^Reverse[Range[0, Floor[Log[2, n]]]],
// Modulus -> 2], Sow[n]], {n, 2, 65535}]][[2, 1]]
static value_type polynomial(std::size_t n)
{
static const value_type nb2_a[max_dimension] = {
2, 3, 7, 11, 13, 19, 25, 31, 37, 41, 47, 55, 59, 61, 67, 73, 87, 91,
97, 103, 109, 115, 117, 131, 137, 143, 145, 157, 167, 171, 185, 191,
193, 203, 211, 213, 229, 239, 241, 247, 253, 283, 285, 299, 301, 313,
319, 333, 351, 355, 357, 361, 369, 375, 379, 391, 395, 397, 415, 419,
425, 433, 445, 451, 463, 471, 477, 487, 499, 501, 505, 515, 529, 535,
539, 545, 557, 563, 587, 601, 607, 613, 617, 623, 631, 637, 647, 661,
665, 675, 677, 687, 695, 701, 719, 721, 731, 757, 761, 769, 787, 789,
799, 803, 817, 827, 841, 847, 859, 865, 875, 877, 883, 895, 901, 911,
929, 949, 953, 967, 971, 973, 981, 985, 995, 1001, 1019, 1033, 1039,
1051, 1053, 1063, 1069, 1077, 1095, 1107, 1123, 1125, 1135, 1153,
1163, 1177, 1193, 1199, 1221, 1225, 1239, 1255, 1261, 1267, 1279,
1291, 1293, 1305, 1311, 1315, 1329, 1341, 1347, 1367, 1377, 1383,
1387, 1413, 1423, 1431, 1435, 1441, 1451, 1465, 1473, 1479, 1509,
1527, 1531, 1555, 1557, 1571, 1573, 1585, 1591, 1603, 1615, 1617,
1627, 1657, 1663, 1669, 1673, 1703, 1709, 1717, 1727, 1729, 1741,
1747, 1759, 1783, 1789, 1807, 1809, 1815, 1821, 1825, 1835, 1845,
1849, 1863, 1869, 1877, 1881, 1891, 1915, 1917, 1921, 1927, 1933,
1939, 1961, 1969, 1989, 2011, 2027, 2035, 2041, 2047, 2053, 2071,
2091, 2093, 2119, 2147, 2149, 2161, 2171, 2189, 2197, 2207, 2217,
2225, 2243, 2255, 2257, 2273, 2279, 2283, 2293, 2317, 2323, 2341,
2345, 2359, 2363, 2365, 2373, 2377, 2385, 2395, 2419, 2421, 2431,
2435, 2447, 2475, 2477, 2489, 2503, 2521, 2533, 2543, 2551, 2561,
2567, 2579, 2581, 2601, 2633, 2657, 2669, 2681, 2687, 2693, 2705,
2717, 2727, 2731, 2739, 2741, 2773, 2783, 2787, 2793, 2799, 2801,
2811, 2819, 2825, 2833, 2867, 2879, 2881, 2891, 2905, 2911, 2917,
2927, 2941, 2951, 2955, 2963, 2965, 2991, 2999, 3005, 3017, 3035,
3037, 3047, 3053, 3083, 3085, 3097, 3103, 3121, 3159, 3169, 3179,
3187, 3189, 3205, 3209, 3223, 3227, 3229, 3251, 3263, 3271, 3277,
3283, 3285, 3299, 3305, 3319, 3331, 3343, 3357, 3367, 3373, 3393,
3399, 3413, 3417, 3427, 3439, 3441, 3475, 3487, 3497, 3515, 3517,
3529, 3543, 3547, 3553, 3559, 3573, 3583, 3589, 3613, 3617, 3623,
3627, 3635, 3641, 3655, 3659, 3669, 3679, 3697, 3707, 3709, 3713,
3731, 3743, 3747, 3771, 3785, 3791, 3805, 3827, 3833, 3851, 3865,
3889, 3895, 3933, 3947, 3949, 3957, 3961, 3971, 3985, 3991, 3995,
4007, 4013, 4021, 4045, 4051, 4069, 4073, 4091, 4105, 4119, 4129,
4147, 4149, 4159, 4173, 4179, 4201, 4215, 4219, 4221, 4225, 4235,
4249, 4259, 4261, 4303, 4305, 4331, 4333, 4351, 4359, 4383, 4387,
4401, 4407, 4411, 4431, 4439, 4449, 4459, 4461, 4473, 4483, 4485,
4497, 4523, 4531, 4569, 4575, 4579, 4591, 4593, 4609, 4621, 4627,
4633, 4645, 4663, 4667, 4669, 4675, 4677, 4711, 4717, 4723, 4735,
4789, 4793, 4801, 4811, 4873, 4879, 4891, 4893, 4897, 4915, 4921,
4927, 4941, 4965, 4977, 5017, 5023, 5027, 5033, 5039, 5051, 5059,
5073, 5079, 5085, 5107, 5109, 5127, 5139, 5169, 5175, 5193, 5199,
5211, 5213, 5223, 5227, 5237, 5247, 5257, 5281, 5287, 5293, 5301,
5325, 5331, 5337, 5343, 5349, 5391, 5405, 5451, 5453, 5505, 5523,
5541, 5545, 5563, 5573, 5591, 5597, 5611, 5625, 5635, 5641, 5659,
5695, 5697, 5703, 5707, 5717, 5721, 5731, 5733, 5743, 5779, 5797,
5821, 5827, 5833, 5841, 5857, 5863, 5875, 5887, 5899, 5909, 5913,
5949, 5955, 5957, 5967, 5975, 5981, 6003, 6005, 6009, 6025, 6031,
6039, 6045, 6061, 6067, 6079, 6081, 6111, 6139, 6151, 6157, 6175,
6179, 6193, 6199, 6217, 6231, 6237, 6253, 6265, 6271, 6275, 6289,
6295, 6305, 6329, 6347, 6349, 6383, 6385, 6395, 6405, 6409, 6427,
6445, 6453, 6465, 6475, 6495, 6501, 6511, 6523, 6529, 6539, 6553,
6577, 6583, 6589, 6601, 6607, 6621, 6631, 6637, 6649, 6683, 6685,
6689, 6699, 6707, 6733, 6739, 6741, 6751, 6755, 6761, 6779, 6795,
6833, 6853, 6865, 6881, 6887, 6891, 6901, 6923, 6925, 6931, 6937,
6943, 6959, 6981, 6999, 7049, 7055, 7057, 7079, 7093, 7097, 7103,
7105, 7115, 7123, 7139, 7165, 7171, 7173, 7183, 7185, 7191, 7207,
7245, 7263, 7303, 7327, 7333, 7351, 7355, 7365, 7369, 7375, 7383,
7403, 7405, 7411, 7425, 7431, 7459, 7471, 7485, 7491, 7505, 7515,
7517, 7527, 7541, 7545, 7555, 7557, 7561, 7569, 7591, 7603, 7617,
7663, 7687, 7701, 7705, 7727, 7739, 7741, 7749, 7761, 7773, 7777,
7783, 7795, 7823, 7831, 7835, 7865, 7871, 7885, 7891, 7907, 7921,
7927, 7939, 7953, 7963, 7975, 7993, 8007, 8011, 8019, 8037, 8049,
8061, 8065, 8077, 8089, 8111, 8123, 8125, 8131, 8133, 8137, 8161,
8173, 8191, 8219, 8231, 8245, 8275, 8293, 8303, 8331, 8333, 8351,
8357, 8367, 8379, 8381, 8387, 8393, 8417, 8435, 8461, 8469, 8489,
8495, 8507, 8515, 8551, 8555, 8569, 8585, 8599, 8605, 8639, 8641,
8647, 8653, 8671, 8675, 8689, 8699, 8729, 8741, 8759, 8765, 8771,
8795, 8797, 8825, 8831, 8841, 8855, 8859, 8883, 8895, 8909, 8943,
8951, 8955, 8965, 8999, 9003, 9031, 9045, 9049, 9071, 9073, 9085,
9095, 9101, 9109, 9123, 9129, 9137, 9143, 9147, 9185, 9197, 9209,
9227, 9235, 9247, 9253, 9257, 9277, 9297, 9303, 9313, 9325, 9343,
9347, 9371, 9373, 9397, 9407, 9409, 9415, 9419, 9443, 9481, 9495,
9501, 9505, 9517, 9529, 9555, 9557, 9571, 9585, 9591, 9607, 9611,
9621, 9625, 9631, 9647, 9661, 9669, 9679, 9687, 9707, 9731, 9733,
9745, 9773, 9791, 9803, 9811, 9817, 9833, 9847, 9851, 9863, 9875,
9881, 9905, 9911, 9917, 9923, 9963, 9973, 10003, 10025, 10043, 10063,
10071, 10077, 10091, 10099, 10105, 10115, 10129, 10145, 10169, 10183,
10187, 10207, 10223, 10225, 10247, 10265, 10271, 10275, 10289, 10299,
10301, 10309, 10343, 10357, 10373, 10411, 10413, 10431, 10445, 10453,
10463, 10467, 10473, 10491, 10505, 10511, 10513, 10523, 10539, 10549,
10559, 10561, 10571, 10581, 10615, 10621, 10625, 10643, 10655, 10671,
10679, 10685, 10691, 10711, 10739, 10741, 10755, 10767, 10781, 10785,
10803, 10805, 10829, 10857, 10863, 10865, 10875, 10877, 10917, 10921,
10929, 10949, 10967, 10971, 10987, 10995, 11009, 11029, 11043, 11045,
11055, 11063, 11075, 11081, 11117, 11135, 11141, 11159, 11163, 11181,
11187, 11225, 11237, 11261, 11279, 11297, 11307, 11309, 11327, 11329,
11341, 11377, 11403, 11405, 11413, 11427, 11439, 11453, 11461, 11473,
11479, 11489, 11495, 11499, 11533, 11545, 11561, 11567, 11575, 11579,
11589, 11611, 11623, 11637, 11657, 11663, 11687, 11691, 11701, 11747,
11761, 11773, 11783, 11795, 11797, 11817, 11849, 11855, 11867, 11869,
11873, 11883, 11919, 11921, 11927, 11933, 11947, 11955, 11961, 11999,
12027, 12029, 12037, 12041, 12049, 12055, 12095, 12097, 12107, 12109,
12121, 12127, 12133, 12137, 12181, 12197, 12207, 12209, 12239, 12253,
12263, 12269, 12277, 12287, 12295, 12309, 12313, 12335, 12361, 12367,
12391, 12409, 12415, 12433, 12449, 12469, 12479, 12481, 12499, 12505,
12517, 12527, 12549, 12559, 12597, 12615, 12621, 12639, 12643, 12657,
12667, 12707, 12713, 12727, 12741, 12745, 12763, 12769, 12779, 12781,
12787, 12799, 12809, 12815, 12829, 12839, 12857, 12875, 12883, 12889,
12901, 12929, 12947, 12953, 12959, 12969, 12983, 12987, 12995, 13015,
13019, 13031, 13063, 13077, 13103, 13137, 13149, 13173, 13207, 13211,
13227, 13241, 13249, 13255, 13269, 13283, 13285, 13303, 13307, 13321,
13339, 13351, 13377, 13389, 13407, 13417, 13431, 13435, 13447, 13459,
13465, 13477, 13501, 13513, 13531, 13543, 13561, 13581, 13599, 13605,
13617, 13623, 13637, 13647, 13661, 13677, 13683, 13695, 13725, 13729,
13753, 13773, 13781, 13785, 13795, 13801, 13807, 13825, 13835, 13855,
13861, 13871, 13883, 13897, 13905, 13915, 13939, 13941, 13969, 13979,
13981, 13997, 14027, 14035, 14037, 14051, 14063, 14085, 14095, 14107,
14113, 14125, 14137, 14145, 14151, 14163, 14193, 14199, 14219, 14229,
14233, 14243, 14277, 14287, 14289, 14295, 14301, 14305, 14323, 14339,
14341, 14359, 14365, 14375, 14387, 14411, 14425, 14441, 14449, 14499,
14513, 14523, 14537, 14543, 14561, 14579, 14585, 14593, 14599, 14603,
14611, 14641, 14671, 14695, 14701, 14723, 14725, 14743, 14753, 14759,
14765, 14795, 14797, 14803, 14831, 14839, 14845, 14855, 14889, 14895,
14909, 14929, 14941, 14945, 14951, 14963, 14965, 14985, 15033, 15039,
15053, 15059, 15061, 15071, 15077, 15081, 15099, 15121, 15147, 15149,
15157, 15167, 15187, 15193, 15203, 15205, 15215, 15217, 15223, 15243,
15257, 15269, 15273, 15287, 15291, 15313, 15335, 15347, 15359, 15373,
15379, 15381, 15391, 15395, 15397, 15419, 15439, 15453, 15469, 15491,
15503, 15517, 15527, 15531, 15545, 15559, 15593, 15611, 15613, 15619,
15639, 15643, 15649, 15661, 15667, 15669, 15681, 15693, 15717, 15721,
15741, 15745, 15765, 15793, 15799, 15811, 15825, 15835, 15847, 15851,
15865, 15877, 15881, 15887, 15899, 15915, 15935, 15937, 15955, 15973,
15977, 16011, 16035, 16061, 16069, 16087, 16093, 16097, 16121, 16141,
16153, 16159, 16165, 16183, 16189, 16195, 16197, 16201, 16209, 16215,
16225, 16259, 16265, 16273, 16299, 16309, 16355, 16375, 16381, 16417,
16427, 16435, 16441, 16447, 16467, 16479, 16485, 16507, 16519, 16553,
16559, 16571, 16573, 16591, 16599, 16619, 16627, 16633, 16651, 16653,
16659, 16699, 16707, 16713, 16727, 16743, 16749, 16785, 16795, 16797,
16807, 16811, 16813, 16821, 16853, 16857, 16881, 16897, 16909, 16965,
16969, 16983, 16993, 17011, 17017, 17023, 17027, 17029, 17053, 17057,
17095, 17099, 17101, 17123, 17129, 17135, 17155, 17161, 17179, 17185,
17191, 17215, 17257, 17275, 17277, 17287, 17301, 17327, 17353, 17373,
17387, 17389, 17407, 17419, 17421, 17475, 17501, 17523, 17545, 17601,
17619, 17621, 17631, 17635, 17649, 17659, 17667, 17673, 17679, 17707,
17721, 17753, 17775, 17783, 17789, 17805, 17817, 17823, 17829, 17847,
17861, 17865, 17873, 17879, 17895, 17907, 17919, 17935, 17949, 17959,
17973, 17991, 18009, 18019, 18033, 18043, 18061, 18067, 18069, 18083,
18085, 18117, 18127, 18139, 18155, 18175, 18213, 18225, 18243, 18255,
18303, 18313, 18321, 18331, 18343, 18357, 18369, 18387, 18393, 18405,
18409, 18415, 18429, 18451, 18457, 18463, 18491, 18499, 18513, 18523,
18529, 18535, 18559, 18563, 18577, 18623, 18631, 18659, 18673, 18679,
18685, 18717, 18721, 18733, 18745, 18753, 18771, 18783, 18789, 18793,
18807, 18823, 18827, 18857, 18895, 18897, 18909, 18913, 18919, 18967,
18997, 19033, 19045, 19067, 19073, 19079, 19083, 19091, 19107, 19119,
19133, 19145, 19165, 19181, 19193, 19231, 19255, 19273, 19291, 19297,
19307, 19309, 19315, 19321, 19333, 19343, 19351, 19361, 19371, 19379,
19385, 19403, 19405, 19413, 19423, 19441, 19451, 19465, 19483, 19485,
19495, 19499, 19519, 19527, 19531, 19539, 19541, 19557, 19581, 19597,
19621, 19645, 19653, 19665, 19671, 19693, 19711, 19733, 19743, 19753,
19761, 19781, 19791, 19793, 19829, 19845, 19855, 19885, 19891, 19905,
19923, 19953, 19963, 19969, 19989, 20003, 20023, 20035, 20041, 20049,
20075, 20077, 20099, 20123, 20147, 20179, 20197, 20201, 20207, 20253,
20257, 20299, 20309, 20319, 20329, 20335, 20353, 20365, 20383, 20389,
20393, 20407, 20411, 20439, 20459, 20461, 20473, 20487, 20511, 20517,
20571, 20573, 20641, 20683, 20693, 20697, 20707, 20713, 20719, 20731,
20763, 20769, 20781, 20799, 20819, 20825, 20831, 20847, 20861, 20875,
20889, 20901, 20913, 20919, 20943, 20945, 20955, 20971, 20973, 20981,
20991, 20997, 21007, 21037, 21093, 21105, 21131, 21145, 21155, 21169,
21181, 21187, 21189, 21199, 21201, 21223, 21227, 21241, 21249, 21273,
21285, 21289, 21303, 21321, 21339, 21351, 21365, 21403, 21405, 21415,
21433, 21439, 21447, 21459, 21477, 21489, 21501, 21507, 21519, 21527,
21557, 21561, 21575, 21593, 21599, 21627, 21645, 21651, 21653, 21663,
21681, 21687, 21691, 21725, 21729, 21739, 21779, 21785, 21807, 21815,
21863, 21867, 21877, 21881, 21887, 21891, 21893, 21905, 21911, 21933,
21953, 21971, 21983, 21993, 22007, 22023, 22029, 22037, 22051, 22057,
22063, 22065, 22103, 22109, 22171, 22187, 22189, 22195, 22209, 22215,
22221, 22257, 22263, 22267, 22315, 22317, 22335, 22347, 22357, 22361,
22371, 22373, 22397, 22419, 22447, 22461, 22467, 22469, 22487, 22503,
22515, 22531, 22545, 22561, 22573, 22579, 22581, 22591, 22593, 22653,
22663, 22667, 22677, 22681, 22691, 22703, 22705, 22737, 22749, 22759,
22763, 22777, 22783, 22803, 22819, 22843, 22863, 22911, 22927, 22935,
22941, 22945, 22951, 22955, 22965, 22987, 23007, 23017, 23037, 23053,
23059, 23071, 23077, 23099, 23101, 23107, 23109, 23113, 23157, 23183,
23207, 23221, 23233, 23251, 23253, 23257, 23287, 23311, 23319, 23325,
23339, 23347, 23353, 23361, 23395, 23401, 23415, 23449, 23459, 23465,
23491, 23493, 23521, 23531, 23545, 23559, 23563, 23577, 23601, 23607,
23625, 23645, 23661, 23673, 23683, 23713, 23743, 23745, 23755, 23757,
23781, 23813, 23825, 23837, 23859, 23861, 23879, 23919, 23943, 23949,
23957, 23967, 23971, 23977, 23995, 24009, 24015, 24027, 24033, 24067,
24079, 24091, 24109, 24135, 24139, 24163, 24189, 24193, 24217, 24229,
24233, 24279, 24283, 24295, 24309, 24327, 24333, 24345, 24351, 24355,
24381, 24387, 24389, 24401, 24417, 24427, 24437, 24457, 24471, 24491,
24525, 24543, 24547, 24549, 24561, 24587, 24589, 24597, 24623, 24637,
24655, 24657, 24673, 24679, 24683, 24713, 24727, 24733, 24737, 24747,
24755, 24761, 24787, 24789, 24823, 24841, 24849, 24877, 24889, 24897,
24915, 24945, 24957, 24991, 24997, 25007, 25019, 25051, 25069, 25077,
25087, 25131, 25139, 25141, 25145, 25159, 25165, 25187, 25199, 25213,
25229, 25247, 25253, 25257, 25265, 25271, 25303, 25307, 25309, 25323,
25325, 25331, 25343, 25379, 25393, 25399, 25405, 25435, 25453, 25461,
25477, 25481, 25489, 25505, 25535, 25583, 25597, 25609, 25623, 25645,
25665, 25671, 25677, 25685, 25739, 25749, 25759, 25769, 25777, 25831,
25845, 25857, 25867, 25881, 25911, 25915, 25923, 25925, 25929, 25947,
25987, 26001, 26023, 26029, 26041, 26047, 26067, 26069, 26073, 26085,
26095, 26097, 26103, 26113, 26119, 26125, 26147, 26171, 26191, 26205,
26219, 26221, 26227, 26243, 26255, 26263, 26279, 26283, 26293, 26297,
26329, 26335, 26345, 26385, 26395, 26401, 26419, 26443, 26463, 26473,
26487, 26497, 26531, 26543, 26551, 26577, 26599, 26603, 26613, 26627,
26641, 26651, 26653, 26667, 26689, 26707, 26735, 26743, 26763, 26765,
26771, 26783, 26789, 26793, 26821, 26825, 26879, 26887, 26905, 26927,
26941, 26967, 26987, 26995, 26997, 27001, 27013, 27023, 27035, 27037,
27041, 27051, 27079, 27085, 27113, 27137, 27143, 27147, 27161, 27171,
27183, 27217, 27227, 27239, 27243, 27245, 27253, 27267, 27287, 27315,
27317, 27327, 27329, 27339, 27341, 27369, 27375, 27387, 27389, 27395,
27415, 27435, 27443, 27449, 27463, 27467, 27477, 27497, 27517, 27521,
27533, 27541, 27551, 27555, 27557, 27569, 27575, 27589, 27607, 27617,
27629, 27635, 27641, 27659, 27673, 27695, 27709, 27717, 27735, 27745,
27763, 27829, 27833, 27839, 27841, 27847, 27851, 27877, 27889, 27909,
27913, 27919, 27927, 27947, 27987, 28003, 28005, 28009, 28027, 28067,
28081, 28091, 28093, 28099, 28101, 28125, 28169, 28199, 28205, 28211,
28225, 28237, 28243, 28271, 28283, 28289, 28295, 28309, 28335, 28343,
28355, 28379, 28381, 28409, 28417, 28437, 28457, 28465, 28475, 28495,
28503, 28507, 28513, 28549, 28561, 28567, 28587, 28597, 28615, 28633,
28639, 28649, 28677, 28701, 28715, 28723, 28725, 28747, 28797, 28801,
28813, 28841, 28855, 28859, 28873, 28879, 28893, 28897, 28947, 28949,
28953, 28963, 28977, 28983, 28989, 29021, 29035, 29065, 29079, 29083,
29089, 29109, 29119, 29131, 29151, 29157, 29175, 29179, 29209, 29215,
29231, 29233, 29243, 29263, 29281, 29287, 29327, 29357, 29363, 29377,
29389, 29395, 29407, 29413, 29425, 29431, 29443, 29449, 29479, 29483,
29505, 29525, 29541, 29551, 29581, 29587, 29605, 29629, 29641, 29649,
29671, 29683, 29685, 29695, 29715, 29717, 29737, 29775, 29783, 29787,
29803, 29805, 29827, 29867, 29875, 29895, 29901, 29909, 29919, 29929,
29947, 29949, 29975, 29979, 29985, 30005, 30017, 30027, 30071, 30075,
30081, 30105, 30115, 30141, 30159, 30161, 30187, 30197, 30201, 30207,
30237, 30265, 30279, 30291, 30293, 30303, 30307, 30309, 30313, 30343,
30357, 30367, 30371, 30383, 30395, 30405, 30417, 30443, 30451, 30457,
30475, 30511, 30537, 30545, 30551, 30573, 30579, 30595, 30601, 30631,
30637, 30645, 30663, 30675, 30677, 30703, 30741, 30757, 30769, 30781,
30799, 30801, 30811, 30829, 30887, 30893, 30899, 30911, 30923, 30925,
30937, 30943, 30953, 30959, 30979, 30991, 30999, 31015, 31027, 31053,
31065, 31087, 31089, 31099, 31105, 31111, 31141, 31153, 31173, 31177,
31191, 31197, 31235, 31259, 31271, 31275, 31285, 31295, 31307, 31317,
31351, 31361, 31373, 31401, 31415, 31419, 31427, 31457, 31475, 31477,
31499, 31523, 31547, 31557, 31567, 31569, 31581, 31591, 31609, 31621,
31631, 31649, 31659, 31673, 31699, 31715, 31729, 31735, 31749, 31753,
31783, 31789, 31833, 31849, 31869, 31883, 31891, 31893, 31907, 31927,
31939, 31953, 31965, 31979, 31993, 31999, 32001, 32021, 32055, 32069,
32073, 32115, 32121, 32143, 32145, 32151, 32167, 32179, 32199, 32205,
32213, 32233, 32251, 32253, 32257, 32269, 32281, 32303, 32325, 32353,
32373, 32383, 32393, 32399, 32411, 32413, 32427, 32447, 32455, 32467,
32483, 32485, 32521, 32545, 32575, 32589, 32597, 32625, 32651, 32653,
32665, 32671, 32675, 32689, 32707, 32709, 32721, 32727, 32737, 32743,
32771, 32785, 32791, 32813, 32821, 32863, 32879, 32887, 32897, 32903,
32915, 32933, 32945, 32957, 32963, 32975, 32989, 32999, 33013, 33023,
33025, 33045, 33061, 33111, 33117, 33121, 33133, 33145, 33157, 33185,
33191, 33209, 33227, 33229, 33237, 33247, 33277, 33299, 33339, 33349,
33407, 33417, 33423, 33435, 33483, 33497, 33507, 33521, 33559, 33563,
33579, 33587, 33607, 33613, 33631, 33635, 33641, 33649, 33675, 33685,
33689, 33711, 33723, 33725, 33733, 33745, 33781, 33817, 33827, 33839,
33841, 33847, 33865, 33895, 33901, 33913, 33923, 33925, 33943, 33953,
33973, 34015, 34031, 34039, 34043, 34045, 34077, 34081, 34087, 34099,
34119, 34123, 34143, 34161, 34171, 34177, 34189, 34211, 34225, 34231,
34245, 34249, 34267, 34285, 34291, 34313, 34321, 34333, 34347, 34389,
34393, 34405, 34429, 34433, 34451, 34473, 34479, 34487, 34499, 34523,
34547, 34559, 34571, 34573, 34581, 34591, 34601, 34609, 34667, 34693,
34697, 34703, 34717, 34731, 34733, 34739, 34751, 34783, 34793, 34801,
34807, 34817, 34823, 34853, 34871, 34875, 34889, 34909, 34913, 34931,
34937, 34947, 34959, 34961, 34995, 34997, 35015, 35033, 35075, 35077,
35081, 35089, 35095, 35111, 35173, 35197, 35221, 35225, 35247, 35279,
35281, 35291, 35293, 35309, 35327, 35351, 35385, 35413, 35427, 35429,
35441, 35451, 35463, 35467, 35487, 35503, 35505, 35549, 35595, 35597,
35643, 35645, 35651, 35693, 35699, 35729, 35741, 35777, 35787, 35797,
35801, 35813, 35825, 35873, 35879, 35911, 35925, 35929, 35939, 35945,
35975, 35987, 36003, 36009, 36027, 36041, 36065, 36075, 36097, 36103,
36107, 36133, 36143, 36163, 36177, 36187, 36205, 36223, 36229, 36233,
36251, 36257, 36287, 36299, 36301, 36325, 36329, 36335, 36343, 36363,
36383, 36411, 36433, 36439, 36467, 36469, 36495, 36503, 36507, 36513,
36543, 36545, 36563, 36575, 36581, 36603, 36623, 36647, 36651, 36665,
36673, 36691, 36693, 36709, 36727, 36733, 36773, 36791, 36797, 36809,
36817, 36833, 36839, 36875, 36889, 36895, 36901, 36919, 36925, 36931,
36951, 36961, 36973, 36981, 37001, 37009, 37019, 37021, 37037, 37091,
37125, 37129, 37135, 37143, 37147, 37149, 37185, 37197, 37239, 37243,
37273, 37283, 37289, 37297, 37309, 37327, 37345, 37379, 37393, 37403,
37409, 37415, 37427, 37439, 37453, 37459, 37471, 37499, 37511, 37525,
37539, 37559, 37577, 37597, 37621, 37625, 37651, 37681, 37687, 37701,
37705, 37719, 37747, 37759, 37763, 37789, 37793, 37813, 37835, 37855,
37871, 37873, 37883, 37903, 37931, 37933, 37941, 37963, 37971, 38007,
38013, 38027, 38035, 38041, 38053, 38057, 38075, 38085, 38103, 38107,
38113, 38119, 38133, 38143, 38151, 38165, 38185, 38193, 38205, 38213,
38241, 38251, 38281, 38299, 38317, 38349, 38367, 38371, 38377, 38419,
38421, 38447, 38449, 38455, 38461, 38467, 38493, 38503, 38521, 38551,
38573, 38593, 38603, 38611, 38623, 38639, 38651, 38661, 38699, 38709,
38713, 38733, 38755, 38805, 38815, 38819, 38821, 38825, 38833, 38875,
38877, 38881, 38899, 38911, 38921, 38945, 38957, 38983, 39061, 39065,
39087, 39099, 39107, 39109, 39127, 39133, 39143, 39155, 39161, 39179,
39193, 39205, 39209, 39215, 39223, 39235, 39237, 39259, 39277, 39295,
39305, 39313, 39323, 39353, 39359, 39361, 39371, 39381, 39395, 39397,
39461, 39473, 39503, 39511, 39515, 39517, 39521, 39533, 39545, 39551,
39557, 39575, 39581, 39595, 39609, 39623, 39627, 39651, 39675, 39697,
39707, 39725, 39731, 39745, 39763, 39775, 39791, 39799, 39805, 39815,
39819, 39827, 39863, 39869, 39889, 39915, 39929, 39935, 39957, 39967,
39983, 39995, 39997, 40017, 40029, 40039, 40051, 40053, 40057, 40069,
40127, 40135, 40149, 40165, 40169, 40177, 40183, 40195, 40277, 40281,
40291, 40311, 40321, 40331, 40345, 40351, 40357, 40381, 40451, 40465,
40471, 40481, 40487, 40505, 40519, 40533, 40537, 40543, 40547, 40553,
40577, 40607, 40611, 40685, 40691, 40715, 40723, 40729, 40739, 40751,
40777, 40783, 40807, 40859, 40877, 40883, 40885, 40909, 40921, 40951,
40971, 40981, 40995, 40997, 41007, 41027, 41051, 41053, 41063, 41067,
41069, 41087, 41097, 41105, 41127, 41141, 41165, 41183, 41193, 41211,
41219, 41231, 41245, 41249, 41255, 41267, 41269, 41273, 41287, 41305,
41327, 41339, 41345, 41375, 41393, 41413, 41423, 41441, 41487, 41501,
41517, 41525, 41537, 41543, 41557, 41571, 41583, 41625, 41641, 41659,
41661, 41669, 41673, 41687, 41691, 41709, 41735, 41739, 41741, 41753,
41759, 41763, 41769, 41797, 41835, 41843, 41861, 41871, 41879, 41889,
41907, 41921, 41933, 41941, 41987, 41989, 41993, 42001, 42067, 42073,
42085, 42113, 42119, 42123, 42133, 42137, 42149, 42159, 42161, 42173,
42179, 42203, 42219, 42221, 42241, 42275, 42277, 42281, 42319, 42355,
42371, 42407, 42425, 42439, 42445, 42473, 42481, 42491, 42515, 42533,
42543, 42551, 42557, 42577, 42593, 42611, 42641, 42651, 42653, 42695,
42737, 42749, 42779, 42795, 42809, 42847, 42865, 42893, 42905, 42929,
42939, 42941, 42959, 42961, 42973, 42983, 43013, 43051, 43059, 43065,
43083, 43085, 43093, 43113, 43119, 43133, 43137, 43155, 43167, 43171,
43177, 43191, 43215, 43229, 43233, 43243, 43275, 43283, 43289, 43301,
43337, 43381, 43409, 43431, 43437, 43455, 43457, 43497, 43503, 43511,
43533, 43541, 43567, 43569, 43587, 43589, 43599, 43601, 43617, 43641,
43677, 43691, 43693, 43699, 43705, 43731, 43743, 43761, 43779, 43791,
43805, 43829, 43833, 43847, 43875, 43901, 43905, 43915, 43929, 43963,
43973, 43985, 43991, 43995, 44007, 44019, 44033, 44039, 44045, 44051,
44073, 44087, 44091, 44101, 44123, 44141, 44147, 44159, 44165, 44175,
44183, 44231, 44245, 44255, 44265, 44285, 44293, 44305, 44315, 44321,
44363, 44365, 44399, 44451, 44463, 44489, 44509, 44519, 44523, 44537,
44553, 44573, 44589, 44601, 44607, 44621, 44639, 44643, 44657, 44663,
44667, 44685, 44693, 44707, 44731, 44759, 44765, 44775, 44789, 44801,
44819, 44831, 44841, 44847, 44859, 44867, 44873, 44903, 44917, 44943,
44957, 44971, 44993, 45011, 45027, 45047, 45053, 45071, 45083, 45101,
45109, 45119, 45141, 45175, 45197, 45203, 45231, 45251, 45253, 45265,
45281, 45299, 45319, 45323, 45325, 45373, 45399, 45405, 45429, 45455,
45463, 45469, 45473, 45511, 45535, 45541, 45579, 45587, 45589, 45635,
45641, 45647, 45685, 45695, 45705, 45723, 45749, 45761, 45791, 45801,
45807, 45815, 45829, 45847, 45863, 45923, 45947, 45953, 45971, 45989,
45993, 46001, 46007, 46021, 46039, 46043, 46045, 46073, 46081, 46093,
46105, 46111, 46121, 46147, 46149, 46167, 46189, 46197, 46207, 46247,
46271, 46297, 46319, 46327, 46345, 46365, 46387, 46399, 46407, 46419,
46421, 46441, 46455, 46459, 46485, 46505, 46523, 46531, 46551, 46561,
46567, 46571, 46585, 46597, 46601, 46615, 46619, 46625, 46631, 46637,
46643, 46645, 46667, 46681, 46715, 46721, 46731, 46745, 46767, 46769,
46801, 46823, 46827, 46855, 46879, 46885, 46917, 46935, 46939, 46955,
46969, 46979, 46993, 46999, 47005, 47009, 47027, 47051, 47101, 47135,
47173, 47183, 47201, 47221, 47237, 47241, 47261, 47265, 47277, 47295,
47315, 47317, 47355, 47363, 47369, 47389, 47399, 47403, 47431, 47445,
47449, 47461, 47479, 47501, 47535, 47547, 47555, 47561, 47569, 47585,
47597, 47603, 47605, 47621, 47631, 47633, 47659, 47673, 47705, 47721,
47727, 47745, 47751, 47757, 47763, 47799, 47831, 47859, 47871, 47873,
47879, 47893, 47897, 47907, 47933, 47939, 47945, 47951, 47953, 47963,
47975, 47989, 48017, 48053, 48063, 48075, 48077, 48101, 48105, 48137,
48179, 48185, 48227, 48229, 48233, 48251, 48267, 48269, 48287, 48297,
48323, 48337, 48349, 48385, 48403, 48421, 48431, 48439, 48453, 48487,
48511, 48515, 48521, 48569, 48577, 48595, 48601, 48613, 48625, 48647,
48661, 48675, 48681, 48695, 48727, 48731, 48737, 48747, 48767, 48771,
48785, 48811, 48853, 48857, 48881, 48919, 48929, 48935, 48947, 48949,
48979, 48997, 49025, 49035, 49059, 49079, 49091, 49115, 49133, 49141,
49151, 49153, 49159, 49171, 49183, 49189, 49225, 49267, 49273, 49285,
49297, 49303, 49309, 49319, 49337, 49355, 49365, 49379, 49403, 49425,
49441, 49459, 49471, 49483, 49503, 49519, 49527, 49531, 49533, 49555,
49573, 49597, 49603, 49609, 49627, 49639, 49645, 49669, 49673, 49687,
49709, 49741, 49747, 49749, 49769, 49817, 49841, 49871, 49873, 49885,
49909, 49921, 49933, 49945, 49957, 49967, 49981, 50007, 50011, 50017,
50035, 50051, 50075, 50077, 50091, 50093, 50111, 50119, 50147, 50159,
50173, 50181, 50209, 50227, 50247, 50251, 50271, 50287, 50301, 50323,
50335, 50341, 50359, 50373, 50391, 50397, 50411, 50425, 50431, 50443,
50453, 50479, 50481, 50505, 50523, 50549, 50553, 50569, 50587, 50593,
50611, 50613, 50623, 50635, 50655, 50665, 50671, 50685, 50735, 50737,
50749, 50757, 50769, 50795, 50805, 50809, 50831, 50839, 50859, 50867,
50873, 50881, 50887, 50893, 50901, 50915, 50921, 50939, 50947, 50953,
51009, 51027, 51033, 51043, 51063, 51097, 51103, 51113, 51139, 51159,
51163, 51189, 51203, 51227, 51253, 51265, 51277, 51295, 51301, 51305,
51349, 51389, 51401, 51445, 51449, 51455, 51457, 51469, 51477, 51487,
51491, 51497, 51505, 51511, 51515, 51547, 51549, 51553, 51583, 51587,
51599, 51627, 51655, 51659, 51661, 51673, 51749, 51753, 51759, 51779,
51785, 51815, 51855, 51885, 51903, 51929, 51939, 51951, 51953, 51965,
51991, 51995, 51997, 52011, 52031, 52053, 52073, 52081, 52091, 52103,
52157, 52183, 52199, 52213, 52231, 52245, 52259, 52285, 52297, 52315,
52333, 52351, 52355, 52357, 52379, 52385, 52391, 52397, 52403, 52417,
52441, 52471, 52475, 52477, 52497, 52523, 52531, 52565, 52579, 52591,
52615, 52639, 52643, 52663, 52677, 52687, 52695, 52705, 52715, 52717,
52729, 52735, 52739, 52753, 52775, 52789, 52793, 52837, 52847, 52849,
52895, 52901, 52923, 52931, 52933, 52937, 52945, 52951, 52979, 52991,
53005, 53017, 53023, 53039, 53085, 53089, 53099, 53107, 53113, 53135,
53147, 53149, 53153, 53163, 53191, 53205, 53225, 53239, 53253, 53257,
53311, 53319, 53325, 53361, 53367, 53383, 53387, 53389, 53397, 53401,
53411, 53425, 53445, 53455, 53457, 53463, 53473, 53497, 53515, 53541,
53545, 53551, 53565, 53585, 53595, 53613, 53659, 53689, 53695, 53697,
53717, 53721, 53743, 53757, 53767, 53781, 53791, 53795, 53801, 53815,
53847, 53867, 53869, 53891, 53903, 53921, 53941, 53963, 54019, 54039,
54055, 54081, 54091, 54105, 54111, 54121, 54135, 54139, 54145, 54163,
54169, 54179, 54193, 54217, 54225, 54237, 54247, 54253, 54293, 54313,
54331, 54365, 54369, 54379, 54423, 54429, 54443, 54451, 54463, 54465,
54483, 54501, 54505, 54513, 54543, 54555, 54567, 54571, 54599, 54613,
54617, 54627, 54653, 54675, 54711, 54723, 54753, 54759, 54771, 54773,
54789, 54823, 54827, 54859, 54879, 54883, 54895, 54909, 54919, 54953,
54967, 54981, 54999, 55009, 55021, 55027, 55061, 55075, 55077, 55089,
55143, 55149, 55167, 55213, 55219, 55221, 55231, 55257, 55287, 55291,
55309, 55315, 55369, 55383, 55405, 55433, 55439, 55451, 55463, 55467,
55477, 55489, 55495, 55507, 55513, 55525, 55561, 55579, 55603, 55617,
55623, 55629, 55647, 55653, 55665, 55691, 55705, 55711, 55715, 55721,
55729, 55747, 55767, 55795, 55801, 55813, 55831, 55847, 55859, 55861,
55871, 55897, 55933, 55947, 55955, 55961, 55971, 55985, 56003, 56029,
56045, 56071, 56095, 56101, 56105, 56123, 56133, 56143, 56161, 56195,
56209, 56225, 56263, 56269, 56277, 56287, 56291, 56297, 56303, 56315,
56317, 56337, 56363, 56373, 56377, 56385, 56431, 56433, 56467, 56479,
56495, 56529, 56535, 56539, 56565, 56601, 56617, 56625, 56645, 56663,
56679, 56691, 56693, 56733, 56749, 56769, 56789, 56805, 56823, 56827,
56839, 56879, 56893, 56905, 56911, 56913, 56941, 56949, 56963, 56965,
56969, 56993, 57005, 57035, 57037, 57043, 57091, 57093, 57111, 57117,
57121, 57139, 57177, 57187, 57193, 57199, 57201, 57253, 57275, 57289,
57307, 57323, 57347, 57359, 57361, 57395, 57397, 57415, 57419, 57439,
57467, 57469, 57485, 57503, 57513, 57521, 57527, 57541, 57559, 57563,
57565, 57581, 57599, 57601, 57611, 57637, 57649, 57673, 57679, 57681,
57693, 57703, 57707, 57727, 57779, 57811, 57817, 57839, 57863, 57867,
57881, 57891, 57905, 57925, 57935, 57959, 57977, 57989, 57999, 58011,
58013, 58017, 58027, 58029, 58047, 58049, 58069, 58127, 58129, 58139,
58165, 58169, 58201, 58211, 58213, 58231, 58253, 58259, 58271, 58277,
58287, 58295, 58307, 58331, 58355, 58367, 58399, 58417, 58441, 58459,
58475, 58477, 58483, 58489, 58501, 58513, 58519, 58525, 58529, 58539,
58571, 58573, 58591, 58609, 58621, 58627, 58629, 58647, 58651, 58669,
58675, 58753, 58773, 58789, 58799, 58855, 58885, 58913, 58937, 58943,
58951, 58963, 58985, 59015, 59067, 59069, 59095, 59101, 59115, 59125,
59129, 59137, 59161, 59177, 59245, 59253, 59267, 59279, 59303, 59307,
59309, 59317, 59339, 59347, 59349, 59365, 59377, 59383, 59393, 59439,
59459, 59471, 59473, 59483, 59501, 59513, 59529, 59537, 59559, 59583,
59585, 59595, 59597, 59603, 59643, 59645, 59651, 59663, 59681, 59687,
59691, 59701, 59737, 59743, 59747, 59753, 59761, 59789, 59831, 59845,
59855, 59863, 59885, 59913, 59931, 59949, 59979, 59993, 60017, 60029,
60033, 60045, 60091, 60099, 60105, 60119, 60141, 60159, 60167, 60171,
60185, 60195, 60201, 60219, 60229, 60247, 60253, 60263, 60267, 60275,
60277, 60311, 60315, 60333, 60339, 60365, 60371, 60373, 60387, 60425,
60433, 60449, 60469, 60491, 60511, 60517, 60521, 60541, 60563, 60569,
60591, 60599, 60605, 60617, 60623, 60671, 60679, 60693, 60707, 60727,
60745, 60765, 60769, 60779, 60823, 60833, 60843, 60851, 60871, 60877,
60889, 60895, 60911, 60913, 60925, 60929, 60939, 60941, 60959, 60969,
61045, 61059, 61065, 61085, 61101, 61113, 61127, 61131, 61145, 61155,
61169, 61175, 61199, 61217, 61229, 61235, 61241, 61261, 61303, 61333,
61343, 61361, 61371, 61409, 61415, 61419, 61427, 61429, 61433, 61447,
61453, 61471, 61481, 61487, 61509, 61533, 61573, 61577, 61591, 61611,
61631, 61639, 61653, 61663, 61681, 61687, 61713, 61723, 61749, 61761,
61767, 61771, 61779, 61795, 61809, 61837, 61843, 61893, 61921, 61927,
61939, 61941, 61951, 61975, 61981, 62023, 62029, 62037, 62041, 62063,
62075, 62087, 62111, 62117, 62171, 62173, 62201, 62207, 62209, 62219,
62229, 62255, 62263, 62275, 62341, 62345, 62353, 62359, 62387, 62431,
62437, 62469, 62479, 62487, 62497, 62521, 62547, 62549, 62563, 62565,
62569, 62587, 62603, 62617, 62627, 62641, 62653, 62659, 62671, 62707,
62709, 62713, 62733, 62745, 62757, 62775, 62779, 62801, 62817, 62829,
62865, 62877, 62887, 62901, 62911, 62913, 62919, 62977, 62997, 63007,
63011, 63035, 63045, 63055, 63069, 63083, 63091, 63107, 63109, 63155,
63157, 63193, 63215, 63227, 63265, 63277, 63295, 63309, 63315, 63337,
63343, 63367, 63371, 63381, 63395, 63409, 63415, 63427, 63433, 63451,
63487, 63491, 63497, 63503, 63517, 63527, 63533, 63545, 63551, 63563,
63599, 63601, 63607, 63635, 63685, 63707, 63713, 63725, 63731, 63733,
63751, 63765, 63779, 63803, 63805, 63823, 63825, 63859, 63865, 63877,
63899, 63923, 63929, 63943, 63971, 63977, 63991, 64001, 64007, 64019,
64035, 64055, 64073, 64107, 64117, 64121, 64127, 64131, 64151, 64155,
64161, 64193, 64203, 64217, 64223, 64229, 64261, 64271, 64289, 64295,
64309, 64333, 64341, 64351, 64361, 64369, 64385, 64397, 64419, 64425,
64439, 64457, 64463, 64475, 64481, 64523, 64525, 64543, 64585, 64603,
64615, 64629, 64643, 64685, 64723, 64751, 64783, 64791, 64797, 64811,
64813, 64825, 64839, 64851, 64881, 64907, 64917, 64921, 64931, 64943,
64945, 64963, 64989, 64993, 65003, 65029, 65069, 65075, 65077, 65089,
65101, 65113, 65119, 65149, 65159, 65171, 65177, 65201, 65213, 65225,
65259, 65279, 65281, 65287, 65299, 65315, 65321, 65335, 65359, 65367,
65373, 65377, 65395, 65407, 65423, 65425, 65459, 65479, 65497, 65513,
65519, 65533};
return nb2_a[n];
}
};
} // namespace qrng_tables
} // namespace detail
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DETAIL_NIEDERREITER_BASE2_TABLE_HPP
@@ -1,84 +0,0 @@
/* boost random/detail/operators.hpp header file
*
* Copyright Steven Watanabe 2010-2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_OPERATORS_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_OPERATORS_HPP
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/detail/workaround.hpp>
#if ACTIV_BOOST_WORKAROUND(ACTIV_BOOST_MSVC, <= 1310) \
|| ACTIV_BOOST_WORKAROUND(__SUNPRO_CC, ACTIV_BOOST_TESTED_AT(0x5100))
#define ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
template<class CharT, class Traits> \
friend std::basic_ostream<CharT,Traits>& \
operator<<(std::basic_ostream<CharT,Traits>& os, const T& t) { \
t.print(os, t); \
return os; \
} \
template<class CharT, class Traits> \
static std::basic_ostream<CharT,Traits>& \
print(std::basic_ostream<CharT,Traits>& os, const T& t)
#define ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
template<class CharT, class Traits> \
friend std::basic_istream<CharT,Traits>& \
operator>>(std::basic_istream<CharT,Traits>& is, T& t) { \
t.read(is, t); \
return is; \
} \
template<class CharT, class Traits> \
static std::basic_istream<CharT,Traits>& \
read(std::basic_istream<CharT,Traits>& is, T& t)
#endif
#if defined(ACTIV_BOOST_BORLANDC)
#define ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
bool operator==(const T& rhs) const \
{ return T::is_equal(*this, rhs); } \
static bool is_equal(const T& lhs, const T& rhs)
#define ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
bool operator!=(const T& rhs) const \
{ return !T::is_equal(*this, rhs); }
#endif
#ifndef ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR
#define ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, T, t) \
template<class CharT, class Traits> \
friend std::basic_ostream<CharT,Traits>& \
operator<<(std::basic_ostream<CharT,Traits>& os, const T& t)
#endif
#ifndef ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR
#define ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, T, t) \
template<class CharT, class Traits> \
friend std::basic_istream<CharT,Traits>& \
operator>>(std::basic_istream<CharT,Traits>& is, T& t)
#endif
#ifndef ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR
#define ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(T, lhs, rhs) \
friend bool operator==(const T& lhs, const T& rhs)
#endif
#ifndef ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR
#define ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(T) \
friend bool operator!=(const T& lhs, const T& rhs) \
{ return !(lhs == rhs); }
#endif
#endif
@@ -1,384 +0,0 @@
/* boost random/detail/polynomial.hpp header file
*
* Copyright Steven Watanabe 2014
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
#include <cstddef>
#include <limits>
#include <vector>
#include <algorithm>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/cstdint.hpp>
namespace Boost {
namespace random {
namespace detail {
class polynomial_ops {
public:
typedef unsigned long digit_t;
static void add(std::size_t size, const digit_t * lhs,
const digit_t * rhs, digit_t * output)
{
for(std::size_t i = 0; i < size; ++i) {
output[i] = lhs[i] ^ rhs[i];
}
}
static void add_shifted_inplace(std::size_t size, const digit_t * lhs,
digit_t * output, std::size_t shift)
{
if(shift == 0) {
add(size, lhs, output, output);
return;
}
std::size_t bits = std::numeric_limits<digit_t>::digits;
digit_t prev = 0;
for(std::size_t i = 0; i < size; ++i) {
digit_t tmp = lhs[i];
output[i] ^= (tmp << shift) | (prev >> (bits-shift));
prev = tmp;
}
output[size] ^= (prev >> (bits-shift));
}
static void multiply_simple(std::size_t size, const digit_t * lhs,
const digit_t * rhs, digit_t * output)
{
std::size_t bits = std::numeric_limits<digit_t>::digits;
for(std::size_t i = 0; i < 2*size; ++i) {
output[i] = 0;
}
for(std::size_t i = 0; i < size; ++i) {
for(std::size_t j = 0; j < bits; ++j) {
if((lhs[i] & (digit_t(1) << j)) != 0) {
add_shifted_inplace(size, rhs, output + i, j);
}
}
}
}
// memory requirements: (size - cutoff) * 4 + next_smaller
static void multiply_karatsuba(std::size_t size,
const digit_t * lhs, const digit_t * rhs,
digit_t * output)
{
if(size < 64) {
multiply_simple(size, lhs, rhs, output);
return;
}
// split in half
std::size_t cutoff = size/2;
multiply_karatsuba(cutoff, lhs, rhs, output);
multiply_karatsuba(size - cutoff, lhs + cutoff, rhs + cutoff,
output + cutoff*2);
std::vector<digit_t> local1(size - cutoff);
std::vector<digit_t> local2(size - cutoff);
// combine the digits for the inner multiply
add(cutoff, lhs, lhs + cutoff, &local1[0]);
if(size & 1) local1[cutoff] = lhs[size - 1];
add(cutoff, rhs + cutoff, rhs, &local2[0]);
if(size & 1) local2[cutoff] = rhs[size - 1];
std::vector<digit_t> local3((size - cutoff) * 2);
multiply_karatsuba(size - cutoff, &local1[0], &local2[0], &local3[0]);
add(cutoff * 2, output, &local3[0], &local3[0]);
add((size - cutoff) * 2, output + cutoff*2, &local3[0], &local3[0]);
// Finally, add the inner result
add((size - cutoff) * 2, output + cutoff, &local3[0], output + cutoff);
}
static void multiply_add_karatsuba(std::size_t size,
const digit_t * lhs, const digit_t * rhs,
digit_t * output)
{
std::vector<digit_t> buf(size * 2);
multiply_karatsuba(size, lhs, rhs, &buf[0]);
add(size * 2, &buf[0], output, output);
}
static void multiply(const digit_t * lhs, std::size_t lhs_size,
const digit_t * rhs, std::size_t rhs_size,
digit_t * output)
{
std::fill_n(output, lhs_size + rhs_size, digit_t(0));
multiply_add(lhs, lhs_size, rhs, rhs_size, output);
}
static void multiply_add(const digit_t * lhs, std::size_t lhs_size,
const digit_t * rhs, std::size_t rhs_size,
digit_t * output)
{
// split into pieces that can be passed to
// karatsuba multiply.
while(lhs_size != 0) {
if(lhs_size < rhs_size) {
std::swap(lhs, rhs);
std::swap(lhs_size, rhs_size);
}
multiply_add_karatsuba(rhs_size, lhs, rhs, output);
lhs += rhs_size;
lhs_size -= rhs_size;
output += rhs_size;
}
}
static void copy_bits(const digit_t * x, std::size_t low, std::size_t high,
digit_t * out)
{
const std::size_t bits = std::numeric_limits<digit_t>::digits;
std::size_t offset = low/bits;
x += offset;
low -= offset*bits;
high -= offset*bits;
std::size_t n = (high-low)/bits;
if(low == 0) {
for(std::size_t i = 0; i < n; ++i) {
out[i] = x[i];
}
} else {
for(std::size_t i = 0; i < n; ++i) {
out[i] = (x[i] >> low) | (x[i+1] << (bits-low));
}
}
if((high-low)%bits) {
digit_t low_mask = (digit_t(1) << ((high-low)%bits)) - 1;
digit_t result = (x[n] >> low);
if(low != 0 && (n+1)*bits < high) {
result |= (x[n+1] << (bits-low));
}
out[n] = (result & low_mask);
}
}
static void shift_left(digit_t * val, std::size_t size, std::size_t shift)
{
const std::size_t bits = std::numeric_limits<digit_t>::digits;
ACTIV_BOOST_ASSERT(shift > 0);
ACTIV_BOOST_ASSERT(shift < bits);
digit_t prev = 0;
for(std::size_t i = 0; i < size; ++i) {
digit_t tmp = val[i];
val[i] = (prev >> (bits - shift)) | (val[i] << shift);
prev = tmp;
}
}
static digit_t sqr(digit_t val) {
const std::size_t bits = std::numeric_limits<digit_t>::digits;
digit_t mask = (digit_t(1) << bits/2) - 1;
for(std::size_t i = bits; i > 1; i /= 2) {
val = ((val & ~mask) << i/2) | (val & mask);
mask = mask & (mask >> i/4);
mask = mask | (mask << i/2);
}
return val;
}
static void sqr(digit_t * val, std::size_t size)
{
const std::size_t bits = std::numeric_limits<digit_t>::digits;
digit_t mask = (digit_t(1) << bits/2) - 1;
for(std::size_t i = 0; i < size; ++i) {
digit_t x = val[size - i - 1];
val[(size - i - 1) * 2] = sqr(x & mask);
val[(size - i - 1) * 2 + 1] = sqr(x >> bits/2);
}
}
// optimized for the case when the modulus has few bits set.
struct sparse_mod {
sparse_mod(const digit_t * divisor, std::size_t divisor_bits)
{
const std::size_t bits = std::numeric_limits<digit_t>::digits;
_remainder_bits = divisor_bits - 1;
for(std::size_t i = 0; i < divisor_bits; ++i) {
if(divisor[i/bits] & (digit_t(1) << i%bits)) {
_bit_indices.push_back(i);
}
}
ACTIV_BOOST_ASSERT(_bit_indices.back() == divisor_bits - 1);
_bit_indices.pop_back();
if(_bit_indices.empty()) {
_block_bits = divisor_bits;
_lower_bits = 0;
} else {
_block_bits = divisor_bits - _bit_indices.back() - 1;
_lower_bits = _bit_indices.back() + 1;
}
_partial_quotient.resize((_block_bits + bits - 1)/bits);
}
void operator()(digit_t * dividend, std::size_t dividend_bits)
{
const std::size_t bits = std::numeric_limits<digit_t>::digits;
while(dividend_bits > _remainder_bits) {
std::size_t block_start = (std::max)(dividend_bits - _block_bits, _remainder_bits);
std::size_t block_size = (dividend_bits - block_start + bits - 1) / bits;
copy_bits(dividend, block_start, dividend_bits, &_partial_quotient[0]);
for(std::size_t i = 0; i < _bit_indices.size(); ++i) {
std::size_t pos = _bit_indices[i] + block_start - _remainder_bits;
add_shifted_inplace(block_size, &_partial_quotient[0], dividend + pos/bits, pos%bits);
}
add_shifted_inplace(block_size, &_partial_quotient[0], dividend + block_start/bits, block_start%bits);
dividend_bits = block_start;
}
}
std::vector<digit_t> _partial_quotient;
std::size_t _remainder_bits;
std::size_t _block_bits;
std::size_t _lower_bits;
std::vector<std::size_t> _bit_indices;
};
// base should have the same number of bits as mod
// base, and mod should both be able to hold a power
// of 2 >= mod_bits. out needs to be twice as large.
static void mod_pow_x(Boost::uintmax_t exponent, const digit_t * mod, std::size_t mod_bits, digit_t * out)
{
const std::size_t bits = std::numeric_limits<digit_t>::digits;
const std::size_t n = (mod_bits + bits - 1) / bits;
const std::size_t highbit = mod_bits - 1;
if(exponent == 0) {
out[0] = 1;
std::fill_n(out + 1, n - 1, digit_t(0));
return;
}
Boost::uintmax_t i = std::numeric_limits<Boost::uintmax_t>::digits - 1;
while(((Boost::uintmax_t(1) << i) & exponent) == 0) {
--i;
}
out[0] = 2;
std::fill_n(out + 1, n - 1, digit_t(0));
sparse_mod m(mod, mod_bits);
while(i--) {
sqr(out, n);
m(out, 2 * mod_bits - 1);
if((Boost::uintmax_t(1) << i) & exponent) {
shift_left(out, n, 1);
if(out[highbit / bits] & (digit_t(1) << highbit%bits))
add(n, out, mod, out);
}
}
}
};
class polynomial
{
typedef polynomial_ops::digit_t digit_t;
public:
polynomial() : _size(0) {}
class reference {
public:
reference(digit_t &value, int idx)
: _value(value), _idx(idx) {}
operator bool() const { return (_value & (digit_t(1) << _idx)) != 0; }
reference& operator=(bool b)
{
if(b) {
_value |= (digit_t(1) << _idx);
} else {
_value &= ~(digit_t(1) << _idx);
}
return *this;
}
reference &operator^=(bool b)
{
_value ^= (digit_t(b) << _idx);
return *this;
}
reference &operator=(const reference &other)
{
return *this = static_cast<bool>(other);
}
private:
digit_t &_value;
int _idx;
};
reference operator[](std::size_t i)
{
static const std::size_t bits = std::numeric_limits<digit_t>::digits;
ensure_bit(i);
return reference(_storage[i/bits], i%bits);
}
bool operator[](std::size_t i) const
{
static const std::size_t bits = std::numeric_limits<digit_t>::digits;
if(i < size())
return (_storage[i/bits] & (digit_t(1) << (i%bits))) != 0;
else
return false;
}
std::size_t size() const
{
return _size;
}
void resize(std::size_t n)
{
static const std::size_t bits = std::numeric_limits<digit_t>::digits;
_storage.resize((n + bits - 1)/bits);
// clear the high order bits in case we're shrinking.
if(n%bits) {
_storage.back() &= ((digit_t(1) << (n%bits)) - 1);
}
_size = n;
}
friend polynomial operator*(const polynomial &lhs, const polynomial &rhs);
friend polynomial mod_pow_x(Boost::uintmax_t exponent, polynomial mod);
private:
std::vector<polynomial_ops::digit_t> _storage;
std::size_t _size;
void ensure_bit(std::size_t i)
{
if(i >= size()) {
resize(i + 1);
}
}
void normalize()
{
while(size() && (*this)[size() - 1] == 0)
resize(size() - 1);
}
};
inline polynomial operator*(const polynomial &lhs, const polynomial &rhs)
{
polynomial result;
result._storage.resize(lhs._storage.size() + rhs._storage.size());
polynomial_ops::multiply(&lhs._storage[0], lhs._storage.size(),
&rhs._storage[0], rhs._storage.size(),
&result._storage[0]);
result._size = lhs._size + rhs._size;
return result;
}
inline polynomial mod_pow_x(Boost::uintmax_t exponent, polynomial mod)
{
polynomial result;
mod.normalize();
std::size_t mod_size = mod.size();
result._storage.resize(mod._storage.size() * 2);
result._size = mod.size() * 2;
polynomial_ops::mod_pow_x(exponent, &mod._storage[0], mod_size, &result._storage[0]);
result.resize(mod.size() - 1);
return result;
}
}
}
}
#endif // ACTIV_BOOST_RANDOM_DETAIL_POLYNOMIAL_HPP
@@ -1,67 +0,0 @@
/* boost random/detail/ptr_helper.hpp header file
*
* Copyright Jens Maurer 2002
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
#include <ActivBoost/config.hpp>
namespace Boost {
namespace random {
namespace detail {
// type_traits could help here, but I don't want to depend on type_traits.
template<class T>
struct ptr_helper
{
typedef T value_type;
typedef T& reference_type;
typedef const T& rvalue_type;
static reference_type ref(T& r) { return r; }
static const T& ref(const T& r) { return r; }
};
template<class T>
struct ptr_helper<T&>
{
typedef T value_type;
typedef T& reference_type;
typedef T& rvalue_type;
static reference_type ref(T& r) { return r; }
static const T& ref(const T& r) { return r; }
};
template<class T>
struct ptr_helper<T*>
{
typedef T value_type;
typedef T& reference_type;
typedef T* rvalue_type;
static reference_type ref(T * p) { return *p; }
static const T& ref(const T * p) { return *p; }
};
} // namespace detail
} // namespace random
} // namespace Boost
//
// ACTIV_BOOST_RANDOM_PTR_HELPER_SPEC --
//
// Helper macro for broken compilers defines specializations of
// ptr_helper.
//
# define ACTIV_BOOST_RANDOM_PTR_HELPER_SPEC(T)
#endif // ACTIV_BOOST_RANDOM_DETAIL_PTR_HELPER_HPP
@@ -1,291 +0,0 @@
/* boost random/detail/qrng_base.hpp header file
*
* Copyright Justinas Vygintas Daugmaudis 2010-2018
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_QRNG_BASE_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_QRNG_BASE_HPP
#include <stdexcept>
#include <vector>
#include <limits>
#include <istream>
#include <ostream>
#include <sstream>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/throw_exception.hpp>
#include <ActivBoost/type_traits/integral_constant.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
//!\file
//!Describes the quasi-random number generator base class template.
namespace Boost {
namespace random {
namespace qrng_detail {
// If the seed is a signed integer type, then we need to
// check that the value is positive:
template <typename Integer>
inline void check_seed_sign(const Integer& v, const Boost::true_type)
{
if (v < 0)
{
Boost::throw_exception( std::range_error("seed must be a positive integer") );
}
}
template <typename Integer>
inline void check_seed_sign(const Integer&, const Boost::false_type) {}
template <typename Integer>
inline void check_seed_sign(const Integer& v)
{
check_seed_sign(v, integral_constant<bool, std::numeric_limits<Integer>::is_signed>());
}
template<typename DerivedT, typename LatticeT, typename SizeT>
class qrng_base
{
public:
typedef SizeT size_type;
typedef typename LatticeT::value_type result_type;
explicit qrng_base(std::size_t dimension)
// Guard against invalid dimensions before creating the lattice
: lattice(prevent_zero_dimension(dimension))
, quasi_state(dimension)
{
derived().seed();
}
// default copy c-tor is fine
// default assignment operator is fine
//!Returns: The dimension of of the quasi-random domain.
//!
//!Throws: nothing.
std::size_t dimension() const { return quasi_state.size(); }
//!Returns: Returns a successive element of an s-dimensional
//!(s = X::dimension()) vector at each invocation. When all elements are
//!exhausted, X::operator() begins anew with the starting element of a
//!subsequent s-dimensional vector.
//!
//!Throws: range_error.
result_type operator()()
{
return curr_elem != dimension() ? load_cached(): next_state();
}
//!Fills a range with quasi-random values.
template<typename Iter> void generate(Iter first, Iter last)
{
for (; first != last; ++first)
*first = this->operator()();
}
//!Effects: Advances *this state as if z consecutive
//!X::operator() invocations were executed.
//!
//!Throws: range_error.
void discard(Boost::uintmax_t z)
{
const std::size_t dimension_value = dimension();
// Compiler knows how to optimize subsequent x / y and x % y
// statements. In fact, gcc does this even at -O1, so don't
// be tempted to "optimize" % via subtraction and multiplication.
Boost::uintmax_t vec_n = z / dimension_value;
std::size_t carry = curr_elem + (z % dimension_value);
vec_n += carry / dimension_value;
carry = carry % dimension_value;
// Avoid overdiscarding by branchlessly correcting the triple
// (D, S + 1, 0) to (D, S, D) (see equality operator)
const bool corr = (!carry) & static_cast<bool>(vec_n);
// Discards vec_n (with correction) consecutive s-dimensional vectors
discard_vector(vec_n - static_cast<Boost::uintmax_t>(corr));
#ifdef ACTIV_BOOST_MSVC
#pragma warning(push)
// disable unary minus operator applied to an unsigned type,
// result still unsigned.
#pragma warning(disable:4146)
#endif
// Sets up the proper position of the element-to-read
// curr_elem = carry + corr*dimension_value
curr_elem = carry ^ (-static_cast<std::size_t>(corr) & dimension_value);
#ifdef ACTIV_BOOST_MSVC
#pragma warning(pop)
#endif
}
//!Writes the textual representation of the generator to a @c std::ostream.
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, qrng_base, s)
{
os << s.dimension() << " " << s.seq_count << " " << s.curr_elem;
return os;
}
//!Reads the textual representation of the generator from a @c std::istream.
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, qrng_base, s)
{
std::size_t dim;
size_type seed;
Boost::uintmax_t z;
if (is >> dim >> std::ws >> seed >> std::ws >> z) // initialize iff success!
{
// Check seed sign before resizing the lattice and/or recomputing state
check_seed_sign(seed);
if (s.dimension() != prevent_zero_dimension(dim))
{
s.lattice.resize(dim);
s.quasi_state.resize(dim);
}
// Fast-forward to the correct state
s.derived().seed(seed);
if (z != 0) s.discard(z);
}
return is;
}
//!Returns true if the two generators will produce identical sequences of outputs.
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(qrng_base, x, y)
{
const std::size_t dimension_value = x.dimension();
// Note that two generators with different seq_counts and curr_elems can
// produce the same sequence because the generator triple
// (D, S, D) is equivalent to (D, S + 1, 0), where D is dimension, S -- seq_count,
// and the last one is curr_elem.
return (dimension_value == y.dimension()) &&
// |x.seq_count - y.seq_count| <= 1
!((x.seq_count < y.seq_count ? y.seq_count - x.seq_count : x.seq_count - y.seq_count)
> static_cast<size_type>(1)) &&
// Potential overflows don't matter here, since we've already ascertained
// that sequence counts differ by no more than 1, so if they overflow, they
// can overflow together.
(x.seq_count + (x.curr_elem / dimension_value) == y.seq_count + (y.curr_elem / dimension_value)) &&
(x.curr_elem % dimension_value == y.curr_elem % dimension_value);
}
//!Returns true if the two generators will produce different sequences of outputs.
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(qrng_base)
protected:
typedef std::vector<result_type> state_type;
typedef typename state_type::iterator state_iterator;
// Getters
size_type curr_seq() const { return seq_count; }
state_iterator state_begin() { return quasi_state.begin(); }
state_iterator state_end() { return quasi_state.end(); }
// Setters
void reset_seq(size_type seq)
{
seq_count = seq;
curr_elem = 0u;
}
private:
DerivedT& derived() throw()
{
return *static_cast<DerivedT * const>(this);
}
// Load the result from the saved state.
result_type load_cached()
{
return quasi_state[curr_elem++];
}
result_type next_state()
{
size_type new_seq = seq_count;
if (ACTIV_BOOST_LIKELY(++new_seq > seq_count))
{
derived().compute_seq(new_seq);
reset_seq(new_seq);
return load_cached();
}
Boost::throw_exception( std::range_error("qrng_base: next_state") );
}
// Discards z consecutive s-dimensional vectors,
// and preserves the position of the element-to-read
void discard_vector(Boost::uintmax_t z)
{
const Boost::uintmax_t max_z = (std::numeric_limits<size_type>::max)() - seq_count;
// Don't allow seq_count + z overflows here
if (max_z < z)
Boost::throw_exception( std::range_error("qrng_base: discard_vector") );
std::size_t tmp = curr_elem;
derived().seed(static_cast<size_type>(seq_count + z));
curr_elem = tmp;
}
static std::size_t prevent_zero_dimension(std::size_t dimension)
{
if (dimension == 0)
Boost::throw_exception( std::invalid_argument("qrng_base: zero dimension") );
return dimension;
}
// Member variables are so ordered with the intention
// that the typical memory access pattern would be
// incremental. Moreover, lattice is put before quasi_state
// because we want to construct lattice first. Lattices
// can do some kind of dimension sanity check (as in
// dimension_assert below), and if that fails then we don't
// need to do any more work.
private:
std::size_t curr_elem;
size_type seq_count;
protected:
LatticeT lattice;
private:
state_type quasi_state;
};
inline void dimension_assert(const char* generator, std::size_t dim, std::size_t maxdim)
{
if (!dim || dim > maxdim)
{
std::ostringstream os;
os << "The " << generator << " quasi-random number generator only supports dimensions in range [1; "
<< maxdim << "], but dimension " << dim << " was supplied.";
Boost::throw_exception( std::invalid_argument(os.str()) );
}
}
} // namespace qrng_detail
} // namespace random
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_DETAIL_QRNG_BASE_HPP
@@ -1,113 +0,0 @@
/* boost random/detail/seed.hpp header file
*
* Copyright Steven Watanabe 2009
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_SEED_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_SEED_HPP
#include <ActivBoost/config.hpp>
// Sun seems to have trouble with the use of SFINAE for the
// templated constructor. So does Borland.
#if !defined(ACTIV_BOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(ACTIV_BOOST_BORLANDC)
#include <ActivBoost/utility/enable_if.hpp>
#include <ActivBoost/type_traits/is_arithmetic.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class T>
struct disable_seed : Boost::disable_if<Boost::is_arithmetic<T> > {};
template<class Engine, class T>
struct disable_constructor : disable_seed<T> {};
template<class Engine>
struct disable_constructor<Engine, Engine> {};
#define ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
template<class Generator> \
explicit Self(Generator& gen, typename ::Boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
#define ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
template<class Generator> \
void seed(Generator& gen, typename ::Boost::random::detail::disable_seed<Generator>::type* = 0)
#define ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
template<class SeedSeq> \
explicit Self(SeedSeq& seq, typename ::Boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0)
#define ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
template<class SeedSeq> \
void seed(SeedSeq& seq, typename ::Boost::random::detail::disable_seed<SeedSeq>::type* = 0)
#define ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
explicit Self(const T& x)
#define ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
void seed(const T& x)
}
}
}
#else
#include <ActivBoost/type_traits/is_arithmetic.hpp>
#define ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
Self(Self& other) { *this = other; } \
Self(const Self& other) { *this = other; } \
template<class Generator> \
explicit Self(Generator& gen) { \
boost_random_constructor_impl(gen, ::Boost::is_arithmetic<Generator>());\
} \
template<class Generator> \
void boost_random_constructor_impl(Generator& gen, ::Boost::false_type)
#define ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
template<class Generator> \
void seed(Generator& gen) { \
boost_random_seed_impl(gen, ::Boost::is_arithmetic<Generator>());\
}\
template<class Generator>\
void boost_random_seed_impl(Generator& gen, ::Boost::false_type)
#define ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
Self(Self& other) { *this = other; } \
Self(const Self& other) { *this = other; } \
template<class SeedSeq> \
explicit Self(SeedSeq& seq) { \
boost_random_constructor_impl(seq, ::Boost::is_arithmetic<SeedSeq>());\
} \
template<class SeedSeq> \
void boost_random_constructor_impl(SeedSeq& seq, ::Boost::false_type)
#define ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
template<class SeedSeq> \
void seed(SeedSeq& seq) { \
boost_random_seed_impl(seq, ::Boost::is_arithmetic<SeedSeq>()); \
} \
template<class SeedSeq> \
void boost_random_seed_impl(SeedSeq& seq, ::Boost::false_type)
#define ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
explicit Self(const T& x) { boost_random_constructor_impl(x, ::Boost::true_type()); }\
void boost_random_constructor_impl(const T& x, ::Boost::true_type)
#define ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
void seed(const T& x) { boost_random_seed_impl(x, ::Boost::true_type()); }\
void boost_random_seed_impl(const T& x, ::Boost::true_type)
#endif
#endif
@@ -1,397 +0,0 @@
/* boost random/detail/seed.hpp header file
*
* Copyright Steven Watanabe 2009
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_SEED_IMPL_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_SEED_IMPL_HPP
#include <stdexcept>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/throw_exception.hpp>
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/integer/static_log2.hpp>
#include <ActivBoost/random/traits.hpp>
#include <ActivBoost/random/detail/const_mod.hpp>
#include <ActivBoost/random/detail/integer_log2.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/random/detail/generator_bits.hpp>
#include <ActivBoost/type_traits/conditional.hpp>
#include <ActivBoost/type_traits/integral_constant.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
namespace detail {
// finds the seed type of an engine, given its
// result_type. If the result_type is integral
// the seed type is the same. If the result_type
// is floating point, the seed type is uint32_t
template<class T>
struct seed_type
{
typedef typename Boost::conditional<Boost::is_integral<T>::value,
T,
Boost::uint32_t
>::type type;
};
template<int N>
struct const_pow_impl
{
template<class T>
static T call(T arg, int n, T result)
{
return const_pow_impl<N / 2>::call(T(arg * arg), n / 2,
n%2 == 0? result : T(result * arg));
}
};
template<>
struct const_pow_impl<0>
{
template<class T>
static T call(T, int, T result)
{
return result;
}
};
// requires N is an upper bound on n
template<int N, class T>
inline T const_pow(T arg, int n) { return const_pow_impl<N>::call(arg, n, T(1)); }
template<class T>
inline T pow2(int n)
{
typedef unsigned int_type;
const int max_bits = std::numeric_limits<int_type>::digits;
T multiplier = T(int_type(1) << (max_bits - 1)) * 2;
return (int_type(1) << (n % max_bits)) *
const_pow<std::numeric_limits<T>::digits / max_bits>(multiplier, n / max_bits);
}
template<class Engine, class Iter>
void generate_from_real(Engine& eng, Iter begin, Iter end)
{
using std::fmod;
typedef typename Engine::result_type RealType;
const int Bits = detail::generator_bits<Engine>::value();
int remaining_bits = 0;
Boost::uint_least32_t saved_bits = 0;
RealType multiplier = pow2<RealType>( Bits);
RealType mult32 = RealType(4294967296.0); // 2^32
while(true) {
RealType val = eng() * multiplier;
int available_bits = Bits;
// Make sure the compiler can optimize this out
// if it isn't possible.
if(Bits < 32 && available_bits < 32 - remaining_bits) {
saved_bits |= Boost::uint_least32_t(val) << remaining_bits;
remaining_bits += Bits;
} else {
// If Bits < 32, then remaining_bits != 0, since
// if remaining_bits == 0, available_bits < 32 - 0,
// and we won't get here to begin with.
if(Bits < 32 || remaining_bits != 0) {
Boost::uint_least32_t divisor =
(Boost::uint_least32_t(1) << (32 - remaining_bits));
Boost::uint_least32_t extra_bits = Boost::uint_least32_t(fmod(val, mult32)) & (divisor - 1);
val = val / divisor;
*begin++ = saved_bits | (extra_bits << remaining_bits);
if(begin == end) return;
available_bits -= 32 - remaining_bits;
remaining_bits = 0;
}
// If Bits < 32 we should never enter this loop
if(Bits >= 32) {
for(; available_bits >= 32; available_bits -= 32) {
Boost::uint_least32_t word = Boost::uint_least32_t(fmod(val, mult32));
val /= mult32;
*begin++ = word;
if(begin == end) return;
}
}
remaining_bits = available_bits;
saved_bits = static_cast<Boost::uint_least32_t>(val);
}
}
}
template<class Engine, class Iter>
void generate_from_int(Engine& eng, Iter begin, Iter end)
{
typedef typename Engine::result_type IntType;
typedef typename Boost::random::traits::make_unsigned<IntType>::type unsigned_type;
int remaining_bits = 0;
Boost::uint_least32_t saved_bits = 0;
unsigned_type range = Boost::random::detail::subtract<IntType>()((eng.max)(), (eng.min)());
int bits =
(range == (std::numeric_limits<unsigned_type>::max)()) ?
std::numeric_limits<unsigned_type>::digits :
detail::integer_log2(range + 1);
{
int discarded_bits = detail::integer_log2(bits);
unsigned_type excess = (range + 1) >> (bits - discarded_bits);
if(excess != 0) {
int extra_bits = detail::integer_log2((excess - 1) ^ excess);
bits = bits - discarded_bits + extra_bits;
}
}
unsigned_type mask = (static_cast<unsigned_type>(2) << (bits - 1)) - 1;
unsigned_type limit = ((range + 1) & ~mask) - 1;
while(true) {
unsigned_type val;
do {
val = Boost::random::detail::subtract<IntType>()(eng(), (eng.min)());
} while(limit != range && val > limit);
val &= mask;
int available_bits = bits;
if(available_bits == 32) {
*begin++ = static_cast<Boost::uint_least32_t>(val) & 0xFFFFFFFFu;
if(begin == end) return;
} else if(available_bits % 32 == 0) {
for(int i = 0; i < available_bits / 32; ++i) {
Boost::uint_least32_t word = Boost::uint_least32_t(val) & 0xFFFFFFFFu;
int suppress_warning = (bits >= 32);
ACTIV_BOOST_ASSERT(suppress_warning == 1);
val >>= (32 * suppress_warning);
*begin++ = word;
if(begin == end) return;
}
} else if(bits < 32 && available_bits < 32 - remaining_bits) {
saved_bits |= Boost::uint_least32_t(val) << remaining_bits;
remaining_bits += bits;
} else {
if(bits < 32 || remaining_bits != 0) {
Boost::uint_least32_t extra_bits = Boost::uint_least32_t(val) & ((Boost::uint_least32_t(1) << (32 - remaining_bits)) - 1);
val >>= 32 - remaining_bits;
*begin++ = saved_bits | (extra_bits << remaining_bits);
if(begin == end) return;
available_bits -= 32 - remaining_bits;
remaining_bits = 0;
}
if(bits >= 32) {
for(; available_bits >= 32; available_bits -= 32) {
Boost::uint_least32_t word = Boost::uint_least32_t(val) & 0xFFFFFFFFu;
int suppress_warning = (bits >= 32);
ACTIV_BOOST_ASSERT(suppress_warning == 1);
val >>= (32 * suppress_warning);
*begin++ = word;
if(begin == end) return;
}
}
remaining_bits = available_bits;
saved_bits = static_cast<Boost::uint_least32_t>(val);
}
}
}
template<class Engine, class Iter>
void generate_impl(Engine& eng, Iter first, Iter last, Boost::true_type)
{
return detail::generate_from_int(eng, first, last);
}
template<class Engine, class Iter>
void generate_impl(Engine& eng, Iter first, Iter last, Boost::false_type)
{
return detail::generate_from_real(eng, first, last);
}
template<class Engine, class Iter>
void generate(Engine& eng, Iter first, Iter last)
{
return detail::generate_impl(eng, first, last, Boost::random::traits::is_integral<typename Engine::result_type>());
}
template<class IntType, IntType m, class SeedSeq>
IntType seed_one_int(SeedSeq& seq)
{
static const int log = ::Boost::conditional<(m == 0),
::Boost::integral_constant<int, (::std::numeric_limits<IntType>::digits)>,
::Boost::static_log2<m> >::type::value;
static const int k =
(log + ((~(static_cast<IntType>(2) << (log - 1)) & m)? 32 : 31)) / 32;
::Boost::uint_least32_t array[log / 32 + 4];
seq.generate(&array[0], &array[0] + k + 3);
IntType s = 0;
for(int j = 0; j < k; ++j) {
IntType digit = const_mod<IntType, m>::apply(IntType(array[j+3]));
IntType mult = IntType(1) << 32*j;
s = const_mod<IntType, m>::mult_add(mult, digit, s);
}
return s;
}
template<class IntType, IntType m, class Iter>
IntType get_one_int(Iter& first, Iter last)
{
static const int log = ::Boost::conditional<(m == 0),
::Boost::integral_constant<int, (::std::numeric_limits<IntType>::digits)>,
::Boost::static_log2<m> >::type::value;
static const int k =
(log + ((~(static_cast<IntType>(2) << (log - 1)) & m)? 32 : 31)) / 32;
IntType s = 0;
for(int j = 0; j < k; ++j) {
if(first == last) {
Boost::throw_exception(::std::invalid_argument("Not enough elements in call to seed."));
}
IntType digit = const_mod<IntType, m>::apply(IntType(*first++));
IntType mult = IntType(1) << 32*j;
s = const_mod<IntType, m>::mult_add(mult, digit, s);
}
return s;
}
// TODO: work in-place whenever possible
template<int w, std::size_t n, class SeedSeq, class UIntType>
void seed_array_int_impl(SeedSeq& seq, UIntType (&x)[n])
{
Boost::uint_least32_t storage[((w+31)/32) * n];
seq.generate(&storage[0], &storage[0] + ((w+31)/32) * n);
for(std::size_t j = 0; j < n; j++) {
UIntType val = 0;
for(std::size_t k = 0; k < (w+31)/32; ++k) {
val += static_cast<UIntType>(storage[(w+31)/32*j + k]) << 32*k;
}
x[j] = val & ::Boost::low_bits_mask_t<w>::sig_bits;
}
}
template<int w, std::size_t n, class SeedSeq, class IntType>
inline void seed_array_int_impl(SeedSeq& seq, IntType (&x)[n], Boost::true_type)
{
ACTIV_BOOST_STATIC_ASSERT_MSG(Boost::is_integral<IntType>::value, "Sorry but this routine has not been ported to non built-in integers as it relies on a reinterpret_cast.");
typedef typename Boost::make_unsigned<IntType>::type unsigned_array[n];
seed_array_int_impl<w>(seq, reinterpret_cast<unsigned_array&>(x));
}
template<int w, std::size_t n, class SeedSeq, class IntType>
inline void seed_array_int_impl(SeedSeq& seq, IntType (&x)[n], Boost::false_type)
{
seed_array_int_impl<w>(seq, x);
}
template<int w, std::size_t n, class SeedSeq, class IntType>
inline void seed_array_int(SeedSeq& seq, IntType (&x)[n])
{
seed_array_int_impl<w>(seq, x, Boost::random::traits::is_signed<IntType>());
}
template<int w, std::size_t n, class Iter, class UIntType>
void fill_array_int_impl(Iter& first, Iter last, UIntType (&x)[n])
{
for(std::size_t j = 0; j < n; j++) {
UIntType val = 0;
for(std::size_t k = 0; k < (w+31)/32; ++k) {
if(first == last) {
Boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
}
val += static_cast<UIntType>(*first++) << 32*k;
}
x[j] = val & ::Boost::low_bits_mask_t<w>::sig_bits;
}
}
template<int w, std::size_t n, class Iter, class IntType>
inline void fill_array_int_impl(Iter& first, Iter last, IntType (&x)[n], Boost::true_type)
{
ACTIV_BOOST_STATIC_ASSERT_MSG(Boost::is_integral<IntType>::value, "Sorry but this routine has not been ported to non built-in integers as it relies on a reinterpret_cast.");
typedef typename Boost::make_unsigned<IntType>::type unsigned_array[n];
fill_array_int_impl<w>(first, last, reinterpret_cast<unsigned_array&>(x));
}
template<int w, std::size_t n, class Iter, class IntType>
inline void fill_array_int_impl(Iter& first, Iter last, IntType (&x)[n], Boost::false_type)
{
fill_array_int_impl<w>(first, last, x);
}
template<int w, std::size_t n, class Iter, class IntType>
inline void fill_array_int(Iter& first, Iter last, IntType (&x)[n])
{
fill_array_int_impl<w>(first, last, x, Boost::random::traits::is_signed<IntType>());
}
template<int w, std::size_t n, class RealType>
void seed_array_real_impl(const Boost::uint_least32_t* storage, RealType (&x)[n])
{
Boost::uint_least32_t mask = ~((~Boost::uint_least32_t(0)) << (w%32));
RealType two32 = 4294967296.0;
const RealType divisor = RealType(1)/detail::pow2<RealType>(w);
unsigned int j;
for(j = 0; j < n; ++j) {
RealType val = RealType(0);
RealType mult = divisor;
for(int k = 0; k < w/32; ++k) {
val += *storage++ * mult;
mult *= two32;
}
if(mask != 0) {
val += (*storage++ & mask) * mult;
}
ACTIV_BOOST_ASSERT(val >= 0);
ACTIV_BOOST_ASSERT(val < 1);
x[j] = val;
}
}
template<int w, std::size_t n, class SeedSeq, class RealType>
void seed_array_real(SeedSeq& seq, RealType (&x)[n])
{
using std::pow;
Boost::uint_least32_t storage[((w+31)/32) * n];
seq.generate(&storage[0], &storage[0] + ((w+31)/32) * n);
seed_array_real_impl<w>(storage, x);
}
template<int w, std::size_t n, class Iter, class RealType>
void fill_array_real(Iter& first, Iter last, RealType (&x)[n])
{
Boost::uint_least32_t mask = ~((~Boost::uint_least32_t(0)) << (w%32));
RealType two32 = 4294967296.0;
const RealType divisor = RealType(1)/detail::pow2<RealType>(w);
unsigned int j;
for(j = 0; j < n; ++j) {
RealType val = RealType(0);
RealType mult = divisor;
for(int k = 0; k < w/32; ++k, ++first) {
if(first == last) Boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
val += *first * mult;
mult *= two32;
}
if(mask != 0) {
if(first == last) Boost::throw_exception(std::invalid_argument("Not enough elements in call to seed."));
val += (*first & mask) * mult;
++first;
}
ACTIV_BOOST_ASSERT(val >= 0);
ACTIV_BOOST_ASSERT(val < 1);
x[j] = val;
}
}
}
}
}
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif
@@ -1,89 +0,0 @@
/* boost random/detail/signed_unsigned_tools.hpp header file
*
* Copyright Jens Maurer 2006
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
#define ACTIV_BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
#include <ActivBoost/limits.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/random/traits.hpp>
namespace Boost {
namespace random {
namespace detail {
/*
* Compute x - y, we know that x >= y, return an unsigned value.
*/
template<class T, bool sgn = std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_bounded>
struct subtract { };
template<class T>
struct subtract<T, /* signed */ false>
{
typedef T result_type;
result_type operator()(T x, T y) { return x - y; }
};
template<class T>
struct subtract<T, /* signed */ true>
{
typedef typename Boost::random::traits::make_unsigned_or_unbounded<T>::type result_type;
result_type operator()(T x, T y)
{
if (y >= 0) // because x >= y, it follows that x >= 0, too
return result_type(x) - result_type(y);
if (x >= 0) // y < 0
// avoid the nasty two's complement case for y == min()
return result_type(x) + result_type(-(y+1)) + 1;
// both x and y are negative: no signed overflow
return result_type(x - y);
}
};
/*
* Compute x + y, x is unsigned, result fits in type of "y".
*/
template<class T1, class T2, bool sgn = (std::numeric_limits<T2>::is_signed && (std::numeric_limits<T1>::digits >= std::numeric_limits<T2>::digits))>
struct add { };
template<class T1, class T2>
struct add<T1, T2, /* signed or else T2 has more digits than T1 so the cast always works - needed when T2 is a multiprecision type and T1 is a native integer */ false>
{
typedef T2 result_type;
result_type operator()(T1 x, T2 y) { return T2(x) + y; }
};
template<class T1, class T2>
struct add<T1, T2, /* signed */ true>
{
typedef T2 result_type;
result_type operator()(T1 x, T2 y)
{
if (y >= 0)
return T2(x) + y;
// y < 0
if (x > T1(-(y+1))) // result >= 0 after subtraction
// avoid the nasty two's complement edge case for y == min()
return T2(x - T1(-(y+1)) - 1);
// abs(x) < abs(y), thus T2 able to represent x
return T2(x) + y;
}
};
} // namespace detail
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_TOOLS
File diff suppressed because it is too large. Load diff
@@ -1,76 +0,0 @@
/* boost random/detail/uniform_int_float.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
#include <ActivBoost/limits.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/integer.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/generator_bits.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class URNG>
class uniform_int_float
{
public:
typedef URNG base_type;
typedef typename base_type::result_type base_result;
typedef typename Boost::uint_t<
(std::numeric_limits<Boost::uintmax_t>::digits <
std::numeric_limits<base_result>::digits)?
std::numeric_limits<Boost::uintmax_t>::digits :
std::numeric_limits<base_result>::digits
>::fast result_type;
uniform_int_float(base_type& rng)
: _rng(rng) {}
static result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 0; }
static result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
std::size_t digits = std::numeric_limits<result_type>::digits;
if(detail::generator_bits<URNG>::value() < digits) {
digits = detail::generator_bits<URNG>::value();
}
return (result_type(2) << (digits - 1)) - 1;
}
base_type& base() { return _rng; }
const base_type& base() const { return _rng; }
result_type operator()()
{
base_result range = static_cast<base_result>((max)())+1;
return static_cast<result_type>(_rng() * range);
}
private:
base_type& _rng;
};
} // namespace detail
} // namespace random
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_DETAIL_UNIFORM_INT_FLOAT_HPP
@@ -1,78 +0,0 @@
/* boost random/vector_io.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DETAIL_VECTOR_IO_HPP
#define ACTIV_BOOST_RANDOM_DETAIL_VECTOR_IO_HPP
#include <vector>
#include <iosfwd>
#include <istream>
#include <ActivBoost/io/ios_state.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class CharT, class Traits, class T>
void print_vector(std::basic_ostream<CharT, Traits>& os,
const std::vector<T>& vec)
{
typename std::vector<T>::const_iterator
iter = vec.begin(),
end = vec.end();
os << os.widen('[');
if(iter != end) {
os << *iter;
++iter;
for(; iter != end; ++iter)
{
os << os.widen(' ') << *iter;
}
}
os << os.widen(']');
}
template<class CharT, class Traits, class T>
void read_vector(std::basic_istream<CharT, Traits>& is, std::vector<T>& vec)
{
CharT ch;
if(!(is >> ch)) {
return;
}
if(ch != is.widen('[')) {
is.putback(ch);
is.setstate(std::ios_base::failbit);
return;
}
Boost::io::basic_ios_exception_saver<CharT, Traits> e(is, std::ios_base::goodbit);
T val;
while(is >> std::ws >> val) {
vec.push_back(val);
}
if(is.fail()) {
is.clear();
e.restore();
if(!(is >> ch)) {
return;
}
if(ch != is.widen(']')) {
is.putback(ch);
is.setstate(std::ios_base::failbit);
}
}
}
}
}
}
#endif // ACTIV_BOOST_RANDOM_DETAIL_VECTOR_IO_HPP
@@ -1,241 +0,0 @@
/* boost random/discard_block.hpp header file
*
* Copyright Jens Maurer 2002
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-03-02 created
*/
#ifndef ACTIV_BOOST_RANDOM_DISCARD_BLOCK_HPP
#define ACTIV_BOOST_RANDOM_DISCARD_BLOCK_HPP
#include <iostream>
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
namespace Boost {
namespace random {
/**
* The class template \discard_block_engine is a model of
* \pseudo_random_number_generator. It modifies
* another generator by discarding parts of its output.
* Out of every block of @c p results, the first @c r
* will be returned and the rest discarded.
*
* Requires: 0 < p <= r
*/
template<class UniformRandomNumberGenerator, std::size_t p, std::size_t r>
class discard_block_engine
{
typedef typename detail::seed_type<
typename UniformRandomNumberGenerator::result_type>::type seed_type;
public:
typedef UniformRandomNumberGenerator base_type;
typedef typename base_type::result_type result_type;
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, block_size = p);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, used_block = r);
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, total_block = p);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, returned_block = r);
ACTIV_BOOST_STATIC_ASSERT(total_block >= returned_block);
/** Uses the default seed for the base generator. */
discard_block_engine() : _rng(), _n(0) { }
/** Constructs a new \discard_block_engine with a copy of rng. */
explicit discard_block_engine(const base_type & rng) : _rng(rng), _n(0) { }
#ifndef ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
/** Constructs a new \discard_block_engine with rng. */
explicit discard_block_engine(base_type && rng) : _rng(rng), _n(0) { }
#endif
/**
* Creates a new \discard_block_engine and seeds the underlying
* generator with @c value
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(discard_block_engine,
seed_type, value)
{ _rng.seed(value); _n = 0; }
/**
* Creates a new \discard_block_engine and seeds the underlying
* generator with @c seq
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(discard_block_engine, SeedSeq, seq)
{ _rng.seed(seq); _n = 0; }
/**
* Creates a new \discard_block_engine and seeds the underlying
* generator with first and last.
*/
template<class It> discard_block_engine(It& first, It last)
: _rng(first, last), _n(0) { }
/** default seeds the underlying generator. */
void seed() { _rng.seed(); _n = 0; }
/** Seeds the underlying generator with s. */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(discard_block_engine, seed_type, s)
{ _rng.seed(s); _n = 0; }
/** Seeds the underlying generator with seq. */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(discard_block_engine, SeedSeq, seq)
{ _rng.seed(seq); _n = 0; }
/** Seeds the underlying generator with first and last. */
template<class It> void seed(It& first, It last)
{ _rng.seed(first, last); _n = 0; }
/** Returns the underlying engine. */
const base_type& base() const { return _rng; }
/** Returns the next value of the generator. */
result_type operator()()
{
if(_n >= returned_block) {
// discard values of random number generator
// Don't use discard, since we still need to
// be somewhat compatible with TR1.
// _rng.discard(total_block - _n);
for(std::size_t i = 0; i < total_block - _n; ++i) {
_rng();
}
_n = 0;
}
++_n;
return _rng();
}
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
template<class It>
void generate(It first, It last)
{ detail::generate(*this, first, last); }
/**
* Returns the smallest value that the generator can produce.
* This is the same as the minimum of the underlying generator.
*/
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_type::min)(); }
/**
* Returns the largest value that the generator can produce.
* This is the same as the maximum of the underlying generator.
*/
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_type::max)(); }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes a \discard_block_engine to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const discard_block_engine& s)
{
os << s._rng << ' ' << s._n;
return os;
}
/** Reads a \discard_block_engine from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, discard_block_engine& s)
{
is >> s._rng >> std::ws >> s._n;
return is;
}
#endif
/** Returns true if the two generators will produce identical sequences. */
friend bool operator==(const discard_block_engine& x,
const discard_block_engine& y)
{ return x._rng == y._rng && x._n == y._n; }
/** Returns true if the two generators will produce different sequences. */
friend bool operator!=(const discard_block_engine& x,
const discard_block_engine& y)
{ return !(x == y); }
private:
base_type _rng;
std::size_t _n;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class URNG, std::size_t p, std::size_t r>
const bool discard_block_engine<URNG, p, r>::has_fixed_range;
template<class URNG, std::size_t p, std::size_t r>
const std::size_t discard_block_engine<URNG, p, r>::total_block;
template<class URNG, std::size_t p, std::size_t r>
const std::size_t discard_block_engine<URNG, p, r>::returned_block;
template<class URNG, std::size_t p, std::size_t r>
const std::size_t discard_block_engine<URNG, p, r>::block_size;
template<class URNG, std::size_t p, std::size_t r>
const std::size_t discard_block_engine<URNG, p, r>::used_block;
#endif
/// \cond \show_deprecated
template<class URNG, int p, int r>
class discard_block : public discard_block_engine<URNG, p, r>
{
typedef discard_block_engine<URNG, p, r> base_t;
public:
typedef typename base_t::result_type result_type;
discard_block() {}
template<class T>
discard_block(T& arg) : base_t(arg) {}
template<class T>
discard_block(const T& arg) : base_t(arg) {}
template<class It>
discard_block(It& first, It last) : base_t(first, last) {}
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (this->base().min)(); }
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (this->base().max)(); }
};
/// \endcond
namespace detail {
template<class Engine>
struct generator_bits;
template<class URNG, std::size_t p, std::size_t r>
struct generator_bits<discard_block_engine<URNG, p, r> > {
static std::size_t value() { return generator_bits<URNG>::value(); }
};
template<class URNG, int p, int r>
struct generator_bits<discard_block<URNG, p, r> > {
static std::size_t value() { return generator_bits<URNG>::value(); }
};
}
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_DISCARD_BLOCK_HPP
@@ -1,640 +0,0 @@
/* boost random/discrete_distribution.hpp header file
*
* Copyright Steven Watanabe 2009-2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_DISCRETE_DISTRIBUTION_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_DISCRETE_DISTRIBUTION_HPP_INCLUDED
#include <vector>
#include <limits>
#include <numeric>
#include <utility>
#include <iterator>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/random/uniform_int_distribution.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/vector_io.hpp>
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
#include <ActivBoost/range/begin.hpp>
#include <ActivBoost/range/end.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class IntType, class WeightType>
struct integer_alias_table {
WeightType get_weight(IntType bin) const {
WeightType result = _average;
if(bin < _excess) ++result;
return result;
}
template<class Iter>
WeightType init_average(Iter begin, Iter end) {
WeightType weight_average = 0;
IntType excess = 0;
IntType n = 0;
// weight_average * n + excess == current partial sum
// This is a bit messy, but it's guaranteed not to overflow
for(Iter iter = begin; iter != end; ++iter) {
++n;
if(*iter < weight_average) {
WeightType diff = weight_average - *iter;
weight_average -= diff / n;
if(diff % n > excess) {
--weight_average;
excess += n - diff % n;
} else {
excess -= diff % n;
}
} else {
WeightType diff = *iter - weight_average;
weight_average += diff / n;
if(diff % n < n - excess) {
excess += diff % n;
} else {
++weight_average;
excess -= n - diff % n;
}
}
}
_alias_table.resize(static_cast<std::size_t>(n));
_average = weight_average;
_excess = excess;
return weight_average;
}
void init_empty()
{
_alias_table.clear();
_alias_table.push_back(std::make_pair(static_cast<WeightType>(1),
static_cast<IntType>(0)));
_average = static_cast<WeightType>(1);
_excess = static_cast<IntType>(0);
}
bool operator==(const integer_alias_table& other) const
{
return _alias_table == other._alias_table &&
_average == other._average && _excess == other._excess;
}
static WeightType normalize(WeightType val, WeightType /* average */)
{
return val;
}
static void normalize(std::vector<WeightType>&) {}
template<class URNG>
WeightType test(URNG &urng) const
{
return uniform_int_distribution<WeightType>(0, _average)(urng);
}
bool accept(IntType result, WeightType val) const
{
return result < _excess || val < _average;
}
static WeightType try_get_sum(const std::vector<WeightType>& weights)
{
WeightType result = static_cast<WeightType>(0);
for(typename std::vector<WeightType>::const_iterator
iter = weights.begin(), end = weights.end();
iter != end; ++iter)
{
if((std::numeric_limits<WeightType>::max)() - result > *iter) {
return static_cast<WeightType>(0);
}
result += *iter;
}
return result;
}
template<class URNG>
static WeightType generate_in_range(URNG &urng, WeightType max)
{
return uniform_int_distribution<WeightType>(
static_cast<WeightType>(0), max-1)(urng);
}
typedef std::vector<std::pair<WeightType, IntType> > alias_table_t;
alias_table_t _alias_table;
WeightType _average;
IntType _excess;
};
template<class IntType, class WeightType>
struct real_alias_table {
WeightType get_weight(IntType) const
{
return WeightType(1.0);
}
template<class Iter>
WeightType init_average(Iter first, Iter last)
{
std::size_t size = std::distance(first, last);
WeightType weight_sum =
std::accumulate(first, last, static_cast<WeightType>(0));
_alias_table.resize(size);
return weight_sum / size;
}
void init_empty()
{
_alias_table.clear();
_alias_table.push_back(std::make_pair(static_cast<WeightType>(1),
static_cast<IntType>(0)));
}
bool operator==(const real_alias_table& other) const
{
return _alias_table == other._alias_table;
}
static WeightType normalize(WeightType val, WeightType average)
{
return val / average;
}
static void normalize(std::vector<WeightType>& weights)
{
WeightType sum =
std::accumulate(weights.begin(), weights.end(),
static_cast<WeightType>(0));
for(typename std::vector<WeightType>::iterator
iter = weights.begin(),
end = weights.end();
iter != end; ++iter)
{
*iter /= sum;
}
}
template<class URNG>
WeightType test(URNG &urng) const
{
return uniform_01<WeightType>()(urng);
}
bool accept(IntType, WeightType) const
{
return true;
}
static WeightType try_get_sum(const std::vector<WeightType>& /* weights */)
{
return static_cast<WeightType>(1);
}
template<class URNG>
static WeightType generate_in_range(URNG &urng, WeightType)
{
return uniform_01<WeightType>()(urng);
}
typedef std::vector<std::pair<WeightType, IntType> > alias_table_t;
alias_table_t _alias_table;
};
template<bool IsIntegral>
struct select_alias_table;
template<>
struct select_alias_table<true> {
template<class IntType, class WeightType>
struct apply {
typedef integer_alias_table<IntType, WeightType> type;
};
};
template<>
struct select_alias_table<false> {
template<class IntType, class WeightType>
struct apply {
typedef real_alias_table<IntType, WeightType> type;
};
};
}
/**
* The class @c discrete_distribution models a \random_distribution.
* It produces integers in the range [0, n) with the probability
* of producing each value is specified by the parameters of the
* distribution.
*/
template<class IntType = int, class WeightType = double>
class discrete_distribution {
public:
typedef WeightType input_type;
typedef IntType result_type;
class param_type {
public:
typedef discrete_distribution distribution_type;
/**
* Constructs a @c param_type object, representing a distribution
* with \f$p(0) = 1\f$ and \f$p(k|k>0) = 0\f$.
*/
param_type() : _probabilities(1, static_cast<WeightType>(1)) {}
/**
* If @c first == @c last, equivalent to the default constructor.
* Otherwise, the values of the range represent weights for the
* possible values of the distribution.
*/
template<class Iter>
param_type(Iter first, Iter last) : _probabilities(first, last)
{
normalize();
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* If wl.size() == 0, equivalent to the default constructor.
* Otherwise, the values of the @c initializer_list represent
* weights for the possible values of the distribution.
*/
param_type(const std::initializer_list<WeightType>& wl)
: _probabilities(wl)
{
normalize();
}
#endif
/**
* If the range is empty, equivalent to the default constructor.
* Otherwise, the elements of the range represent
* weights for the possible values of the distribution.
*/
template<class Range>
explicit param_type(const Range& range)
: _probabilities(Boost::begin(range), Boost::end(range))
{
normalize();
}
/**
* If nw is zero, equivalent to the default constructor.
* Otherwise, the range of the distribution is [0, nw),
* and the weights are found by calling fw with values
* evenly distributed between \f$\mbox{xmin} + \delta/2\f$ and
* \f$\mbox{xmax} - \delta/2\f$, where
* \f$\delta = (\mbox{xmax} - \mbox{xmin})/\mbox{nw}\f$.
*/
template<class Func>
param_type(std::size_t nw, double xmin, double xmax, Func fw)
{
std::size_t n = (nw == 0) ? 1 : nw;
double delta = (xmax - xmin) / n;
ACTIV_BOOST_ASSERT(delta > 0);
for(std::size_t k = 0; k < n; ++k) {
_probabilities.push_back(fw(xmin + k*delta + delta/2));
}
normalize();
}
/**
* Returns a vector containing the probabilities of each possible
* value of the distribution.
*/
std::vector<WeightType> probabilities() const
{
return _probabilities;
}
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
detail::print_vector(os, parm._probabilities);
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
std::vector<WeightType> temp;
detail::read_vector(is, temp);
if(is) {
parm._probabilities.swap(temp);
}
return is;
}
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{
return lhs._probabilities == rhs._probabilities;
}
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
/// @cond show_private
friend class discrete_distribution;
explicit param_type(const discrete_distribution& dist)
: _probabilities(dist.probabilities())
{}
void normalize()
{
impl_type::normalize(_probabilities);
}
std::vector<WeightType> _probabilities;
/// @endcond
};
/**
* Creates a new @c discrete_distribution object that has
* \f$p(0) = 1\f$ and \f$p(i|i>0) = 0\f$.
*/
discrete_distribution()
{
_impl.init_empty();
}
/**
* Constructs a discrete_distribution from an iterator range.
* If @c first == @c last, equivalent to the default constructor.
* Otherwise, the values of the range represent weights for the
* possible values of the distribution.
*/
template<class Iter>
discrete_distribution(Iter first, Iter last)
{
init(first, last);
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a @c discrete_distribution from a @c std::initializer_list.
* If the @c initializer_list is empty, equivalent to the default
* constructor. Otherwise, the values of the @c initializer_list
* represent weights for the possible values of the distribution.
* For example, given the distribution
*
* @code
* discrete_distribution<> dist{1, 4, 5};
* @endcode
*
* The probability of a 0 is 1/10, the probability of a 1 is 2/5,
* the probability of a 2 is 1/2, and no other values are possible.
*/
discrete_distribution(std::initializer_list<WeightType> wl)
{
init(wl.begin(), wl.end());
}
#endif
/**
* Constructs a discrete_distribution from a Boost.Range range.
* If the range is empty, equivalent to the default constructor.
* Otherwise, the values of the range represent weights for the
* possible values of the distribution.
*/
template<class Range>
explicit discrete_distribution(const Range& range)
{
init(Boost::begin(range), Boost::end(range));
}
/**
* Constructs a discrete_distribution that approximates a function.
* If nw is zero, equivalent to the default constructor.
* Otherwise, the range of the distribution is [0, nw),
* and the weights are found by calling fw with values
* evenly distributed between \f$\mbox{xmin} + \delta/2\f$ and
* \f$\mbox{xmax} - \delta/2\f$, where
* \f$\delta = (\mbox{xmax} - \mbox{xmin})/\mbox{nw}\f$.
*/
template<class Func>
discrete_distribution(std::size_t nw, double xmin, double xmax, Func fw)
{
std::size_t n = (nw == 0) ? 1 : nw;
double delta = (xmax - xmin) / n;
ACTIV_BOOST_ASSERT(delta > 0);
std::vector<WeightType> weights;
for(std::size_t k = 0; k < n; ++k) {
weights.push_back(fw(xmin + k*delta + delta/2));
}
init(weights.begin(), weights.end());
}
/**
* Constructs a discrete_distribution from its parameters.
*/
explicit discrete_distribution(const param_type& parm)
{
param(parm);
}
/**
* Returns a value distributed according to the parameters of the
* discrete_distribution.
*/
template<class URNG>
IntType operator()(URNG& urng) const
{
ACTIV_BOOST_ASSERT(!_impl._alias_table.empty());
IntType result;
WeightType test;
do {
result = uniform_int_distribution<IntType>((min)(), (max)())(urng);
test = _impl.test(urng);
} while(!_impl.accept(result, test));
if(test < _impl._alias_table[static_cast<std::size_t>(result)].first) {
return result;
} else {
return(_impl._alias_table[static_cast<std::size_t>(result)].second);
}
}
/**
* Returns a value distributed according to the parameters
* specified by param.
*/
template<class URNG>
IntType operator()(URNG& urng, const param_type& parm) const
{
if(WeightType limit = impl_type::try_get_sum(parm._probabilities)) {
WeightType val = impl_type::generate_in_range(urng, limit);
WeightType sum = 0;
std::size_t result = 0;
for(typename std::vector<WeightType>::const_iterator
iter = parm._probabilities.begin(),
end = parm._probabilities.end();
iter != end; ++iter, ++result)
{
sum += *iter;
if(sum > val) {
return result;
}
}
// This shouldn't be reachable, but round-off error
// can prevent any match from being found when val is
// very close to 1.
return static_cast<IntType>(parm._probabilities.size() - 1);
} else {
// WeightType is integral and sum(parm._probabilities)
// would overflow. Just use the easy solution.
return discrete_distribution(parm)(urng);
}
}
/** Returns the smallest value that the distribution can produce. */
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
/** Returns the largest value that the distribution can produce. */
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return static_cast<result_type>(_impl._alias_table.size() - 1); }
/**
* Returns a vector containing the probabilities of each
* value of the distribution. For example, given
*
* @code
* discrete_distribution<> dist = { 1, 4, 5 };
* std::vector<double> p = dist.param();
* @endcode
*
* the vector, p will contain {0.1, 0.4, 0.5}.
*
* If @c WeightType is integral, then the weights
* will be returned unchanged.
*/
std::vector<WeightType> probabilities() const
{
std::vector<WeightType> result(_impl._alias_table.size(), static_cast<WeightType>(0));
std::size_t i = 0;
for(typename impl_type::alias_table_t::const_iterator
iter = _impl._alias_table.begin(),
end = _impl._alias_table.end();
iter != end; ++iter, ++i)
{
WeightType val = iter->first;
result[i] += val;
result[static_cast<std::size_t>(iter->second)] += _impl.get_weight(i) - val;
}
impl_type::normalize(result);
return(result);
}
/** Returns the parameters of the distribution. */
param_type param() const
{
return param_type(*this);
}
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
init(parm._probabilities.begin(), parm._probabilities.end());
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() {}
/** Writes a distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, discrete_distribution, dd)
{
os << dd.param();
return os;
}
/** Reads a distribution from a @c std::istream */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, discrete_distribution, dd)
{
param_type parm;
if(is >> parm) {
dd.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will return the
* same sequence of values, when passed equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(discrete_distribution, lhs, rhs)
{
return lhs._impl == rhs._impl;
}
/**
* Returns true if the two distributions may return different
* sequences of values, when passed equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(discrete_distribution)
private:
/// @cond show_private
template<class Iter>
void init(Iter first, Iter last, std::input_iterator_tag)
{
std::vector<WeightType> temp(first, last);
init(temp.begin(), temp.end());
}
template<class Iter>
void init(Iter first, Iter last, std::forward_iterator_tag)
{
size_t input_size = std::distance(first, last);
std::vector<std::pair<WeightType, IntType> > below_average;
std::vector<std::pair<WeightType, IntType> > above_average;
below_average.reserve(input_size);
above_average.reserve(input_size);
WeightType weight_average = _impl.init_average(first, last);
WeightType normalized_average = _impl.get_weight(0);
std::size_t i = 0;
for(; first != last; ++first, ++i) {
WeightType val = impl_type::normalize(*first, weight_average);
std::pair<WeightType, IntType> elem(val, static_cast<IntType>(i));
if(val < normalized_average) {
below_average.push_back(elem);
} else {
above_average.push_back(elem);
}
}
typename impl_type::alias_table_t::iterator
b_iter = below_average.begin(),
b_end = below_average.end(),
a_iter = above_average.begin(),
a_end = above_average.end()
;
while(b_iter != b_end && a_iter != a_end) {
_impl._alias_table[static_cast<std::size_t>(b_iter->second)] =
std::make_pair(b_iter->first, a_iter->second);
a_iter->first -= (_impl.get_weight(b_iter->second) - b_iter->first);
if(a_iter->first < normalized_average) {
*b_iter = *a_iter++;
} else {
++b_iter;
}
}
for(; b_iter != b_end; ++b_iter) {
_impl._alias_table[static_cast<std::size_t>(b_iter->second)].first =
_impl.get_weight(b_iter->second);
}
for(; a_iter != a_end; ++a_iter) {
_impl._alias_table[static_cast<std::size_t>(a_iter->second)].first =
_impl.get_weight(a_iter->second);
}
}
template<class Iter>
void init(Iter first, Iter last)
{
if(first == last) {
_impl.init_empty();
} else {
typename std::iterator_traits<Iter>::iterator_category category;
init(first, last, category);
}
}
typedef typename detail::select_alias_table<
(::Boost::is_integral<WeightType>::value)
>::template apply<IntType, WeightType>::type impl_type;
impl_type _impl;
/// @endcond
};
}
}
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif
@@ -1,386 +0,0 @@
/* boost random/exponential_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Copyright Jason Rhinelander 2016
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/int_float_pair.hpp>
#include <ActivBoost/random/uniform_01.hpp>
namespace Boost {
namespace random {
namespace detail {
// tables for the ziggurat algorithm
template<class RealType>
struct exponential_table {
static const RealType table_x[257];
static const RealType table_y[257];
};
template<class RealType>
const RealType exponential_table<RealType>::table_x[257] = {
8.6971174701310497140, 7.6971174701310497140, 6.9410336293772123602, 6.4783784938325698538,
6.1441646657724730491, 5.8821443157953997963, 5.6664101674540337371, 5.4828906275260628694,
5.3230905057543986131, 5.1814872813015010392, 5.0542884899813047117, 4.9387770859012514838,
4.8329397410251125881, 4.7352429966017412526, 4.6444918854200854873, 4.5597370617073515513,
4.4802117465284221949, 4.4052876934735729805, 4.3344436803172730116, 4.2672424802773661873,
4.2033137137351843802, 4.1423408656640511251, 4.0840513104082974638, 4.0282085446479365106,
3.9746060666737884793, 3.9230625001354895926, 3.8734176703995089983, 3.8255294185223367372,
3.7792709924116678992, 3.7345288940397975350, 3.6912010902374189454, 3.6491955157608538478,
3.6084288131289096339, 3.5688252656483374051, 3.5303158891293438633, 3.4928376547740601814,
3.4563328211327607625, 3.4207483572511205323, 3.3860354424603017887, 3.3521490309001100106,
3.3190474709707487166, 3.2866921715990692095, 3.2550473085704501813, 3.2240795652862645207,
3.1937579032122407483, 3.1640533580259734580, 3.1349388580844407393, 3.1063890623398246660,
3.0783802152540905188, 3.0508900166154554479, 3.0238975044556767713, 2.9973829495161306949,
2.9713277599210896472, 2.9457143948950456386, 2.9205262865127406647, 2.8957477686001416838,
2.8713640120155362592, 2.8473609656351888266, 2.8237253024500354905, 2.8004443702507381944,
2.7775061464397572041, 2.7548991965623453650, 2.7326126361947007411, 2.7106360958679293686,
2.6889596887418041593, 2.6675739807732670816, 2.6464699631518093905, 2.6256390267977886123,
2.6050729387408355373, 2.5847638202141406911, 2.5647041263169053687, 2.5448866271118700928,
2.5253043900378279427, 2.5059507635285939648, 2.4868193617402096807, 2.4679040502973649846,
2.4491989329782498908, 2.4306983392644199088, 2.4123968126888708336, 2.3942890999214583288,
2.3763701405361408194, 2.3586350574093374601, 2.3410791477030346875, 2.3236978743901964559,
2.3064868582835798692, 2.2894418705322694265, 2.2725588255531546952, 2.2558337743672190441,
2.2392628983129087111, 2.2228425031110364013, 2.2065690132576635755, 2.1904389667232199235,
2.1744490099377744673, 2.1585958930438856781, 2.1428764653998416425, 2.1272876713173679737,
2.1118265460190418108, 2.0964902118017147637, 2.0812758743932248696, 2.0661808194905755036,
2.0512024094685848641, 2.0363380802487695916, 2.0215853383189260770, 2.0069417578945183144,
1.9924049782135764992, 1.9779727009573602295, 1.9636426877895480401, 1.9494127580071845659,
1.9352807862970511135, 1.9212447005915276767, 1.9073024800183871196, 1.8934521529393077332,
1.8796917950722108462, 1.8660195276928275962, 1.8524335159111751661, 1.8389319670188793980,
1.8255131289035192212, 1.8121752885263901413, 1.7989167704602903934, 1.7857359354841254047,
1.7726311792313049959, 1.7596009308890742369, 1.7466436519460739352, 1.7337578349855711926,
1.7209420025219350428, 1.7081947058780575683, 1.6955145241015377061, 1.6829000629175537544,
1.6703499537164519163, 1.6578628525741725325, 1.6454374393037234057, 1.6330724165359912048,
1.6207665088282577216, 1.6085184617988580769, 1.5963270412864831349, 1.5841910325326886695,
1.5721092393862294810, 1.5600804835278879161, 1.5481036037145133070, 1.5361774550410318943,
1.5243009082192260050, 1.5124728488721167573, 1.5006921768428164936, 1.4889578055167456003,
1.4772686611561334579, 1.4656236822457450411, 1.4540218188487932264, 1.4424620319720121876,
1.4309432929388794104, 1.4194645827699828254, 1.4080248915695353509, 1.3966232179170417110,
1.3852585682631217189, 1.3739299563284902176, 1.3626364025050864742, 1.3513769332583349176,
1.3401505805295045843, 1.3289563811371163220, 1.3177933761763245480, 1.3066606104151739482,
1.2955571316866007210, 1.2844819902750125450, 1.2734342382962410994, 1.2624129290696153434,
1.2514171164808525098, 1.2404458543344064544, 1.2294981956938491599, 1.2185731922087903071,
1.2076698934267612830, 1.1967873460884031665, 1.1859245934042023557, 1.1750806743109117687,
1.1642546227056790397, 1.1534454666557748056, 1.1426522275816728928, 1.1318739194110786733,
1.1211095477013306083, 1.1103581087274114281, 1.0996185885325976575, 1.0888899619385472598,
1.0781711915113727024, 1.0674612264799681530, 1.0567590016025518414, 1.0460634359770445503,
1.0353734317905289496, 1.0246878730026178052, 1.0140056239570971074, 1.0033255279156973717,
0.99264640550727647009, 0.98196705308506317914, 0.97128624098390397896, 0.96060271166866709917,
0.94991517776407659940, 0.93922231995526297952, 0.92852278474721113999, 0.91781518207004493915,
0.90709808271569100600, 0.89637001558989069006, 0.88562946476175228052, 0.87487486629102585352,
0.86410460481100519511, 0.85331700984237406386, 0.84251035181036928333, 0.83168283773427388393,
0.82083260655441252290, 0.80995772405741906620, 0.79905617735548788109, 0.78812586886949324977,
0.77716460975913043936, 0.76617011273543541328, 0.75513998418198289808, 0.74407171550050873971,
0.73296267358436604916, 0.72181009030875689912, 0.71061105090965570413, 0.69936248110323266174,
0.68806113277374858613, 0.67670356802952337911, 0.66528614139267855405, 0.65380497984766565353,
0.64225596042453703448, 0.63063468493349100113, 0.61893645139487678178, 0.60715622162030085137,
0.59528858429150359384, 0.58332771274877027785, 0.57126731653258903915, 0.55910058551154127652,
0.54682012516331112550, 0.53441788123716615385, 0.52188505159213564105, 0.50921198244365495319,
0.49638804551867159754, 0.48340149165346224782, 0.47023927508216945338, 0.45688684093142071279,
0.44332786607355296305, 0.42954394022541129589, 0.41551416960035700100, 0.40121467889627836229,
0.38661797794112021568, 0.37169214532991786118, 0.35639976025839443721, 0.34069648106484979674,
0.32452911701691008547, 0.30783295467493287307, 0.29052795549123115167, 0.27251318547846547924,
0.25365836338591284433, 0.23379048305967553619, 0.21267151063096745264, 0.18995868962243277774,
0.16512762256418831796, 0.13730498094001380420, 0.10483850756582017915, 0.063852163815003480173,
0
};
template<class RealType>
const RealType exponential_table<RealType>::table_y[257] = {
0, 0.00045413435384149675545, 0.00096726928232717452884, 0.0015362997803015723824,
0.0021459677437189061793, 0.0027887987935740759640, 0.0034602647778369039855, 0.0041572951208337952532,
0.0048776559835423925804, 0.0056196422072054831710, 0.0063819059373191794422, 0.0071633531836349841425,
0.0079630774380170392396, 0.0087803149858089752347, 0.0096144136425022094101, 0.010464810181029979488,
0.011331013597834597488, 0.012212592426255380661, 0.013109164931254991070, 0.014020391403181937334,
0.014945968011691148079, 0.015885621839973162490, 0.016839106826039946359, 0.017806200410911360563,
0.018786700744696029497, 0.019780424338009741737, 0.020787204072578117603, 0.021806887504283582125,
0.022839335406385238829, 0.023884420511558170348, 0.024942026419731782971, 0.026012046645134218076,
0.027094383780955798424, 0.028188948763978634421, 0.029295660224637394015, 0.030414443910466605492,
0.031545232172893605499, 0.032687963508959533317, 0.033842582150874329031, 0.035009037697397411067,
0.036187284781931419754, 0.037377282772959360128, 0.038578995503074859626, 0.039792391023374122670,
0.041017441380414820816, 0.042254122413316231413, 0.043502413568888183301, 0.044762297732943280694,
0.046033761076175166762, 0.047316792913181548703, 0.048611385573379494401, 0.049917534282706374944,
0.051235237055126279830, 0.052564494593071689595, 0.053905310196046085104, 0.055257689676697038322,
0.056621641283742874438, 0.057997175631200659098, 0.059384305633420264487, 0.060783046445479636051,
0.062193415408540996150, 0.063615431999807331076, 0.065049117786753755036, 0.066494496385339779043,
0.067951593421936607770, 0.069420436498728751675, 0.070901055162371828426, 0.072393480875708743023,
0.073897746992364746308, 0.075413888734058408453, 0.076941943170480510100, 0.078481949201606426042,
0.080033947542319910023, 0.081597980709237420930, 0.083174093009632380354, 0.084762330532368125386,
0.086362741140756912277, 0.087975374467270219300, 0.089600281910032864534, 0.091237516631040162057,
0.092887133556043546523, 0.094549189376055853718, 0.096223742550432800103, 0.097910853311492199618,
0.099610583670637128826, 0.10132299742595363588, 0.10304816017125771553, 0.10478613930657016928,
0.10653700405000166218, 0.10830082545103379867, 0.11007767640518539026, 0.11186763167005629731,
0.11367076788274431301, 0.11548716357863353664, 0.11731689921155557057, 0.11916005717532768467,
0.12101672182667483729, 0.12288697950954513498, 0.12477091858083096578, 0.12666862943751066518,
0.12858020454522817870, 0.13050573846833078225, 0.13244532790138752023, 0.13439907170221363078,
0.13636707092642885841, 0.13834942886358021406, 0.14034625107486244210, 0.14235764543247220043,
0.14438372216063476473, 0.14642459387834493787, 0.14848037564386679222, 0.15055118500103990354,
0.15263714202744286154, 0.15473836938446807312, 0.15685499236936522013, 0.15898713896931420572,
0.16113493991759203183, 0.16329852875190180795, 0.16547804187493600915, 0.16767361861725019322,
0.16988540130252766513, 0.17211353531532005700, 0.17435816917135348788, 0.17661945459049489581,
0.17889754657247831241, 0.18119260347549629488, 0.18350478709776746150, 0.18583426276219711495,
0.18818119940425430485, 0.19054576966319540013, 0.19292814997677133873, 0.19532852067956322315,
0.19774706610509886464, 0.20018397469191127727, 0.20263943909370901930, 0.20511365629383770880,
0.20760682772422204205, 0.21011915938898825914, 0.21265086199297827522, 0.21520215107537867786,
0.21777324714870053264, 0.22036437584335949720, 0.22297576805812018050, 0.22560766011668406495,
0.22826029393071670664, 0.23093391716962742173, 0.23362878343743333945, 0.23634515245705964715,
0.23908329026244917002, 0.24184346939887722761, 0.24462596913189210901, 0.24743107566532763894,
0.25025908236886230967, 0.25311029001562948171, 0.25598500703041538015, 0.25888354974901621678,
0.26180624268936295243, 0.26475341883506220209, 0.26772541993204481808, 0.27072259679906003167,
0.27374530965280298302, 0.27679392844851734458, 0.27986883323697289920, 0.28297041453878076010,
0.28609907373707684673, 0.28925522348967773308, 0.29243928816189258772, 0.29565170428126120948,
0.29889292101558177099, 0.30216340067569352897, 0.30546361924459023541, 0.30879406693456016794,
0.31215524877417956945, 0.31554768522712893632, 0.31897191284495723773, 0.32242848495608914289,
0.32591797239355619822, 0.32944096426413633091, 0.33299806876180896713, 0.33658991402867758144,
0.34021714906678004560, 0.34388044470450243010, 0.34758049462163698567, 0.35131801643748334681,
0.35509375286678745925, 0.35890847294874976196, 0.36276297335481777335, 0.36665807978151414890,
0.37059464843514599421, 0.37457356761590215193, 0.37859575940958081092, 0.38266218149600982112,
0.38677382908413768115, 0.39093173698479710717, 0.39513698183329015336, 0.39939068447523107877,
0.40369401253053026739, 0.40804818315203238238, 0.41245446599716116772, 0.41691418643300289465,
0.42142872899761659635, 0.42599954114303435739, 0.43062813728845883923, 0.43531610321563659758,
0.44006510084235387501, 0.44487687341454851593, 0.44975325116275498919, 0.45469615747461548049,
0.45970761564213768669, 0.46478975625042618067, 0.46994482528395999841, 0.47517519303737738299,
0.48048336393045423016, 0.48587198734188493564, 0.49134386959403255500, 0.49690198724154955294,
0.50254950184134769289, 0.50828977641064283495, 0.51412639381474855788, 0.52006317736823356823,
0.52610421398361972602, 0.53225388026304326945, 0.53851687200286186590, 0.54489823767243963663,
0.55140341654064131685, 0.55803828226258748140, 0.56480919291240022434, 0.57172304866482579008,
0.57878735860284503057, 0.58601031847726802755, 0.59340090169173341521, 0.60096896636523224742,
0.60872538207962206507, 0.61668218091520762326, 0.62485273870366592605, 0.63325199421436607968,
0.64189671642726607018, 0.65080583341457104881, 0.66000084107899974178, 0.66950631673192477684,
0.67935057226476538741, 0.68956649611707798890, 0.70019265508278816709, 0.71127476080507597882,
0.72286765959357200702, 0.73503809243142351530, 0.74786862198519510742, 0.76146338884989624862,
0.77595685204011559675, 0.79152763697249565519, 0.80842165152300838005, 0.82699329664305033399,
0.84778550062398962096, 0.87170433238120363669, 0.90046992992574643800, 0.93814368086217467916,
1
};
template<class RealType = double>
struct unit_exponential_distribution
{
template<class Engine>
RealType operator()(Engine& eng) {
const double * const table_x = exponential_table<double>::table_x;
const double * const table_y = exponential_table<double>::table_y;
RealType shift(0);
for(;;) {
std::pair<RealType, int> vals = generate_int_float_pair<RealType, 8>(eng);
int i = vals.second;
RealType x = vals.first * RealType(table_x[i]);
if(x < RealType(table_x[i + 1])) return shift + x;
// For i=0 we need to generate from the tail, but because this is an exponential
// distribution, the tail looks exactly like the body, so we can simply repeat with a
// shift:
if (i == 0) shift += RealType(table_x[1]);
else {
RealType y01 = uniform_01<RealType>()(eng);
RealType y = RealType(table_y[i]) + y01 * RealType(table_y[i+1] - table_y[i]);
// All we care about is whether these are < or > 0; these values are equal to
// (lbound) or proportional to (ubound) `y` minus the lower/upper bound.
RealType y_above_ubound = RealType(table_x[i] - table_x[i+1]) * y01 - (RealType(table_x[i]) - x),
y_above_lbound = y - (RealType(table_y[i+1]) + (RealType(table_x[i+1]) - x) * RealType(table_y[i+1]));
if (y_above_ubound < 0 // if above the upper bound reject immediately
&&
(
y_above_lbound < 0 // If below the lower bound accept immediately
||
y < f(x) // Otherwise it's between the bounds and we need a full check
)
) {
return x + shift;
}
}
}
}
static RealType f(RealType x) {
using std::exp;
return exp(-x);
}
};
} // namespace detail
/**
* The exponential distribution is a model of \random_distribution with
* a single parameter lambda.
*
* It has \f$\displaystyle p(x) = \lambda e^{-\lambda x}\f$
*
* The implementation uses the "ziggurat" algorithm, as described in
*
* @blockquote
* "The Ziggurat Method for Generating Random Variables",
* George Marsaglia and Wai Wan Tsang, Journal of Statistical Software
* Volume 5, Number 8 (2000), 1-7.
* @endblockquote
*/
template<class RealType = double>
class exponential_distribution
{
public:
typedef RealType input_type;
typedef RealType result_type;
class param_type
{
public:
typedef exponential_distribution distribution_type;
/**
* Constructs parameters with a given lambda.
*
* Requires: lambda > 0
*/
param_type(RealType lambda_arg = RealType(1.0))
: _lambda(lambda_arg) { ACTIV_BOOST_ASSERT(_lambda > RealType(0)); }
/** Returns the lambda parameter of the distribution. */
RealType lambda() const { return _lambda; }
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._lambda;
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._lambda;
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._lambda == rhs._lambda; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _lambda;
};
/**
* Constructs an exponential_distribution with a given lambda.
*
* Requires: lambda > 0
*/
explicit exponential_distribution(RealType lambda_arg = RealType(1.0))
: _lambda(lambda_arg) { ACTIV_BOOST_ASSERT(_lambda > RealType(0)); }
/**
* Constructs an exponential_distribution from its parameters
*/
explicit exponential_distribution(const param_type& parm)
: _lambda(parm.lambda()) {}
// compiler-generated copy ctor and assignment operator are fine
/** Returns the lambda parameter of the distribution. */
RealType lambda() const { return _lambda; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return RealType(0); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return (std::numeric_limits<RealType>::infinity)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_lambda); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm) { _lambda = parm.lambda(); }
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/**
* Returns a random variate distributed according to the
* exponential distribution.
*/
template<class Engine>
result_type operator()(Engine& eng) const
{
detail::unit_exponential_distribution<RealType> impl;
return impl(eng) / _lambda;
}
/**
* Returns a random variate distributed according to the exponential
* distribution with parameters specified by param.
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm) const
{
return exponential_distribution(parm)(eng);
}
/** Writes the distribution to a std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, exponential_distribution, ed)
{
os << ed._lambda;
return os;
}
/** Reads the distribution from a std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, exponential_distribution, ed)
{
is >> ed._lambda;
return is;
}
/**
* Returns true iff the two distributions will produce identical
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(exponential_distribution, lhs, rhs)
{ return lhs._lambda == rhs._lambda; }
/**
* Returns true iff the two distributions will produce different
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(exponential_distribution)
private:
result_type _lambda;
};
} // namespace random
using random::exponential_distribution;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
@@ -1,177 +0,0 @@
/* boost random/extreme_value_distribution.hpp header file
*
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <istream>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/uniform_01.hpp>
namespace Boost {
namespace random {
/**
* The extreme value distribution is a real valued distribution with two
* parameters a and b.
*
* It has \f$\displaystyle p(x) = \frac{1}{b}e^{\frac{a-x}{b} - e^\frac{a-x}{b}}\f$.
*/
template<class RealType = double>
class extreme_value_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef extreme_value_distribution distribution_type;
/**
* Constructs a @c param_type from the "a" and "b" parameters
* of the distribution.
*
* Requires: b > 0
*/
explicit param_type(RealType a_arg = 1.0, RealType b_arg = 1.0)
: _a(a_arg), _b(b_arg)
{}
/** Returns the "a" parameter of the distribtuion. */
RealType a() const { return _a; }
/** Returns the "b" parameter of the distribution. */
RealType b() const { return _b; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._a << ' ' << parm._b; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._a >> std::ws >> parm._b; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._a == rhs._a && lhs._b == rhs._b; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _a;
RealType _b;
};
/**
* Constructs an @c extreme_value_distribution from its "a" and "b" parameters.
*
* Requires: b > 0
*/
explicit extreme_value_distribution(RealType a_arg = 1.0, RealType b_arg = 1.0)
: _a(a_arg), _b(b_arg)
{}
/** Constructs an @c extreme_value_distribution from its parameters. */
explicit extreme_value_distribution(const param_type& parm)
: _a(parm.a()), _b(parm.b())
{}
/**
* Returns a random variate distributed according to the
* @c extreme_value_distribution.
*/
template<class URNG>
RealType operator()(URNG& urng) const
{
using std::log;
return _a - log(-log(uniform_01<RealType>()(urng))) * _b;
}
/**
* Returns a random variate distributed accordint to the extreme
* value distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return extreme_value_distribution(parm)(urng);
}
/** Returns the "a" parameter of the distribution. */
RealType a() const { return _a; }
/** Returns the "b" parameter of the distribution. */
RealType b() const { return _b; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return -std::numeric_limits<RealType>::infinity(); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return std::numeric_limits<RealType>::infinity(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_a, _b); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_a = parm.a();
_b = parm.b();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Writes an @c extreme_value_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, extreme_value_distribution, wd)
{
os << wd.param();
return os;
}
/** Reads an @c extreme_value_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, extreme_value_distribution, wd)
{
param_type parm;
if(is >> parm) {
wd.param(parm);
}
return is;
}
/**
* Returns true if the two instances of @c extreme_value_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(extreme_value_distribution, lhs, rhs)
{ return lhs._a == rhs._a && lhs._b == rhs._b; }
/**
* Returns true if the two instances of @c extreme_value_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(extreme_value_distribution)
private:
RealType _a;
RealType _b;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
-367
View File
@@ -1,367 +0,0 @@
/* boost random/faure.hpp header file
*
* Copyright Justinas Vygintas Daugmaudis 2010-2018
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef ACTIV_BOOST_RANDOM_FAURE_HPP
#define ACTIV_BOOST_RANDOM_FAURE_HPP
#include <ActivBoost/random/detail/qrng_base.hpp>
#include <cmath>
#include <vector>
#include <algorithm>
#include <ActivBoost/assert.hpp>
namespace Boost {
namespace random {
/** @cond */
namespace detail {
namespace qrng_tables {
// There is no particular reason why 187 first primes were chosen
// to be put into this table. The only reason was, perhaps, that
// the number of dimensions for Faure generator would be around
// the same order of magnitude as the number of dimensions supported
// by the Sobol qrng.
struct primes
{
typedef unsigned short value_type;
ACTIV_BOOST_STATIC_CONSTANT(int, number_of_primes = 187);
// A function that returns lower bound prime for a given n
static value_type lower_bound(std::size_t n)
{
static const value_type prim_a[number_of_primes] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619,
631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787,
797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953,
967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031,
1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093,
1097, 1103, 1109, 1117 };
qrng_detail::dimension_assert("Faure", n, prim_a[number_of_primes - 1]);
return *std::lower_bound(prim_a, prim_a + number_of_primes, n);
}
};
} // namespace qrng_tables
} // namespace detail
namespace qrng_detail {
namespace fr {
// Returns the integer part of the logarithm base Base of arg.
// In erroneous situations, e.g., integer_log(base, 0) the function
// returns 0 and does not report the error. This is the intended
// behavior.
template <typename T>
inline T integer_log(T base, T arg)
{
T ilog = T();
while (base <= arg)
{
arg /= base; ++ilog;
}
return ilog;
}
// Perform exponentiation by squaring (potential for code reuse in multiprecision::powm)
template <typename T>
inline T integer_pow(T base, T e)
{
T result = static_cast<T>(1);
while (e)
{
if (e & static_cast<T>(1))
result *= base;
e >>= 1;
base *= base;
}
return result;
}
} // namespace fr
// Computes a table of binomial coefficients modulo qs.
template<typename RealType, typename SeqSizeT, typename PrimeTable>
struct binomial_coefficients
{
typedef RealType value_type;
typedef SeqSizeT size_type;
// Binomial values modulo qs_base will never be bigger than qs_base.
// We can choose an appropriate integer type to hold modulo values and
// shave off memory footprint.
typedef typename PrimeTable::value_type packed_uint_t;
// default copy c-tor is fine
explicit binomial_coefficients(std::size_t dimension)
{
resize(dimension);
}
void resize(std::size_t dimension)
{
qs_base = PrimeTable::lower_bound(dimension);
// Throw away previously computed coefficients.
// This will trigger recomputation on next update
coeff.clear();
}
template <typename Iterator>
void update(size_type seq, Iterator first, Iterator last)
{
if (first != last)
{
const size_type ilog = fr::integer_log(static_cast<size_type>(qs_base), seq);
const size_type hisum = ilog + 1;
if (coeff.size() != size_hint(hisum)) {
ytemp.resize(static_cast<std::size_t>(hisum)); // cast safe because log is small
compute_coefficients(hisum);
qs_pow = fr::integer_pow(static_cast<size_type>(qs_base), ilog);
}
*first = compute_recip(seq, ytemp.rbegin());
// Find other components using the Faure method.
++first;
for ( ; first != last; ++first)
{
*first = RealType();
RealType r = static_cast<RealType>(1);
for (size_type i = 0; i != hisum; ++i)
{
RealType ztemp = ytemp[static_cast<std::size_t>(i)] * upper_element(i, i, hisum);
for (size_type j = i + 1; j != hisum; ++j)
ztemp += ytemp[static_cast<std::size_t>(j)] * upper_element(i, j, hisum);
// Sum ( J <= I <= HISUM ) ( old ytemp(i) * binom(i,j) ) mod QS.
ytemp[static_cast<std::size_t>(i)] = std::fmod(ztemp, static_cast<RealType>(qs_base));
r *= static_cast<RealType>(qs_base);
*first += ytemp[static_cast<std::size_t>(i)] / r;
}
}
}
}
private:
inline static size_type size_hint(size_type n)
{
return n * (n + 1) / 2;
}
packed_uint_t& upper_element(size_type i, size_type j, size_type dim)
{
ACTIV_BOOST_ASSERT( i < dim );
ACTIV_BOOST_ASSERT( j < dim );
ACTIV_BOOST_ASSERT( i <= j );
return coeff[static_cast<std::size_t>((i * (2 * dim - i + 1)) / 2 + j - i)];
}
template<typename Iterator>
RealType compute_recip(size_type seq, Iterator out) const
{
// Here we do
// Sum ( 0 <= J <= HISUM ) YTEMP(J) * QS**J
// Sum ( 0 <= J <= HISUM ) YTEMP(J) / QS**(J+1)
// in one go
RealType r = RealType();
size_type m, k = qs_pow;
for( ; k != 0; ++out, seq = m, k /= qs_base )
{
m = seq % k;
RealType v = static_cast<RealType>((seq - m) / k); // RealType <- size type
r += v;
r /= static_cast<RealType>(qs_base);
*out = v; // saves double dereference
}
return r;
}
void compute_coefficients(const size_type n)
{
// Resize and initialize to zero
coeff.resize(static_cast<std::size_t>(size_hint(n)));
std::fill(coeff.begin(), coeff.end(), packed_uint_t());
// The first row and the diagonal is assigned to 1
upper_element(0, 0, n) = 1;
for (size_type i = 1; i < n; ++i)
{
upper_element(0, i, n) = 1;
upper_element(i, i, n) = 1;
}
// Computes binomial coefficients MOD qs_base
for (size_type i = 1; i < n; ++i)
{
for (size_type j = i + 1; j < n; ++j)
{
upper_element(i, j, n) = ( upper_element(i, j-1, n) +
upper_element(i-1, j-1, n) ) % qs_base;
}
}
}
private:
packed_uint_t qs_base;
// here we cache precomputed data; note that binomial coefficients have
// to be recomputed iff the integer part of the logarithm of seq changes,
// which happens relatively rarely.
std::vector<packed_uint_t> coeff; // packed upper (!) triangular matrix
std::vector<RealType> ytemp;
size_type qs_pow;
};
} // namespace qrng_detail
typedef detail::qrng_tables::primes default_faure_prime_table;
/** @endcond */
//!Instantiations of class template faure_engine model a \quasi_random_number_generator.
//!The faure_engine uses the algorithm described in
//! \blockquote
//!Henri Faure,
//!Discrepance de suites associees a un systeme de numeration (en dimension s),
//!Acta Arithmetica,
//!Volume 41, 1982, pages 337-351.
//! \endblockquote
//
//! \blockquote
//!Bennett Fox,
//!Algorithm 647:
//!Implementation and Relative Efficiency of Quasirandom
//!Sequence Generators,
//!ACM Transactions on Mathematical Software,
//!Volume 12, Number 4, December 1986, pages 362-376.
//! \endblockquote
//!
//!In the following documentation @c X denotes the concrete class of the template
//!faure_engine returning objects of type @c RealType, u and v are the values of @c X.
//!
//!Some member functions may throw exceptions of type @c std::bad_alloc.
template<typename RealType, typename SeqSizeT, typename PrimeTable = default_faure_prime_table>
class faure_engine
: public qrng_detail::qrng_base<
faure_engine<RealType, SeqSizeT, PrimeTable>
, qrng_detail::binomial_coefficients<RealType, SeqSizeT, PrimeTable>
, SeqSizeT
>
{
typedef faure_engine<RealType, SeqSizeT, PrimeTable> self_t;
typedef qrng_detail::binomial_coefficients<RealType, SeqSizeT, PrimeTable> lattice_t;
typedef qrng_detail::qrng_base<self_t, lattice_t, SeqSizeT> base_t;
friend class qrng_detail::qrng_base<self_t, lattice_t, SeqSizeT>;
public:
typedef RealType result_type;
/** @copydoc Boost::random::niederreiter_base2_engine::min() */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return static_cast<result_type>(0); }
/** @copydoc Boost::random::niederreiter_base2_engine::max() */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return static_cast<result_type>(1); }
//!Effects: Constructs the `s`-dimensional default Faure quasi-random number generator.
//!
//!Throws: bad_alloc, invalid_argument.
explicit faure_engine(std::size_t s)
: base_t(s) // initialize the binomial table here
{}
/** @copydetails Boost::random::niederreiter_base2_engine::seed(UIntType)
* Throws: bad_alloc.
*/
void seed(SeqSizeT init = 0)
{
compute_seq(init);
base_t::reset_seq(init);
}
#ifdef ACTIV_BOOST_RANDOM_DOXYGEN
//=========================Doxygen needs this!==============================
/** @copydoc Boost::random::niederreiter_base2_engine::dimension() */
std::size_t dimension() const { return base_t::dimension(); }
/** @copydoc Boost::random::niederreiter_base2_engine::operator()() */
result_type operator()()
{
return base_t::operator()();
}
/** @copydoc Boost::random::niederreiter_base2_engine::discard(Boost::uintmax_t)
* Throws: bad_alloc.
*/
void discard(Boost::uintmax_t z)
{
base_t::discard(z);
}
/** Returns true if the two generators will produce identical sequences of outputs. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(faure_engine, x, y)
{ return static_cast<const base_t&>(x) == y; }
/** Returns true if the two generators will produce different sequences of outputs. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(faure_engine)
/** Writes the textual representation of the generator to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, faure_engine, s)
{ return os << static_cast<const base_t&>(s); }
/** Reads the textual representation of the generator from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, faure_engine, s)
{ return is >> static_cast<base_t&>(s); }
#endif // ACTIV_BOOST_RANDOM_DOXYGEN
private:
/** @cond hide_private_members */
void compute_seq(SeqSizeT seq)
{
qrng_detail::check_seed_sign(seq);
this->lattice.update(seq, this->state_begin(), this->state_end());
}
/** @endcond */
};
/**
* @attention This specialization of \faure_engine supports up to 1117 dimensions.
*
* However, it is possible to provide your own prime table to \faure_engine should the default one be insufficient.
*/
typedef faure_engine<double, Boost::uint_least64_t, default_faure_prime_table> faure;
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_FAURE_HPP
@@ -1,183 +0,0 @@
/* boost random/fisher_f_distribution.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_FISHER_F_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_FISHER_F_DISTRIBUTION_HPP
#include <iosfwd>
#include <istream>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/chi_squared_distribution.hpp>
namespace Boost {
namespace random {
/**
* The Fisher F distribution is a real valued distribution with two
* parameters m and n.
*
* It has \f$\displaystyle p(x) =
* \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)}
* \left(\frac{m}{n}\right)^{m/2}
* x^{(m/2)-1} \left(1+\frac{mx}{n}\right)^{-(m+n)/2}
* \f$.
*/
template<class RealType = double>
class fisher_f_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef fisher_f_distribution distribution_type;
/**
* Constructs a @c param_type from the "m" and "n" parameters
* of the distribution.
*
* Requires: m > 0 and n > 0
*/
explicit param_type(RealType m_arg = RealType(1.0),
RealType n_arg = RealType(1.0))
: _m(m_arg), _n(n_arg)
{}
/** Returns the "m" parameter of the distribtuion. */
RealType m() const { return _m; }
/** Returns the "n" parameter of the distribution. */
RealType n() const { return _n; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._m << ' ' << parm._n; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._m >> std::ws >> parm._n; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._m == rhs._m && lhs._n == rhs._n; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _m;
RealType _n;
};
/**
* Constructs a @c fisher_f_distribution from its "m" and "n" parameters.
*
* Requires: m > 0 and n > 0
*/
explicit fisher_f_distribution(RealType m_arg = RealType(1.0),
RealType n_arg = RealType(1.0))
: _impl_m(m_arg), _impl_n(n_arg)
{}
/** Constructs an @c fisher_f_distribution from its parameters. */
explicit fisher_f_distribution(const param_type& parm)
: _impl_m(parm.m()), _impl_n(parm.n())
{}
/**
* Returns a random variate distributed according to the
* F distribution.
*/
template<class URNG>
RealType operator()(URNG& urng)
{
return (_impl_m(urng) * n()) / (_impl_n(urng) * m());
}
/**
* Returns a random variate distributed according to the
* F distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return fisher_f_distribution(parm)(urng);
}
/** Returns the "m" parameter of the distribution. */
RealType m() const { return _impl_m.n(); }
/** Returns the "n" parameter of the distribution. */
RealType n() const { return _impl_n.n(); }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return std::numeric_limits<RealType>::infinity(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(m(), n()); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
typedef chi_squared_distribution<RealType> impl_type;
typename impl_type::param_type m_param(parm.m());
_impl_m.param(m_param);
typename impl_type::param_type n_param(parm.n());
_impl_n.param(n_param);
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Writes an @c fisher_f_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, fisher_f_distribution, fd)
{
os << fd.param();
return os;
}
/** Reads an @c fisher_f_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, fisher_f_distribution, fd)
{
param_type parm;
if(is >> parm) {
fd.param(parm);
}
return is;
}
/**
* Returns true if the two instances of @c fisher_f_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(fisher_f_distribution, lhs, rhs)
{ return lhs._impl_m == rhs._impl_m && lhs._impl_n == rhs._impl_n; }
/**
* Returns true if the two instances of @c fisher_f_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(fisher_f_distribution)
private:
chi_squared_distribution<RealType> _impl_m;
chi_squared_distribution<RealType> _impl_n;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_EXTREME_VALUE_DISTRIBUTION_HPP
@@ -1,292 +0,0 @@
/* boost random/gamma_distribution.hpp header file
*
* Copyright Jens Maurer 2002
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <istream>
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/exponential_distribution.hpp>
namespace Boost {
namespace random {
// The algorithm is taken from Knuth
/**
* The gamma distribution is a continuous distribution with two
* parameters alpha and beta. It produces values > 0.
*
* It has
* \f$\displaystyle p(x) = x^{\alpha-1}\frac{e^{-x/\beta}}{\beta^\alpha\Gamma(\alpha)}\f$.
*/
template<class RealType = double>
class gamma_distribution
{
public:
typedef RealType input_type;
typedef RealType result_type;
class param_type
{
public:
typedef gamma_distribution distribution_type;
/**
* Constructs a @c param_type object from the "alpha" and "beta"
* parameters.
*
* Requires: alpha > 0 && beta > 0
*/
param_type(const RealType& alpha_arg = RealType(1.0),
const RealType& beta_arg = RealType(1.0))
: _alpha(alpha_arg), _beta(beta_arg)
{
}
/** Returns the "alpha" parameter of the distribution. */
RealType alpha() const { return _alpha; }
/** Returns the "beta" parameter of the distribution. */
RealType beta() const { return _beta; }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const param_type& parm)
{
os << parm._alpha << ' ' << parm._beta;
return os;
}
/** Reads the parameters from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is, param_type& parm)
{
is >> parm._alpha >> std::ws >> parm._beta;
return is;
}
#endif
/** Returns true if the two sets of parameters are the same. */
friend bool operator==(const param_type& lhs, const param_type& rhs)
{
return lhs._alpha == rhs._alpha && lhs._beta == rhs._beta;
}
/** Returns true if the two sets fo parameters are different. */
friend bool operator!=(const param_type& lhs, const param_type& rhs)
{
return !(lhs == rhs);
}
private:
RealType _alpha;
RealType _beta;
};
#ifndef ACTIV_BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
ACTIV_BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
#endif
/**
* Creates a new gamma_distribution with parameters "alpha" and "beta".
*
* Requires: alpha > 0 && beta > 0
*/
explicit gamma_distribution(const result_type& alpha_arg = result_type(1.0),
const result_type& beta_arg = result_type(1.0))
: _exp(result_type(1)), _alpha(alpha_arg), _beta(beta_arg)
{
ACTIV_BOOST_ASSERT(_alpha > result_type(0));
ACTIV_BOOST_ASSERT(_beta > result_type(0));
init();
}
/** Constructs a @c gamma_distribution from its parameters. */
explicit gamma_distribution(const param_type& parm)
: _exp(result_type(1)), _alpha(parm.alpha()), _beta(parm.beta())
{
init();
}
// compiler-generated copy ctor and assignment operator are fine
/** Returns the "alpha" paramter of the distribution. */
RealType alpha() const { return _alpha; }
/** Returns the "beta" parameter of the distribution. */
RealType beta() const { return _beta; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
/* Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return (std::numeric_limits<RealType>::infinity)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_alpha, _beta); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_alpha = parm.alpha();
_beta = parm.beta();
init();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { _exp.reset(); }
/**
* Returns a random variate distributed according to
* the gamma distribution.
*/
template<class Engine>
result_type operator()(Engine& eng)
{
#ifndef ACTIV_BOOST_NO_STDC_NAMESPACE
// allow for Koenig lookup
using std::tan; using std::sqrt; using std::exp; using std::log;
using std::pow;
#endif
if(_alpha == result_type(1)) {
return _exp(eng) * _beta;
} else if(_alpha > result_type(1)) {
// Can we have a Boost::mathconst please?
const result_type pi = result_type(3.14159265358979323846);
for(;;) {
result_type y = tan(pi * uniform_01<RealType>()(eng));
result_type x = sqrt(result_type(2)*_alpha-result_type(1))*y
+ _alpha-result_type(1);
if(x <= result_type(0))
continue;
if(uniform_01<RealType>()(eng) >
(result_type(1)+y*y) * exp((_alpha-result_type(1))
*log(x/(_alpha-result_type(1)))
- sqrt(result_type(2)*_alpha
-result_type(1))*y))
continue;
return x * _beta;
}
} else /* alpha < 1.0 */ {
for(;;) {
result_type u = uniform_01<RealType>()(eng);
result_type y = _exp(eng);
result_type x, q;
if(u < _p) {
x = exp(-y/_alpha);
q = _p*exp(-x);
} else {
x = result_type(1)+y;
q = _p + (result_type(1)-_p) * pow(x,_alpha-result_type(1));
}
if(u >= q)
continue;
return x * _beta;
}
}
}
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return gamma_distribution(parm)(urng);
}
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes a @c gamma_distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const gamma_distribution& gd)
{
os << gd.param();
return os;
}
/** Reads a @c gamma_distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, gamma_distribution& gd)
{
gd.read(is);
return is;
}
#endif
/**
* Returns true if the two distributions will produce identical
* sequences of random variates given equal generators.
*/
friend bool operator==(const gamma_distribution& lhs,
const gamma_distribution& rhs)
{
return lhs._alpha == rhs._alpha
&& lhs._beta == rhs._beta
&& lhs._exp == rhs._exp;
}
/**
* Returns true if the two distributions can produce different
* sequences of random variates, given equal generators.
*/
friend bool operator!=(const gamma_distribution& lhs,
const gamma_distribution& rhs)
{
return !(lhs == rhs);
}
private:
/// \cond hide_private_members
template<class CharT, class Traits>
void read(std::basic_istream<CharT, Traits>& is)
{
param_type parm;
if(is >> parm) {
param(parm);
}
}
void init()
{
#ifndef ACTIV_BOOST_NO_STDC_NAMESPACE
// allow for Koenig lookup
using std::exp;
#endif
_p = exp(result_type(1)) / (_alpha + exp(result_type(1)));
}
/// \endcond
exponential_distribution<RealType> _exp;
result_type _alpha;
result_type _beta;
// some data precomputed from the parameters
result_type _p;
};
} // namespace random
using random::gamma_distribution;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_GAMMA_DISTRIBUTION_HPP
@@ -1,95 +0,0 @@
/* boost random/generate_canonical.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_GENERATE_CANONICAL_HPP
#define ACTIV_BOOST_RANDOM_GENERATE_CANONICAL_HPP
#include <algorithm>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/type_traits/is_integral.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/random/detail/generator_bits.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class RealType, std::size_t bits, class URNG>
RealType generate_canonical_impl(URNG& g, Boost::true_type /*is_integral*/)
{
using std::pow;
typedef typename URNG::result_type base_result;
std::size_t digits = std::numeric_limits<RealType>::digits;
RealType R = RealType((g.max)()) - RealType((g.min)()) + 1;
RealType mult = R;
RealType limit =
pow(RealType(2),
RealType((std::min)(static_cast<std::size_t>(bits), digits)));
RealType S = RealType(detail::subtract<base_result>()(g(), (g.min)()));
while(mult < limit) {
RealType inc = RealType(detail::subtract<base_result>()(g(), (g.min)()));
S += inc * mult;
mult *= R;
}
return S / mult;
}
template<class RealType, std::size_t bits, class URNG>
RealType generate_canonical_impl(URNG& g, Boost::false_type /*is_integral*/)
{
using std::pow;
using std::floor;
ACTIV_BOOST_ASSERT((g.min)() == 0);
ACTIV_BOOST_ASSERT((g.max)() == 1);
std::size_t digits = std::numeric_limits<RealType>::digits;
std::size_t engine_bits = detail::generator_bits<URNG>::value();
std::size_t b = (std::min)(bits, digits);
RealType R = pow(RealType(2), RealType(engine_bits));
RealType mult = R;
RealType limit = pow(RealType(2), RealType(b));
RealType S = RealType(g() - (g.min)());
while(mult < limit) {
RealType inc(floor((RealType(g()) - RealType((g.min)())) * R));
S += inc * mult;
mult *= R;
}
return S / mult;
}
}
/**
* Returns a value uniformly distributed in the range [0, 1)
* with at least @c bits random bits.
*/
template<class RealType, std::size_t bits, class URNG>
RealType generate_canonical(URNG& g)
{
RealType result = detail::generate_canonical_impl<RealType, bits>(
g, Boost::random::traits::is_integral<typename URNG::result_type>());
ACTIV_BOOST_ASSERT(result >= 0);
ACTIV_BOOST_ASSERT(result <= 1);
if(result == 1) {
result -= std::numeric_limits<RealType>::epsilon() / 2;
ACTIV_BOOST_ASSERT(result != 1);
}
return result;
}
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_GENERATE_CANONICAL_HPP
@@ -1,267 +0,0 @@
/* boost random/geometric_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp> // std::log
#include <iosfwd>
#include <ios>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/uniform_01.hpp>
namespace Boost {
namespace random {
/**
* An instantiation of the class template @c geometric_distribution models
* a \random_distribution. The distribution produces positive
* integers which are the number of bernoulli trials
* with probability @c p required to get one that fails.
*
* For the geometric distribution, \f$p(i) = p(1-p)^{i}\f$.
*
* @xmlwarning
* This distribution has been updated to match the C++ standard.
* Its behavior has changed from the original
* Boost::geometric_distribution. A backwards compatible
* wrapper is provided in namespace Boost.
* @endxmlwarning
*/
template<class IntType = int, class RealType = double>
class geometric_distribution
{
public:
typedef RealType input_type;
typedef IntType result_type;
class param_type
{
public:
typedef geometric_distribution distribution_type;
/** Constructs the parameters with p. */
explicit param_type(RealType p_arg = RealType(0.5))
: _p(p_arg)
{
ACTIV_BOOST_ASSERT(RealType(0) < _p && _p < RealType(1));
}
/** Returns the p parameter of the distribution. */
RealType p() const { return _p; }
/** Writes the parameters to a std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._p;
return os;
}
/** Reads the parameters from a std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
double p_in;
if(is >> p_in) {
if(p_in > RealType(0) && p_in < RealType(1)) {
parm._p = p_in;
} else {
is.setstate(std::ios_base::failbit);
}
}
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._p == rhs._p; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _p;
};
/**
* Contructs a new geometric_distribution with the paramter @c p.
*
* Requires: 0 < p < 1
*/
explicit geometric_distribution(const RealType& p_arg = RealType(0.5))
: _p(p_arg)
{
ACTIV_BOOST_ASSERT(RealType(0) < _p && _p < RealType(1));
init();
}
/** Constructs a new geometric_distribution from its parameters. */
explicit geometric_distribution(const param_type& parm)
: _p(parm.p())
{
init();
}
// compiler-generated copy ctor and assignment operator are fine
/** Returns: the distribution parameter @c p */
RealType p() const { return _p; }
/** Returns the smallest value that the distribution can produce. */
IntType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return IntType(0); }
/** Returns the largest value that the distribution can produce. */
IntType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return (std::numeric_limits<IntType>::max)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_p); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_p = parm.p();
init();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/**
* Returns a random variate distributed according to the
* geometric_distribution.
*/
template<class Engine>
result_type operator()(Engine& eng) const
{
using std::log;
using std::floor;
RealType x = RealType(1) - Boost::uniform_01<RealType>()(eng);
return IntType(floor(log(x) / _log_1mp));
}
/**
* Returns a random variate distributed according to the
* geometric distribution with parameters specified by param.
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm) const
{ return geometric_distribution(parm)(eng); }
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, geometric_distribution, gd)
{
os << gd._p;
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, geometric_distribution, gd)
{
param_type parm;
if(is >> parm) {
gd.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will produce identical
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(geometric_distribution, lhs, rhs)
{ return lhs._p == rhs._p; }
/**
* Returns true if the two distributions may produce different
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(geometric_distribution)
private:
/// \cond show_private
void init()
{
using std::log;
_log_1mp = log(1 - _p);
}
RealType _p;
RealType _log_1mp;
/// \endcond
};
} // namespace random
/// \cond show_deprecated
/**
* Provided for backwards compatibility. This class is
* deprecated. It provides the old behavior of geometric_distribution
* with \f$p(i) = (1-p) p^{i-1}\f$.
*/
template<class IntType = int, class RealType = double>
class geometric_distribution
{
public:
typedef RealType input_type;
typedef IntType result_type;
explicit geometric_distribution(RealType p_arg = RealType(0.5))
: _impl(1 - p_arg) {}
RealType p() const { return 1 - _impl.p(); }
void reset() {}
template<class Engine>
IntType operator()(Engine& eng) const { return _impl(eng) + IntType(1); }
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, geometric_distribution, gd)
{
os << gd.p();
return os;
}
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, geometric_distribution, gd)
{
RealType val;
if(is >> val) {
typename impl_type::param_type impl_param(1 - val);
gd._impl.param(impl_param);
}
return is;
}
private:
typedef random::geometric_distribution<IntType, RealType> impl_type;
impl_type _impl;
};
/// \endcond
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
@@ -1,872 +0,0 @@
/* boost random/hyperexponential_distribution.hpp header file
*
* Copyright Marco Guazzone 2014
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* Much of the code here taken by Boost::math::hyperexponential_distribution.
* To this end, we would like to thank Paul Bristow and John Maddock for their
* valuable feedback.
*
* \author Marco Guazzone (marco.guazzone@gmail.com)
*/
#ifndef ACTIV_BOOST_RANDOM_HYPEREXPONENTIAL_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_HYPEREXPONENTIAL_DISTRIBUTION_HPP
#include <ActivBoost/config.hpp>
#include <ActivBoost/core/cmath.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/vector_io.hpp>
#include <ActivBoost/random/discrete_distribution.hpp>
#include <ActivBoost/random/exponential_distribution.hpp>
#include <ActivBoost/range/begin.hpp>
#include <ActivBoost/range/end.hpp>
#include <ActivBoost/range/size.hpp>
#include <ActivBoost/type_traits/has_pre_increment.hpp>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <iterator>
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
# include <initializer_list>
#endif // ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>
namespace Boost { namespace random {
namespace hyperexp_detail {
template <typename T>
std::vector<T>& normalize(std::vector<T>& v)
{
if (v.size() == 0)
{
return v;
}
const T sum = std::accumulate(v.begin(), v.end(), static_cast<T>(0));
T final_sum = 0;
const typename std::vector<T>::iterator end = --v.end();
for (typename std::vector<T>::iterator it = v.begin();
it != end;
++it)
{
*it /= sum;
final_sum += *it;
}
*end = 1-final_sum; // avoids round off errors thus ensuring the probabilities really sum to 1
return v;
}
template <typename RealT>
bool check_probabilities(std::vector<RealT> const& probabilities)
{
const std::size_t n = probabilities.size();
RealT sum = 0;
for (std::size_t i = 0; i < n; ++i)
{
if (probabilities[i] < 0
|| probabilities[i] > 1
|| !(Boost::core::isfinite)(probabilities[i]))
{
return false;
}
sum += probabilities[i];
}
//NOTE: the check below seems to fail on some architectures.
// So we commented it.
//// - We try to keep phase probabilities correctly normalized in the distribution constructors
//// - However in practice we have to allow for a very slight divergence from a sum of exactly 1:
////if (std::abs(sum-1) > (std::numeric_limits<RealT>::epsilon()*2))
//// This is from Knuth "The Art of Computer Programming: Vol.2, 3rd Ed", and can be used to
//// check is two numbers are approximately equal
//const RealT one = 1;
//const RealT tol = std::numeric_limits<RealT>::epsilon()*2.0;
//if (std::abs(sum-one) > (std::max(std::abs(sum), std::abs(one))*tol))
//{
// return false;
//}
return true;
}
template <typename RealT>
bool check_rates(std::vector<RealT> const& rates)
{
const std::size_t n = rates.size();
for (std::size_t i = 0; i < n; ++i)
{
if (rates[i] <= 0
|| !(Boost::core::isfinite)(rates[i]))
{
return false;
}
}
return true;
}
template <typename RealT>
bool check_params(std::vector<RealT> const& probabilities, std::vector<RealT> const& rates)
{
if (probabilities.size() != rates.size())
{
return false;
}
return check_probabilities(probabilities)
&& check_rates(rates);
}
} // Namespace hyperexp_detail
/**
* The hyperexponential distribution is a real-valued continuous distribution
* with two parameters, the <em>phase probability vector</em> \c probs and the
* <em>rate vector</em> \c rates.
*
* A \f$k\f$-phase hyperexponential distribution is a mixture of \f$k\f$
* exponential distributions.
* For this reason, it is also referred to as <em>mixed exponential
* distribution</em> or <em>parallel \f$k\f$-phase exponential
* distribution</em>.
*
* A \f$k\f$-phase hyperexponential distribution is characterized by two
* parameters, namely a <em>phase probability vector</em> \f$\mathbf{\alpha}=(\alpha_1,\ldots,\alpha_k)\f$ and a <em>rate vector</em> \f$\mathbf{\lambda}=(\lambda_1,\ldots,\lambda_k)\f$.
*
* A \f$k\f$-phase hyperexponential distribution is frequently used in
* <em>queueing theory</em> to model the distribution of the superposition of
* \f$k\f$ independent events, like, for instance, the service time distribution
* of a queueing station with \f$k\f$ servers in parallel where the \f$i\f$-th
* server is chosen with probability \f$\alpha_i\f$ and its service time
* distribution is an exponential distribution with rate \f$\lambda_i\f$
* (Allen,1990; Papadopolous et al.,1993; Trivedi,2002).
*
* For instance, CPUs service-time distribution in a computing system has often
* been observed to possess such a distribution (Rosin,1965).
* Also, the arrival of different types of customer to a single queueing station
* is often modeled as a hyperexponential distribution (Papadopolous et al.,1993).
* Similarly, if a product manufactured in several parallel assemply lines and
* the outputs are merged, the failure density of the overall product is likely
* to be hyperexponential (Trivedi,2002).
*
* Finally, since the hyperexponential distribution exhibits a high Coefficient
* of Variation (CoV), that is a CoV > 1, it is especially suited to fit
* empirical data with large CoV (Feitelson,2014; Wolski et al.,2013) and to
* approximate <em>long-tail probability distributions</em> (Feldmann et al.,1998).
*
* See (Boost,2014) for more information and examples.
*
* A \f$k\f$-phase hyperexponential distribution has a probability density
* function
* \f[
* f(x) = \sum_{i=1}^k \alpha_i \lambda_i e^{-x\lambda_i}
* \f]
* where:
* - \f$k\f$ is the <em>number of phases</em> and also the size of the input
* vector parameters,
* - \f$\mathbf{\alpha}=(\alpha_1,\ldots,\alpha_k)\f$ is the <em>phase probability
* vector</em> parameter, and
* - \f$\mathbf{\lambda}=(\lambda_1,\ldots,\lambda_k)\f$ is the <em>rate vector</em>
* parameter.
* .
*
* Given a \f$k\f$-phase hyperexponential distribution with phase probability
* vector \f$\mathbf{\alpha}\f$ and rate vector \f$\mathbf{\lambda}\f$, the
* random variate generation algorithm consists of the following steps (Tyszer,1999):
* -# Generate a random variable \f$U\f$ uniformly distribution on the interval \f$(0,1)\f$.
* -# Use \f$U\f$ to select the appropriate \f$\lambda_i\f$ (e.g., the
* <em>alias method</em> can possibly be used for this step).
* -# Generate an exponentially distributed random variable \f$X\f$ with rate parameter \f$\lambda_i\f$.
* -# Return \f$X\f$.
* .
*
* References:
* -# A.O. Allen, <em>Probability, Statistics, and Queuing Theory with Computer Science Applications, Second Edition</em>, Academic Press, 1990.
* -# Boost C++ Libraries, <em>Boost.Math / Statistical Distributions: Hyperexponential Distribution</em>, Online: http://www.boost.org/doc/libs/release/libs/math/doc/html/dist.html , 2014.
* -# D.G. Feitelson, <em>Workload Modeling for Computer Systems Performance Evaluation</em>, Cambridge University Press, 2014
* -# A. Feldmann and W. Whitt, <em>Fitting mixtures of exponentials to long-tail distributions to analyze network performance models</em>, Performance Evaluation 31(3-4):245, doi:10.1016/S0166-5316(97)00003-5, 1998.
* -# H.T. Papadopolous, C. Heavey and J. Browne, <em>Queueing Theory in Manufacturing Systems Analysis and Design</em>, Chapman & Hall/CRC, 1993, p. 35.
* -# R.F. Rosin, <em>Determining a computing center environment</em>, Communications of the ACM 8(7):463-468, 1965.
* -# K.S. Trivedi, <em>Probability and Statistics with Reliability, Queueing, and Computer Science Applications</em>, John Wiley & Sons, Inc., 2002.
* -# J. Tyszer, <em>Object-Oriented Computer Simulation of Discrete-Event Systems</em>, Springer, 1999.
* -# Wikipedia, <em>Hyperexponential Distribution</em>, Online: http://en.wikipedia.org/wiki/Hyperexponential_distribution , 2014.
* -# Wolfram Mathematica, <em>Hyperexponential Distribution</em>, Online: http://reference.wolfram.com/language/ref/HyperexponentialDistribution.html , 2014.
* .
*
* \author Marco Guazzone (marco.guazzone@gmail.com)
*/
template<class RealT = double>
class hyperexponential_distribution
{
public: typedef RealT result_type;
public: typedef RealT input_type;
/**
* The parameters of a hyperexponential distribution.
*
* Stores the <em>phase probability vector</em> and the <em>rate vector</em>
* of the hyperexponential distribution.
*
* \author Marco Guazzone (marco.guazzone@gmail.com)
*/
public: class param_type
{
public: typedef hyperexponential_distribution distribution_type;
/**
* Constructs a \c param_type with the default parameters
* of the distribution.
*/
public: param_type()
: probs_(1, 1),
rates_(1, 1)
{
}
/**
* Constructs a \c param_type from the <em>phase probability vector</em>
* and <em>rate vector</em> parameters of the distribution.
*
* The <em>phase probability vector</em> parameter is given by the range
* defined by [\a prob_first, \a prob_last) iterator pair, and the
* <em>rate vector</em> parameter is given by the range defined by
* [\a rate_first, \a rate_last) iterator pair.
*
* \tparam ProbIterT Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
* \tparam RateIterT Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
*
* \param prob_first The iterator to the beginning of the range of non-negative real elements representing the phase probabilities; if elements don't sum to 1, they are normalized.
* \param prob_last The iterator to the ending of the range of non-negative real elements representing the phase probabilities; if elements don't sum to 1, they are normalized.
* \param rate_first The iterator to the beginning of the range of non-negative real elements representing the rates.
* \param rate_last The iterator to the ending of the range of non-negative real elements representing the rates.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
public: template <typename ProbIterT, typename RateIterT>
param_type(ProbIterT prob_first, ProbIterT prob_last,
RateIterT rate_first, RateIterT rate_last)
: probs_(prob_first, prob_last),
rates_(rate_first, rate_last)
{
hyperexp_detail::normalize(probs_);
assert( hyperexp_detail::check_params(probs_, rates_) );
}
/**
* Constructs a \c param_type from the <em>phase probability vector</em>
* and <em>rate vector</em> parameters of the distribution.
*
* The <em>phase probability vector</em> parameter is given by the range
* defined by \a prob_range, and the <em>rate vector</em> parameter is
* given by the range defined by \a rate_range.
*
* \tparam ProbRangeT Must meet the requirements of <a href="boost:/libs/range/doc/html/range/concepts.html">Range</a> concept.
* \tparam RateRangeT Must meet the requirements of <a href="boost:/libs/range/doc/html/range/concepts.html">Range</a> concept.
*
* \param prob_range The range of non-negative real elements representing the phase probabilities; if elements don't sum to 1, they are normalized.
* \param rate_range The range of positive real elements representing the rates.
*
* \note
* The final \c disable_if parameter is an implementation detail that
* differentiates between this two argument constructor and the
* iterator-based two argument constructor described below.
*/
// We SFINAE this out of existance if either argument type is
// incrementable as in that case the type is probably an iterator:
public: template <typename ProbRangeT, typename RateRangeT>
param_type(ProbRangeT const& prob_range,
RateRangeT const& rate_range,
typename Boost::disable_if_c<Boost::has_pre_increment<ProbRangeT>::value || Boost::has_pre_increment<RateRangeT>::value>::type* = 0)
: probs_(Boost::begin(prob_range), Boost::end(prob_range)),
rates_(Boost::begin(rate_range), Boost::end(rate_range))
{
hyperexp_detail::normalize(probs_);
assert( hyperexp_detail::check_params(probs_, rates_) );
}
/**
* Constructs a \c param_type from the <em>rate vector</em> parameter of
* the distribution and with equal phase probabilities.
*
* The <em>rate vector</em> parameter is given by the range defined by
* [\a rate_first, \a rate_last) iterator pair, and the <em>phase
* probability vector</em> parameter is set to the equal phase
* probabilities (i.e., to a vector of the same length \f$k\f$ of the
* <em>rate vector</em> and with each element set to \f$1.0/k\f$).
*
* \tparam RateIterT Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
* \tparam RateIterT2 Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
*
* \param rate_first The iterator to the beginning of the range of non-negative real elements representing the rates.
* \param rate_last The iterator to the ending of the range of non-negative real elements representing the rates.
*
* \note
* The final \c disable_if parameter is an implementation detail that
* differentiates between this two argument constructor and the
* range-based two argument constructor described above.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
// We SFINAE this out of existance if the argument type is
// incrementable as in that case the type is probably an iterator.
public: template <typename RateIterT>
param_type(RateIterT rate_first,
RateIterT rate_last,
typename Boost::enable_if_c<Boost::has_pre_increment<RateIterT>::value>::type* = 0)
: probs_(std::distance(rate_first, rate_last), 1), // will be normalized below
rates_(rate_first, rate_last)
{
assert(probs_.size() == rates_.size());
}
/**
* Constructs a @c param_type from the "rates" parameters
* of the distribution and with equal phase probabilities.
*
* The <em>rate vector</em> parameter is given by the range defined by
* \a rate_range, and the <em>phase probability vector</em> parameter is
* set to the equal phase probabilities (i.e., to a vector of the same
* length \f$k\f$ of the <em>rate vector</em> and with each element set
* to \f$1.0/k\f$).
*
* \tparam RateRangeT Must meet the requirements of <a href="boost:/libs/range/doc/html/range/concepts.html">Range</a> concept.
*
* \param rate_range The range of positive real elements representing the rates.
*/
public: template <typename RateRangeT>
param_type(RateRangeT const& rate_range)
: probs_(Boost::size(rate_range), 1), // Will be normalized below
rates_(Boost::begin(rate_range), Boost::end(rate_range))
{
hyperexp_detail::normalize(probs_);
assert( hyperexp_detail::check_params(probs_, rates_) );
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a \c param_type from the <em>phase probability vector</em>
* and <em>rate vector</em> parameters of the distribution.
*
* The <em>phase probability vector</em> parameter is given by the
* <em>brace-init-list</em> (ISO,2014,sec. 8.5.4 [dcl.init.list])
* defined by \a l1, and the <em>rate vector</em> parameter is given by the
* <em>brace-init-list</em> (ISO,2014,sec. 8.5.4 [dcl.init.list])
* defined by \a l2.
*
* \param l1 The initializer list for inizializing the phase probability vector.
* \param l2 The initializer list for inizializing the rate vector.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
public: param_type(std::initializer_list<RealT> l1, std::initializer_list<RealT> l2)
: probs_(l1.begin(), l1.end()),
rates_(l2.begin(), l2.end())
{
hyperexp_detail::normalize(probs_);
assert( hyperexp_detail::check_params(probs_, rates_) );
}
/**
* Constructs a \c param_type from the <em>rate vector</em> parameter
* of the distribution and with equal phase probabilities.
*
* The <em>rate vector</em> parameter is given by the
* <em>brace-init-list</em> (ISO,2014,sec. 8.5.4 [dcl.init.list])
* defined by \a l1, and the <em>phase probability vector</em> parameter is
* set to the equal phase probabilities (i.e., to a vector of the same
* length \f$k\f$ of the <em>rate vector</em> and with each element set
* to \f$1.0/k\f$).
*
* \param l1 The initializer list for inizializing the rate vector.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
public: param_type(std::initializer_list<RealT> l1)
: probs_(std::distance(l1.begin(), l1.end()), 1), // Will be normalized below
rates_(l1.begin(), l1.end())
{
hyperexp_detail::normalize(probs_);
assert( hyperexp_detail::check_params(probs_, rates_) );
}
#endif // ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Gets the <em>phase probability vector</em> parameter of the distribtuion.
*
* \return The <em>phase probability vector</em> parameter of the distribution.
*
* \note
* The returned probabilities are the normalized version of the ones
* passed at construction time.
*/
public: std::vector<RealT> probabilities() const
{
return probs_;
}
/**
* Gets the <em>rate vector</em> parameter of the distribtuion.
*
* \return The <em>rate vector</em> parameter of the distribution.
*/
public: std::vector<RealT> rates() const
{
return rates_;
}
/** Writes a \c param_type to a \c std::ostream. */
public: ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, param)
{
detail::print_vector(os, param.probs_);
os << ' ';
detail::print_vector(os, param.rates_);
return os;
}
/** Reads a \c param_type from a \c std::istream. */
public: ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, param)
{
// NOTE: if \c std::ios_base::exceptions is set, the code below may
// throw in case of a I/O failure.
// To prevent leaving the state of \c param inconsistent:
// - if an exception is thrown, the state of \c param is left
// unchanged (i.e., is the same as the one at the beginning
// of the function's execution), and
// - the state of \c param only after reading the whole input.
std::vector<RealT> probs;
std::vector<RealT> rates;
// Reads probability and rate vectors
detail::read_vector(is, probs);
if (!is)
{
return is;
}
is >> std::ws;
detail::read_vector(is, rates);
if (!is)
{
return is;
}
// Update the state of the param_type object
if (probs.size() > 0)
{
param.probs_.swap(probs);
probs.clear();
}
if (rates.size() > 0)
{
param.rates_.swap(rates);
rates.clear();
}
// Adjust vector sizes (if needed)
if (param.probs_.size() != param.rates_.size()
|| param.probs_.size() == 0)
{
const std::size_t np = param.probs_.size();
const std::size_t nr = param.rates_.size();
if (np > nr)
{
param.rates_.resize(np, 1);
}
else if (nr > np)
{
param.probs_.resize(nr, 1);
}
else
{
param.probs_.resize(1, 1);
param.rates_.resize(1, 1);
}
}
// Normalize probabilities
// NOTE: this cannot be done earlier since the probability vector
// can be changed due to size conformance
hyperexp_detail::normalize(param.probs_);
//post: vector size conformance
assert(param.probs_.size() == param.rates_.size());
return is;
}
/** Returns true if the two sets of parameters are the same. */
public: ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{
return lhs.probs_ == rhs.probs_
&& lhs.rates_ == rhs.rates_;
}
/** Returns true if the two sets of parameters are the different. */
public: ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private: std::vector<RealT> probs_; ///< The <em>phase probability vector</em> parameter of the distribution
private: std::vector<RealT> rates_; ///< The <em>rate vector</em> parameter of the distribution
}; // param_type
/**
* Constructs a 1-phase \c hyperexponential_distribution (i.e., an
* exponential distribution) with rate 1.
*/
public: hyperexponential_distribution()
: dd_(std::vector<RealT>(1, 1)),
rates_(1, 1)
{
// empty
}
/**
* Constructs a \c hyperexponential_distribution from the <em>phase
* probability vector</em> and <em>rate vector</em> parameters of the
* distribution.
*
* The <em>phase probability vector</em> parameter is given by the range
* defined by [\a prob_first, \a prob_last) iterator pair, and the
* <em>rate vector</em> parameter is given by the range defined by
* [\a rate_first, \a rate_last) iterator pair.
*
* \tparam ProbIterT Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
* \tparam RateIterT Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
*
* \param prob_first The iterator to the beginning of the range of non-negative real elements representing the phase probabilities; if elements don't sum to 1, they are normalized.
* \param prob_last The iterator to the ending of the range of non-negative real elements representing the phase probabilities; if elements don't sum to 1, they are normalized.
* \param rate_first The iterator to the beginning of the range of non-negative real elements representing the rates.
* \param rate_last The iterator to the ending of the range of non-negative real elements representing the rates.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
public: template <typename ProbIterT, typename RateIterT>
hyperexponential_distribution(ProbIterT prob_first, ProbIterT prob_last,
RateIterT rate_first, RateIterT rate_last)
: dd_(prob_first, prob_last),
rates_(rate_first, rate_last)
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
/**
* Constructs a \c hyperexponential_distribution from the <em>phase
* probability vector</em> and <em>rate vector</em> parameters of the
* distribution.
*
* The <em>phase probability vector</em> parameter is given by the range
* defined by \a prob_range, and the <em>rate vector</em> parameter is
* given by the range defined by \a rate_range.
*
* \tparam ProbRangeT Must meet the requirements of <a href="boost:/libs/range/doc/html/range/concepts.html">Range</a> concept.
* \tparam RateRangeT Must meet the requirements of <a href="boost:/libs/range/doc/html/range/concepts.html">Range</a> concept.
*
* \param prob_range The range of non-negative real elements representing the phase probabilities; if elements don't sum to 1, they are normalized.
* \param rate_range The range of positive real elements representing the rates.
*
* \note
* The final \c disable_if parameter is an implementation detail that
* differentiates between this two argument constructor and the
* iterator-based two argument constructor described below.
*/
// We SFINAE this out of existance if either argument type is
// incrementable as in that case the type is probably an iterator:
public: template <typename ProbRangeT, typename RateRangeT>
hyperexponential_distribution(ProbRangeT const& prob_range,
RateRangeT const& rate_range,
typename Boost::disable_if_c<Boost::has_pre_increment<ProbRangeT>::value || Boost::has_pre_increment<RateRangeT>::value>::type* = 0)
: dd_(prob_range),
rates_(Boost::begin(rate_range), Boost::end(rate_range))
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
/**
* Constructs a \c hyperexponential_distribution from the <em>rate
* vector</em> parameter of the distribution and with equal phase
* probabilities.
*
* The <em>rate vector</em> parameter is given by the range defined by
* [\a rate_first, \a rate_last) iterator pair, and the <em>phase
* probability vector</em> parameter is set to the equal phase
* probabilities (i.e., to a vector of the same length \f$k\f$ of the
* <em>rate vector</em> and with each element set to \f$1.0/k\f$).
*
* \tparam RateIterT Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
* \tparam RateIterT2 Must meet the requirements of \c InputIterator concept (ISO,2014,sec. 24.2.3 [input.iterators]).
*
* \param rate_first The iterator to the beginning of the range of non-negative real elements representing the rates.
* \param rate_last The iterator to the ending of the range of non-negative real elements representing the rates.
*
* \note
* The final \c disable_if parameter is an implementation detail that
* differentiates between this two argument constructor and the
* range-based two argument constructor described above.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
// We SFINAE this out of existance if the argument type is
// incrementable as in that case the type is probably an iterator.
public: template <typename RateIterT>
hyperexponential_distribution(RateIterT rate_first,
RateIterT rate_last,
typename Boost::enable_if_c<Boost::has_pre_increment<RateIterT>::value>::type* = 0)
: dd_(std::vector<RealT>(std::distance(rate_first, rate_last), 1)),
rates_(rate_first, rate_last)
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
/**
* Constructs a @c param_type from the "rates" parameters
* of the distribution and with equal phase probabilities.
*
* The <em>rate vector</em> parameter is given by the range defined by
* \a rate_range, and the <em>phase probability vector</em> parameter is
* set to the equal phase probabilities (i.e., to a vector of the same
* length \f$k\f$ of the <em>rate vector</em> and with each element set
* to \f$1.0/k\f$).
*
* \tparam RateRangeT Must meet the requirements of <a href="boost:/libs/range/doc/html/range/concepts.html">Range</a> concept.
*
* \param rate_range The range of positive real elements representing the rates.
*/
public: template <typename RateRangeT>
hyperexponential_distribution(RateRangeT const& rate_range)
: dd_(std::vector<RealT>(Boost::size(rate_range), 1)),
rates_(Boost::begin(rate_range), Boost::end(rate_range))
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
/**
* Constructs a \c hyperexponential_distribution from its parameters.
*
* \param param The parameters of the distribution.
*/
public: explicit hyperexponential_distribution(param_type const& param)
: dd_(param.probabilities()),
rates_(param.rates())
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a \c hyperexponential_distribution from the <em>phase
* probability vector</em> and <em>rate vector</em> parameters of the
* distribution.
*
* The <em>phase probability vector</em> parameter is given by the
* <em>brace-init-list</em> (ISO,2014,sec. 8.5.4 [dcl.init.list])
* defined by \a l1, and the <em>rate vector</em> parameter is given by the
* <em>brace-init-list</em> (ISO,2014,sec. 8.5.4 [dcl.init.list])
* defined by \a l2.
*
* \param l1 The initializer list for inizializing the phase probability vector.
* \param l2 The initializer list for inizializing the rate vector.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
public: hyperexponential_distribution(std::initializer_list<RealT> const& l1, std::initializer_list<RealT> const& l2)
: dd_(l1.begin(), l1.end()),
rates_(l2.begin(), l2.end())
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
/**
* Constructs a \c hyperexponential_distribution from the <em>rate
* vector</em> parameter of the distribution and with equal phase
* probabilities.
*
* The <em>rate vector</em> parameter is given by the
* <em>brace-init-list</em> (ISO,2014,sec. 8.5.4 [dcl.init.list])
* defined by \a l1, and the <em>phase probability vector</em> parameter is
* set to the equal phase probabilities (i.e., to a vector of the same
* length \f$k\f$ of the <em>rate vector</em> and with each element set
* to \f$1.0/k\f$).
*
* \param l1 The initializer list for inizializing the rate vector.
*
* References:
* -# ISO, <em>ISO/IEC 14882-2014: Information technology - Programming languages - C++</em>, 2014
* .
*/
public: hyperexponential_distribution(std::initializer_list<RealT> const& l1)
: dd_(std::vector<RealT>(std::distance(l1.begin(), l1.end()), 1)),
rates_(l1.begin(), l1.end())
{
assert( hyperexp_detail::check_params(dd_.probabilities(), rates_) );
}
#endif
/**
* Gets a random variate distributed according to the
* hyperexponential distribution.
*
* \tparam URNG Must meet the requirements of \uniform_random_number_generator.
*
* \param urng A uniform random number generator object.
*
* \return A random variate distributed according to the hyperexponential distribution.
*/
public: template<class URNG>\
RealT operator()(URNG& urng) const
{
const int i = dd_(urng);
return Boost::random::exponential_distribution<RealT>(rates_[i])(urng);
}
/**
* Gets a random variate distributed according to the hyperexponential
* distribution with parameters specified by \c param.
*
* \tparam URNG Must meet the requirements of \uniform_random_number_generator.
*
* \param urng A uniform random number generator object.
* \param param A distribution parameter object.
*
* \return A random variate distributed according to the hyperexponential distribution.
* distribution with parameters specified by \c param.
*/
public: template<class URNG>
RealT operator()(URNG& urng, const param_type& param) const
{
return hyperexponential_distribution(param)(urng);
}
/** Returns the number of phases of the distribution. */
public: std::size_t num_phases() const
{
return rates_.size();
}
/** Returns the <em>phase probability vector</em> parameter of the distribution. */
public: std::vector<RealT> probabilities() const
{
return dd_.probabilities();
}
/** Returns the <em>rate vector</em> parameter of the distribution. */
public: std::vector<RealT> rates() const
{
return rates_;
}
/** Returns the smallest value that the distribution can produce. */
public: RealT min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{
return 0;
}
/** Returns the largest value that the distribution can produce. */
public: RealT max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{
return std::numeric_limits<RealT>::infinity();
}
/** Returns the parameters of the distribution. */
public: param_type param() const
{
std::vector<RealT> probs = dd_.probabilities();
return param_type(probs.begin(), probs.end(), rates_.begin(), rates_.end());
}
/** Sets the parameters of the distribution. */
public: void param(param_type const& param)
{
dd_.param(typename Boost::random::discrete_distribution<int,RealT>::param_type(param.probabilities()));
rates_ = param.rates();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
public: void reset()
{
// empty
}
/** Writes an @c hyperexponential_distribution to a @c std::ostream. */
public: ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, hyperexponential_distribution, hd)
{
os << hd.param();
return os;
}
/** Reads an @c hyperexponential_distribution from a @c std::istream. */
public: ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, hyperexponential_distribution, hd)
{
param_type param;
if(is >> param)
{
hd.param(param);
}
return is;
}
/**
* Returns true if the two instances of @c hyperexponential_distribution will
* return identical sequences of values given equal generators.
*/
public: ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(hyperexponential_distribution, lhs, rhs)
{
return lhs.dd_ == rhs.dd_
&& lhs.rates_ == rhs.rates_;
}
/**
* Returns true if the two instances of @c hyperexponential_distribution will
* return different sequences of values given equal generators.
*/
public: ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(hyperexponential_distribution)
private: Boost::random::discrete_distribution<int,RealT> dd_; ///< The \c discrete_distribution used to sample the phase probability and choose the rate
private: std::vector<RealT> rates_; ///< The <em>rate vector</em> parameter of the distribution
}; // hyperexponential_distribution
}} // namespace Boost::random
#endif // ACTIV_BOOST_RANDOM_HYPEREXPONENTIAL_DISTRIBUTION_HPP
@@ -1,283 +0,0 @@
/* boost random/independent_bits.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_INDEPENDENT_BITS_HPP
#define ACTIV_BOOST_RANDOM_INDEPENDENT_BITS_HPP
#include <istream>
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/random/traits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/integer_log2.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
namespace Boost {
namespace random {
/**
* An instantiation of class template @c independent_bits_engine
* model a \pseudo_random_number_generator. It generates random
* numbers distributed between [0, 2^w) by combining one or
* more invocations of the base engine.
*
* Requires: 0 < w <= std::numeric_limits<UIntType>::digits
*/
template<class Engine, std::size_t w, class UIntType>
class independent_bits_engine
{
public:
typedef Engine base_type;
typedef UIntType result_type;
typedef typename Engine::result_type base_result_type;
// Required by old Boost.Random concept
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 0; }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return max_imp(Boost::is_integral<UIntType>()); }
/**
* Constructs an @c independent_bits_engine using the
* default constructor of the base generator.
*/
independent_bits_engine() { }
/**
* Constructs an @c independent_bits_engine, using seed as
* the constructor argument for both base generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(independent_bits_engine,
base_result_type, seed_arg)
{
_base.seed(seed_arg);
}
/**
* Constructs an @c independent_bits_engine, using seq as
* the constructor argument for the base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(independent_bits_engine,
SeedSeq, seq)
{ _base.seed(seq); }
/** Constructs an @c independent_bits_engine by copying @c base. */
independent_bits_engine(const base_type& base_arg) : _base(base_arg) {}
/**
* Contructs an @c independent_bits_engine with
* values from the range defined by the input iterators first
* and last. first will be modified to point to the element
* after the last one used.
*
* Throws: @c std::invalid_argument if the input range is too small.
*
* Exception Safety: Basic
*/
template<class It>
independent_bits_engine(It& first, It last) : _base(first, last) { }
/**
* Seeds an @c independent_bits_engine using the default
* seed of the base generator.
*/
void seed() { _base.seed(); }
/**
* Seeds an @c independent_bits_engine, using @c seed as the
* seed for the base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(independent_bits_engine,
base_result_type, seed_arg)
{ _base.seed(seed_arg); }
/**
* Seeds an @c independent_bits_engine, using @c seq to
* seed the base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(independent_bits_engine,
SeedSeq, seq)
{ _base.seed(seq); }
/**
* Seeds an @c independent_bits_engine with
* values from the range defined by the input iterators first
* and last. first will be modified to point to the element
* after the last one used.
*
* Throws: @c std::invalid_argument if the input range is too small.
*
* Exception Safety: Basic
*/
template<class It> void seed(It& first, It last)
{ _base.seed(first, last); }
/** Returns the next value of the generator. */
result_type operator()()
{
// While it may seem wasteful to recalculate this
// every time, both msvc and gcc can propagate
// constants, resolving this at compile time.
base_unsigned range =
detail::subtract<base_result_type>()((_base.max)(), (_base.min)());
std::size_t m =
(range == (std::numeric_limits<base_unsigned>::max)()) ?
std::numeric_limits<base_unsigned>::digits :
detail::integer_log2(range + 1);
std::size_t n = (w + m - 1) / m;
std::size_t w0, n0;
base_unsigned y0, y1;
base_unsigned y0_mask, y1_mask;
calc_params(n, range, w0, n0, y0, y1, y0_mask, y1_mask);
if(base_unsigned(range - y0 + 1) > y0 / n) {
// increment n and try again.
++n;
calc_params(n, range, w0, n0, y0, y1, y0_mask, y1_mask);
}
ACTIV_BOOST_ASSERT(n0*w0 + (n - n0)*(w0 + 1) == w);
ACTIV_BOOST_ASSERT((n == 1) == (w0 == w));
// special case to avoid undefined behavior from shifting
if(n == 1) {
ACTIV_BOOST_ASSERT(n0 == 1);
base_unsigned u;
do {
u = detail::subtract<base_result_type>()(_base(), (_base.min)());
} while(u > base_unsigned(y0 - 1));
return u & y0_mask;
}
result_type S = 0;
for(std::size_t k = 0; k < n0; ++k) {
base_unsigned u;
do {
u = detail::subtract<base_result_type>()(_base(), (_base.min)());
} while(u > base_unsigned(y0 - 1));
S = (S << w0) + (u & y0_mask);
}
for(std::size_t k = 0; k < (n - n0); ++k) {
base_unsigned u;
do {
u = detail::subtract<base_result_type>()(_base(), (_base.min)());
} while(u > base_unsigned(y1 - 1));
S = (S << (w0 + 1)) + (u & y1_mask);
}
return S;
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t i = 0; i < z; ++i) {
(*this)();
}
}
const base_type& base() const { return _base; }
/**
* Writes the textual representation if the generator to a @c std::ostream.
* The textual representation of the engine is the textual representation
* of the base engine.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, independent_bits_engine, r)
{
os << r._base;
return os;
}
/**
* Reads the state of an @c independent_bits_engine from a
* @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, independent_bits_engine, r)
{
is >> r._base;
return is;
}
/**
* Returns: true iff the two @c independent_bits_engines will
* produce the same sequence of values.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(independent_bits_engine, x, y)
{ return x._base == y._base; }
/**
* Returns: true iff the two @c independent_bits_engines will
* produce different sequences of values.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(independent_bits_engine)
private:
/// \cond show_private
typedef typename Boost::random::traits::make_unsigned<base_result_type>::type base_unsigned;
static ACTIV_BOOST_CONSTEXPR UIntType max_imp(const Boost::true_type&)
{
return Boost::low_bits_mask_t<w>::sig_bits;
}
static UIntType max_imp(const Boost::false_type&)
{
// We have a multiprecision integer type:
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_specialized);
return w < std::numeric_limits<UIntType>::digits ? UIntType((UIntType(1) << w) - 1) : UIntType((((UIntType(1) << (w - 1)) - 1) << 1) | 1u);
}
void calc_params(
std::size_t n, base_unsigned range,
std::size_t& w0, std::size_t& n0,
base_unsigned& y0, base_unsigned& y1,
base_unsigned& y0_mask, base_unsigned& y1_mask)
{
ACTIV_BOOST_ASSERT(w >= n);
w0 = w/n;
n0 = n - w % n;
y0_mask = (base_unsigned(2) << (w0 - 1)) - 1;
y1_mask = (y0_mask << 1) | 1;
y0 = (range + 1) & ~y0_mask;
y1 = (range + 1) & ~y1_mask;
ACTIV_BOOST_ASSERT(y0 != 0 || base_unsigned(range + 1) == 0);
}
/// \endcond
Engine _base;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
template<class Engine, std::size_t w, class UIntType>
const bool independent_bits_engine<Engine, w, UIntType>::has_fixed_range;
#endif
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_INDEPENDENT_BITS_HPP
@@ -1,266 +0,0 @@
/* boost random/inversive_congruential.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
#define ACTIV_BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
#include <iosfwd>
#include <stdexcept>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/const_mod.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
// Eichenauer and Lehn 1986
/**
* Instantiations of class template @c inversive_congruential_engine model a
* \pseudo_random_number_generator. It uses the inversive congruential
* algorithm (ICG) described in
*
* @blockquote
* "Inversive pseudorandom number generators: concepts, results and links",
* Peter Hellekalek, In: "Proceedings of the 1995 Winter Simulation
* Conference", C. Alexopoulos, K. Kang, W.R. Lilegdon, and D. Goldsman
* (editors), 1995, pp. 255-262. ftp://random.mat.sbg.ac.at/pub/data/wsc95.ps
* @endblockquote
*
* The output sequence is defined by x(n+1) = (a*inv(x(n)) - b) (mod p),
* where x(0), a, b, and the prime number p are parameters of the generator.
* The expression inv(k) denotes the multiplicative inverse of k in the
* field of integer numbers modulo p, with inv(0) := 0.
*
* The template parameter IntType shall denote a signed integral type large
* enough to hold p; a, b, and p are the parameters of the generators. The
* template parameter val is the validation value checked by validation.
*
* @xmlnote
* The implementation currently uses the Euclidian Algorithm to compute
* the multiplicative inverse. Therefore, the inversive generators are about
* 10-20 times slower than the others (see section"performance"). However,
* the paper talks of only 3x slowdown, so the Euclidian Algorithm is probably
* not optimal for calculating the multiplicative inverse.
* @endxmlnote
*/
template<class IntType, IntType a, IntType b, IntType p>
class inversive_congruential_engine
{
public:
typedef IntType result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(result_type, multiplier = a);
ACTIV_BOOST_STATIC_CONSTANT(result_type, increment = b);
ACTIV_BOOST_STATIC_CONSTANT(result_type, modulus = p);
ACTIV_BOOST_STATIC_CONSTANT(IntType, default_seed = 1);
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return b == 0 ? 1 : 0; }
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return p-1; }
/**
* Constructs an @c inversive_congruential_engine, seeding it with
* the default seed.
*/
inversive_congruential_engine() { seed(); }
/**
* Constructs an @c inversive_congruential_engine, seeding it with @c x0.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(inversive_congruential_engine,
IntType, x0)
{ seed(x0); }
/**
* Constructs an @c inversive_congruential_engine, seeding it with values
* produced by a call to @c seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(inversive_congruential_engine,
SeedSeq, seq)
{ seed(seq); }
/**
* Constructs an @c inversive_congruential_engine, seeds it
* with values taken from the itrator range [first, last),
* and adjusts first to point to the element after the last one
* used. If there are not enough elements, throws @c std::invalid_argument.
*
* first and last must be input iterators.
*/
template<class It> inversive_congruential_engine(It& first, It last)
{ seed(first, last); }
/**
* Calls seed(default_seed)
*/
void seed() { seed(default_seed); }
/**
* If c mod m is zero and x0 mod m is zero, changes the current value of
* the generator to 1. Otherwise, changes it to x0 mod m. If c is zero,
* distinct seeds in the range [1,m) will leave the generator in distinct
* states. If c is not zero, the range is [0,m).
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(inversive_congruential_engine, IntType, x0)
{
// wrap _x if it doesn't fit in the destination
if(modulus == 0) {
_value = x0;
} else {
_value = x0 % modulus;
}
// handle negative seeds
if(_value <= 0 && _value != 0) {
_value += modulus;
}
// adjust to the correct range
if(increment == 0 && _value == 0) {
_value = 1;
}
ACTIV_BOOST_ASSERT(_value >= (min)());
ACTIV_BOOST_ASSERT(_value <= (max)());
}
/**
* Seeds an @c inversive_congruential_engine using values from a SeedSeq.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(inversive_congruential_engine, SeedSeq, seq)
{ seed(detail::seed_one_int<IntType, modulus>(seq)); }
/**
* seeds an @c inversive_congruential_engine with values taken
* from the itrator range [first, last) and adjusts @c first to
* point to the element after the last one used. If there are
* not enough elements, throws @c std::invalid_argument.
*
* @c first and @c last must be input iterators.
*/
template<class It> void seed(It& first, It last)
{ seed(detail::get_one_int<IntType, modulus>(first, last)); }
/** Returns the next output of the generator. */
IntType operator()()
{
typedef const_mod<IntType, p> do_mod;
_value = do_mod::mult_add(a, do_mod::invert(_value), b);
return _value;
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
/**
* Writes the textual representation of the generator to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, inversive_congruential_engine, x)
{
os << x._value;
return os;
}
/**
* Reads the textual representation of the generator from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, inversive_congruential_engine, x)
{
is >> x._value;
return is;
}
/**
* Returns true if the two generators will produce identical
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(inversive_congruential_engine, x, y)
{ return x._value == y._value; }
/**
* Returns true if the two generators will produce different
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(inversive_congruential_engine)
private:
IntType _value;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class IntType, IntType a, IntType b, IntType p>
const bool inversive_congruential_engine<IntType, a, b, p>::has_fixed_range;
template<class IntType, IntType a, IntType b, IntType p>
const typename inversive_congruential_engine<IntType, a, b, p>::result_type inversive_congruential_engine<IntType, a, b, p>::multiplier;
template<class IntType, IntType a, IntType b, IntType p>
const typename inversive_congruential_engine<IntType, a, b, p>::result_type inversive_congruential_engine<IntType, a, b, p>::increment;
template<class IntType, IntType a, IntType b, IntType p>
const typename inversive_congruential_engine<IntType, a, b, p>::result_type inversive_congruential_engine<IntType, a, b, p>::modulus;
template<class IntType, IntType a, IntType b, IntType p>
const typename inversive_congruential_engine<IntType, a, b, p>::result_type inversive_congruential_engine<IntType, a, b, p>::default_seed;
#endif
/// \cond show_deprecated
// provided for backwards compatibility
template<class IntType, IntType a, IntType b, IntType p, IntType val = 0>
class inversive_congruential : public inversive_congruential_engine<IntType, a, b, p>
{
typedef inversive_congruential_engine<IntType, a, b, p> base_type;
public:
inversive_congruential(IntType x0 = 1) : base_type(x0) {}
template<class It>
inversive_congruential(It& first, It last) : base_type(first, last) {}
};
/// \endcond
/**
* The specialization hellekalek1995 was suggested in
*
* @blockquote
* "Inversive pseudorandom number generators: concepts, results and links",
* Peter Hellekalek, In: "Proceedings of the 1995 Winter Simulation
* Conference", C. Alexopoulos, K. Kang, W.R. Lilegdon, and D. Goldsman
* (editors), 1995, pp. 255-262. ftp://random.mat.sbg.ac.at/pub/data/wsc95.ps
* @endblockquote
*/
typedef inversive_congruential_engine<uint32_t, 9102, 2147483647-36884165,
2147483647> hellekalek1995;
} // namespace random
using random::hellekalek1995;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
@@ -1,537 +0,0 @@
/* boost random/lagged_fibonacci.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2013-10-14 fixed some warnings with Wshadow (mgaunard)
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_LAGGED_FIBONACCI_HPP
#define ACTIV_BOOST_RANDOM_LAGGED_FIBONACCI_HPP
#include <istream>
#include <iosfwd>
#include <algorithm> // std::max
#include <iterator>
#include <ActivBoost/config/no_tr1/cmath.hpp> // std::pow
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/random/linear_congruential.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/generator_seed_seq.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template \lagged_fibonacci_engine model a
* \pseudo_random_number_generator. It uses a lagged Fibonacci
* algorithm with two lags @c p and @c q:
* x(i) = x(i-p) + x(i-q) (mod 2<sup>w</sup>) with p > q.
*/
template<class UIntType, int w, unsigned int p, unsigned int q>
class lagged_fibonacci_engine
{
public:
typedef UIntType result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(int, word_size = w);
ACTIV_BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
ACTIV_BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, default_seed = 331u);
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return low_bits_mask_t<w>::sig_bits; }
/** Creates a new @c lagged_fibonacci_engine and calls @c seed(). */
lagged_fibonacci_engine() { seed(); }
/** Creates a new @c lagged_fibonacci_engine and calls @c seed(value). */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_engine,
UIntType, value)
{ seed(value); }
/** Creates a new @c lagged_fibonacci_engine and calls @c seed(seq). */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci_engine,
SeedSeq, seq)
{ seed(seq); }
/**
* Creates a new @c lagged_fibonacci_engine and calls @c seed(first, last).
*/
template<class It> lagged_fibonacci_engine(It& first, It last)
{ seed(first, last); }
// compiler-generated copy ctor and assignment operator are fine
/** Calls @c seed(default_seed). */
void seed() { seed(default_seed); }
/**
* Sets the state of the generator to values produced by
* a \minstd_rand0 generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(lagged_fibonacci_engine,
UIntType, value)
{
minstd_rand0 intgen(static_cast<Boost::uint32_t>(value));
detail::generator_seed_seq<minstd_rand0> gen(intgen);
seed(gen);
}
/**
* Sets the state of the generator using values produced by seq.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(lagged_fibonacci_engine, SeedSeq, seq)
{
detail::seed_array_int<w>(seq, x);
i = long_lag;
}
/**
* Sets the state of the generator to values from the iterator
* range [first, last). If there are not enough elements in the
* range [first, last) throws @c std::invalid_argument.
*/
template<class It>
void seed(It& first, It last)
{
detail::fill_array_int<w>(first, last, x);
i = long_lag;
}
/** Returns the next value of the generator. */
result_type operator()()
{
if(i >= long_lag)
fill();
return x[i++];
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
/**
* Writes the textual representation of the generator to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, lagged_fibonacci_engine, f)
{
os << f.i;
for(unsigned int j = 0; j < f.long_lag; ++j)
os << ' ' << f.x[j];
return os;
}
/**
* Reads the textual representation of the generator from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, lagged_fibonacci_engine, f)
{
is >> f.i >> std::ws;
for(unsigned int j = 0; j < f.long_lag; ++j)
is >> f.x[j] >> std::ws;
return is;
}
/**
* Returns true if the two generators will produce identical
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(lagged_fibonacci_engine, x_, y_)
{ return x_.i == y_.i && std::equal(x_.x, x_.x+long_lag, y_.x); }
/**
* Returns true if the two generators will produce different
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(lagged_fibonacci_engine)
private:
/// \cond show_private
void fill();
/// \endcond
unsigned int i;
UIntType x[long_lag];
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class UIntType, int w, unsigned int p, unsigned int q>
const bool lagged_fibonacci_engine<UIntType, w, p, q>::has_fixed_range;
template<class UIntType, int w, unsigned int p, unsigned int q>
const unsigned int lagged_fibonacci_engine<UIntType, w, p, q>::long_lag;
template<class UIntType, int w, unsigned int p, unsigned int q>
const unsigned int lagged_fibonacci_engine<UIntType, w, p, q>::short_lag;
template<class UIntType, int w, unsigned int p, unsigned int q>
const UIntType lagged_fibonacci_engine<UIntType, w, p, q>::default_seed;
#endif
/// \cond show_private
template<class UIntType, int w, unsigned int p, unsigned int q>
void lagged_fibonacci_engine<UIntType, w, p, q>::fill()
{
// two loops to avoid costly modulo operations
{ // extra scope for MSVC brokenness w.r.t. for scope
for(unsigned int j = 0; j < short_lag; ++j)
x[j] = (x[j] + x[j+(long_lag-short_lag)]) & low_bits_mask_t<w>::sig_bits;
}
for(unsigned int j = short_lag; j < long_lag; ++j)
x[j] = (x[j] + x[j-short_lag]) & low_bits_mask_t<w>::sig_bits;
i = 0;
}
/// \endcond
/// \cond show_deprecated
// provided for backwards compatibility
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType v = 0>
class lagged_fibonacci : public lagged_fibonacci_engine<UIntType, w, p, q>
{
typedef lagged_fibonacci_engine<UIntType, w, p, q> base_type;
public:
lagged_fibonacci() {}
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci, UIntType, val)
{ this->seed(val); }
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci, SeedSeq, seq)
{ this->seed(seq); }
template<class It>
lagged_fibonacci(It& first, It last) : base_type(first, last) {}
};
/// \endcond
// lagged Fibonacci generator for the range [0..1)
// contributed by Matthias Troyer
// for p=55, q=24 originally by G. J. Mitchell and D. P. Moore 1958
/**
* Instantiations of class template @c lagged_fibonacci_01 model a
* \pseudo_random_number_generator. It uses a lagged Fibonacci
* algorithm with two lags @c p and @c q, evaluated in floating-point
* arithmetic: x(i) = x(i-p) + x(i-q) (mod 1) with p > q. See
*
* @blockquote
* "Uniform random number generators for supercomputers", Richard Brent,
* Proc. of Fifth Australian Supercomputer Conference, Melbourne,
* Dec. 1992, pp. 704-706.
* @endblockquote
*
* @xmlnote
* The quality of the generator crucially depends on the choice
* of the parameters. User code should employ one of the sensibly
* parameterized generators such as \lagged_fibonacci607 instead.
* @endxmlnote
*
* The generator requires considerable amounts of memory for the storage
* of its state array. For example, \lagged_fibonacci607 requires about
* 4856 bytes and \lagged_fibonacci44497 requires about 350 KBytes.
*/
template<class RealType, int w, unsigned int p, unsigned int q>
class lagged_fibonacci_01_engine
{
public:
typedef RealType result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(int, word_size = w);
ACTIV_BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
ACTIV_BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
ACTIV_BOOST_STATIC_CONSTANT(Boost::uint32_t, default_seed = 331u);
/** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(). */
lagged_fibonacci_01_engine() { seed(); }
/** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(value). */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_01_engine, uint32_t, value)
{ seed(value); }
/** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(gen). */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci_01_engine, SeedSeq, seq)
{ seed(seq); }
template<class It> lagged_fibonacci_01_engine(It& first, It last)
{ seed(first, last); }
// compiler-generated copy ctor and assignment operator are fine
/** Calls seed(default_seed). */
void seed() { seed(default_seed); }
/**
* Constructs a \minstd_rand0 generator with the constructor parameter
* value and calls seed with it. Distinct seeds in the range
* [1, 2147483647) will produce generators with different states. Other
* seeds will be equivalent to some seed within this range. See
* \linear_congruential_engine for details.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(lagged_fibonacci_01_engine, Boost::uint32_t, value)
{
minstd_rand0 intgen(value);
detail::generator_seed_seq<minstd_rand0> gen(intgen);
seed(gen);
}
/**
* Seeds this @c lagged_fibonacci_01_engine using values produced by
* @c seq.generate.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(lagged_fibonacci_01_engine, SeedSeq, seq)
{
detail::seed_array_real<w>(seq, x);
i = long_lag;
}
/**
* Seeds this @c lagged_fibonacci_01_engine using values from the
* iterator range [first, last). If there are not enough elements
* in the range, throws @c std::invalid_argument.
*/
template<class It>
void seed(It& first, It last)
{
detail::fill_array_real<w>(first, last, x);
i = long_lag;
}
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return result_type(0); }
/** Returns the upper bound of the generators outputs. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return result_type(1); }
/** Returns the next value of the generator. */
result_type operator()()
{
if(i >= long_lag)
fill();
return x[i++];
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ return detail::generate_from_real(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
/**
* Writes the textual representation of the generator to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, lagged_fibonacci_01_engine, f)
{
// allow for Koenig lookup
using std::pow;
os << f.i;
std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left);
for(unsigned int j = 0; j < f.long_lag; ++j)
os << ' ' << f.x[j] * f.modulus();
os.flags(oldflags);
return os;
}
/**
* Reads the textual representation of the generator from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, lagged_fibonacci_01_engine, f)
{
is >> f.i;
for(unsigned int j = 0; j < f.long_lag; ++j) {
typename lagged_fibonacci_01_engine::result_type value;
is >> std::ws >> value;
f.x[j] = value / f.modulus();
}
return is;
}
/**
* Returns true if the two generators will produce identical
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(lagged_fibonacci_01_engine, x_, y_)
{ return x_.i == y_.i && std::equal(x_.x, x_.x+long_lag, y_.x); }
/**
* Returns true if the two generators will produce different
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(lagged_fibonacci_01_engine)
private:
/// \cond show_private
void fill();
static RealType modulus()
{
using std::pow;
return pow(RealType(2), word_size);
}
/// \endcond
unsigned int i;
RealType x[long_lag];
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class RealType, int w, unsigned int p, unsigned int q>
const bool lagged_fibonacci_01_engine<RealType, w, p, q>::has_fixed_range;
template<class RealType, int w, unsigned int p, unsigned int q>
const unsigned int lagged_fibonacci_01_engine<RealType, w, p, q>::long_lag;
template<class RealType, int w, unsigned int p, unsigned int q>
const unsigned int lagged_fibonacci_01_engine<RealType, w, p, q>::short_lag;
template<class RealType, int w, unsigned int p, unsigned int q>
const int lagged_fibonacci_01_engine<RealType,w,p,q>::word_size;
template<class RealType, int w, unsigned int p, unsigned int q>
const Boost::uint32_t lagged_fibonacci_01_engine<RealType,w,p,q>::default_seed;
#endif
/// \cond show_private
template<class RealType, int w, unsigned int p, unsigned int q>
void lagged_fibonacci_01_engine<RealType, w, p, q>::fill()
{
// two loops to avoid costly modulo operations
{ // extra scope for MSVC brokenness w.r.t. for scope
for(unsigned int j = 0; j < short_lag; ++j) {
RealType t = x[j] + x[j+(long_lag-short_lag)];
if(t >= RealType(1))
t -= RealType(1);
x[j] = t;
}
}
for(unsigned int j = short_lag; j < long_lag; ++j) {
RealType t = x[j] + x[j-short_lag];
if(t >= RealType(1))
t -= RealType(1);
x[j] = t;
}
i = 0;
}
/// \endcond
/// \cond show_deprecated
// provided for backwards compatibility
template<class RealType, int w, unsigned int p, unsigned int q>
class lagged_fibonacci_01 : public lagged_fibonacci_01_engine<RealType, w, p, q>
{
typedef lagged_fibonacci_01_engine<RealType, w, p, q> base_type;
public:
lagged_fibonacci_01() {}
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_01, Boost::uint32_t, val)
{ this->seed(val); }
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci_01, SeedSeq, seq)
{ this->seed(seq); }
template<class It>
lagged_fibonacci_01(It& first, It last) : base_type(first, last) {}
};
/// \endcond
namespace detail {
template<class Engine>
struct generator_bits;
template<class RealType, int w, unsigned int p, unsigned int q>
struct generator_bits<lagged_fibonacci_01_engine<RealType, w, p, q> >
{
static std::size_t value() { return w; }
};
template<class RealType, int w, unsigned int p, unsigned int q>
struct generator_bits<lagged_fibonacci_01<RealType, w, p, q> >
{
static std::size_t value() { return w; }
};
}
#ifdef ACTIV_BOOST_RANDOM_DOXYGEN
namespace detail {
/**
* The specializations lagged_fibonacci607 ... lagged_fibonacci44497
* use well tested lags.
*
* See
*
* @blockquote
* "On the Periods of Generalized Fibonacci Recurrences", Richard P. Brent
* Computer Sciences Laboratory Australian National University, December 1992
* @endblockquote
*
* The lags used here can be found in
*
* @blockquote
* "Uniform random number generators for supercomputers", Richard Brent,
* Proc. of Fifth Australian Supercomputer Conference, Melbourne,
* Dec. 1992, pp. 704-706.
* @endblockquote
*/
struct lagged_fibonacci_doc {};
}
#endif
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 607, 273> lagged_fibonacci607;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 1279, 418> lagged_fibonacci1279;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 2281, 1252> lagged_fibonacci2281;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 3217, 576> lagged_fibonacci3217;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 4423, 2098> lagged_fibonacci4423;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 9689, 5502> lagged_fibonacci9689;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 19937, 9842> lagged_fibonacci19937;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 23209, 13470> lagged_fibonacci23209;
/** @copydoc Boost::random::detail::lagged_fibonacci_doc */
typedef lagged_fibonacci_01_engine<double, 48, 44497, 21034> lagged_fibonacci44497;
} // namespace random
using random::lagged_fibonacci607;
using random::lagged_fibonacci1279;
using random::lagged_fibonacci2281;
using random::lagged_fibonacci3217;
using random::lagged_fibonacci4423;
using random::lagged_fibonacci9689;
using random::lagged_fibonacci19937;
using random::lagged_fibonacci23209;
using random::lagged_fibonacci44497;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_LAGGED_FIBONACCI_HPP
@@ -1,175 +0,0 @@
/* boost random/laplace_distribution.hpp header file
*
* Copyright Steven Watanabe 2014
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_LAPLACE_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_LAPLACE_DISTRIBUTION_HPP
#include <cassert>
#include <istream>
#include <iosfwd>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/exponential_distribution.hpp>
namespace Boost {
namespace random {
/**
* The laplace distribution is a real-valued distribution with
* two parameters, mean and beta.
*
* It has \f$\displaystyle p(x) = \frac{e^-{\frac{|x-\mu|}{\beta}}}{2\beta}\f$.
*/
template<class RealType = double>
class laplace_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef laplace_distribution distribution_type;
/**
* Constructs a @c param_type from the "mean" and "beta" parameters
* of the distribution.
*/
explicit param_type(RealType mean_arg = RealType(0.0),
RealType beta_arg = RealType(1.0))
: _mean(mean_arg), _beta(beta_arg)
{}
/** Returns the "mean" parameter of the distribtuion. */
RealType mean() const { return _mean; }
/** Returns the "beta" parameter of the distribution. */
RealType beta() const { return _beta; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._mean << ' ' << parm._beta; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._mean >> std::ws >> parm._beta; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._mean == rhs._mean && lhs._beta == rhs._beta; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _mean;
RealType _beta;
};
/**
* Constructs an @c laplace_distribution from its "mean" and "beta" parameters.
*/
explicit laplace_distribution(RealType mean_arg = RealType(0.0),
RealType beta_arg = RealType(1.0))
: _mean(mean_arg), _beta(beta_arg)
{}
/** Constructs an @c laplace_distribution from its parameters. */
explicit laplace_distribution(const param_type& parm)
: _mean(parm.mean()), _beta(parm.beta())
{}
/**
* Returns a random variate distributed according to the
* laplace distribution.
*/
template<class URNG>
RealType operator()(URNG& urng) const
{
RealType exponential = exponential_distribution<RealType>()(urng);
if(uniform_01<RealType>()(urng) < 0.5)
exponential = -exponential;
return _mean + _beta * exponential;
}
/**
* Returns a random variate distributed accordint to the laplace
* distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return laplace_distribution(parm)(urng);
}
/** Returns the "mean" parameter of the distribution. */
RealType mean() const { return _mean; }
/** Returns the "beta" parameter of the distribution. */
RealType beta() const { return _beta; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return RealType(-std::numeric_limits<RealType>::infinity()); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return RealType(std::numeric_limits<RealType>::infinity()); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_mean, _beta); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_mean = parm.mean();
_beta = parm.beta();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Writes an @c laplace_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, laplace_distribution, wd)
{
os << wd.param();
return os;
}
/** Reads an @c laplace_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, laplace_distribution, wd)
{
param_type parm;
if(is >> parm) {
wd.param(parm);
}
return is;
}
/**
* Returns true if the two instances of @c laplace_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(laplace_distribution, lhs, rhs)
{ return lhs._mean == rhs._mean && lhs._beta == rhs._beta; }
/**
* Returns true if the two instances of @c laplace_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(laplace_distribution)
private:
RealType _mean;
RealType _beta;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_LAPLACE_DISTRIBUTION_HPP
@@ -1,468 +0,0 @@
/* boost random/linear_congruential.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
#define ACTIV_BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
#include <iostream>
#include <stdexcept>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/type_traits/is_arithmetic.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/const_mod.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
#include <ActivBoost/detail/workaround.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template linear_congruential_engine model a
* \pseudo_random_number_generator. Linear congruential pseudo-random
* number generators are described in:
*
* @blockquote
* "Mathematical methods in large-scale computing units", D. H. Lehmer,
* Proc. 2nd Symposium on Large-Scale Digital Calculating Machines,
* Harvard University Press, 1951, pp. 141-146
* @endblockquote
*
* Let x(n) denote the sequence of numbers returned by some pseudo-random
* number generator. Then for the linear congruential generator,
* x(n+1) := (a * x(n) + c) mod m. Parameters for the generator are
* x(0), a, c, m. The template parameter IntType shall denote an integral
* type. It must be large enough to hold values a, c, and m. The template
* parameters a and c must be smaller than m.
*
* Note: The quality of the generator crucially depends on the choice of
* the parameters. User code should use one of the sensibly parameterized
* generators such as minstd_rand instead.
*/
template<class IntType, IntType a, IntType c, IntType m>
class linear_congruential_engine
{
public:
typedef IntType result_type;
// Required for old Boost.Random concept
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(IntType, multiplier = a);
ACTIV_BOOST_STATIC_CONSTANT(IntType, increment = c);
ACTIV_BOOST_STATIC_CONSTANT(IntType, modulus = m);
ACTIV_BOOST_STATIC_CONSTANT(IntType, default_seed = 1);
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
ACTIV_BOOST_STATIC_ASSERT(m == 0 || a < m);
ACTIV_BOOST_STATIC_ASSERT(m == 0 || c < m);
/**
* Constructs a @c linear_congruential_engine, using the default seed
*/
linear_congruential_engine() { seed(); }
/**
* Constructs a @c linear_congruential_engine, seeding it with @c x0.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(linear_congruential_engine,
IntType, x0)
{ seed(x0); }
/**
* Constructs a @c linear_congruential_engine, seeding it with values
* produced by a call to @c seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(linear_congruential_engine,
SeedSeq, seq)
{ seed(seq); }
/**
* Constructs a @c linear_congruential_engine and seeds it
* with values taken from the itrator range [first, last)
* and adjusts first to point to the element after the last one
* used. If there are not enough elements, throws @c std::invalid_argument.
*
* first and last must be input iterators.
*/
template<class It>
linear_congruential_engine(It& first, It last)
{
seed(first, last);
}
// compiler-generated copy constructor and assignment operator are fine
/**
* Calls seed(default_seed)
*/
void seed() { seed(default_seed); }
/**
* If c mod m is zero and x0 mod m is zero, changes the current value of
* the generator to 1. Otherwise, changes it to x0 mod m. If c is zero,
* distinct seeds in the range [1,m) will leave the generator in distinct
* states. If c is not zero, the range is [0,m).
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(linear_congruential_engine, IntType, x0_)
{
// Work around a msvc 12/14 optimizer bug, which causes
// the line _x = 1 to run unconditionally sometimes.
// Creating a local copy seems to make it work.
IntType x0 = x0_;
// wrap _x if it doesn't fit in the destination
if(modulus == 0) {
_x = x0;
} else {
_x = x0 % modulus;
}
// handle negative seeds
if(_x < 0) {
_x += modulus;
}
// adjust to the correct range
if(increment == 0 && _x == 0) {
_x = 1;
}
ACTIV_BOOST_ASSERT(_x >= (min)());
ACTIV_BOOST_ASSERT(_x <= (max)());
}
/**
* Seeds a @c linear_congruential_engine using values from a SeedSeq.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(linear_congruential_engine, SeedSeq, seq)
{ seed(detail::seed_one_int<IntType, m>(seq)); }
/**
* seeds a @c linear_congruential_engine with values taken
* from the itrator range [first, last) and adjusts @c first to
* point to the element after the last one used. If there are
* not enough elements, throws @c std::invalid_argument.
*
* @c first and @c last must be input iterators.
*/
template<class It>
void seed(It& first, It last)
{ seed(detail::get_one_int<IntType, m>(first, last)); }
/**
* Returns the smallest value that the @c linear_congruential_engine
* can produce.
*/
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return c == 0 ? 1 : 0; }
/**
* Returns the largest value that the @c linear_congruential_engine
* can produce.
*/
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return modulus-1; }
/** Returns the next value of the @c linear_congruential_engine. */
IntType operator()()
{
_x = const_mod<IntType, m>::mult_add(a, _x, c);
return _x;
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
typedef const_mod<IntType, m> mod_type;
IntType b_inv = mod_type::invert(a-1);
IntType b_gcd = mod_type::mult(a-1, b_inv);
if(b_gcd == 1) {
IntType a_z = mod_type::pow(a, z);
_x = mod_type::mult_add(a_z, _x,
mod_type::mult(mod_type::mult(c, b_inv), a_z - 1));
} else {
// compute (a^z - 1)*c % (b_gcd * m) / (b / b_gcd) * inv(b / b_gcd)
// we're storing the intermediate result / b_gcd
IntType a_zm1_over_gcd = 0;
IntType a_km1_over_gcd = (a - 1) / b_gcd;
Boost::uintmax_t exponent = z;
while(exponent != 0) {
if(exponent % 2 == 1) {
a_zm1_over_gcd =
mod_type::mult_add(
b_gcd,
mod_type::mult(a_zm1_over_gcd, a_km1_over_gcd),
mod_type::add(a_zm1_over_gcd, a_km1_over_gcd));
}
a_km1_over_gcd = mod_type::mult_add(
b_gcd,
mod_type::mult(a_km1_over_gcd, a_km1_over_gcd),
mod_type::add(a_km1_over_gcd, a_km1_over_gcd));
exponent /= 2;
}
IntType a_z = mod_type::mult_add(b_gcd, a_zm1_over_gcd, 1);
IntType num = mod_type::mult(c, a_zm1_over_gcd);
b_inv = mod_type::invert((a-1)/b_gcd);
_x = mod_type::mult_add(a_z, _x, mod_type::mult(b_inv, num));
}
}
friend bool operator==(const linear_congruential_engine& x,
const linear_congruential_engine& y)
{ return x._x == y._x; }
friend bool operator!=(const linear_congruential_engine& x,
const linear_congruential_engine& y)
{ return !(x == y); }
#if !defined(ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS)
/** Writes a @c linear_congruential_engine to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const linear_congruential_engine& lcg)
{
return os << lcg._x;
}
/** Reads a @c linear_congruential_engine from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is,
linear_congruential_engine& lcg)
{
lcg.read(is);
return is;
}
#endif
private:
/// \cond show_private
template<class CharT, class Traits>
void read(std::basic_istream<CharT, Traits>& is) {
IntType x;
if(is >> x) {
if(x >= (min)() && x <= (max)()) {
_x = x;
} else {
is.setstate(std::ios_base::failbit);
}
}
}
/// \endcond
IntType _x;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class IntType, IntType a, IntType c, IntType m>
const bool linear_congruential_engine<IntType, a, c, m>::has_fixed_range;
template<class IntType, IntType a, IntType c, IntType m>
const IntType linear_congruential_engine<IntType,a,c,m>::multiplier;
template<class IntType, IntType a, IntType c, IntType m>
const IntType linear_congruential_engine<IntType,a,c,m>::increment;
template<class IntType, IntType a, IntType c, IntType m>
const IntType linear_congruential_engine<IntType,a,c,m>::modulus;
template<class IntType, IntType a, IntType c, IntType m>
const IntType linear_congruential_engine<IntType,a,c,m>::default_seed;
#endif
/// \cond show_deprecated
// provided for backwards compatibility
template<class IntType, IntType a, IntType c, IntType m, IntType val = 0>
class linear_congruential : public linear_congruential_engine<IntType, a, c, m>
{
typedef linear_congruential_engine<IntType, a, c, m> base_type;
public:
linear_congruential(IntType x0 = 1) : base_type(x0) {}
template<class It>
linear_congruential(It& first, It last) : base_type(first, last) {}
};
/// \endcond
/**
* The specialization \minstd_rand0 was originally suggested in
*
* @blockquote
* A pseudo-random number generator for the System/360, P.A. Lewis,
* A.S. Goodman, J.M. Miller, IBM Systems Journal, Vol. 8, No. 2,
* 1969, pp. 136-146
* @endblockquote
*
* It is examined more closely together with \minstd_rand in
*
* @blockquote
* "Random Number Generators: Good ones are hard to find",
* Stephen K. Park and Keith W. Miller, Communications of
* the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201
* @endblockquote
*/
typedef linear_congruential_engine<uint32_t, 16807, 0, 2147483647> minstd_rand0;
/** The specialization \minstd_rand was suggested in
*
* @blockquote
* "Random Number Generators: Good ones are hard to find",
* Stephen K. Park and Keith W. Miller, Communications of
* the ACM, Vol. 31, No. 10, October 1988, pp. 1192-1201
* @endblockquote
*/
typedef linear_congruential_engine<uint32_t, 48271, 0, 2147483647> minstd_rand;
#if !defined(ACTIV_BOOST_NO_INT64_T) && !defined(ACTIV_BOOST_NO_INTEGRAL_INT64_T)
/**
* Class @c rand48 models a \pseudo_random_number_generator. It uses
* the linear congruential algorithm with the parameters a = 0x5DEECE66D,
* c = 0xB, m = 2**48. It delivers identical results to the @c lrand48()
* function available on some systems (assuming lcong48 has not been called).
*
* It is only available on systems where @c uint64_t is provided as an
* integral type, so that for example static in-class constants and/or
* enum definitions with large @c uint64_t numbers work.
*/
class rand48
{
public:
typedef Boost::uint32_t result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
/**
* Returns the smallest value that the generator can produce
*/
static ACTIV_BOOST_CONSTEXPR uint32_t min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
/**
* Returns the largest value that the generator can produce
*/
static ACTIV_BOOST_CONSTEXPR uint32_t max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 0x7FFFFFFF; }
/** Seeds the generator with the default seed. */
rand48() : lcf(cnv(static_cast<uint32_t>(1))) {}
/**
* Constructs a \rand48 generator with x(0) := (x0 << 16) | 0x330e.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(rand48, result_type, x0)
{ seed(x0); }
/**
* Seeds the generator with values produced by @c seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(rand48, SeedSeq, seq)
{ seed(seq); }
/**
* Seeds the generator using values from an iterator range,
* and updates first to point one past the last value consumed.
*/
template<class It> rand48(It& first, It last) : lcf(first, last) { }
// compiler-generated copy ctor and assignment operator are fine
/** Seeds the generator with the default seed. */
void seed() { seed(static_cast<uint32_t>(1)); }
/**
* Changes the current value x(n) of the generator to (x0 << 16) | 0x330e.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(rand48, result_type, x0)
{ lcf.seed(cnv(x0)); }
/**
* Seeds the generator using values from an iterator range,
* and updates first to point one past the last value consumed.
*/
template<class It> void seed(It& first, It last) { lcf.seed(first,last); }
/**
* Seeds the generator with values produced by @c seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(rand48, SeedSeq, seq)
{ lcf.seed(seq); }
/** Returns the next value of the generator. */
uint32_t operator()() { return static_cast<uint32_t>(lcf() >> 17); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z) { lcf.discard(z); }
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{
for(; first != last; ++first) {
*first = (*this)();
}
}
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes a @c rand48 to a @c std::ostream. */
template<class CharT,class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os, const rand48& r)
{ os << r.lcf; return os; }
/** Reads a @c rand48 from a @c std::istream. */
template<class CharT,class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, rand48& r)
{ is >> r.lcf; return is; }
#endif
/**
* Returns true if the two generators will produce identical
* sequences of values.
*/
friend bool operator==(const rand48& x, const rand48& y)
{ return x.lcf == y.lcf; }
/**
* Returns true if the two generators will produce different
* sequences of values.
*/
friend bool operator!=(const rand48& x, const rand48& y)
{ return !(x == y); }
private:
/// \cond show_private
typedef random::linear_congruential_engine<uint64_t,
// xxxxULL is not portable
uint64_t(0xDEECE66DUL) | (uint64_t(0x5) << 32),
0xB, uint64_t(1)<<48> lcf_t;
lcf_t lcf;
static Boost::uint64_t cnv(Boost::uint32_t x)
{ return (static_cast<uint64_t>(x) << 16) | 0x330e; }
/// \endcond
};
#endif /* !ACTIV_BOOST_NO_INT64_T && !ACTIV_BOOST_NO_INTEGRAL_INT64_T */
} // namespace random
using random::minstd_rand0;
using random::minstd_rand;
using random::rand48;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
@@ -1,217 +0,0 @@
/* boost random/linear_feedback_shift.hpp header file
*
* Copyright Jens Maurer 2002
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
#define ACTIV_BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
#include <iosfwd>
#include <stdexcept>
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
namespace Boost {
namespace random {
/**
* Instatiations of @c linear_feedback_shift model a
* \pseudo_random_number_generator. It was originally
* proposed in
*
* @blockquote
* "Random numbers generated by linear recurrence modulo two.",
* Tausworthe, R. C.(1965), Mathematics of Computation 19, 201-209.
* @endblockquote
*/
template<class UIntType, int w, int k, int q, int s>
class linear_feedback_shift_engine
{
public:
typedef UIntType result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(int, word_size = w);
ACTIV_BOOST_STATIC_CONSTANT(int, exponent1 = k);
ACTIV_BOOST_STATIC_CONSTANT(int, exponent2 = q);
ACTIV_BOOST_STATIC_CONSTANT(int, step_size = s);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, default_seed = 341);
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return wordmask(); }
ACTIV_BOOST_STATIC_ASSERT(w > 0);
ACTIV_BOOST_STATIC_ASSERT(q > 0);
ACTIV_BOOST_STATIC_ASSERT(k < w);
ACTIV_BOOST_STATIC_ASSERT(0 < 2*q && 2*q < k);
ACTIV_BOOST_STATIC_ASSERT(0 < s && s <= k-q);
/** Constructs a @c linear_feedback_shift_engine, using the default seed. */
linear_feedback_shift_engine() { seed(); }
/** Constructs a @c linear_feedback_shift_engine, seeding it with s0. */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(linear_feedback_shift_engine,
UIntType, s0)
{ seed(s0); }
/** Constructs a @c linear_feedback_shift_engine, seeding it with seq. */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(linear_feedback_shift_engine,
SeedSeq, seq)
{ seed(seq); }
/**
* Constructs a @c linear_feedback_shift_engine, seeding it with
* values from the range [first, last).
*/
template<class It> linear_feedback_shift_engine(It& first, It last)
{ seed(first, last); }
/** Seeds a @c linear_feedback_shift_engine with the default seed. */
void seed() { seed(default_seed); }
/** Seeds a @c linear_feedback_shift_engine with @c s0. */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(linear_feedback_shift_engine,
UIntType, s0)
{
value = s0 & wordmask();
if(value < (1 << (w-k))) {
value += 1 << (w-k);
}
}
/**
* Seeds a @c linear_feedback_shift_engine with values
* produced by @c seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(linear_feedback_shift_engine,
SeedSeq, seq)
{ seed(detail::seed_one_int<UIntType, (UIntType(2) << (w - 1))>(seq)); }
/**
* Seeds a @c linear_feedback_shift_engine with values
* from the range [first, last).
*/
template<class It> void seed(It& first, It last)
{
seed(detail::get_one_int<UIntType, (UIntType(2) << (w - 1))>(first, last));
}
/** Returns the next value of the generator. */
result_type operator()()
{
const UIntType b = (((value << q) ^ value) & wordmask()) >> (k-s);
const UIntType mask = (wordmask() << (w-k)) & wordmask();
value = ((value & mask) << s) ^ b;
return value;
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
/**
* Writes the textual representation of the generator to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, linear_feedback_shift_engine, x)
{
os << x.value;
return os;
}
/**
* Reads the textual representation of the generator from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, linear_feedback_shift_engine, x)
{
is >> x.value;
return is;
}
/**
* Returns true if the two generators will produce identical
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(linear_feedback_shift_engine, x, y)
{ return x.value == y.value; }
/**
* Returns true if the two generators will produce different
* sequences of outputs.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(linear_feedback_shift_engine)
private:
/// \cond show_private
static ACTIV_BOOST_CONSTEXPR UIntType wordmask() { return Boost::low_bits_mask_t<w>::sig_bits; }
/// \endcond
UIntType value;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class UIntType, int w, int k, int q, int s>
const bool linear_feedback_shift_engine<UIntType, w, k, q, s>::has_fixed_range;
template<class UIntType, int w, int k, int q, int s>
const int linear_feedback_shift_engine<UIntType, w, k, q, s>::word_size;
template<class UIntType, int w, int k, int q, int s>
const int linear_feedback_shift_engine<UIntType, w, k, q, s>::exponent1;
template<class UIntType, int w, int k, int q, int s>
const int linear_feedback_shift_engine<UIntType, w, k, q, s>::exponent2;
template<class UIntType, int w, int k, int q, int s>
const int linear_feedback_shift_engine<UIntType, w, k, q, s>::step_size;
template<class UIntType, int w, int k, int q, int s>
const UIntType linear_feedback_shift_engine<UIntType, w, k, q, s>::default_seed;
#endif
/// \cond show_deprecated
/** Provided for backwards compatibility. */
template<class UIntType, int w, int k, int q, int s, UIntType v = 0>
class linear_feedback_shift :
public linear_feedback_shift_engine<UIntType, w, k, q, s>
{
typedef linear_feedback_shift_engine<UIntType, w, k, q, s> base_type;
public:
linear_feedback_shift() {}
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(linear_feedback_shift,
SeedSeq, seq)
{ seed(seq); }
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(linear_feedback_shift,
UIntType, val)
{ seed(val); }
template<class It>
linear_feedback_shift(It& first, It last) : base_type(first, last) {}
};
/// \endcond
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP
@@ -1,254 +0,0 @@
/* boost random/lognormal_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp> // std::exp, std::sqrt
#include <cassert>
#include <iosfwd>
#include <istream>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/normal_distribution.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template lognormal_distribution model a
* \random_distribution. Such a distribution produces random numbers
* with \f$\displaystyle p(x) = \frac{1}{x s \sqrt{2\pi}} e^{\frac{-\left(\log(x)-m\right)^2}{2s^2}}\f$
* for x > 0.
*
* @xmlwarning
* This distribution has been updated to match the C++ standard.
* Its behavior has changed from the original
* Boost::lognormal_distribution. A backwards compatible
* version is provided in namespace Boost.
* @endxmlwarning
*/
template<class RealType = double>
class lognormal_distribution
{
public:
typedef typename normal_distribution<RealType>::input_type input_type;
typedef RealType result_type;
class param_type
{
public:
typedef lognormal_distribution distribution_type;
/** Constructs the parameters of a lognormal_distribution. */
explicit param_type(RealType m_arg = RealType(0.0),
RealType s_arg = RealType(1.0))
: _m(m_arg), _s(s_arg) {}
/** Returns the "m" parameter of the distribution. */
RealType m() const { return _m; }
/** Returns the "s" parameter of the distribution. */
RealType s() const { return _s; }
/** Writes the parameters to a std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._m << " " << parm._s;
return os;
}
/** Reads the parameters from a std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._m >> std::ws >> parm._s;
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._m == rhs._m && lhs._s == rhs._s; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _m;
RealType _s;
};
/**
* Constructs a lognormal_distribution. @c m and @c s are the
* parameters of the distribution.
*/
explicit lognormal_distribution(RealType m_arg = RealType(0.0),
RealType s_arg = RealType(1.0))
: _normal(m_arg, s_arg) {}
/**
* Constructs a lognormal_distribution from its parameters.
*/
explicit lognormal_distribution(const param_type& parm)
: _normal(parm.m(), parm.s()) {}
// compiler-generated copy ctor and assignment operator are fine
/** Returns the m parameter of the distribution. */
RealType m() const { return _normal.mean(); }
/** Returns the s parameter of the distribution. */
RealType s() const { return _normal.sigma(); }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return RealType(0); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return (std::numeric_limits<RealType>::infinity)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(m(), s()); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
typedef normal_distribution<RealType> normal_type;
typename normal_type::param_type normal_param(parm.m(), parm.s());
_normal.param(normal_param);
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { _normal.reset(); }
/**
* Returns a random variate distributed according to the
* lognormal distribution.
*/
template<class Engine>
result_type operator()(Engine& eng)
{
using std::exp;
return exp(_normal(eng));
}
/**
* Returns a random variate distributed according to the
* lognormal distribution with parameters specified by param.
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm)
{ return lognormal_distribution(parm)(eng); }
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, lognormal_distribution, ld)
{
os << ld._normal;
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, lognormal_distribution, ld)
{
is >> ld._normal;
return is;
}
/**
* Returns true if the two distributions will produce identical
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(lognormal_distribution, lhs, rhs)
{ return lhs._normal == rhs._normal; }
/**
* Returns true if the two distributions may produce different
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(lognormal_distribution)
private:
normal_distribution<result_type> _normal;
};
} // namespace random
/// \cond show_deprecated
/**
* Provided for backwards compatibility. This class is
* deprecated. It provides the old behavior of lognormal_distribution with
* \f$\displaystyle p(x) = \frac{1}{x \sigma_N \sqrt{2\pi}} e^{\frac{-\left(\log(x)-\mu_N\right)^2}{2\sigma_N^2}}\f$
* for x > 0, where \f$\displaystyle \mu_N = \log\left(\frac{\mu^2}{\sqrt{\sigma^2 + \mu^2}}\right)\f$ and
* \f$\displaystyle \sigma_N = \sqrt{\log\left(1 + \frac{\sigma^2}{\mu^2}\right)}\f$.
*/
template<class RealType = double>
class lognormal_distribution
{
public:
typedef typename normal_distribution<RealType>::input_type input_type;
typedef RealType result_type;
lognormal_distribution(RealType mean_arg = RealType(1.0),
RealType sigma_arg = RealType(1.0))
: _mean(mean_arg), _sigma(sigma_arg)
{
init();
}
RealType mean() const { return _mean; }
RealType sigma() const { return _sigma; }
void reset() { _normal.reset(); }
template<class Engine>
RealType operator()(Engine& eng)
{
using std::exp;
return exp(_normal(eng) * _nsigma + _nmean);
}
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, lognormal_distribution, ld)
{
os << ld._normal << " " << ld._mean << " " << ld._sigma;
return os;
}
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, lognormal_distribution, ld)
{
is >> ld._normal >> std::ws >> ld._mean >> std::ws >> ld._sigma;
ld.init();
return is;
}
private:
/// \cond show_private
void init()
{
using std::log;
using std::sqrt;
_nmean = log(_mean*_mean/sqrt(_sigma*_sigma + _mean*_mean));
_nsigma = sqrt(log(_sigma*_sigma/_mean/_mean+result_type(1)));
}
RealType _mean;
RealType _sigma;
RealType _nmean;
RealType _nsigma;
normal_distribution<RealType> _normal;
/// \endcond
};
/// \endcond
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
@@ -1,682 +0,0 @@
/* boost random/mersenne_twister.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2013-10-14 fixed some warnings with Wshadow (mgaunard)
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_MERSENNE_TWISTER_HPP
#define ACTIV_BOOST_RANDOM_MERSENNE_TWISTER_HPP
#include <iosfwd>
#include <istream>
#include <stdexcept>
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/ptr_helper.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
#include <ActivBoost/random/detail/generator_seed_seq.hpp>
#include <ActivBoost/random/detail/polynomial.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template mersenne_twister_engine model a
* \pseudo_random_number_generator. It uses the algorithm described in
*
* @blockquote
* "Mersenne Twister: A 623-dimensionally equidistributed uniform
* pseudo-random number generator", Makoto Matsumoto and Takuji Nishimura,
* ACM Transactions on Modeling and Computer Simulation: Special Issue on
* Uniform Random Number Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
* @endblockquote
*
* @xmlnote
* The boost variant has been implemented from scratch and does not
* derive from or use mt19937.c provided on the above WWW site. However, it
* was verified that both produce identical output.
* @endxmlnote
*
* The seeding from an integer was changed in April 2005 to address a
* <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html">weakness</a>.
*
* The quality of the generator crucially depends on the choice of the
* parameters. User code should employ one of the sensibly parameterized
* generators such as \mt19937 instead.
*
* The generator requires considerable amounts of memory for the storage of
* its state array. For example, \mt11213b requires about 1408 bytes and
* \mt19937 requires about 2496 bytes.
*/
template<class UIntType,
std::size_t w, std::size_t n, std::size_t m, std::size_t r,
UIntType a, std::size_t u, UIntType d, std::size_t s,
UIntType b, std::size_t t,
UIntType c, std::size_t l, UIntType f>
class mersenne_twister_engine
{
public:
typedef UIntType result_type;
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, word_size = w);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, state_size = n);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, shift_size = m);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, mask_bits = r);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, xor_mask = a);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, tempering_u = u);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, tempering_d = d);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, tempering_s = s);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, tempering_b = b);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, tempering_t = t);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, tempering_c = c);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, tempering_l = l);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, initialization_multiplier = f);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, default_seed = 5489u);
// backwards compatibility
ACTIV_BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, output_u = u);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, output_s = s);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, output_b = b);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, output_t = t);
ACTIV_BOOST_STATIC_CONSTANT(UIntType, output_c = c);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, output_l = l);
// old Boost.Random concept requirements
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
/**
* Constructs a @c mersenne_twister_engine and calls @c seed().
*/
mersenne_twister_engine() { seed(); }
/**
* Constructs a @c mersenne_twister_engine and calls @c seed(value).
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister_engine,
UIntType, value)
{ seed(value); }
template<class It> mersenne_twister_engine(It& first, It last)
{ seed(first,last); }
/**
* Constructs a mersenne_twister_engine and calls @c seed(gen).
*
* @xmlnote
* The copy constructor will always be preferred over
* the templated constructor.
* @endxmlnote
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(mersenne_twister_engine,
SeedSeq, seq)
{ seed(seq); }
// compiler-generated copy ctor and assignment operator are fine
/** Calls @c seed(default_seed). */
void seed() { seed(default_seed); }
/**
* Sets the state x(0) to v mod 2w. Then, iteratively,
* sets x(i) to
* (i + f * (x(i-1) xor (x(i-1) rshift w-2))) mod 2<sup>w</sup>
* for i = 1 .. n-1. x(n) is the first value to be returned by operator().
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister_engine, UIntType, value)
{
// New seeding algorithm from
// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
// In the previous versions, MSBs of the seed affected only MSBs of the
// state x[].
const UIntType mask = (max)();
x[0] = value & mask;
for (i = 1; i < n; i++) {
// See Knuth "The Art of Computer Programming"
// Vol. 2, 3rd ed., page 106
x[i] = (f * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
}
normalize_state();
}
/**
* Seeds a mersenne_twister_engine using values produced by seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(mersenne_twister_engine, SeeqSeq, seq)
{
detail::seed_array_int<w>(seq, x);
i = n;
normalize_state();
}
/** Sets the state of the generator using values from an iterator range. */
template<class It>
void seed(It& first, It last)
{
detail::fill_array_int<w>(first, last, x);
i = n;
normalize_state();
}
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 0; }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return Boost::low_bits_mask_t<w>::sig_bits; }
/** Produces the next value of the generator. */
result_type operator()();
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/**
* Advances the state of the generator by @c z steps. Equivalent to
*
* @code
* for(unsigned long long i = 0; i < z; ++i) {
* gen();
* }
* @endcode
*/
void discard(Boost::uintmax_t z)
{
#ifndef ACTIV_BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD
#define ACTIV_BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD 10000000
#endif
if(z > ACTIV_BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD) {
discard_many(z);
} else {
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
}
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes a mersenne_twister_engine to a @c std::ostream */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const mersenne_twister_engine& mt)
{
mt.print(os);
return os;
}
/** Reads a mersenne_twister_engine from a @c std::istream */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is,
mersenne_twister_engine& mt)
{
for(std::size_t j = 0; j < mt.state_size; ++j)
is >> mt.x[j] >> std::ws;
// MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template
// value parameter "n" available from the class template scope, so use
// the static constant with the same value
mt.i = mt.state_size;
return is;
}
#endif
/**
* Returns true if the two generators are in the same state,
* and will thus produce identical sequences.
*/
friend bool operator==(const mersenne_twister_engine& x_,
const mersenne_twister_engine& y_)
{
if(x_.i < y_.i) return x_.equal_imp(y_);
else return y_.equal_imp(x_);
}
/**
* Returns true if the two generators are in different states.
*/
friend bool operator!=(const mersenne_twister_engine& x_,
const mersenne_twister_engine& y_)
{ return !(x_ == y_); }
private:
/// \cond show_private
void twist();
/**
* Does the work of operator==. This is in a member function
* for portability. Some compilers, such as msvc 7.1 and
* Sun CC 5.10 can't access template parameters or static
* members of the class from inline friend functions.
*
* requires i <= other.i
*/
bool equal_imp(const mersenne_twister_engine& other) const
{
UIntType back[n];
std::size_t offset = other.i - i;
for(std::size_t j = 0; j + offset < n; ++j)
if(x[j] != other.x[j+offset])
return false;
rewind(&back[n-1], offset);
for(std::size_t j = 0; j < offset; ++j)
if(back[j + n - offset] != other.x[j])
return false;
return true;
}
/**
* Does the work of operator<<. This is in a member function
* for portability.
*/
template<class CharT, class Traits>
void print(std::basic_ostream<CharT, Traits>& os) const
{
UIntType data[n];
for(std::size_t j = 0; j < i; ++j) {
data[j + n - i] = x[j];
}
if(i != n) {
rewind(&data[n - i - 1], n - i);
}
os << data[0];
for(std::size_t j = 1; j < n; ++j) {
os << ' ' << data[j];
}
}
/**
* Copies z elements of the state preceding x[0] into
* the array whose last element is last.
*/
void rewind(UIntType* last, std::size_t z) const
{
const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
const UIntType lower_mask = ~upper_mask;
UIntType y0 = x[m-1] ^ x[n-1];
if(y0 & (static_cast<UIntType>(1) << (w-1))) {
y0 = ((y0 ^ a) << 1) | 1;
} else {
y0 = y0 << 1;
}
for(std::size_t sz = 0; sz < z; ++sz) {
UIntType y1 =
rewind_find(last, sz, m-1) ^ rewind_find(last, sz, n-1);
if(y1 & (static_cast<UIntType>(1) << (w-1))) {
y1 = ((y1 ^ a) << 1) | 1;
} else {
y1 = y1 << 1;
}
*(last - sz) = (y0 & upper_mask) | (y1 & lower_mask);
y0 = y1;
}
}
/**
* Converts an arbitrary array into a valid generator state.
* First we normalize x[0], so that it contains the same
* value we would get by running the generator forwards
* and then in reverse. (The low order r bits are redundant).
* Then, if the state consists of all zeros, we set the
* high order bit of x[0] to 1. This function only needs to
* be called by seed, since the state transform preserves
* this relationship.
*/
void normalize_state()
{
const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
const UIntType lower_mask = ~upper_mask;
UIntType y0 = x[m-1] ^ x[n-1];
if(y0 & (static_cast<UIntType>(1) << (w-1))) {
y0 = ((y0 ^ a) << 1) | 1;
} else {
y0 = y0 << 1;
}
x[0] = (x[0] & upper_mask) | (y0 & lower_mask);
// fix up the state if it's all zeroes.
for(std::size_t j = 0; j < n; ++j) {
if(x[j] != 0) return;
}
x[0] = static_cast<UIntType>(1) << (w-1);
}
/**
* Given a pointer to the last element of the rewind array,
* and the current size of the rewind array, finds an element
* relative to the next available slot in the rewind array.
*/
UIntType
rewind_find(UIntType* last, std::size_t size, std::size_t j) const
{
std::size_t index = (j + n - size + n - 1) % n;
if(index < n - size) {
return x[index];
} else {
return *(last - (n - 1 - index));
}
}
/**
* Optimized algorithm for large jumps.
*
* Hiroshi Haramoto, Makoto Matsumoto, and Pierre L'Ecuyer. 2008.
* A Fast Jump Ahead Algorithm for Linear Recurrences in a Polynomial
* Space. In Proceedings of the 5th international conference on
* Sequences and Their Applications (SETA '08).
* DOI=10.1007/978-3-540-85912-3_26
*/
void discard_many(Boost::uintmax_t z)
{
// Compute the minimal polynomial, phi(t)
// This depends only on the transition function,
// which is constant. The characteristic
// polynomial is the same as the minimal
// polynomial for a maximum period generator
// (which should be all specializations of
// mersenne_twister.) Even if it weren't,
// the characteristic polynomial is guaranteed
// to be a multiple of the minimal polynomial,
// which is good enough.
detail::polynomial phi = get_characteristic_polynomial();
// calculate g(t) = t^z % phi(t)
detail::polynomial g = mod_pow_x(z, phi);
// h(s_0, t) = \sum_{i=0}^{2k-1}o(s_i)t^{2k-i-1}
detail::polynomial h;
const std::size_t num_bits = w*n - r;
for(std::size_t j = 0; j < num_bits * 2; ++j) {
// Yes, we're advancing the generator state
// here, but it doesn't matter because
// we're going to overwrite it completely
// in reconstruct_state.
if(i >= n) twist();
h[2*num_bits - j - 1] = x[i++] & UIntType(1);
}
// g(t)h(s_0, t)
detail::polynomial gh = g * h;
detail::polynomial result;
for(std::size_t j = 0; j <= num_bits; ++j) {
result[j] = gh[2*num_bits - j - 1];
}
reconstruct_state(result);
}
static detail::polynomial get_characteristic_polynomial()
{
const std::size_t num_bits = w*n - r;
detail::polynomial helper;
helper[num_bits - 1] = 1;
mersenne_twister_engine tmp;
tmp.reconstruct_state(helper);
// Skip the first num_bits elements, since we
// already know what they are.
for(std::size_t j = 0; j < num_bits; ++j) {
if(tmp.i >= n) tmp.twist();
if(j == num_bits - 1)
assert((tmp.x[tmp.i] & 1) == 1);
else
assert((tmp.x[tmp.i] & 1) == 0);
++tmp.i;
}
detail::polynomial phi;
phi[num_bits] = 1;
detail::polynomial next_bits = tmp.as_polynomial(num_bits);
for(std::size_t j = 0; j < num_bits; ++j) {
int val = next_bits[j] ^ phi[num_bits-j-1];
phi[num_bits-j-1] = val;
if(val) {
for(std::size_t k = j + 1; k < num_bits; ++k) {
phi[num_bits-k-1] ^= next_bits[k-j-1];
}
}
}
return phi;
}
detail::polynomial as_polynomial(std::size_t size) {
detail::polynomial result;
for(std::size_t j = 0; j < size; ++j) {
if(i >= n) twist();
result[j] = x[i++] & UIntType(1);
}
return result;
}
void reconstruct_state(const detail::polynomial& p)
{
const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
const UIntType lower_mask = ~upper_mask;
const std::size_t num_bits = w*n - r;
for(std::size_t j = num_bits - n + 1; j <= num_bits; ++j)
x[j % n] = p[j];
UIntType y0 = 0;
for(std::size_t j = num_bits + 1; j >= n - 1; --j) {
UIntType y1 = x[j % n] ^ x[(j + m) % n];
if(p[j - n + 1])
y1 = (y1 ^ a) << UIntType(1) | UIntType(1);
else
y1 = y1 << UIntType(1);
x[(j + 1) % n] = (y0 & upper_mask) | (y1 & lower_mask);
y0 = y1;
}
i = 0;
}
/// \endcond
// state representation: next output is o(x(i))
// x[0] ... x[k] x[k+1] ... x[n-1] represents
// x(i-k) ... x(i) x(i+1) ... x(i-k+n-1)
UIntType x[n];
std::size_t i;
};
/// \cond show_private
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
#define ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(type, name) \
template<class UIntType, std::size_t w, std::size_t n, std::size_t m, \
std::size_t r, UIntType a, std::size_t u, UIntType d, std::size_t s, \
UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f> \
const type mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::name
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, word_size);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, state_size);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, shift_size);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, mask_bits);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, xor_mask);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_u);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_d);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_s);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_b);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_t);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_c);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_l);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, initialization_multiplier);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, default_seed);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, parameter_a);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_u );
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_s);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_b);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_t);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_c);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_l);
ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT(bool, has_fixed_range);
#undef ACTIV_BOOST_RANDOM_MT_DEFINE_CONSTANT
#endif
template<class UIntType,
std::size_t w, std::size_t n, std::size_t m, std::size_t r,
UIntType a, std::size_t u, UIntType d, std::size_t s,
UIntType b, std::size_t t,
UIntType c, std::size_t l, UIntType f>
void
mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::twist()
{
const UIntType upper_mask = (~static_cast<UIntType>(0)) << r;
const UIntType lower_mask = ~upper_mask;
const std::size_t unroll_factor = 6;
const std::size_t unroll_extra1 = (n-m) % unroll_factor;
const std::size_t unroll_extra2 = (m-1) % unroll_factor;
// split loop to avoid costly modulo operations
{ // extra scope for MSVC brokenness w.r.t. for scope
for(std::size_t j = 0; j < n-m-unroll_extra1; j++) {
UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
x[j] = x[j+m] ^ (y >> 1) ^ ((x[j+1]&1) * a);
}
}
{
for(std::size_t j = n-m-unroll_extra1; j < n-m; j++) {
UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
x[j] = x[j+m] ^ (y >> 1) ^ ((x[j+1]&1) * a);
}
}
{
for(std::size_t j = n-m; j < n-1-unroll_extra2; j++) {
UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
x[j] = x[j-(n-m)] ^ (y >> 1) ^ ((x[j+1]&1) * a);
}
}
{
for(std::size_t j = n-1-unroll_extra2; j < n-1; j++) {
UIntType y = (x[j] & upper_mask) | (x[j+1] & lower_mask);
x[j] = x[j-(n-m)] ^ (y >> 1) ^ ((x[j+1]&1) * a);
}
}
// last iteration
UIntType y = (x[n-1] & upper_mask) | (x[0] & lower_mask);
x[n-1] = x[m-1] ^ (y >> 1) ^ ((x[0]&1) * a);
i = 0;
}
/// \endcond
template<class UIntType,
std::size_t w, std::size_t n, std::size_t m, std::size_t r,
UIntType a, std::size_t u, UIntType d, std::size_t s,
UIntType b, std::size_t t,
UIntType c, std::size_t l, UIntType f>
inline typename
mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::result_type
mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::operator()()
{
if(i == n)
twist();
// Step 4
UIntType z = x[i];
++i;
z ^= ((z >> u) & d);
z ^= ((z << s) & b);
z ^= ((z << t) & c);
z ^= (z >> l);
return z;
}
/**
* The specializations \mt11213b and \mt19937 are from
*
* @blockquote
* "Mersenne Twister: A 623-dimensionally equidistributed
* uniform pseudo-random number generator", Makoto Matsumoto
* and Takuji Nishimura, ACM Transactions on Modeling and
* Computer Simulation: Special Issue on Uniform Random Number
* Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
* @endblockquote
*/
typedef mersenne_twister_engine<uint32_t,32,351,175,19,0xccab8ee7,
11,0xffffffff,7,0x31b6ab00,15,0xffe50000,17,1812433253> mt11213b;
/**
* The specializations \mt11213b and \mt19937 are from
*
* @blockquote
* "Mersenne Twister: A 623-dimensionally equidistributed
* uniform pseudo-random number generator", Makoto Matsumoto
* and Takuji Nishimura, ACM Transactions on Modeling and
* Computer Simulation: Special Issue on Uniform Random Number
* Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
* @endblockquote
*/
typedef mersenne_twister_engine<uint32_t,32,624,397,31,0x9908b0df,
11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253> mt19937;
#if !defined(ACTIV_BOOST_NO_INT64_T) && !defined(ACTIV_BOOST_NO_INTEGRAL_INT64_T)
typedef mersenne_twister_engine<uint64_t,64,312,156,31,
UINT64_C(0xb5026f5aa96619e9),29,UINT64_C(0x5555555555555555),17,
UINT64_C(0x71d67fffeda60000),37,UINT64_C(0xfff7eee000000000),43,
UINT64_C(6364136223846793005)> mt19937_64;
#endif
/// \cond show_deprecated
template<class UIntType,
int w, int n, int m, int r,
UIntType a, int u, std::size_t s,
UIntType b, int t,
UIntType c, int l, UIntType v>
class mersenne_twister :
public mersenne_twister_engine<UIntType,
w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253>
{
typedef mersenne_twister_engine<UIntType,
w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253> base_type;
public:
mersenne_twister() {}
ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(mersenne_twister, Gen, gen)
{ seed(gen); }
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister, UIntType, val)
{ seed(val); }
template<class It>
mersenne_twister(It& first, It last) : base_type(first, last) {}
void seed() { base_type::seed(); }
ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED(mersenne_twister, Gen, gen)
{
detail::generator_seed_seq<Gen> seq(gen);
base_type::seed(seq);
}
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister, UIntType, val)
{ base_type::seed(val); }
template<class It>
void seed(It& first, It last) { base_type::seed(first, last); }
};
/// \endcond
} // namespace random
using random::mt11213b;
using random::mt19937;
using random::mt19937_64;
} // namespace Boost
ACTIV_BOOST_RANDOM_PTR_HELPER_SPEC(Boost::mt11213b)
ACTIV_BOOST_RANDOM_PTR_HELPER_SPEC(Boost::mt19937)
ACTIV_BOOST_RANDOM_PTR_HELPER_SPEC(Boost::mt19937_64)
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_MERSENNE_TWISTER_HPP
-313
View File
@@ -1,313 +0,0 @@
/* boost random/mixmax.hpp header file
*
* Copyright Kostas Savvidis 2008-2019
*
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2019-04-23 created
*/
#ifndef ACTIV_BOOST_RANDOM_MIXMAX_HPP
#define ACTIV_BOOST_RANDOM_MIXMAX_HPP
#include <sstream>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/array.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template mixmax_engine model,
* \pseudo_random_number_generator .
* It uses the MIXMAX generator algorithms from:
*
* @blockquote
* G.K.Savvidy and N.G.Ter-Arutyunian,
* On the Monte Carlo simulation of physical systems,
* J.Comput.Phys. 97, 566 (1991);
* Preprint EPI-865-16-86, Yerevan, Jan. 1986
* http://dx.doi.org/10.1016/0021-9991(91)90015-D
*
* K.Savvidy
* The MIXMAX random number generator
* Comp. Phys. Commun. 196 (2015), pp 161–165
* http://dx.doi.org/10.1016/j.cpc.2015.06.003
*
* K.Savvidy and G.Savvidy
* Spectrum and Entropy of C-systems. MIXMAX random number generator
* Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38
* http://dx.doi.org/10.1016/j.chaos.2016.05.003
* @endblockquote
*
* The generator crucially depends on the choice of the
* parameters. The valid sets of parameters are from the published papers above.
*
*/
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> // MIXMAX TEMPLATE PARAMETERS
class mixmax_engine{
public:
// Interfaces required by C++11 std::random and Boost::random
typedef Boost::uint64_t result_type ;
ACTIV_BOOST_STATIC_CONSTANT(Boost::uint64_t,mixmax_min=0);
ACTIV_BOOST_STATIC_CONSTANT(Boost::uint64_t,mixmax_max=((1ULL<<61)-1));
ACTIV_BOOST_STATIC_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() {return mixmax_min;}
ACTIV_BOOST_STATIC_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() {return mixmax_max;}
static const bool has_fixed_range = false;
ACTIV_BOOST_STATIC_CONSTANT(int,N=Ndim); ///< The main internal parameter, size of the defining MIXMAX matrix
// CONSTRUCTORS:
explicit mixmax_engine(); ///< Constructor, unit vector as initial state, acted on by A^2^512
explicit mixmax_engine(Boost::uint64_t); ///< Constructor, one 64-bit seed
explicit mixmax_engine(uint32_t clusterID, uint32_t machineID, uint32_t runID, uint32_t streamID ); ///< Constructor, four 32-bit seeds for 128-bit seeding flexibility
void seed(Boost::uint64_t seedval=default_seed){seed_uniquestream( &S, 0, 0, (uint32_t)(seedval>>32), (uint32_t)seedval );} ///< seed with one 64-bit seed
private: // DATATYPES
struct rng_state_st{
Boost::array<Boost::uint64_t, Ndim> V;
Boost::uint64_t sumtot;
int counter;
};
typedef struct rng_state_st rng_state_t; // struct alias
rng_state_t S;
public: // SEEDING FUNCTIONS
template<class It> mixmax_engine(It& first, It last) { seed(first,last); }
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(mixmax_engine, SeedSeq, seq){ seed(seq); }
/** Sets the state of the generator using values from an iterator range. */
template<class It>
void seed(It& first, It last){
uint32_t v[4];
detail::fill_array_int<32>(first, last, v);
seed_uniquestream( &S, v[0], v[1], v[2], v[3]);
}
/** Sets the state of the generator using values from a seed_seq. */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(mixmax_engine, SeeqSeq, seq){
uint32_t v[4];
detail::seed_array_int<32>(seq, v);
seed_uniquestream( &S, v[0], v[1], v[2], v[3]);
}
/** return one uint64 between min=0 and max=2^61-1 */
Boost::uint64_t operator()(){
if (S.counter<=(Ndim-1) ){
return S.V[S.counter++];
}else{
S.sumtot = iterate_raw_vec(S.V.data(), S.sumtot);
S.counter=2;
return S.V[1];
}
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last) { detail::generate_from_int(*this, first, last); }
void discard(Boost::uint64_t nsteps) { for(Boost::uint64_t j = 0; j < nsteps; ++j) (*this)(); } ///< discard n steps, required in Boost::random
/** save the state of the RNG to a stream */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<< (std::basic_ostream<CharT,Traits>& ost, const mixmax_engine& me){
ost << Ndim << " " << me.S.counter << " " << me.S.sumtot << " ";
for (int j=0; (j< (Ndim) ); j++) {
ost << (Boost::uint64_t)me.S.V[j] << " ";
}
ost << "\n";
ost.flush();
return ost;
}
/** read the state of the RNG from a stream */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>> (std::basic_istream<CharT,Traits> &in, mixmax_engine& me){
// will set std::ios::failbit if the input format is not right
Boost::array<Boost::uint64_t, Ndim> vec;
Boost::uint64_t sum=0, savedsum=0, counter=0;
in >> counter >> std::ws;
ACTIV_BOOST_ASSERT(counter==Ndim);
in >> counter >> std::ws;
in >> savedsum >> std::ws;
for(int j=0;j<Ndim;j++) {
in >> std::ws >> vec[j] ;
sum=me.MOD_MERSENNE(sum+vec[j]);
}
if (sum == savedsum && counter>0 && counter<Ndim){
me.S.V=vec; me.S.counter = counter; me.S.sumtot=savedsum;
}else{
in.setstate(std::ios::failbit);
}
return in;
}
friend bool operator==(const mixmax_engine & x,
const mixmax_engine & y){return x.S.counter==y.S.counter && x.S.sumtot==y.S.sumtot && x.S.V==y.S.V ;}
friend bool operator!=(const mixmax_engine & x,
const mixmax_engine & y){return !operator==(x,y);}
private:
ACTIV_BOOST_STATIC_CONSTANT(int, BITS=61);
ACTIV_BOOST_STATIC_CONSTANT(Boost::uint64_t, M61=2305843009213693951ULL);
ACTIV_BOOST_STATIC_CONSTANT(Boost::uint64_t, default_seed=1);
inline Boost::uint64_t MOD_MERSENNE(Boost::uint64_t k) {return ((((k)) & M61) + (((k)) >> BITS) );}
inline Boost::uint64_t MULWU(Boost::uint64_t k);
inline void seed_vielbein(rng_state_t* X, unsigned int i); // seeds with the i-th unit vector, i = 0..Ndim-1, for testing only
inline void seed_uniquestream( rng_state_t* Xin, uint32_t clusterID, uint32_t machineID, uint32_t runID, uint32_t streamID );
inline Boost::uint64_t iterate_raw_vec(Boost::uint64_t* Y, Boost::uint64_t sumtotOld);
inline Boost::uint64_t apply_bigskip(Boost::uint64_t* Vout, Boost::uint64_t* Vin, uint32_t clusterID, uint32_t machineID, uint32_t runID, uint32_t streamID );
inline Boost::uint64_t modadd(Boost::uint64_t foo, Boost::uint64_t bar);
inline Boost::uint64_t fmodmulM61(Boost::uint64_t cum, Boost::uint64_t s, Boost::uint64_t a);
};
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::mixmax_engine()
///< constructor, with no params, seeds with seed=0, random numbers are as good as from any other seed
{
seed_uniquestream( &S, 0, 0, 0, default_seed);
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::mixmax_engine(Boost::uint64_t seedval){
///< constructor, one uint64_t seed, random numbers are statistically independent from any two distinct seeds, e.g. consecutive seeds are ok
seed_uniquestream( &S, 0, 0, (uint32_t)(seedval>>32), (uint32_t)seedval );
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::mixmax_engine(uint32_t clusterID, uint32_t machineID, uint32_t runID, uint32_t streamID){
// constructor, four 32-bit seeds for 128-bit seeding flexibility
seed_uniquestream( &S, clusterID, machineID, runID, streamID );
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> uint64_t mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::MULWU (uint64_t k){ return (( (k)<<(SPECIALMUL) & M61) ^ ( (k) >> (BITS-SPECIALMUL)) ) ;}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> Boost::uint64_t mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::iterate_raw_vec(Boost::uint64_t* Y, Boost::uint64_t sumtotOld){
// operates with a raw vector, uses known sum of elements of Y
Boost::uint64_t tempP=0, tempV=sumtotOld;
Y[0] = tempV;
Boost::uint64_t sumtot = Y[0], ovflow = 0; // will keep a running sum of all new elements
for (int i=1; i<Ndim; i++){
Boost::uint64_t tempPO = MULWU(tempP);
tempV = (tempV+tempPO);
tempP = modadd(tempP, Y[i]);
tempV = modadd(tempV, tempP); // new Y[i] = old Y[i] + old partial * m
Y[i] = tempV;
sumtot += tempV; if (sumtot < tempV) {ovflow++;}
}
return MOD_MERSENNE(MOD_MERSENNE(sumtot) + (ovflow <<3 ));
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> void mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::seed_vielbein(rng_state_t* X, unsigned int index){
for (int i=0; i < Ndim; i++){
X->V[i] = 0;
}
if (index<Ndim) { X->V[index] = 1; }else{ X->V[0]=1; }
X->counter = Ndim; // set the counter to Ndim if iteration should happen right away
X->sumtot = 1;
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> void mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::seed_uniquestream( rng_state_t* Xin, uint32_t clusterID, uint32_t machineID, uint32_t runID, uint32_t streamID ){
seed_vielbein(Xin,0);
Xin->sumtot = apply_bigskip(Xin->V.data(), Xin->V.data(), clusterID, machineID, runID, streamID );
Xin->counter = 1;
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> Boost::uint64_t mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::apply_bigskip( Boost::uint64_t* Vout, Boost::uint64_t* Vin, uint32_t clusterID, uint32_t machineID, uint32_t runID, uint32_t streamID ){
/*
makes a derived state vector, Vout, from the mother state vector Vin
by skipping a large number of steps, determined by the given seeding ID's
it is mathematically guaranteed that the substreams derived in this way from the SAME (!!!) Vin will not collide provided
1) at least one bit of ID is different
2) less than 10^100 numbers are drawn from the stream
(this is good enough : a single CPU will not exceed this in the lifetime of the universe, 10^19 sec,
even if it had a clock cycle of Planck time, 10^44 Hz )
Caution: never apply this to a derived vector, just choose some mother vector Vin, for example the unit vector by seed_vielbein(X,0),
and use it in all your runs, just change runID to get completely nonoverlapping streams of random numbers on a different day.
clusterID and machineID are provided for the benefit of large organizations who wish to ensure that a simulation
which is running in parallel on a large number of clusters and machines will have non-colliding source of random numbers.
did i repeat it enough times? the non-collision guarantee is absolute, not probabilistic
*/
const Boost::uint64_t skipMat17[128][17] =
#include "ActivBoost/random/detail/mixmax_skip_N17.ipp"
;
const Boost::uint64_t* skipMat[128];
ACTIV_BOOST_ASSERT(Ndim==17);
for (int i=0; i<128; i++) { skipMat[i] = skipMat17[i];}
uint32_t IDvec[4] = {streamID, runID, machineID, clusterID};
Boost::uint64_t Y[Ndim], cum[Ndim];
Boost::uint64_t sumtot=0;
for (int i=0; i<Ndim; i++) { Y[i] = Vin[i]; sumtot = modadd( sumtot, Vin[i]); } ;
for (int IDindex=0; IDindex<4; IDindex++) { // go from lower order to higher order ID
uint32_t id=IDvec[IDindex];
int r = 0;
while (id){
if (id & 1) {
Boost::uint64_t* rowPtr = (Boost::uint64_t*)skipMat[r + IDindex*8*sizeof(uint32_t)];
for (int i=0; i<Ndim; i++){ cum[i] = 0; }
for (int j=0; j<Ndim; j++){ // j is lag, enumerates terms of the poly
// for zero lag Y is already given
Boost::uint64_t coeff = rowPtr[j]; // same coeff for all i
for (int i =0; i<Ndim; i++){
cum[i] = fmodmulM61( cum[i], coeff , Y[i] ) ;
}
sumtot = iterate_raw_vec(Y, sumtot);
}
sumtot=0;
for (int i=0; i<Ndim; i++){ Y[i] = cum[i]; sumtot = modadd( sumtot, cum[i]); } ;
}
id = (id >> 1); r++; // bring up the r-th bit in the ID
}
}
sumtot=0;
for (int i=0; i<Ndim; i++){ Vout[i] = Y[i]; sumtot = modadd( sumtot, Y[i]); } ; // returns sumtot, and copy the vector over to Vout
return (sumtot) ;
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> inline Boost::uint64_t mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::fmodmulM61(Boost::uint64_t cum, Boost::uint64_t s, Boost::uint64_t a){
// works on all platforms, including 32-bit linux, PPC and PPC64, ARM and Windows
const Boost::uint64_t MASK32=0xFFFFFFFFULL;
Boost::uint64_t o,ph,pl,ah,al;
o=(s)*a;
ph = ((s)>>32);
pl = (s) & MASK32;
ah = a>>32;
al = a & MASK32;
o = (o & M61) + ((ph*ah)<<3) + ((ah*pl+al*ph + ((al*pl)>>32))>>29) ;
o += cum;
o = (o & M61) + ((o>>61));
return o;
}
template <int Ndim, unsigned int SPECIALMUL, Boost::int64_t SPECIAL> Boost::uint64_t mixmax_engine <Ndim, SPECIALMUL, SPECIAL> ::modadd(Boost::uint64_t foo, Boost::uint64_t bar){
return MOD_MERSENNE(foo+bar);
}
/* @copydoc Boost::random::detail::mixmax_engine_doc */
/** Instantiation with a valid parameter set. */
typedef mixmax_engine<17,36,0> mixmax;
}// namespace random
}// namespace Boost
#endif // ACTIV_BOOST_RANDOM_MIXMAX_HPP
@@ -1,220 +0,0 @@
/* boost random/negative_binomial_distribution.hpp header file
*
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_HPP_INCLUDED
#include <iosfwd>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/gamma_distribution.hpp>
#include <ActivBoost/random/poisson_distribution.hpp>
namespace Boost {
namespace random {
/**
* The negative binomial distribution is an integer valued
* distribution with two parameters, @c k and @c p. The
* distribution produces non-negative values.
*
* The distribution function is
* \f$\displaystyle P(i) = {k+i-1\choose i}p^k(1-p)^i\f$.
*
* This implementation uses a gamma-poisson mixture.
*/
template<class IntType = int, class RealType = double>
class negative_binomial_distribution {
public:
typedef IntType result_type;
typedef RealType input_type;
class param_type {
public:
typedef negative_binomial_distribution distribution_type;
/**
* Construct a param_type object. @c k and @c p
* are the parameters of the distribution.
*
* Requires: k >=0 && 0 <= p <= 1
*/
explicit param_type(IntType k_arg = 1, RealType p_arg = RealType (0.5))
: _k(k_arg), _p(p_arg)
{}
/** Returns the @c k parameter of the distribution. */
IntType k() const { return _k; }
/** Returns the @c p parameter of the distribution. */
RealType p() const { return _p; }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const param_type& parm)
{
os << parm._p << " " << parm._k;
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, param_type& parm)
{
is >> parm._p >> std::ws >> parm._k;
return is;
}
#endif
/** Returns true if the parameters have the same values. */
friend bool operator==(const param_type& lhs, const param_type& rhs)
{
return lhs._k == rhs._k && lhs._p == rhs._p;
}
/** Returns true if the parameters have different values. */
friend bool operator!=(const param_type& lhs, const param_type& rhs)
{
return !(lhs == rhs);
}
private:
IntType _k;
RealType _p;
};
/**
* Construct a @c negative_binomial_distribution object. @c k and @c p
* are the parameters of the distribution.
*
* Requires: k >=0 && 0 <= p <= 1
*/
explicit negative_binomial_distribution(IntType k_arg = 1,
RealType p_arg = RealType(0.5))
: _k(k_arg), _p(p_arg)
{}
/**
* Construct an @c negative_binomial_distribution object from the
* parameters.
*/
explicit negative_binomial_distribution(const param_type& parm)
: _k(parm.k()), _p(parm.p())
{}
/**
* Returns a random variate distributed according to the
* negative binomial distribution.
*/
template<class URNG>
IntType operator()(URNG& urng) const
{
gamma_distribution<RealType> gamma(_k, (1-_p)/_p);
poisson_distribution<IntType, RealType> poisson(gamma(urng));
return poisson(urng);
}
/**
* Returns a random variate distributed according to the negative
* binomial distribution with parameters specified by @c param.
*/
template<class URNG>
IntType operator()(URNG& urng, const param_type& parm) const
{
return negative_binomial_distribution(parm)(urng);
}
/** Returns the @c k parameter of the distribution. */
IntType k() const { return _k; }
/** Returns the @c p parameter of the distribution. */
RealType p() const { return _p; }
/** Returns the smallest value that the distribution can produce. */
IntType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const { return 0; }
/** Returns the largest value that the distribution can produce. */
IntType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const
{ return (std::numeric_limits<IntType>::max)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_k, _p); }
/** Sets parameters of the distribution. */
void param(const param_type& parm)
{
_k = parm.k();
_p = parm.p();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const negative_binomial_distribution& bd)
{
os << bd.param();
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is,
negative_binomial_distribution& bd)
{
bd.read(is);
return is;
}
#endif
/** Returns true if the two distributions will produce the same
sequence of values, given equal generators. */
friend bool operator==(const negative_binomial_distribution& lhs,
const negative_binomial_distribution& rhs)
{
return lhs._k == rhs._k && lhs._p == rhs._p;
}
/** Returns true if the two distributions could produce different
sequences of values, given equal generators. */
friend bool operator!=(const negative_binomial_distribution& lhs,
const negative_binomial_distribution& rhs)
{
return !(lhs == rhs);
}
private:
/// @cond \show_private
template<class CharT, class Traits>
void read(std::basic_istream<CharT, Traits>& is) {
param_type parm;
if(is >> parm) {
param(parm);
}
}
// parameters
IntType _k;
RealType _p;
/// @endcond
};
}
}
#endif
@@ -1,360 +0,0 @@
/* boost random/nierderreiter_base2.hpp header file
*
* Copyright Justinas Vygintas Daugmaudis 2010-2018
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef ACTIV_BOOST_RANDOM_NIEDERREITER_BASE2_HPP
#define ACTIV_BOOST_RANDOM_NIEDERREITER_BASE2_HPP
#include <ActivBoost/random/detail/niederreiter_base2_table.hpp>
#include <ActivBoost/random/detail/gray_coded_qrng.hpp>
#include <ActivBoost/dynamic_bitset.hpp>
namespace Boost {
namespace random {
/** @cond */
namespace qrng_detail {
namespace nb2 {
// Return the base 2 logarithm for a given bitset v
template <typename DynamicBitset>
inline typename DynamicBitset::size_type
bitset_log2(const DynamicBitset& v)
{
if (v.none())
Boost::throw_exception( std::invalid_argument("bitset_log2") );
typename DynamicBitset::size_type hibit = v.size() - 1;
while (!v.test(hibit))
--hibit;
return hibit;
}
// Multiply polynomials over Z_2.
template <typename PolynomialT, typename DynamicBitset>
inline void modulo2_multiply(PolynomialT P, DynamicBitset& v, DynamicBitset& pt)
{
pt.reset(); // pt == 0
for (; P; P >>= 1, v <<= 1)
if (P & 1) pt ^= v;
pt.swap(v);
}
// Calculate the values of the constants V(J,R) as
// described in BFN section 3.3.
//
// pb = polynomial defined in section 2.3 of BFN.
template <typename DynamicBitset>
inline void calculate_v(const DynamicBitset& pb,
typename DynamicBitset::size_type kj,
typename DynamicBitset::size_type pb_degree,
DynamicBitset& v)
{
typedef typename DynamicBitset::size_type size_type;
// Now choose values of V in accordance with
// the conditions in section 3.3.
size_type r = 0;
for ( ; r != kj; ++r)
v.reset(r);
// Quoting from BFN: "Our program currently sets each K_q
// equal to eq. This has the effect of setting all unrestricted
// values of v to 1."
for ( ; r < pb_degree; ++r)
v.set(r);
// Calculate the remaining V's using the recursion of section 2.3,
// remembering that the B's have the opposite sign.
for ( ; r != v.size(); ++r)
{
bool term = false;
for (typename DynamicBitset::size_type k = 0; k < pb_degree; ++k)
{
term ^= pb.test(k) & v[r + k - pb_degree];
}
v[r] = term;
}
}
} // namespace nb2
template<typename UIntType, unsigned w, typename Nb2Table>
struct niederreiter_base2_lattice
{
typedef UIntType value_type;
ACTIV_BOOST_STATIC_ASSERT(w > 0u);
ACTIV_BOOST_STATIC_CONSTANT(unsigned, bit_count = w);
private:
typedef std::vector<value_type> container_type;
public:
explicit niederreiter_base2_lattice(std::size_t dimension)
{
resize(dimension);
}
void resize(std::size_t dimension)
{
typedef Boost::dynamic_bitset<> bitset_type;
dimension_assert("Niederreiter base 2", dimension, Nb2Table::max_dimension);
// Initialize the bit array
container_type cj(bit_count * dimension);
// Reserve temporary space for lattice computation
bitset_type v, pb, tmp;
// Compute Niedderreiter base 2 lattice
for (std::size_t dim = 0; dim != dimension; ++dim)
{
const typename Nb2Table::value_type poly = Nb2Table::polynomial(dim);
if (poly > (std::numeric_limits<value_type>::max)()) {
Boost::throw_exception( std::range_error("niederreiter_base2: polynomial value outside the given value type range") );
}
const unsigned degree = qrng_detail::msb(poly); // integer log2(poly)
const unsigned space_required = degree * ((bit_count / degree) + 1); // ~ degree + bit_count
v.resize(degree + bit_count - 1);
// For each dimension, we need to calculate powers of an
// appropriate irreducible polynomial, see Niederreiter
// page 65, just below equation (19).
// Copy the appropriate irreducible polynomial into PX,
// and its degree into E. Set polynomial B = PX ** 0 = 1.
// M is the degree of B. Subsequently B will hold higher
// powers of PX.
pb.resize(space_required); tmp.resize(space_required);
typename bitset_type::size_type kj, pb_degree = 0;
pb.reset(); // pb == 0
pb.set(pb_degree); // set the proper bit for the pb_degree
value_type j = high_bit_mask_t<bit_count - 1>::high_bit;
do
{
// Now choose a value of Kj as defined in section 3.3.
// We must have 0 <= Kj < E*J = M.
// The limit condition on Kj does not seem to be very relevant
// in this program.
kj = pb_degree;
// Now multiply B by PX so B becomes PX**J.
// In section 2.3, the values of Bi are defined with a minus sign :
// don't forget this if you use them later!
nb2::modulo2_multiply(poly, pb, tmp);
pb_degree += degree;
if (pb_degree >= pb.size()) {
// Note that it is quite possible for kj to become bigger than
// the new computed value of pb_degree.
pb_degree = nb2::bitset_log2(pb);
}
// If U = 0, we need to set B to the next power of PX
// and recalculate V.
nb2::calculate_v(pb, kj, pb_degree, v);
// Niederreiter (page 56, after equation (7), defines two
// variables Q and U. We do not need Q explicitly, but we
// do need U.
// Advance Niederreiter's state variables.
for (unsigned u = 0; j && u != degree; ++u, j >>= 1)
{
// Now C is obtained from V. Niederreiter
// obtains A from V (page 65, near the bottom), and then gets
// C from A (page 56, equation (7)). However this can be done
// in one step. Here CI(J,R) corresponds to
// Niederreiter's C(I,J,R), whose values we pack into array
// CJ so that CJ(I,R) holds all the values of C(I,J,R) for J from 1 to NBITS.
for (unsigned r = 0; r != bit_count; ++r) {
value_type& num = cj[dimension * r + dim];
// set the jth bit in num
num = (num & ~j) | (-v[r + u] & j);
}
}
} while (j != 0);
}
bits.swap(cj);
}
typename container_type::const_iterator iter_at(std::size_t n) const
{
ACTIV_BOOST_ASSERT(!(n > bits.size()));
return bits.begin() + n;
}
private:
container_type bits;
};
} // namespace qrng_detail
typedef detail::qrng_tables::niederreiter_base2 default_niederreiter_base2_table;
/** @endcond */
//!Instantiations of class template niederreiter_base2_engine model a \quasi_random_number_generator.
//!The niederreiter_base2_engine uses the algorithm described in
//! \blockquote
//!Bratley, Fox, Niederreiter, ACM Trans. Model. Comp. Sim. 2, 195 (1992).
//! \endblockquote
//!
//!\attention niederreiter_base2_engine skips trivial zeroes at the start of the sequence. For example,
//!the beginning of the 2-dimensional Niederreiter base 2 sequence in @c uniform_01 distribution will look
//!like this:
//!\code{.cpp}
//!0.5, 0.5,
//!0.75, 0.25,
//!0.25, 0.75,
//!0.375, 0.375,
//!0.875, 0.875,
//!...
//!\endcode
//!
//!In the following documentation @c X denotes the concrete class of the template
//!niederreiter_base2_engine returning objects of type @c UIntType, u and v are the values of @c X.
//!
//!Some member functions may throw exceptions of type std::range_error. This
//!happens when the quasi-random domain is exhausted and the generator cannot produce
//!any more values. The length of the low discrepancy sequence is given by
//! \f$L=Dimension \times (2^{w} - 1)\f$.
template<typename UIntType, unsigned w, typename Nb2Table = default_niederreiter_base2_table>
class niederreiter_base2_engine
: public qrng_detail::gray_coded_qrng<
qrng_detail::niederreiter_base2_lattice<UIntType, w, Nb2Table>
>
{
typedef qrng_detail::niederreiter_base2_lattice<UIntType, w, Nb2Table> lattice_t;
typedef qrng_detail::gray_coded_qrng<lattice_t> base_t;
public:
//!Effects: Constructs the default `s`-dimensional Niederreiter base 2 quasi-random number generator.
//!
//!Throws: bad_alloc, invalid_argument, range_error.
explicit niederreiter_base2_engine(std::size_t s)
: base_t(s) // initialize lattice here
{}
#ifdef ACTIV_BOOST_RANDOM_DOXYGEN
//=========================Doxygen needs this!==============================
typedef UIntType result_type;
//!Returns: Tight lower bound on the set of values returned by operator().
//!
//!Throws: nothing.
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_t::min)(); }
//!Returns: Tight upper bound on the set of values returned by operator().
//!
//!Throws: nothing.
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_t::max)(); }
//!Returns: The dimension of of the quasi-random domain.
//!
//!Throws: nothing.
std::size_t dimension() const { return base_t::dimension(); }
//!Effects: Resets the quasi-random number generator state to
//!the one given by the default construction. Equivalent to u.seed(0).
//!
//!\brief Throws: nothing.
void seed()
{
base_t::seed();
}
//!Effects: Effectively sets the quasi-random number generator state to the `init`-th
//!vector in the `s`-dimensional quasi-random domain, where `s` == X::dimension().
//!\code
//!X u, v;
//!for(int i = 0; i < N; ++i)
//! for( std::size_t j = 0; j < u.dimension(); ++j )
//! u();
//!v.seed(N);
//!assert(u() == v());
//!\endcode
//!
//!\brief Throws: range_error.
void seed(UIntType init)
{
base_t::seed(init);
}
//!Returns: Returns a successive element of an `s`-dimensional
//!(s = X::dimension()) vector at each invocation. When all elements are
//!exhausted, X::operator() begins anew with the starting element of a
//!subsequent `s`-dimensional vector.
//!
//!Throws: range_error.
result_type operator()()
{
return base_t::operator()();
}
//!Effects: Advances *this state as if `z` consecutive
//!X::operator() invocations were executed.
//!\code
//!X u = v;
//!for(int i = 0; i < N; ++i)
//! u();
//!v.discard(N);
//!assert(u() == v());
//!\endcode
//!
//!Throws: range_error.
void discard(Boost::uintmax_t z)
{
base_t::discard(z);
}
//!Returns true if the two generators will produce identical sequences of outputs.
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(niederreiter_base2_engine, x, y)
{ return static_cast<const base_t&>(x) == y; }
//!Returns true if the two generators will produce different sequences of outputs.
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(niederreiter_base2_engine)
//!Writes the textual representation of the generator to a @c std::ostream.
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, niederreiter_base2_engine, s)
{ return os << static_cast<const base_t&>(s); }
//!Reads the textual representation of the generator from a @c std::istream.
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, niederreiter_base2_engine, s)
{ return is >> static_cast<base_t&>(s); }
#endif // ACTIV_BOOST_RANDOM_DOXYGEN
};
/**
* @attention This specialization of \niederreiter_base2_engine supports up to 4720 dimensions.
*
* Binary irreducible polynomials (primes in the ring `GF(2)[X]`, evaluated at `X=2`) were generated
* while condition `max(prime)` < 2<sup>16</sup> was satisfied.
*
* There are exactly 4720 such primes, which yields a Niederreiter base 2 table for 4720 dimensions.
*
* However, it is possible to provide your own table to \niederreiter_base2_engine should the default one be insufficient.
*/
typedef niederreiter_base2_engine<Boost::uint_least64_t, 64u, default_niederreiter_base2_table> niederreiter_base2;
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_NIEDERREITER_BASE2_HPP
@@ -1,221 +0,0 @@
/* boost random/non_central_chi_squared_distribution.hpp header file
*
* Copyright Thijs van den Berg 2014
*
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_NON_CENTRAL_CHI_SQUARED_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_NON_CENTRAL_CHI_SQUARED_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <istream>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/uniform_real_distribution.hpp>
#include <ActivBoost/random/normal_distribution.hpp>
#include <ActivBoost/random/chi_squared_distribution.hpp>
#include <ActivBoost/random/poisson_distribution.hpp>
namespace Boost {
namespace random {
/**
* The noncentral chi-squared distribution is a real valued distribution with
* two parameter, @c k and @c lambda. The distribution produces values > 0.
*
* This is the distribution of the sum of squares of k Normal distributed
* variates each with variance one and \f$\lambda\f$ the sum of squares of the
* normal means.
*
* The distribution function is
* \f$\displaystyle P(x) = \frac{1}{2} e^{-(x+\lambda)/2} \left( \frac{x}{\lambda} \right)^{k/4-1/2} I_{k/2-1}( \sqrt{\lambda x} )\f$.
* where \f$\displaystyle I_\nu(z)\f$ is a modified Bessel function of the
* first kind.
*
* The algorithm is taken from
*
* @blockquote
* "Monte Carlo Methods in Financial Engineering", Paul Glasserman,
* 2003, XIII, 596 p, Stochastic Modelling and Applied Probability, Vol. 53,
* ISBN 978-0-387-21617-1, p 124, Fig. 3.5.
* @endblockquote
*/
template <typename RealType = double>
class non_central_chi_squared_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef non_central_chi_squared_distribution distribution_type;
/**
* Constructs the parameters of a non_central_chi_squared_distribution.
* @c k and @c lambda are the parameter of the distribution.
*
* Requires: k > 0 && lambda > 0
*/
explicit
param_type(RealType k_arg = RealType(1), RealType lambda_arg = RealType(1))
: _k(k_arg), _lambda(lambda_arg)
{
ACTIV_BOOST_ASSERT(k_arg > RealType(0));
ACTIV_BOOST_ASSERT(lambda_arg > RealType(0));
}
/** Returns the @c k parameter of the distribution */
RealType k() const { return _k; }
/** Returns the @c lambda parameter of the distribution */
RealType lambda() const { return _lambda; }
/** Writes the parameters of the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._k << ' ' << parm._lambda;
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._k >> std::ws >> parm._lambda;
return is;
}
/** Returns true if the parameters have the same values. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._k == rhs._k && lhs._lambda == rhs._lambda; }
/** Returns true if the parameters have different values. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _k;
RealType _lambda;
};
/**
* Construct a @c non_central_chi_squared_distribution object. @c k and
* @c lambda are the parameter of the distribution.
*
* Requires: k > 0 && lambda > 0
*/
explicit
non_central_chi_squared_distribution(RealType k_arg = RealType(1), RealType lambda_arg = RealType(1))
: _param(k_arg, lambda_arg)
{
ACTIV_BOOST_ASSERT(k_arg > RealType(0));
ACTIV_BOOST_ASSERT(lambda_arg > RealType(0));
}
/**
* Construct a @c non_central_chi_squared_distribution object from the parameter.
*/
explicit
non_central_chi_squared_distribution(const param_type& parm)
: _param( parm )
{ }
/**
* Returns a random variate distributed according to the
* non central chi squared distribution specified by @c param.
*/
template<typename URNG>
RealType operator()(URNG& eng, const param_type& parm) const
{ return non_central_chi_squared_distribution(parm)(eng); }
/**
* Returns a random variate distributed according to the
* non central chi squared distribution.
*/
template<typename URNG>
RealType operator()(URNG& eng)
{
using std::sqrt;
if (_param.k() > 1) {
Boost::random::normal_distribution<RealType> n_dist;
Boost::random::chi_squared_distribution<RealType> c_dist(_param.k() - RealType(1));
RealType _z = n_dist(eng);
RealType _x = c_dist(eng);
RealType term1 = _z + sqrt(_param.lambda());
return term1*term1 + _x;
}
else {
Boost::random::poisson_distribution<> p_dist(_param.lambda()/RealType(2));
Boost::random::poisson_distribution<>::result_type _p = p_dist(eng);
Boost::random::chi_squared_distribution<RealType> c_dist(_param.k() + RealType(2)*_p);
return c_dist(eng);
}
}
/** Returns the @c k parameter of the distribution. */
RealType k() const { return _param.k(); }
/** Returns the @c lambda parameter of the distribution. */
RealType lambda() const { return _param.lambda(); }
/** Returns the parameters of the distribution. */
param_type param() const { return _param; }
/** Sets parameters of the distribution. */
void param(const param_type& parm) { _param = parm; }
/** Resets the distribution, so that subsequent uses does not depend on values already produced by it.*/
void reset() {}
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const
{ return RealType(0); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const
{ return (std::numeric_limits<RealType>::infinity)(); }
/** Writes the parameters of the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, non_central_chi_squared_distribution, dist)
{
os << dist.param();
return os;
}
/** reads the parameters of the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, non_central_chi_squared_distribution, dist)
{
param_type parm;
if(is >> parm) {
dist.param(parm);
}
return is;
}
/** Returns true if two distributions have the same parameters and produce
the same sequence of random numbers given equal generators.*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(non_central_chi_squared_distribution, lhs, rhs)
{ return lhs.param() == rhs.param(); }
/** Returns true if two distributions have different parameters and/or can produce
different sequences of random numbers given equal generators.*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(non_central_chi_squared_distribution)
private:
/// @cond show_private
param_type _param;
/// @endcond
};
} // namespace random
} // namespace Boost
#endif
@@ -1,374 +0,0 @@
/* boost random/normal_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2010-2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <istream>
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/int_float_pair.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/random/exponential_distribution.hpp>
namespace Boost {
namespace random {
namespace detail {
// tables for the ziggurat algorithm
template<class RealType>
struct normal_table {
static const RealType table_x[129];
static const RealType table_y[129];
};
template<class RealType>
const RealType normal_table<RealType>::table_x[129] = {
3.7130862467403632609, 3.4426198558966521214, 3.2230849845786185446, 3.0832288582142137009,
2.9786962526450169606, 2.8943440070186706210, 2.8231253505459664379, 2.7611693723841538514,
2.7061135731187223371, 2.6564064112581924999, 2.6109722484286132035, 2.5690336259216391328,
2.5300096723854666170, 2.4934545220919507609, 2.4590181774083500943, 2.4264206455302115930,
2.3954342780074673425, 2.3658713701139875435, 2.3375752413355307354, 2.3104136836950021558,
2.2842740596736568056, 2.2590595738653295251, 2.2346863955870569803, 2.2110814088747278106,
2.1881804320720206093, 2.1659267937448407377, 2.1442701823562613518, 2.1231657086697899595,
2.1025731351849988838, 2.0824562379877246441, 2.0627822745039633575, 2.0435215366506694976,
2.0246469733729338782, 2.0061338699589668403, 1.9879595741230607243, 1.9701032608497132242,
1.9525457295488889058, 1.9352692282919002011, 1.9182573008597320303, 1.9014946531003176140,
1.8849670357028692380, 1.8686611409895420085, 1.8525645117230870617, 1.8366654602533840447,
1.8209529965910050740, 1.8054167642140487420, 1.7900469825946189862, 1.7748343955807692457,
1.7597702248942318749, 1.7448461281083765085, 1.7300541605582435350, 1.7153867407081165482,
1.7008366185643009437, 1.6863968467734863258, 1.6720607540918522072, 1.6578219209482075462,
1.6436741568569826489, 1.6296114794646783962, 1.6156280950371329644, 1.6017183802152770587,
1.5878768648844007019, 1.5740982160167497219, 1.5603772223598406870, 1.5467087798535034608,
1.5330878776675560787, 1.5195095847593707806, 1.5059690368565502602, 1.4924614237746154081,
1.4789819769830978546, 1.4655259573357946276, 1.4520886428822164926, 1.4386653166774613138,
1.4252512545068615734, 1.4118417124397602509, 1.3984319141236063517, 1.3850170377251486449,
1.3715922024197322698, 1.3581524543224228739, 1.3446927517457130432, 1.3312079496576765017,
1.3176927832013429910, 1.3041418501204215390, 1.2905495919178731508, 1.2769102735516997175,
1.2632179614460282310, 1.2494664995643337480, 1.2356494832544811749, 1.2217602305309625678,
1.2077917504067576028, 1.1937367078237721994, 1.1795873846544607035, 1.1653356361550469083,
1.1509728421389760651, 1.1364898520030755352, 1.1218769225722540661, 1.1071236475235353980,
1.0922188768965537614, 1.0771506248819376573, 1.0619059636836193998, 1.0464709007525802629,
1.0308302360564555907, 1.0149673952392994716, 0.99886423348064351303, 0.98250080350276038481,
0.96585507938813059489, 0.94890262549791195381, 0.93161619660135381056, 0.91396525100880177644,
0.89591535256623852894, 0.87742742909771569142, 0.85845684317805086354, 0.83895221428120745572,
0.81885390668331772331, 0.79809206062627480454, 0.77658398787614838598, 0.75423066443451007146,
0.73091191062188128150, 0.70647961131360803456, 0.68074791864590421664, 0.65347863871504238702,
0.62435859730908822111, 0.59296294244197797913, 0.55869217837551797140, 0.52065603872514491759,
0.47743783725378787681, 0.42654798630330512490, 0.36287143102841830424, 0.27232086470466385065,
0
};
template<class RealType>
const RealType normal_table<RealType>::table_y[129] = {
0, 0.0026696290839025035092, 0.0055489952208164705392, 0.0086244844129304709682,
0.011839478657982313715, 0.015167298010672042468, 0.018592102737165812650, 0.022103304616111592615,
0.025693291936149616572, 0.029356317440253829618, 0.033087886146505155566, 0.036884388786968774128,
0.040742868074790604632, 0.044660862200872429800, 0.048636295860284051878, 0.052667401903503169793,
0.056752663481538584188, 0.060890770348566375972, 0.065080585213631873753, 0.069321117394180252601,
0.073611501884754893389, 0.077950982514654714188, 0.082338898242957408243, 0.086774671895542968998,
0.091257800827634710201, 0.09578784912257815216, 0.10036444102954554013, 0.10498725541035453978,
0.10965602101581776100, 0.11437051244988827452, 0.11913054670871858767, 0.12393598020398174246,
0.12878670619710396109, 0.13368265258464764118, 0.13862377998585103702, 0.14361008009193299469,
0.14864157424369696566, 0.15371831220958657066, 0.15884037114093507813, 0.16400785468492774791,
0.16922089223892475176, 0.17447963833240232295, 0.17978427212496211424, 0.18513499701071343216,
0.19053204032091372112, 0.19597565311811041399, 0.20146611007620324118, 0.20700370944187380064,
0.21258877307373610060, 0.21822164655637059599, 0.22390269938713388747, 0.22963232523430270355,
0.23541094226572765600, 0.24123899354775131610, 0.24711694751469673582, 0.25304529850976585934,
0.25902456739871074263, 0.26505530225816194029, 0.27113807914102527343, 0.27727350292189771153,
0.28346220822601251779, 0.28970486044581049771, 0.29600215684985583659, 0.30235482778947976274,
0.30876363800925192282, 0.31522938806815752222, 0.32175291587920862031, 0.32833509837615239609,
0.33497685331697116147, 0.34167914123501368412, 0.34844296754987246935, 0.35526938485154714435,
0.36215949537303321162, 0.36911445366827513952, 0.37613546951445442947, 0.38322381105988364587,
0.39038080824138948916, 0.39760785649804255208, 0.40490642081148835099, 0.41227804010702462062,
0.41972433205403823467, 0.42724699830956239880, 0.43484783025466189638, 0.44252871528024661483,
0.45029164368692696086, 0.45813871627287196483, 0.46607215269457097924, 0.47409430069824960453,
0.48220764633483869062, 0.49041482528932163741, 0.49871863547658432422, 0.50712205108130458951,
0.51562823824987205196, 0.52424057267899279809, 0.53296265938998758838, 0.54179835503172412311,
0.55075179312105527738, 0.55982741271069481791, 0.56902999107472161225, 0.57836468112670231279,
0.58783705444182052571, 0.59745315095181228217, 0.60721953663260488551, 0.61714337082656248870,
0.62723248525781456578, 0.63749547734314487428, 0.64794182111855080873, 0.65858200005865368016,
0.66942766735770616891, 0.68049184100641433355, 0.69178914344603585279, 0.70333609902581741633,
0.71515150742047704368, 0.72725691835450587793, 0.73967724368333814856, 0.75244155918570380145,
0.76558417390923599480, 0.77914608594170316563, 0.79317701178385921053, 0.80773829469612111340,
0.82290721139526200050, 0.83878360531064722379, 0.85550060788506428418, 0.87324304892685358879,
0.89228165080230272301, 0.91304364799203805999, 0.93628268170837107547, 0.96359969315576759960,
1
};
template<class RealType = double>
struct unit_normal_distribution
{
template<class Engine>
RealType operator()(Engine& eng) {
const double * const table_x = normal_table<double>::table_x;
const double * const table_y = normal_table<double>::table_y;
for(;;) {
std::pair<RealType, int> vals = generate_int_float_pair<RealType, 8>(eng);
int i = vals.second;
int sign = (i & 1) * 2 - 1;
i = i >> 1;
RealType x = vals.first * RealType(table_x[i]);
if(x < table_x[i + 1]) return x * sign;
if(i == 0) return generate_tail(eng) * sign;
RealType y01 = uniform_01<RealType>()(eng);
RealType y = RealType(table_y[i]) + y01 * RealType(table_y[i + 1] - table_y[i]);
// These store the value y - bound, or something proportional to that difference:
RealType y_above_ubound, y_above_lbound;
// There are three cases to consider:
// - convex regions (where x[i] > x[j] >= 1)
// - concave regions (where 1 <= x[i] < x[j])
// - region containing the inflection point (where x[i] > 1 > x[j])
// For convex (concave), exp^(-x^2/2) is bounded below (above) by the tangent at
// (x[i],y[i]) and is bounded above (below) by the diagonal line from (x[i+1],y[i+1]) to
// (x[i],y[i]).
//
// *If* the inflection point region satisfies slope(x[i+1]) < slope(diagonal), then we
// can treat the inflection region as a convex region: this condition is necessary and
// sufficient to ensure that the curve lies entirely below the diagonal (that, in turn,
// also implies that it will be above the tangent at x[i]).
//
// For the current table size (128), this is satisfied: slope(x[i+1]) = -0.60653 <
// slope(diag) = -0.60649, and so we have only two cases below instead of three.
if (table_x[i] >= 1) { // convex (incl. inflection)
y_above_ubound = RealType(table_x[i] - table_x[i+1]) * y01 - (RealType(table_x[i]) - x);
y_above_lbound = y - (RealType(table_y[i]) + (RealType(table_x[i]) - x) * RealType(table_y[i]) * RealType(table_x[i]));
}
else { // concave
y_above_lbound = RealType(table_x[i] - table_x[i+1]) * y01 - (RealType(table_x[i]) - x);
y_above_ubound = y - (RealType(table_y[i]) + (RealType(table_x[i]) - x) * RealType(table_y[i]) * RealType(table_x[i]));
}
if (y_above_ubound < 0 // if above the upper bound reject immediately
&&
(
y_above_lbound < 0 // If below the lower bound accept immediately
||
y < f(x) // Otherwise it's between the bounds and we need a full check
)
) {
return x * sign;
}
}
}
static RealType f(RealType x) {
using std::exp;
return exp(-(x*x/2));
}
// Generate from the tail using rejection sampling from the exponential(x_1) distribution,
// shifted by x_1. This looks a little different from the usual rejection sampling because it
// transforms the condition by taking the log of both sides, thus avoiding the costly exp() call
// on the RHS, then takes advantage of the fact that -log(unif01) is simply generating an
// exponential (by inverse cdf sampling) by replacing the log(unif01) on the LHS with a
// exponential(1) draw, y.
template<class Engine>
RealType generate_tail(Engine& eng) {
const RealType tail_start = RealType(normal_table<double>::table_x[1]);
Boost::random::exponential_distribution<RealType> exp_x(tail_start);
Boost::random::exponential_distribution<RealType> exp_y;
for(;;) {
RealType x = exp_x(eng);
RealType y = exp_y(eng);
// If we were doing non-transformed rejection sampling, this condition would be:
// if (unif01 < exp(-.5*x*x)) return x + tail_start;
if(2*y > x*x) return x + tail_start;
}
}
};
} // namespace detail
/**
* Instantiations of class template normal_distribution model a
* \random_distribution. Such a distribution produces random numbers
* @c x distributed with probability density function
* \f$\displaystyle p(x) =
* \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
* \f$,
* where mean and sigma are the parameters of the distribution.
*
* The implementation uses the "ziggurat" algorithm, as described in
*
* @blockquote
* "The Ziggurat Method for Generating Random Variables",
* George Marsaglia and Wai Wan Tsang, Journal of Statistical Software,
* Volume 5, Number 8 (2000), 1-7.
* @endblockquote
*/
template<class RealType = double>
class normal_distribution
{
public:
typedef RealType input_type;
typedef RealType result_type;
class param_type {
public:
typedef normal_distribution distribution_type;
/**
* Constructs a @c param_type with a given mean and
* standard deviation.
*
* Requires: sigma >= 0
*/
explicit param_type(RealType mean_arg = RealType(0.0),
RealType sigma_arg = RealType(1.0))
: _mean(mean_arg),
_sigma(sigma_arg)
{}
/** Returns the mean of the distribution. */
RealType mean() const { return _mean; }
/** Returns the standand deviation of the distribution. */
RealType sigma() const { return _sigma; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._mean << " " << parm._sigma ; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._mean >> std::ws >> parm._sigma; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._mean == rhs._mean && lhs._sigma == rhs._sigma; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _mean;
RealType _sigma;
};
/**
* Constructs a @c normal_distribution object. @c mean and @c sigma are
* the parameters for the distribution.
*
* Requires: sigma >= 0
*/
explicit normal_distribution(const RealType& mean_arg = RealType(0.0),
const RealType& sigma_arg = RealType(1.0))
: _mean(mean_arg), _sigma(sigma_arg)
{
ACTIV_BOOST_ASSERT(_sigma >= RealType(0));
}
/**
* Constructs a @c normal_distribution object from its parameters.
*/
explicit normal_distribution(const param_type& parm)
: _mean(parm.mean()), _sigma(parm.sigma())
{}
/** Returns the mean of the distribution. */
RealType mean() const { return _mean; }
/** Returns the standard deviation of the distribution. */
RealType sigma() const { return _sigma; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return -std::numeric_limits<RealType>::infinity(); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return std::numeric_limits<RealType>::infinity(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_mean, _sigma); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_mean = parm.mean();
_sigma = parm.sigma();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Returns a normal variate. */
template<class Engine>
result_type operator()(Engine& eng)
{
detail::unit_normal_distribution<RealType> impl;
return impl(eng) * _sigma + _mean;
}
/** Returns a normal variate with parameters specified by @c param. */
template<class URNG>
result_type operator()(URNG& urng, const param_type& parm)
{
return normal_distribution(parm)(urng);
}
/** Writes a @c normal_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, normal_distribution, nd)
{
os << nd._mean << " " << nd._sigma;
return os;
}
/** Reads a @c normal_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, normal_distribution, nd)
{
is >> std::ws >> nd._mean >> std::ws >> nd._sigma;
return is;
}
/**
* Returns true if the two instances of @c normal_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(normal_distribution, lhs, rhs)
{
return lhs._mean == rhs._mean && lhs._sigma == rhs._sigma;
}
/**
* Returns true if the two instances of @c normal_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(normal_distribution)
private:
RealType _mean, _sigma;
};
} // namespace random
using random::normal_distribution;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_NORMAL_DISTRIBUTION_HPP
@@ -1,466 +0,0 @@
/* boost random/piecewise_constant_distribution.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_HPP_INCLUDED
#include <vector>
#include <numeric>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/uniform_real.hpp>
#include <ActivBoost/random/discrete_distribution.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/vector_io.hpp>
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
#include <ActivBoost/range/begin.hpp>
#include <ActivBoost/range/end.hpp>
namespace Boost {
namespace random {
/**
* The class @c piecewise_constant_distribution models a \random_distribution.
*/
template<class RealType = double, class WeightType = double>
class piecewise_constant_distribution {
public:
typedef std::size_t input_type;
typedef RealType result_type;
class param_type {
public:
typedef piecewise_constant_distribution distribution_type;
/**
* Constructs a @c param_type object, representing a distribution
* that produces values uniformly distributed in the range [0, 1).
*/
param_type()
{
_weights.push_back(WeightType(1));
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
}
/**
* Constructs a @c param_type object from two iterator ranges
* containing the interval boundaries and the interval weights.
* If there are less than two boundaries, then this is equivalent to
* the default constructor and creates a single interval, [0, 1).
*
* The values of the interval boundaries must be strictly
* increasing, and the number of weights must be one less than
* the number of interval boundaries. If there are extra
* weights, they are ignored.
*/
template<class IntervalIter, class WeightIter>
param_type(IntervalIter intervals_first, IntervalIter intervals_last,
WeightIter weight_first)
: _intervals(intervals_first, intervals_last)
{
if(_intervals.size() < 2) {
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
_weights.push_back(WeightType(1));
} else {
_weights.reserve(_intervals.size() - 1);
for(std::size_t i = 0; i < _intervals.size() - 1; ++i) {
_weights.push_back(*weight_first++);
}
}
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a @c param_type object from an
* initializer_list containing the interval boundaries
* and a unary function specifying the weights. Each
* weight is determined by calling the function at the
* midpoint of the corresponding interval.
*
* If the initializer_list contains less than two elements,
* this is equivalent to the default constructor and the
* distribution will produce values uniformly distributed
* in the range [0, 1).
*/
template<class T, class F>
param_type(const std::initializer_list<T>& il, F f)
: _intervals(il.begin(), il.end())
{
if(_intervals.size() < 2) {
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
_weights.push_back(WeightType(1));
} else {
_weights.reserve(_intervals.size() - 1);
for(std::size_t i = 0; i < _intervals.size() - 1; ++i) {
RealType midpoint = (_intervals[i] + _intervals[i + 1]) / 2;
_weights.push_back(f(midpoint));
}
}
}
#endif
/**
* Constructs a @c param_type object from Boost.Range
* ranges holding the interval boundaries and the weights. If
* there are less than two interval boundaries, this is equivalent
* to the default constructor and the distribution will produce
* values uniformly distributed in the range [0, 1). The
* number of weights must be one less than the number of
* interval boundaries.
*/
template<class IntervalRange, class WeightRange>
param_type(const IntervalRange& intervals_arg,
const WeightRange& weights_arg)
: _intervals(Boost::begin(intervals_arg), Boost::end(intervals_arg)),
_weights(Boost::begin(weights_arg), Boost::end(weights_arg))
{
if(_intervals.size() < 2) {
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
_weights.push_back(WeightType(1));
}
}
/**
* Constructs the parameters for a distribution that approximates a
* function. The range of the distribution is [xmin, xmax). This
* range is divided into nw equally sized intervals and the weights
* are found by calling the unary function f on the midpoints of the
* intervals.
*/
template<class F>
param_type(std::size_t nw, RealType xmin, RealType xmax, F f)
{
std::size_t n = (nw == 0) ? 1 : nw;
double delta = (xmax - xmin) / n;
ACTIV_BOOST_ASSERT(delta > 0);
for(std::size_t k = 0; k < n; ++k) {
_weights.push_back(f(xmin + k*delta + delta/2));
_intervals.push_back(xmin + k*delta);
}
_intervals.push_back(xmax);
}
/** Returns a vector containing the interval boundaries. */
std::vector<RealType> intervals() const { return _intervals; }
/**
* Returns a vector containing the probability densities
* over all the intervals of the distribution.
*/
std::vector<RealType> densities() const
{
RealType sum = std::accumulate(_weights.begin(), _weights.end(),
static_cast<RealType>(0));
std::vector<RealType> result;
result.reserve(_weights.size());
for(std::size_t i = 0; i < _weights.size(); ++i) {
RealType width = _intervals[i + 1] - _intervals[i];
result.push_back(_weights[i] / (sum * width));
}
return result;
}
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
detail::print_vector(os, parm._intervals);
detail::print_vector(os, parm._weights);
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
std::vector<RealType> new_intervals;
std::vector<WeightType> new_weights;
detail::read_vector(is, new_intervals);
detail::read_vector(is, new_weights);
if(is) {
parm._intervals.swap(new_intervals);
parm._weights.swap(new_weights);
}
return is;
}
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{
return lhs._intervals == rhs._intervals
&& lhs._weights == rhs._weights;
}
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
friend class piecewise_constant_distribution;
std::vector<RealType> _intervals;
std::vector<WeightType> _weights;
};
/**
* Creates a new @c piecewise_constant_distribution with
* a single interval, [0, 1).
*/
piecewise_constant_distribution()
{
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
}
/**
* Constructs a piecewise_constant_distribution from two iterator ranges
* containing the interval boundaries and the interval weights.
* If there are less than two boundaries, then this is equivalent to
* the default constructor and creates a single interval, [0, 1).
*
* The values of the interval boundaries must be strictly
* increasing, and the number of weights must be one less than
* the number of interval boundaries. If there are extra
* weights, they are ignored.
*
* For example,
*
* @code
* double intervals[] = { 0.0, 1.0, 4.0 };
* double weights[] = { 1.0, 1.0 };
* piecewise_constant_distribution<> dist(
* &intervals[0], &intervals[0] + 3, &weights[0]);
* @endcode
*
* The distribution has a 50% chance of producing a
* value between 0 and 1 and a 50% chance of producing
* a value between 1 and 4.
*/
template<class IntervalIter, class WeightIter>
piecewise_constant_distribution(IntervalIter first_interval,
IntervalIter last_interval,
WeightIter first_weight)
: _intervals(first_interval, last_interval)
{
if(_intervals.size() < 2) {
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
} else {
std::vector<WeightType> actual_weights;
actual_weights.reserve(_intervals.size() - 1);
for(std::size_t i = 0; i < _intervals.size() - 1; ++i) {
actual_weights.push_back(*first_weight++);
}
typedef discrete_distribution<std::size_t, WeightType> bins_type;
typename bins_type::param_type bins_param(actual_weights);
_bins.param(bins_param);
}
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a piecewise_constant_distribution from an
* initializer_list containing the interval boundaries
* and a unary function specifying the weights. Each
* weight is determined by calling the function at the
* midpoint of the corresponding interval.
*
* If the initializer_list contains less than two elements,
* this is equivalent to the default constructor and the
* distribution will produce values uniformly distributed
* in the range [0, 1).
*/
template<class T, class F>
piecewise_constant_distribution(std::initializer_list<T> il, F f)
: _intervals(il.begin(), il.end())
{
if(_intervals.size() < 2) {
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
} else {
std::vector<WeightType> actual_weights;
actual_weights.reserve(_intervals.size() - 1);
for(std::size_t i = 0; i < _intervals.size() - 1; ++i) {
RealType midpoint = (_intervals[i] + _intervals[i + 1]) / 2;
actual_weights.push_back(f(midpoint));
}
typedef discrete_distribution<std::size_t, WeightType> bins_type;
typename bins_type::param_type bins_param(actual_weights);
_bins.param(bins_param);
}
}
#endif
/**
* Constructs a piecewise_constant_distribution from Boost.Range
* ranges holding the interval boundaries and the weights. If
* there are less than two interval boundaries, this is equivalent
* to the default constructor and the distribution will produce
* values uniformly distributed in the range [0, 1). The
* number of weights must be one less than the number of
* interval boundaries.
*/
template<class IntervalsRange, class WeightsRange>
piecewise_constant_distribution(const IntervalsRange& intervals_arg,
const WeightsRange& weights_arg)
: _bins(weights_arg),
_intervals(Boost::begin(intervals_arg), Boost::end(intervals_arg))
{
if(_intervals.size() < 2) {
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
}
}
/**
* Constructs a piecewise_constant_distribution that approximates a
* function. The range of the distribution is [xmin, xmax). This
* range is divided into nw equally sized intervals and the weights
* are found by calling the unary function f on the midpoints of the
* intervals.
*/
template<class F>
piecewise_constant_distribution(std::size_t nw,
RealType xmin,
RealType xmax,
F f)
: _bins(nw, xmin, xmax, f)
{
if(nw == 0) { nw = 1; }
RealType delta = (xmax - xmin) / nw;
_intervals.reserve(nw + 1);
for(std::size_t i = 0; i < nw; ++i) {
_intervals.push_back(xmin + i * delta);
}
_intervals.push_back(xmax);
}
/**
* Constructs a piecewise_constant_distribution from its parameters.
*/
explicit piecewise_constant_distribution(const param_type& parm)
: _bins(parm._weights),
_intervals(parm._intervals)
{
}
/**
* Returns a value distributed according to the parameters of the
* piecewist_constant_distribution.
*/
template<class URNG>
RealType operator()(URNG& urng) const
{
std::size_t i = _bins(urng);
return uniform_real<RealType>(_intervals[i], _intervals[i+1])(urng);
}
/**
* Returns a value distributed according to the parameters
* specified by param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return piecewise_constant_distribution(parm)(urng);
}
/** Returns the smallest value that the distribution can produce. */
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return _intervals.front(); }
/** Returns the largest value that the distribution can produce. */
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return _intervals.back(); }
/**
* Returns a vector containing the probability density
* over each interval.
*/
std::vector<RealType> densities() const
{
std::vector<RealType> result(_bins.probabilities());
for(std::size_t i = 0; i < result.size(); ++i) {
result[i] /= (_intervals[i+1] - _intervals[i]);
}
return(result);
}
/** Returns a vector containing the interval boundaries. */
std::vector<RealType> intervals() const { return _intervals; }
/** Returns the parameters of the distribution. */
param_type param() const
{
return param_type(_intervals, _bins.probabilities());
}
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
std::vector<RealType> new_intervals(parm._intervals);
typedef discrete_distribution<std::size_t, WeightType> bins_type;
typename bins_type::param_type bins_param(parm._weights);
_bins.param(bins_param);
_intervals.swap(new_intervals);
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { _bins.reset(); }
/** Writes a distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(
os, piecewise_constant_distribution, pcd)
{
os << pcd.param();
return os;
}
/** Reads a distribution from a @c std::istream */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(
is, piecewise_constant_distribution, pcd)
{
param_type parm;
if(is >> parm) {
pcd.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will return the
* same sequence of values, when passed equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(
piecewise_constant_distribution, lhs, rhs)
{
return lhs._bins == rhs._bins && lhs._intervals == rhs._intervals;
}
/**
* Returns true if the two distributions may return different
* sequences of values, when passed equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(piecewise_constant_distribution)
private:
discrete_distribution<std::size_t, WeightType> _bins;
std::vector<RealType> _intervals;
};
}
}
#endif
@@ -1,531 +0,0 @@
/* boost random/piecewise_linear_distribution.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_HPP_INCLUDED
#define ACTIV_BOOST_RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_HPP_INCLUDED
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/uniform_real.hpp>
#include <ActivBoost/random/discrete_distribution.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/vector_io.hpp>
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
#include <ActivBoost/range/begin.hpp>
#include <ActivBoost/range/end.hpp>
namespace Boost {
namespace random {
/**
* The class @c piecewise_linear_distribution models a \random_distribution.
*/
template<class RealType = double>
class piecewise_linear_distribution {
public:
typedef std::size_t input_type;
typedef RealType result_type;
class param_type {
public:
typedef piecewise_linear_distribution distribution_type;
/**
* Constructs a @c param_type object, representing a distribution
* that produces values uniformly distributed in the range [0, 1).
*/
param_type()
{
_weights.push_back(RealType(1));
_weights.push_back(RealType(1));
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
}
/**
* Constructs a @c param_type object from two iterator ranges
* containing the interval boundaries and weights at the boundaries.
* If there are fewer than two boundaries, then this is equivalent to
* the default constructor and the distribution will produce values
* uniformly distributed in the range [0, 1).
*
* The values of the interval boundaries must be strictly
* increasing, and the number of weights must be the same as
* the number of interval boundaries. If there are extra
* weights, they are ignored.
*/
template<class IntervalIter, class WeightIter>
param_type(IntervalIter intervals_first, IntervalIter intervals_last,
WeightIter weight_first)
: _intervals(intervals_first, intervals_last)
{
if(_intervals.size() < 2) {
_intervals.clear();
_weights.push_back(RealType(1));
_weights.push_back(RealType(1));
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
} else {
_weights.reserve(_intervals.size());
for(std::size_t i = 0; i < _intervals.size(); ++i) {
_weights.push_back(*weight_first++);
}
}
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a @c param_type object from an initializer_list
* containing the interval boundaries and a unary function
* specifying the weights at the boundaries. Each weight is
* determined by calling the function at the corresponding point.
*
* If the initializer_list contains fewer than two elements,
* this is equivalent to the default constructor and the
* distribution will produce values uniformly distributed
* in the range [0, 1).
*/
template<class T, class F>
param_type(const std::initializer_list<T>& il, F f)
: _intervals(il.begin(), il.end())
{
if(_intervals.size() < 2) {
_intervals.clear();
_weights.push_back(RealType(1));
_weights.push_back(RealType(1));
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
} else {
_weights.reserve(_intervals.size());
for(typename std::vector<RealType>::const_iterator
iter = _intervals.begin(), end = _intervals.end();
iter != end; ++iter)
{
_weights.push_back(f(*iter));
}
}
}
#endif
/**
* Constructs a @c param_type object from Boost.Range ranges holding
* the interval boundaries and the weights at the boundaries. If
* there are fewer than two interval boundaries, this is equivalent
* to the default constructor and the distribution will produce
* values uniformly distributed in the range [0, 1). The
* number of weights must be equal to the number of
* interval boundaries.
*/
template<class IntervalRange, class WeightRange>
param_type(const IntervalRange& intervals_arg,
const WeightRange& weights_arg)
: _intervals(Boost::begin(intervals_arg), Boost::end(intervals_arg)),
_weights(Boost::begin(weights_arg), Boost::end(weights_arg))
{
if(_intervals.size() < 2) {
_weights.clear();
_weights.push_back(RealType(1));
_weights.push_back(RealType(1));
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
}
}
/**
* Constructs the parameters for a distribution that approximates a
* function. The range of the distribution is [xmin, xmax). This
* range is divided into nw equally sized intervals and the weights
* are found by calling the unary function f on the boundaries of the
* intervals.
*/
template<class F>
param_type(std::size_t nw, RealType xmin, RealType xmax, F f)
{
std::size_t n = (nw == 0) ? 1 : nw;
double delta = (xmax - xmin) / n;
ACTIV_BOOST_ASSERT(delta > 0);
for(std::size_t k = 0; k < n; ++k) {
_weights.push_back(f(xmin + k*delta));
_intervals.push_back(xmin + k*delta);
}
_weights.push_back(f(xmax));
_intervals.push_back(xmax);
}
/** Returns a vector containing the interval boundaries. */
std::vector<RealType> intervals() const { return _intervals; }
/**
* Returns a vector containing the probability densities
* at all the interval boundaries.
*/
std::vector<RealType> densities() const
{
RealType sum = static_cast<RealType>(0);
for(std::size_t i = 0; i < _intervals.size() - 1; ++i) {
RealType width = _intervals[i + 1] - _intervals[i];
sum += (_weights[i] + _weights[i + 1]) * width / 2;
}
std::vector<RealType> result;
result.reserve(_weights.size());
for(typename std::vector<RealType>::const_iterator
iter = _weights.begin(), end = _weights.end();
iter != end; ++iter)
{
result.push_back(*iter / sum);
}
return result;
}
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
detail::print_vector(os, parm._intervals);
detail::print_vector(os, parm._weights);
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
std::vector<RealType> new_intervals;
std::vector<RealType> new_weights;
detail::read_vector(is, new_intervals);
detail::read_vector(is, new_weights);
if(is) {
parm._intervals.swap(new_intervals);
parm._weights.swap(new_weights);
}
return is;
}
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{
return lhs._intervals == rhs._intervals
&& lhs._weights == rhs._weights;
}
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
friend class piecewise_linear_distribution;
std::vector<RealType> _intervals;
std::vector<RealType> _weights;
};
/**
* Creates a new @c piecewise_linear_distribution that
* produces values uniformly distributed in the range [0, 1).
*/
piecewise_linear_distribution()
{
default_init();
}
/**
* Constructs a piecewise_linear_distribution from two iterator ranges
* containing the interval boundaries and the weights at the boundaries.
* If there are fewer than two boundaries, then this is equivalent to
* the default constructor and creates a distribution that
* produces values uniformly distributed in the range [0, 1).
*
* The values of the interval boundaries must be strictly
* increasing, and the number of weights must be equal to
* the number of interval boundaries. If there are extra
* weights, they are ignored.
*
* For example,
*
* @code
* double intervals[] = { 0.0, 1.0, 2.0 };
* double weights[] = { 0.0, 1.0, 0.0 };
* piecewise_constant_distribution<> dist(
* &intervals[0], &intervals[0] + 3, &weights[0]);
* @endcode
*
* produces a triangle distribution.
*/
template<class IntervalIter, class WeightIter>
piecewise_linear_distribution(IntervalIter first_interval,
IntervalIter last_interval,
WeightIter first_weight)
: _intervals(first_interval, last_interval)
{
if(_intervals.size() < 2) {
default_init();
} else {
_weights.reserve(_intervals.size());
for(std::size_t i = 0; i < _intervals.size(); ++i) {
_weights.push_back(*first_weight++);
}
init();
}
}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/**
* Constructs a piecewise_linear_distribution from an
* initializer_list containing the interval boundaries
* and a unary function specifying the weights. Each
* weight is determined by calling the function at the
* corresponding interval boundary.
*
* If the initializer_list contains fewer than two elements,
* this is equivalent to the default constructor and the
* distribution will produce values uniformly distributed
* in the range [0, 1).
*/
template<class T, class F>
piecewise_linear_distribution(std::initializer_list<T> il, F f)
: _intervals(il.begin(), il.end())
{
if(_intervals.size() < 2) {
default_init();
} else {
_weights.reserve(_intervals.size());
for(typename std::vector<RealType>::const_iterator
iter = _intervals.begin(), end = _intervals.end();
iter != end; ++iter)
{
_weights.push_back(f(*iter));
}
init();
}
}
#endif
/**
* Constructs a piecewise_linear_distribution from Boost.Range
* ranges holding the interval boundaries and the weights. If
* there are fewer than two interval boundaries, this is equivalent
* to the default constructor and the distribution will produce
* values uniformly distributed in the range [0, 1). The
* number of weights must be equal to the number of
* interval boundaries.
*/
template<class IntervalsRange, class WeightsRange>
piecewise_linear_distribution(const IntervalsRange& intervals_arg,
const WeightsRange& weights_arg)
: _intervals(Boost::begin(intervals_arg), Boost::end(intervals_arg)),
_weights(Boost::begin(weights_arg), Boost::end(weights_arg))
{
if(_intervals.size() < 2) {
default_init();
} else {
init();
}
}
/**
* Constructs a piecewise_linear_distribution that approximates a
* function. The range of the distribution is [xmin, xmax). This
* range is divided into nw equally sized intervals and the weights
* are found by calling the unary function f on the interval boundaries.
*/
template<class F>
piecewise_linear_distribution(std::size_t nw,
RealType xmin,
RealType xmax,
F f)
{
if(nw == 0) { nw = 1; }
RealType delta = (xmax - xmin) / nw;
_intervals.reserve(nw + 1);
for(std::size_t i = 0; i < nw; ++i) {
RealType x = xmin + i * delta;
_intervals.push_back(x);
_weights.push_back(f(x));
}
_intervals.push_back(xmax);
_weights.push_back(f(xmax));
init();
}
/**
* Constructs a piecewise_linear_distribution from its parameters.
*/
explicit piecewise_linear_distribution(const param_type& parm)
: _intervals(parm._intervals),
_weights(parm._weights)
{
init();
}
/**
* Returns a value distributed according to the parameters of the
* piecewise_linear_distribution.
*/
template<class URNG>
RealType operator()(URNG& urng) const
{
std::size_t i = _bins(urng);
bool is_in_rectangle = (i % 2 == 0);
i = i / 2;
uniform_real<RealType> dist(_intervals[i], _intervals[i+1]);
if(is_in_rectangle) {
return dist(urng);
} else if(_weights[i] < _weights[i+1]) {
return (std::max)(dist(urng), dist(urng));
} else {
return (std::min)(dist(urng), dist(urng));
}
}
/**
* Returns a value distributed according to the parameters
* specified by param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return piecewise_linear_distribution(parm)(urng);
}
/** Returns the smallest value that the distribution can produce. */
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return _intervals.front(); }
/** Returns the largest value that the distribution can produce. */
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return _intervals.back(); }
/**
* Returns a vector containing the probability densities
* at the interval boundaries.
*/
std::vector<RealType> densities() const
{
RealType sum = static_cast<RealType>(0);
for(std::size_t i = 0; i < _intervals.size() - 1; ++i) {
RealType width = _intervals[i + 1] - _intervals[i];
sum += (_weights[i] + _weights[i + 1]) * width / 2;
}
std::vector<RealType> result;
result.reserve(_weights.size());
for(typename std::vector<RealType>::const_iterator
iter = _weights.begin(), end = _weights.end();
iter != end; ++iter)
{
result.push_back(*iter / sum);
}
return result;
}
/** Returns a vector containing the interval boundaries. */
std::vector<RealType> intervals() const { return _intervals; }
/** Returns the parameters of the distribution. */
param_type param() const
{
return param_type(_intervals, _weights);
}
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
std::vector<RealType> new_intervals(parm._intervals);
std::vector<RealType> new_weights(parm._weights);
init(new_intervals, new_weights);
_intervals.swap(new_intervals);
_weights.swap(new_weights);
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { _bins.reset(); }
/** Writes a distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(
os, piecewise_linear_distribution, pld)
{
os << pld.param();
return os;
}
/** Reads a distribution from a @c std::istream */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(
is, piecewise_linear_distribution, pld)
{
param_type parm;
if(is >> parm) {
pld.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will return the
* same sequence of values, when passed equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(
piecewise_linear_distribution, lhs, rhs)
{
return lhs._intervals == rhs._intervals && lhs._weights == rhs._weights;
}
/**
* Returns true if the two distributions may return different
* sequences of values, when passed equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(piecewise_linear_distribution)
private:
/// @cond \show_private
void init(const std::vector<RealType>& intervals_arg,
const std::vector<RealType>& weights_arg)
{
using std::abs;
std::vector<RealType> bin_weights;
bin_weights.reserve((intervals_arg.size() - 1) * 2);
for(std::size_t i = 0; i < intervals_arg.size() - 1; ++i) {
RealType width = intervals_arg[i + 1] - intervals_arg[i];
RealType w1 = weights_arg[i];
RealType w2 = weights_arg[i + 1];
bin_weights.push_back((std::min)(w1, w2) * width);
bin_weights.push_back(abs(w1 - w2) * width / 2);
}
typedef discrete_distribution<std::size_t, RealType> bins_type;
typename bins_type::param_type bins_param(bin_weights);
_bins.param(bins_param);
}
void init()
{
init(_intervals, _weights);
}
void default_init()
{
_intervals.clear();
_intervals.push_back(RealType(0));
_intervals.push_back(RealType(1));
_weights.clear();
_weights.push_back(RealType(1));
_weights.push_back(RealType(1));
init();
}
discrete_distribution<std::size_t, RealType> _bins;
std::vector<RealType> _intervals;
std::vector<RealType> _weights;
/// @endcond
};
}
}
#endif
@@ -1,360 +0,0 @@
/* boost random/poisson_distribution.hpp header file
*
* Copyright Jens Maurer 2002
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <cstdlib>
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class RealType>
struct poisson_table {
static RealType value[10];
};
template<class RealType>
RealType poisson_table<RealType>::value[10] = {
0.0,
0.0,
0.69314718055994529,
1.7917594692280550,
3.1780538303479458,
4.7874917427820458,
6.5792512120101012,
8.5251613610654147,
10.604602902745251,
12.801827480081469
};
}
/**
* An instantiation of the class template @c poisson_distribution is a
* model of \random_distribution. The poisson distribution has
* \f$p(i) = \frac{e^{-\lambda}\lambda^i}{i!}\f$
*
* This implementation is based on the PTRD algorithm described
*
* @blockquote
* "The transformed rejection method for generating Poisson random variables",
* Wolfgang Hormann, Insurance: Mathematics and Economics
* Volume 12, Issue 1, February 1993, Pages 39-45
* @endblockquote
*/
template<class IntType = int, class RealType = double>
class poisson_distribution {
public:
typedef IntType result_type;
typedef RealType input_type;
class param_type {
public:
typedef poisson_distribution distribution_type;
/**
* Construct a param_type object with the parameter "mean"
*
* Requires: mean > 0
*/
explicit param_type(RealType mean_arg = RealType(1))
: _mean(mean_arg)
{
ACTIV_BOOST_ASSERT(_mean > 0);
}
/* Returns the "mean" parameter of the distribution. */
RealType mean() const { return _mean; }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const param_type& parm)
{
os << parm._mean;
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is, param_type& parm)
{
is >> parm._mean;
return is;
}
#endif
/** Returns true if the parameters have the same values. */
friend bool operator==(const param_type& lhs, const param_type& rhs)
{
return lhs._mean == rhs._mean;
}
/** Returns true if the parameters have different values. */
friend bool operator!=(const param_type& lhs, const param_type& rhs)
{
return !(lhs == rhs);
}
private:
RealType _mean;
};
/**
* Constructs a @c poisson_distribution with the parameter @c mean.
*
* Requires: mean > 0
*/
explicit poisson_distribution(RealType mean_arg = RealType(1))
: _mean(mean_arg)
{
ACTIV_BOOST_ASSERT(_mean > 0);
init();
}
/**
* Construct an @c poisson_distribution object from the
* parameters.
*/
explicit poisson_distribution(const param_type& parm)
: _mean(parm.mean())
{
init();
}
/**
* Returns a random variate distributed according to the
* poisson distribution.
*/
template<class URNG>
IntType operator()(URNG& urng) const
{
if(use_inversion()) {
return invert(urng);
} else {
return generate(urng);
}
}
/**
* Returns a random variate distributed according to the
* poisson distribution with parameters specified by param.
*/
template<class URNG>
IntType operator()(URNG& urng, const param_type& parm) const
{
return poisson_distribution(parm)(urng);
}
/** Returns the "mean" parameter of the distribution. */
RealType mean() const { return _mean; }
/** Returns the smallest value that the distribution can produce. */
IntType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const { return 0; }
/** Returns the largest value that the distribution can produce. */
IntType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION() const
{ return (std::numeric_limits<IntType>::max)(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_mean); }
/** Sets parameters of the distribution. */
void param(const param_type& parm)
{
_mean = parm.mean();
init();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
/** Writes the parameters of the distribution to a @c std::ostream. */
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os,
const poisson_distribution& pd)
{
os << pd.param();
return os;
}
/** Reads the parameters of the distribution from a @c std::istream. */
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, poisson_distribution& pd)
{
pd.read(is);
return is;
}
#endif
/** Returns true if the two distributions will produce the same
sequence of values, given equal generators. */
friend bool operator==(const poisson_distribution& lhs,
const poisson_distribution& rhs)
{
return lhs._mean == rhs._mean;
}
/** Returns true if the two distributions could produce different
sequences of values, given equal generators. */
friend bool operator!=(const poisson_distribution& lhs,
const poisson_distribution& rhs)
{
return !(lhs == rhs);
}
private:
/// @cond show_private
template<class CharT, class Traits>
void read(std::basic_istream<CharT, Traits>& is) {
param_type parm;
if(is >> parm) {
param(parm);
}
}
bool use_inversion() const
{
return _mean < 10;
}
static RealType log_factorial(IntType k)
{
ACTIV_BOOST_ASSERT(k >= 0);
ACTIV_BOOST_ASSERT(k < 10);
return detail::poisson_table<RealType>::value[k];
}
void init()
{
using std::sqrt;
using std::exp;
if(use_inversion()) {
_u._exp_mean = exp(-_mean);
} else {
_u._ptrd.smu = sqrt(_mean);
_u._ptrd.b = 0.931 + 2.53 * _u._ptrd.smu;
_u._ptrd.a = -0.059 + 0.02483 * _u._ptrd.b;
_u._ptrd.inv_alpha = 1.1239 + 1.1328 / (_u._ptrd.b - 3.4);
_u._ptrd.v_r = 0.9277 - 3.6224 / (_u._ptrd.b - 2);
}
}
template<class URNG>
IntType generate(URNG& urng) const
{
using std::floor;
using std::abs;
using std::log;
while(true) {
RealType u;
RealType v = uniform_01<RealType>()(urng);
if(v <= 0.86 * _u._ptrd.v_r) {
u = v / _u._ptrd.v_r - 0.43;
return static_cast<IntType>(floor(
(2*_u._ptrd.a/(0.5-abs(u)) + _u._ptrd.b)*u + _mean + 0.445));
}
if(v >= _u._ptrd.v_r) {
u = uniform_01<RealType>()(urng) - 0.5;
} else {
u = v/_u._ptrd.v_r - 0.93;
u = ((u < 0)? -0.5 : 0.5) - u;
v = uniform_01<RealType>()(urng) * _u._ptrd.v_r;
}
RealType us = 0.5 - abs(u);
if(us < 0.013 && v > us) {
continue;
}
RealType k = floor((2*_u._ptrd.a/us + _u._ptrd.b)*u+_mean+0.445);
v = v*_u._ptrd.inv_alpha/(_u._ptrd.a/(us*us) + _u._ptrd.b);
RealType log_sqrt_2pi = 0.91893853320467267;
if(k >= 10) {
if(log(v*_u._ptrd.smu) <= (k + 0.5)*log(_mean/k)
- _mean
- log_sqrt_2pi
+ k
- (1/12. - (1/360. - 1/(1260.*k*k))/(k*k))/k) {
return static_cast<IntType>(k);
}
} else if(k >= 0) {
if(log(v) <= k*log(_mean)
- _mean
- log_factorial(static_cast<IntType>(k))) {
return static_cast<IntType>(k);
}
}
}
}
template<class URNG>
IntType invert(URNG& urng) const
{
RealType p = _u._exp_mean;
IntType x = 0;
RealType u = uniform_01<RealType>()(urng);
while(u > p) {
u = u - p;
++x;
p = _mean * p / x;
}
return x;
}
RealType _mean;
union {
// for ptrd
struct {
RealType v_r;
RealType a;
RealType b;
RealType smu;
RealType inv_alpha;
} _ptrd;
// for inversion
RealType _exp_mean;
} _u;
/// @endcond
};
} // namespace random
using random::poisson_distribution;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
@@ -1,143 +0,0 @@
/* boost random/random_device.hpp header file
*
* Copyright Jens Maurer 2000
* Copyright Steven Watanabe 2010-2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* $Id$
*
* Revision history
* 2000-02-18 Portability fixes (thanks to Beman Dawes)
*/
// See http://www.boost.org/libs/random for documentation.
#ifndef ACTIV_BOOST_RANDOM_RANDOM_DEVICE_HPP
#define ACTIV_BOOST_RANDOM_RANDOM_DEVICE_HPP
#include <string>
#include <ActivBoost/config.hpp>
#include <ActivBoost/noncopyable.hpp>
#include <ActivBoost/random/detail/auto_link.hpp>
#include <ActivBoost/system/config.hpp> // force autolink to find Boost.System
namespace Boost {
namespace random {
/**
* Class \random_device models a \nondeterministic_random_number_generator.
* It uses one or more implementation-defined stochastic processes to
* generate a sequence of uniformly distributed non-deterministic random
* numbers. For those environments where a non-deterministic random number
* generator is not available, class random_device must not be implemented. See
*
* @blockquote
* "Randomness Recommendations for Security", D. Eastlake, S. Crocker,
* J. Schiller, Network Working Group, RFC 1750, December 1994
* @endblockquote
*
* for further discussions.
*
* @xmlnote
* Some operating systems abstract the computer hardware enough
* to make it difficult to non-intrusively monitor stochastic processes.
* However, several do provide a special device for exactly this purpose.
* It seems to be impossible to emulate the functionality using Standard
* C++ only, so users should be aware that this class may not be available
* on all platforms.
* @endxmlnote
*
* <b>Implementation Note for Linux</b>
*
* On the Linux operating system, token is interpreted as a filesystem
* path. It is assumed that this path denotes an operating system
* pseudo-device which generates a stream of non-deterministic random
* numbers. The pseudo-device should never signal an error or end-of-file.
* Otherwise, @c std::ios_base::failure is thrown. By default,
* \random_device uses the /dev/urandom pseudo-device to retrieve
* the random numbers. Another option would be to specify the /dev/random
* pseudo-device, which blocks on reads if the entropy pool has no more
* random bits available.
*
* <b>Implementation Note for Windows</b>
*
* On the Windows operating system, token is interpreted as the name
* of a cryptographic service provider. By default \random_device uses
* MS_DEF_PROV.
*
* <b>Performance</b>
*
* The test program <a href="\boost/libs/random/performance/nondet_random_speed.cpp">
* nondet_random_speed.cpp</a> measures the execution times of the
* random_device.hpp implementation of the above algorithms in a tight
* loop. The performance has been evaluated on an
* Intel(R) Core(TM) i7 CPU Q 840 \@ 1.87GHz, 1867 Mhz with
* Visual C++ 2010, Microsoft Windows 7 Professional and with gcc 4.4.5,
* Ubuntu Linux 2.6.35-25-generic.
*
* <table cols="2">
* <tr><th>Platform</th><th>time per invocation [microseconds]</th></tr>
* <tr><td> Windows </td><td>2.9</td></tr>
* <tr><td> Linux </td><td>1.7</td></tr>
* </table>
*
* The measurement error is estimated at +/- 1 usec.
*/
class random_device : private noncopyable
{
public:
typedef unsigned int result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
/** Returns the smallest value that the \random_device can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
/** Returns the largest value that the \random_device can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () { return ~0u; }
/** Constructs a @c random_device, optionally using the default device. */
ACTIV_BOOST_RANDOM_DECL random_device();
/**
* Constructs a @c random_device, optionally using the given token as an
* access specification (for example, a URL) to some implementation-defined
* service for monitoring a stochastic process.
*/
ACTIV_BOOST_RANDOM_DECL explicit random_device(const std::string& token);
ACTIV_BOOST_RANDOM_DECL ~random_device();
/**
* Returns: An entropy estimate for the random numbers returned by
* operator(), in the range min() to log2( max()+1). A deterministic
* random number generator (e.g. a pseudo-random number engine)
* has entropy 0.
*
* Throws: Nothing.
*/
ACTIV_BOOST_RANDOM_DECL double entropy() const;
/** Returns a random value in the range [min, max]. */
ACTIV_BOOST_RANDOM_DECL unsigned int operator()();
/** Fills a range with random 32-bit values. */
template<class Iter>
void generate(Iter begin, Iter end)
{
for(; begin != end; ++begin) {
*begin = (*this)();
}
}
private:
class impl;
impl * pimpl;
};
} // namespace random
using random::random_device;
} // namespace Boost
#endif /* ACTIV_BOOST_RANDOM_RANDOM_DEVICE_HPP */
@@ -1,73 +0,0 @@
/* boost random/random_number_generator.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
#define ACTIV_BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/uniform_int_distribution.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template random_number_generator model a
* RandomNumberGenerator (std:25.2.11 [lib.alg.random.shuffle]). On
* each invocation, it returns a uniformly distributed integer in
* the range [0..n).
*
* The template parameter IntType shall denote some integer-like value type.
*/
template<class URNG, class IntType = long>
class random_number_generator
{
public:
typedef URNG base_type;
typedef IntType argument_type;
typedef IntType result_type;
/**
* Constructs a random_number_generator functor with the given
* \uniform_random_number_generator as the underlying source of
* random numbers.
*/
random_number_generator(base_type& rng) : _rng(rng) {}
// compiler-generated copy ctor is fine
// assignment is disallowed because there is a reference member
/**
* Returns a value in the range [0, n)
*/
result_type operator()(argument_type n)
{
ACTIV_BOOST_ASSERT(n > 0);
return uniform_int_distribution<IntType>(0, n-1)(_rng);
}
private:
base_type& _rng;
};
} // namespace random
using random::random_number_generator;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP
@@ -1,99 +0,0 @@
/* boost random/ranlux.hpp header file
*
* Copyright Jens Maurer 2002
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 created
*/
#ifndef ACTIV_BOOST_RANDOM_RANLUX_HPP
#define ACTIV_BOOST_RANDOM_RANLUX_HPP
#include <ActivBoost/config.hpp>
#include <ActivBoost/random/subtract_with_carry.hpp>
#include <ActivBoost/random/discard_block.hpp>
namespace Boost {
namespace random {
namespace detail {
/**
* The ranlux family of generators are described in
*
* @blockquote
* "A portable high-quality random number generator for lattice field theory
* calculations", M. Luescher, Computer Physics Communications, 79 (1994)
* pp 100-110.
* @endblockquote
*
* The levels are given in
*
* @blockquote
* "RANLUX: A Fortran implementation of the high-quality
* pseudorandom number generator of Luescher", F. James,
* Computer Physics Communications 79 (1994) 111-114
* @endblockquote
*/
class ranlux_documentation {};
}
typedef subtract_with_carry_engine<uint32_t, 24, 10, 24> ranlux_base;
typedef subtract_with_carry_01_engine<float, 24, 10, 24> ranlux_base_01;
typedef subtract_with_carry_01_engine<double, 48, 10, 24> ranlux64_base_01;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux_base, 223, 24> ranlux3;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux_base, 389, 24> ranlux4;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux_base_01, 223, 24> ranlux3_01;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux_base_01, 389, 24> ranlux4_01;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux64_base_01, 223, 24> ranlux64_3_01;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux64_base_01, 389, 24> ranlux64_4_01;
#if !defined(ACTIV_BOOST_NO_INT64_T) && !defined(ACTIV_BOOST_NO_INTEGRAL_INT64_T)
typedef subtract_with_carry_engine<uint64_t, 48, 10, 24> ranlux64_base;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux64_base, 223, 24> ranlux64_3;
/** @copydoc Boost::random::detail::ranlux_documentation */
typedef discard_block_engine<ranlux64_base, 389, 24> ranlux64_4;
#endif /* !ACTIV_BOOST_NO_INT64_T && !ACTIV_BOOST_NO_INTEGRAL_INT64_T */
typedef subtract_with_carry_engine<uint32_t, 24, 10, 24> ranlux24_base;
typedef subtract_with_carry_engine<uint64_t, 48, 5, 12> ranlux48_base;
typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
#if !defined(ACTIV_BOOST_NO_INT64_T) && !defined(ACTIV_BOOST_NO_INTEGRAL_INT64_T)
typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
#endif
}
using random::ranlux3;
using random::ranlux4;
using random::ranlux3_01;
using random::ranlux4_01;
using random::ranlux64_3_01;
using random::ranlux64_4_01;
#if !defined(ACTIV_BOOST_NO_INT64_T) && !defined(ACTIV_BOOST_NO_INTEGRAL_INT64_T)
using random::ranlux64_3;
using random::ranlux64_4;
#endif
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_LINEAR_CONGRUENTIAL_HPP
@@ -1,118 +0,0 @@
/* boost random/seed_seq.hpp header file
*
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_SEED_SEQ_HPP
#define ACTIV_BOOST_RANDOM_SEED_SEQ_HPP
#include <ActivBoost/config.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/range/begin.hpp>
#include <ActivBoost/range/end.hpp>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <iterator>
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
#include <initializer_list>
#endif
namespace Boost {
namespace random {
/**
* The class @c seed_seq stores a sequence of 32-bit words
* for seeding a \pseudo_random_number_generator. These
* words will be combined to fill the entire state of the
* generator.
*/
class seed_seq {
public:
typedef Boost::uint_least32_t result_type;
/** Initializes a seed_seq to hold an empty sequence. */
seed_seq() {}
#ifndef ACTIV_BOOST_NO_CXX11_HDR_INITIALIZER_LIST
/** Initializes the sequence from an initializer_list. */
template<class T>
seed_seq(const std::initializer_list<T>& il) : v(il.begin(), il.end()) {}
#endif
/** Initializes the sequence from an iterator range. */
template<class Iter>
seed_seq(Iter first, Iter last) : v(first, last) {}
/** Initializes the sequence from Boost.Range range. */
template<class Range>
explicit seed_seq(const Range& range)
: v(Boost::begin(range), Boost::end(range)) {}
/**
* Fills a range with 32-bit values based on the stored sequence.
*
* Requires: Iter must be a Random Access Iterator whose value type
* is an unsigned integral type at least 32 bits wide.
*/
template<class Iter>
void generate(Iter first, Iter last) const
{
typedef typename std::iterator_traits<Iter>::value_type value_type;
std::fill(first, last, static_cast<value_type>(0x8b8b8b8bu));
std::size_t s = v.size();
std::size_t n = last - first;
std::size_t t =
(n >= 623) ? 11 :
(n >= 68) ? 7 :
(n >= 39) ? 5 :
(n >= 7) ? 3 :
(n - 1)/2;
std::size_t p = (n - t) / 2;
std::size_t q = p + t;
std::size_t m = (std::max)(s+1, n);
value_type mask = 0xffffffffu;
for(std::size_t k = 0; k < m; ++k) {
value_type r1 = static_cast<value_type>
(*(first + k%n) ^ *(first + (k+p)%n) ^ *(first + (k+n-1)%n));
r1 = r1 ^ (r1 >> 27);
r1 = (r1 * 1664525u) & mask;
value_type r2 = static_cast<value_type>(r1 +
((k == 0) ? s :
(k <= s) ? k % n + v[k - 1] :
(k % n)));
*(first + (k+p)%n) = (*(first + (k+p)%n) + r1) & mask;
*(first + (k+q)%n) = (*(first + (k+q)%n) + r2) & mask;
*(first + k%n) = r2;
}
for(std::size_t k = m; k < m + n; ++k) {
value_type r3 = static_cast<value_type>
((*(first + k%n) + *(first + (k+p)%n) + *(first + (k+n-1)%n))
& mask);
r3 = r3 ^ (r3 >> 27);
r3 = (r3 * 1566083941u) & mask;
value_type r4 = static_cast<value_type>(r3 - k%n);
*(first + (k+p)%n) ^= r3;
*(first + (k+q)%n) ^= r4;
*(first + k%n) = r4;
}
}
/** Returns the size of the sequence. */
std::size_t size() const { return v.size(); }
/** Writes the stored sequence to iter. */
template<class Iter>
void param(Iter out) { std::copy(v.begin(), v.end(), out); }
private:
std::vector<result_type> v;
};
}
}
#endif
@@ -1,269 +0,0 @@
/* boost random/shuffle_order.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_SHUFFLE_ORDER_HPP
#define ACTIV_BOOST_RANDOM_SHUFFLE_ORDER_HPP
#include <iostream>
#include <algorithm> // std::copy
#include <cassert>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/random/linear_congruential.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
/**
* Instatiations of class template @c shuffle_order_engine model a
* \pseudo_random_number_generator. It mixes the output
* of some (usually \linear_congruential_engine)
* \uniform_random_number_generator to get better statistical properties.
* The algorithm is described in
*
* @blockquote
* "Improving a poor random number generator", Carter Bays
* and S.D. Durham, ACM Transactions on Mathematical Software,
* Vol 2, No. 1, March 1976, pp. 59-64.
* http://doi.acm.org/10.1145/355666.355670
* @endblockquote
*
* The output of the base generator is buffered in an array of
* length k. Every output X(n) has a second role: It gives an
* index into the array where X(n+1) will be retrieved. Used
* array elements are replaced with fresh output from the base
* generator.
*
* Template parameters are the base generator and the array
* length k, which should be around 100.
*/
template<class UniformRandomNumberGenerator, std::size_t k>
class shuffle_order_engine
{
public:
typedef UniformRandomNumberGenerator base_type;
typedef typename base_type::result_type result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, buffer_size = k);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, table_size = k);
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
ACTIV_BOOST_STATIC_ASSERT(k > 0);
/**
* Constructs a @c shuffle_order_engine by invoking the
* default constructor of the base generator.
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
shuffle_order_engine() : _rng() { init(); }
/**
* Constructs a @c shuffle_output_engine by invoking the one-argument
* constructor of the base generator with the parameter seed.
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(shuffle_order_engine,
result_type, s)
{ _rng.seed(s); init(); }
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(shuffle_order_engine, SeedSeq, seq)
{ _rng.seed(seq); init(); }
/**
* Constructs a @c shuffle_output_engine by using a copy
* of the provided generator.
*
* Precondition: The template argument UniformRandomNumberGenerator
* shall denote a CopyConstructible type.
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
explicit shuffle_order_engine(const base_type & rng) : _rng(rng) { init(); }
#ifndef ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
explicit shuffle_order_engine(base_type&& rng) : _rng(rng) { init(); }
#endif
template<class It> shuffle_order_engine(It& first, It last)
: _rng(first, last) { init(); }
void seed() { _rng.seed(); init(); }
/**
* Invokes the one-argument seed method of the base generator
* with the parameter seed and re-initializes the internal buffer array.
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(shuffle_order_engine,
result_type, seed_arg)
{ _rng.seed(seed_arg); init(); }
/**
* Invokes the one-argument seed method of the base generator
* with the parameter seq and re-initializes the internal buffer array.
*
* Complexity: Exactly k+1 invocations of the base generator.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(shuffle_order_engine, SeedSeq, seq)
{ _rng.seed(seq); init(); }
template<class It> void seed(It& first, It last)
{ _rng.seed(first, last); init(); }
const base_type& base() const { return _rng; }
result_type operator()() {
// calculating the range every time may seem wasteful. However, this
// makes the information locally available for the optimizer.
typedef typename Boost::random::traits::make_unsigned<result_type>::type base_unsigned;
const base_unsigned brange =
detail::subtract<result_type>()((max)(), (min)());
const base_unsigned off =
detail::subtract<result_type>()(y, (min)());
base_unsigned j;
if(k == 1) {
j = 0;
} else if(brange < (std::numeric_limits<base_unsigned>::max)() / k) {
// try to do it in the native type if we know that it won't
// overflow
j = k * off / (brange + 1);
} else if(brange < (std::numeric_limits<uintmax_t>::max)() / k) {
// Otherwise try to use uint64_t
j = static_cast<base_unsigned>(
static_cast<uintmax_t>(off) * k /
(static_cast<uintmax_t>(brange) + 1));
} else {
Boost::uintmax_t divisor =
static_cast<Boost::uintmax_t>(brange) + 1;
j = static_cast<base_unsigned>(detail::muldiv(off, k, divisor));
}
// assert(0 <= j && j < k);
y = v[j];
v[j] = _rng();
return y;
}
/** Advances the generator by z steps. */
void discard(Boost::uintmax_t z)
{
for(Boost::uintmax_t j = 0; j < z; ++j) {
(*this)();
}
}
/** Fills a range with pseudo-random values. */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_type::min)(); }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_type::max)(); }
/** Writes a @c shuffle_order_engine to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, shuffle_order_engine, s)
{
os << s._rng;
for(std::size_t i = 0; i < k; ++i)
os << ' ' << s.v[i];
os << ' ' << s.y;
return os;
}
/** Reads a @c shuffle_order_engine from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, shuffle_order_engine, s)
{
is >> s._rng;
for(std::size_t i = 0; i < k; ++i)
is >> std::ws >> s.v[i];
is >> std::ws >> s.y;
return is;
}
/** Returns true if the two generators will produce identical sequences. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(shuffle_order_engine, x, y)
{ return x._rng == y._rng && x.y == y.y && std::equal(x.v, x.v+k, y.v); }
/** Returns true if the two generators will produce different sequences. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(shuffle_order_engine)
private:
/// \cond show_private
void init()
{
// we cannot use std::generate, because it uses pass-by-value for _rng
for(result_type * p = v; p != v+k; ++p)
*p = _rng();
y = _rng();
}
/// \endcond
base_type _rng;
result_type v[k];
result_type y;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class URNG, std::size_t k>
const bool shuffle_order_engine<URNG, k>::has_fixed_range;
template<class URNG, std::size_t k>
const std::size_t shuffle_order_engine<URNG, k>::table_size;
template<class URNG, std::size_t k>
const std::size_t shuffle_order_engine<URNG, k>::buffer_size;
#endif
/**
* According to Harry Erwin (private e-mail), the specialization
* @c kreutzer1986 was suggested in:
*
* @blockquote
* "System Simulation: Programming Styles and Languages (International
* Computer Science Series)", Wolfgang Kreutzer, Addison-Wesley, December 1986.
* @endblockquote
*/
typedef shuffle_order_engine<
linear_congruential_engine<uint32_t, 1366, 150889, 714025>,
97> kreutzer1986;
/**
* The specialization @c knuth_b is specified by the C++ standard.
* It is described in
*
* @blockquote
* "The Art of Computer Programming, Second Edition, Volume 2,
* Seminumerical Algorithms", Donald Knuth, Addison-Wesley, 1981.
* @endblockquote
*/
typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
} // namespace random
using random::kreutzer1986;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
@@ -1,51 +0,0 @@
/* boost random/shuffle_output.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
#define ACTIV_BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
#include <ActivBoost/random/shuffle_order.hpp>
namespace Boost {
namespace random {
/// \cond
template<typename URNG, int k,
typename URNG::result_type val = 0>
class shuffle_output : public shuffle_order_engine<URNG, k>
{
typedef shuffle_order_engine<URNG, k> base_t;
public:
typedef typename base_t::result_type result_type;
shuffle_output() {}
template<class T>
explicit shuffle_output(T& arg) : base_t(arg) {}
template<class T>
explicit shuffle_output(const T& arg) : base_t(arg) {}
template<class It>
shuffle_output(It& first, It last) : base_t(first, last) {}
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (this->base().min)(); }
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (this->base().max)(); }
};
/// \endcond
}
}
#endif // ACTIV_BOOST_RANDOM_SHUFFLE_OUTPUT_HPP
-238
View File
@@ -1,238 +0,0 @@
/* boost random/sobol.hpp header file
*
* Copyright Justinas Vygintas Daugmaudis 2010-2018
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef ACTIV_BOOST_RANDOM_SOBOL_HPP
#define ACTIV_BOOST_RANDOM_SOBOL_HPP
#include <ActivBoost/random/detail/sobol_table.hpp>
#include <ActivBoost/random/detail/gray_coded_qrng.hpp>
#include <ActivBoost/assert.hpp>
namespace Boost {
namespace random {
/** @cond */
namespace qrng_detail {
// sobol_lattice sets up the random-number generator to produce a Sobol
// sequence of at most max dims-dimensional quasi-random vectors.
// Adapted from ACM TOMS algorithm 659, see
// http://doi.acm.org/10.1145/42288.214372
template<typename UIntType, unsigned w, typename SobolTables>
struct sobol_lattice
{
typedef UIntType value_type;
ACTIV_BOOST_STATIC_ASSERT(w > 0u);
ACTIV_BOOST_STATIC_CONSTANT(unsigned, bit_count = w);
private:
typedef std::vector<value_type> container_type;
public:
explicit sobol_lattice(std::size_t dimension)
{
resize(dimension);
}
// default copy c-tor is fine
void resize(std::size_t dimension)
{
dimension_assert("Sobol", dimension, SobolTables::max_dimension);
// Initialize the bit array
container_type cj(bit_count * dimension);
// Initialize direction table in dimension 0
for (unsigned k = 0; k != bit_count; ++k)
cj[dimension*k] = static_cast<value_type>(1);
// Initialize in remaining dimensions.
for (std::size_t dim = 1; dim < dimension; ++dim)
{
const typename SobolTables::value_type poly = SobolTables::polynomial(dim-1);
if (poly > (std::numeric_limits<value_type>::max)()) {
Boost::throw_exception( std::range_error("sobol: polynomial value outside the given value type range") );
}
const unsigned degree = qrng_detail::msb(poly); // integer log2(poly)
// set initial values of m from table
for (unsigned k = 0; k != degree; ++k)
cj[dimension*k + dim] = SobolTables::minit(dim-1, k);
// Calculate remaining elements for this dimension,
// as explained in Bratley+Fox, section 2.
for (unsigned j = degree; j < bit_count; ++j)
{
typename SobolTables::value_type p_i = poly;
const std::size_t bit_offset = dimension*j + dim;
cj[bit_offset] = cj[dimension*(j-degree) + dim];
for (unsigned k = 0; k != degree; ++k, p_i >>= 1)
{
int rem = degree - k;
cj[bit_offset] ^= ((p_i & 1) * cj[dimension*(j-rem) + dim]) << rem;
}
}
}
// Shift columns by appropriate power of 2.
unsigned p = 1u;
for (int j = bit_count-1-1; j >= 0; --j, ++p)
{
const std::size_t bit_offset = dimension * j;
for (std::size_t dim = 0; dim != dimension; ++dim)
cj[bit_offset + dim] <<= p;
}
bits.swap(cj);
}
typename container_type::const_iterator iter_at(std::size_t n) const
{
ACTIV_BOOST_ASSERT(!(n > bits.size()));
return bits.begin() + n;
}
private:
container_type bits;
};
} // namespace qrng_detail
typedef detail::qrng_tables::sobol default_sobol_table;
/** @endcond */
//!Instantiations of class template sobol_engine model a \quasi_random_number_generator.
//!The sobol_engine uses the algorithm described in
//! \blockquote
//![Bratley+Fox, TOMS 14, 88 (1988)]
//!and [Antonov+Saleev, USSR Comput. Maths. Math. Phys. 19, 252 (1980)]
//! \endblockquote
//!
//!\attention sobol_engine skips trivial zeroes at the start of the sequence. For example, the beginning
//!of the 2-dimensional Sobol sequence in @c uniform_01 distribution will look like this:
//!\code{.cpp}
//!0.5, 0.5,
//!0.75, 0.25,
//!0.25, 0.75,
//!0.375, 0.375,
//!0.875, 0.875,
//!...
//!\endcode
//!
//!In the following documentation @c X denotes the concrete class of the template
//!sobol_engine returning objects of type @c UIntType, u and v are the values of @c X.
//!
//!Some member functions may throw exceptions of type @c std::range_error. This
//!happens when the quasi-random domain is exhausted and the generator cannot produce
//!any more values. The length of the low discrepancy sequence is given by \f$L=Dimension \times (2^{w} - 1)\f$.
template<typename UIntType, unsigned w, typename SobolTables = default_sobol_table>
class sobol_engine
: public qrng_detail::gray_coded_qrng<
qrng_detail::sobol_lattice<UIntType, w, SobolTables>
>
{
typedef qrng_detail::sobol_lattice<UIntType, w, SobolTables> lattice_t;
typedef qrng_detail::gray_coded_qrng<lattice_t> base_t;
public:
//!Effects: Constructs the default `s`-dimensional Sobol quasi-random number generator.
//!
//!Throws: bad_alloc, invalid_argument, range_error.
explicit sobol_engine(std::size_t s)
: base_t(s)
{}
// default copy c-tor is fine
#ifdef ACTIV_BOOST_RANDOM_DOXYGEN
//=========================Doxygen needs this!==============================
typedef UIntType result_type;
/** @copydoc Boost::random::niederreiter_base2_engine::min() */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_t::min)(); }
/** @copydoc Boost::random::niederreiter_base2_engine::max() */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (base_t::max)(); }
/** @copydoc Boost::random::niederreiter_base2_engine::dimension() */
std::size_t dimension() const { return base_t::dimension(); }
/** @copydoc Boost::random::niederreiter_base2_engine::seed() */
void seed()
{
base_t::seed();
}
/** @copydoc Boost::random::niederreiter_base2_engine::seed(UIntType) */
void seed(UIntType init)
{
base_t::seed(init);
}
/** @copydoc Boost::random::niederreiter_base2_engine::operator()() */
result_type operator()()
{
return base_t::operator()();
}
/** @copydoc Boost::random::niederreiter_base2_engine::discard(Boost::uintmax_t) */
void discard(Boost::uintmax_t z)
{
base_t::discard(z);
}
/** Returns true if the two generators will produce identical sequences of outputs. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(sobol_engine, x, y)
{ return static_cast<const base_t&>(x) == y; }
/** Returns true if the two generators will produce different sequences of outputs. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(sobol_engine)
/** Writes the textual representation of the generator to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, sobol_engine, s)
{ return os << static_cast<const base_t&>(s); }
/** Reads the textual representation of the generator from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, sobol_engine, s)
{ return is >> static_cast<base_t&>(s); }
#endif // ACTIV_BOOST_RANDOM_DOXYGEN
};
/**
* @attention This specialization of \sobol_engine supports up to 3667 dimensions.
*
* Data on the primitive binary polynomials `a` and the corresponding starting values `m`
* for Sobol sequences in up to 21201 dimensions was taken from
*
* @blockquote
* S. Joe and F. Y. Kuo, Constructing Sobol sequences with better two-dimensional projections,
* SIAM J. Sci. Comput. 30, 2635-2654 (2008).
* @endblockquote
*
* See the original tables up to dimension 21201: https://web.archive.org/web/20170802022909/http://web.maths.unsw.edu.au/~fkuo/sobol/new-joe-kuo-6.21201
*
* For practical reasons the default table uses only the subset of binary polynomials `a` < 2<sup>16</sup>.
*
* However, it is possible to provide your own table to \sobol_engine should the default one be insufficient.
*/
typedef sobol_engine<Boost::uint_least64_t, 64u, default_sobol_table> sobol;
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_SOBOL_HPP
@@ -1,180 +0,0 @@
/* boost random/student_t_distribution.hpp header file
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_STUDENT_T_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_STUDENT_T_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/chi_squared_distribution.hpp>
#include <ActivBoost/random/normal_distribution.hpp>
namespace Boost {
namespace random {
/**
* The Student t distribution is a real valued distribution with one
* parameter n, the number of degrees of freedom.
*
* It has \f$\displaystyle p(x) =
* \frac{1}{\sqrt{n\pi}}
* \frac{\Gamma((n+1)/2)}{\Gamma(n/2)}
* \left(1+\frac{x^2}{n}\right)^{-(n+1)/2}
* \f$.
*/
template<class RealType = double>
class student_t_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef student_t_distribution distribution_type;
/**
* Constructs a @c param_type with "n" degrees of freedom.
*
* Requires: n > 0
*/
explicit param_type(RealType n_arg = RealType(1.0))
: _n(n_arg)
{}
/** Returns the number of degrees of freedom of the distribution. */
RealType n() const { return _n; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._n; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._n; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._n == rhs._n; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _n;
};
/**
* Constructs an @c student_t_distribution with "n" degrees of freedom.
*
* Requires: n > 0
*/
explicit student_t_distribution(RealType n_arg = RealType(1.0))
: _normal(), _chi_squared(n_arg)
{}
/** Constructs an @c student_t_distribution from its parameters. */
explicit student_t_distribution(const param_type& parm)
: _normal(), _chi_squared(parm.n())
{}
/**
* Returns a random variate distributed according to the
* Student t distribution.
*/
template<class URNG>
RealType operator()(URNG& urng)
{
using std::sqrt;
return _normal(urng) / sqrt(_chi_squared(urng) / n());
}
/**
* Returns a random variate distributed accordint to the Student
* t distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return student_t_distribution(parm)(urng);
}
/** Returns the number of degrees of freedom. */
RealType n() const { return _chi_squared.n(); }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return -std::numeric_limits<RealType>::infinity(); }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return std::numeric_limits<RealType>::infinity(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(n()); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
typedef chi_squared_distribution<RealType> chi_squared_type;
typename chi_squared_type::param_type chi_squared_param(parm.n());
_chi_squared.param(chi_squared_param);
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset()
{
_normal.reset();
_chi_squared.reset();
}
/** Writes a @c student_t_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, student_t_distribution, td)
{
os << td.param();
return os;
}
/** Reads a @c student_t_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, student_t_distribution, td)
{
param_type parm;
if(is >> parm) {
td.param(parm);
}
return is;
}
/**
* Returns true if the two instances of @c student_t_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(student_t_distribution, lhs, rhs)
{ return lhs._normal == rhs._normal && lhs._chi_squared == rhs._chi_squared; }
/**
* Returns true if the two instances of @c student_t_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(student_t_distribution)
private:
normal_distribution<RealType> _normal;
chi_squared_distribution<RealType> _chi_squared;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_STUDENT_T_DISTRIBUTION_HPP
@@ -1,613 +0,0 @@
/* boost random/subtract_with_carry.hpp header file
*
* Copyright Jens Maurer 2002
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2002-03-02 created
*/
#ifndef ACTIV_BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP
#define ACTIV_BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp> // std::pow
#include <iostream>
#include <algorithm> // std::equal
#include <stdexcept>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/cstdint.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/integer/static_log2.hpp>
#include <ActivBoost/integer/integer_mask.hpp>
#include <ActivBoost/detail/workaround.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
#include <ActivBoost/random/detail/generator_seed_seq.hpp>
#include <ActivBoost/random/linear_congruential.hpp>
namespace Boost {
namespace random {
namespace detail {
struct subtract_with_carry_discard
{
template<class Engine>
static void apply(Engine& eng, Boost::uintmax_t z)
{
typedef typename Engine::result_type IntType;
const std::size_t short_lag = Engine::short_lag;
const std::size_t long_lag = Engine::long_lag;
std::size_t k = eng.k;
IntType carry = eng.carry;
if(k != 0) {
// increment k until it becomes 0.
if(k < short_lag) {
std::size_t limit = (short_lag - k) < z?
short_lag : (k + static_cast<std::size_t>(z));
for(std::size_t j = k; j < limit; ++j) {
carry = eng.do_update(j, j + long_lag - short_lag, carry);
}
}
std::size_t limit = (long_lag - k) < z?
long_lag : (k + static_cast<std::size_t>(z));
std::size_t start = (k < short_lag ? short_lag : k);
for(std::size_t j = start; j < limit; ++j) {
carry = eng.do_update(j, j - short_lag, carry);
}
}
k = ((z % long_lag) + k) % long_lag;
if(k < z) {
// main loop: update full blocks from k = 0 to long_lag
for(std::size_t i = 0; i < (z - k) / long_lag; ++i) {
for(std::size_t j = 0; j < short_lag; ++j) {
carry = eng.do_update(j, j + long_lag - short_lag, carry);
}
for(std::size_t j = short_lag; j < long_lag; ++j) {
carry = eng.do_update(j, j - short_lag, carry);
}
}
// Update the last partial block
std::size_t limit = short_lag < k? short_lag : k;
for(std::size_t j = 0; j < limit; ++j) {
carry = eng.do_update(j, j + long_lag - short_lag, carry);
}
for(std::size_t j = short_lag; j < k; ++j) {
carry = eng.do_update(j, j - short_lag, carry);
}
}
eng.carry = carry;
eng.k = k;
}
};
}
/**
* Instantiations of @c subtract_with_carry_engine model a
* \pseudo_random_number_generator. The algorithm is
* described in
*
* @blockquote
* "A New Class of Random Number Generators", George
* Marsaglia and Arif Zaman, Annals of Applied Probability,
* Volume 1, Number 3 (1991), 462-480.
* @endblockquote
*/
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
class subtract_with_carry_engine
{
public:
typedef IntType result_type;
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, word_size = w);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, long_lag = r);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, short_lag = s);
ACTIV_BOOST_STATIC_CONSTANT(uint32_t, default_seed = 19780503u);
// Required by the old Boost.Random concepts
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
// Backwards compatibility
ACTIV_BOOST_STATIC_CONSTANT(result_type, modulus = (result_type(1) << w));
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
/**
* Constructs a new @c subtract_with_carry_engine and seeds
* it with the default seed.
*/
subtract_with_carry_engine() { seed(); }
/**
* Constructs a new @c subtract_with_carry_engine and seeds
* it with @c value.
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry_engine,
IntType, value)
{ seed(value); }
/**
* Constructs a new @c subtract_with_carry_engine and seeds
* it with values produced by @c seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(subtract_with_carry_engine,
SeedSeq, seq)
{ seed(seq); }
/**
* Constructs a new @c subtract_with_carry_engine and seeds
* it with values from a range. first is updated to point
* one past the last value consumed. If there are not
* enough elements in the range to fill the entire state of
* the generator, throws @c std::invalid_argument.
*/
template<class It> subtract_with_carry_engine(It& first, It last)
{ seed(first,last); }
// compiler-generated copy ctor and assignment operator are fine
/** Seeds the generator with the default seed. */
void seed() { seed(default_seed); }
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(subtract_with_carry_engine,
IntType, value)
{
typedef linear_congruential_engine<uint32_t,40014,0,2147483563> gen_t;
gen_t intgen(static_cast<Boost::uint32_t>(value == 0 ? default_seed : value));
detail::generator_seed_seq<gen_t> gen(intgen);
seed(gen);
}
/** Seeds the generator with values produced by @c seq.generate(). */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(subtract_with_carry, SeedSeq, seq)
{
detail::seed_array_int<w>(seq, x);
carry = (x[long_lag-1] == 0);
k = 0;
}
/**
* Seeds the generator with values from a range. Updates @c first to
* point one past the last consumed value. If the range does not
* contain enough elements to fill the entire state of the generator,
* throws @c std::invalid_argument.
*/
template<class It>
void seed(It& first, It last)
{
detail::fill_array_int<w>(first, last, x);
carry = (x[long_lag-1] == 0);
k = 0;
}
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return 0; }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return Boost::low_bits_mask_t<w>::sig_bits; }
/** Returns the next value of the generator. */
result_type operator()()
{
std::size_t short_index =
(k < short_lag)?
(k + long_lag - short_lag) :
(k - short_lag);
carry = do_update(k, short_index, carry);
IntType result = x[k];
++k;
if(k >= long_lag)
k = 0;
return result;
}
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
detail::subtract_with_carry_discard::apply(*this, z);
}
/** Fills a range with random values. */
template<class It>
void generate(It first, It last)
{ detail::generate_from_int(*this, first, last); }
/** Writes a @c subtract_with_carry_engine to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, subtract_with_carry_engine, f)
{
for(unsigned int j = 0; j < f.long_lag; ++j)
os << f.compute(j) << ' ';
os << f.carry;
return os;
}
/** Reads a @c subtract_with_carry_engine from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, subtract_with_carry_engine, f)
{
for(unsigned int j = 0; j < f.long_lag; ++j)
is >> f.x[j] >> std::ws;
is >> f.carry;
f.k = 0;
return is;
}
/**
* Returns true if the two generators will produce identical
* sequences of values.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(subtract_with_carry_engine, x, y)
{
for(unsigned int j = 0; j < r; ++j)
if(x.compute(j) != y.compute(j))
return false;
return true;
}
/**
* Returns true if the two generators will produce different
* sequences of values.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(subtract_with_carry_engine)
private:
/// \cond show_private
// returns x(i-r+index), where index is in 0..r-1
IntType compute(unsigned int index) const
{
return x[(k+index) % long_lag];
}
friend struct detail::subtract_with_carry_discard;
IntType do_update(std::size_t current, std::size_t short_index, IntType carry)
{
IntType delta;
IntType temp = x[current] + carry;
if (x[short_index] >= temp) {
// x(n) >= 0
delta = x[short_index] - temp;
carry = 0;
} else {
// x(n) < 0
delta = modulus - temp + x[short_index];
carry = 1;
}
x[current] = delta;
return carry;
}
/// \endcond
// state representation; next output (state) is x(i)
// x[0] ... x[k] x[k+1] ... x[long_lag-1] represents
// x(i-k) ... x(i) x(i+1) ... x(i-k+long_lag-1)
// speed: base: 20-25 nsec
// ranlux_4: 230 nsec, ranlux_7: 430 nsec, ranlux_14: 810 nsec
// This state representation makes operator== and save/restore more
// difficult, because we've already computed "too much" and thus
// have to undo some steps to get at x(i-r) etc.
// state representation: next output (state) is x(i)
// x[0] ... x[k] x[k+1] ... x[long_lag-1] represents
// x(i-k) ... x(i) x(i-long_lag+1) ... x(i-k-1)
// speed: base 28 nsec
// ranlux_4: 370 nsec, ranlux_7: 688 nsec, ranlux_14: 1343 nsec
IntType x[long_lag];
std::size_t k;
IntType carry;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
const bool subtract_with_carry_engine<IntType, w, s, r>::has_fixed_range;
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
const IntType subtract_with_carry_engine<IntType, w, s, r>::modulus;
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
const std::size_t subtract_with_carry_engine<IntType, w, s, r>::word_size;
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
const std::size_t subtract_with_carry_engine<IntType, w, s, r>::long_lag;
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
const std::size_t subtract_with_carry_engine<IntType, w, s, r>::short_lag;
template<class IntType, std::size_t w, std::size_t s, std::size_t r>
const uint32_t subtract_with_carry_engine<IntType, w, s, r>::default_seed;
#endif
// use a floating-point representation to produce values in [0..1)
/**
* Instantiations of \subtract_with_carry_01_engine model a
* \pseudo_random_number_generator. The algorithm is
* described in
*
* @blockquote
* "A New Class of Random Number Generators", George
* Marsaglia and Arif Zaman, Annals of Applied Probability,
* Volume 1, Number 3 (1991), 462-480.
* @endblockquote
*/
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
class subtract_with_carry_01_engine
{
public:
typedef RealType result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, word_size = w);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, long_lag = r);
ACTIV_BOOST_STATIC_CONSTANT(std::size_t, short_lag = s);
ACTIV_BOOST_STATIC_CONSTANT(Boost::uint32_t, default_seed = 19780503u);
ACTIV_BOOST_STATIC_ASSERT(!std::numeric_limits<result_type>::is_integer);
/** Creates a new \subtract_with_carry_01_engine using the default seed. */
subtract_with_carry_01_engine() { init_modulus(); seed(); }
/** Creates a new subtract_with_carry_01_engine and seeds it with value. */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry_01_engine,
Boost::uint32_t, value)
{ init_modulus(); seed(value); }
/**
* Creates a new \subtract_with_carry_01_engine and seeds with values
* produced by seq.generate().
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(subtract_with_carry_01_engine,
SeedSeq, seq)
{ init_modulus(); seed(seq); }
/**
* Creates a new \subtract_with_carry_01_engine and seeds it with values
* from a range. Advances first to point one past the last consumed
* value. If the range does not contain enough elements to fill the
* entire state, throws @c std::invalid_argument.
*/
template<class It> subtract_with_carry_01_engine(It& first, It last)
{ init_modulus(); seed(first,last); }
private:
/// \cond show_private
void init_modulus()
{
#ifndef ACTIV_BOOST_NO_STDC_NAMESPACE
// allow for Koenig lookup
using std::pow;
#endif
_modulus = pow(RealType(2), RealType(word_size));
}
/// \endcond
public:
// compiler-generated copy ctor and assignment operator are fine
/** Seeds the generator with the default seed. */
void seed() { seed(default_seed); }
/** Seeds the generator with @c value. */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(subtract_with_carry_01_engine,
Boost::uint32_t, value)
{
typedef linear_congruential_engine<uint32_t, 40014, 0, 2147483563> gen_t;
gen_t intgen(value == 0 ? default_seed : value);
detail::generator_seed_seq<gen_t> gen(intgen);
seed(gen);
}
/** Seeds the generator with values produced by @c seq.generate(). */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(subtract_with_carry_01_engine,
SeedSeq, seq)
{
detail::seed_array_real<w>(seq, x);
carry = (x[long_lag-1] ? result_type(0) : result_type(1 / _modulus));
k = 0;
}
/**
* Seeds the generator with values from a range. Updates first to
* point one past the last consumed element. If there are not
* enough elements in the range to fill the entire state, throws
* @c std::invalid_argument.
*/
template<class It>
void seed(It& first, It last)
{
detail::fill_array_real<w>(first, last, x);
carry = (x[long_lag-1] ? result_type(0) : result_type(1 / _modulus));
k = 0;
}
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return result_type(0); }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return result_type(1); }
/** Returns the next value of the generator. */
result_type operator()()
{
std::size_t short_index =
(k < short_lag) ?
(k + long_lag - short_lag) :
(k - short_lag);
carry = do_update(k, short_index, carry);
RealType result = x[k];
++k;
if(k >= long_lag)
k = 0;
return result;
}
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{ detail::subtract_with_carry_discard::apply(*this, z); }
/** Fills a range with random values. */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_real(*this, first, last); }
/** Writes a \subtract_with_carry_01_engine to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, subtract_with_carry_01_engine, f)
{
std::ios_base::fmtflags oldflags =
os.flags(os.dec | os.fixed | os.left);
for(unsigned int j = 0; j < f.long_lag; ++j)
os << (f.compute(j) * f._modulus) << ' ';
os << (f.carry * f._modulus);
os.flags(oldflags);
return os;
}
/** Reads a \subtract_with_carry_01_engine from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, subtract_with_carry_01_engine, f)
{
RealType value;
for(unsigned int j = 0; j < long_lag; ++j) {
is >> value >> std::ws;
f.x[j] = value / f._modulus;
}
is >> value;
f.carry = value / f._modulus;
f.k = 0;
return is;
}
/** Returns true if the two generators will produce identical sequences. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(subtract_with_carry_01_engine, x, y)
{
for(unsigned int j = 0; j < r; ++j)
if(x.compute(j) != y.compute(j))
return false;
return true;
}
/** Returns true if the two generators will produce different sequences. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(subtract_with_carry_01_engine)
private:
/// \cond show_private
RealType compute(unsigned int index) const
{
return x[(k+index) % long_lag];
}
friend struct detail::subtract_with_carry_discard;
RealType do_update(std::size_t current, std::size_t short_index, RealType carry)
{
RealType delta = x[short_index] - x[current] - carry;
if(delta < 0) {
delta += RealType(1);
carry = RealType(1)/_modulus;
} else {
carry = 0;
}
x[current] = delta;
return carry;
}
/// \endcond
std::size_t k;
RealType carry;
RealType x[long_lag];
RealType _modulus;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
const bool subtract_with_carry_01_engine<RealType, w, s, r>::has_fixed_range;
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
const std::size_t subtract_with_carry_01_engine<RealType, w, s, r>::word_size;
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
const std::size_t subtract_with_carry_01_engine<RealType, w, s, r>::long_lag;
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
const std::size_t subtract_with_carry_01_engine<RealType, w, s, r>::short_lag;
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
const uint32_t subtract_with_carry_01_engine<RealType, w, s, r>::default_seed;
#endif
/// \cond show_deprecated
template<class IntType, IntType m, unsigned s, unsigned r, IntType v>
class subtract_with_carry :
public subtract_with_carry_engine<IntType,
Boost::static_log2<m>::value, s, r>
{
typedef subtract_with_carry_engine<IntType,
Boost::static_log2<m>::value, s, r> base_type;
public:
subtract_with_carry() {}
ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(subtract_with_carry, Gen, gen)
{ seed(gen); }
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry,
IntType, val)
{ seed(val); }
template<class It>
subtract_with_carry(It& first, It last) : base_type(first, last) {}
void seed() { base_type::seed(); }
ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED(subtract_with_carry, Gen, gen)
{
detail::generator_seed_seq<Gen> seq(gen);
base_type::seed(seq);
}
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(subtract_with_carry, IntType, val)
{ base_type::seed(val); }
template<class It>
void seed(It& first, It last) { base_type::seed(first, last); }
};
template<class RealType, int w, unsigned s, unsigned r, int v = 0>
class subtract_with_carry_01 :
public subtract_with_carry_01_engine<RealType, w, s, r>
{
typedef subtract_with_carry_01_engine<RealType, w, s, r> base_type;
public:
subtract_with_carry_01() {}
ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(subtract_with_carry_01, Gen, gen)
{ seed(gen); }
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry_01,
uint32_t, val)
{ seed(val); }
template<class It>
subtract_with_carry_01(It& first, It last) : base_type(first, last) {}
void seed() { base_type::seed(); }
ACTIV_BOOST_RANDOM_DETAIL_GENERATOR_SEED(subtract_with_carry_01, Gen, gen)
{
detail::generator_seed_seq<Gen> seq(gen);
base_type::seed(seq);
}
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(subtract_with_carry_01, uint32_t, val)
{ base_type::seed(val); }
template<class It>
void seed(It& first, It last) { base_type::seed(first, last); }
};
/// \endcond
namespace detail {
template<class Engine>
struct generator_bits;
template<class RealType, std::size_t w, std::size_t s, std::size_t r>
struct generator_bits<subtract_with_carry_01_engine<RealType, w, s, r> > {
static std::size_t value() { return w; }
};
template<class RealType, int w, unsigned s, unsigned r, int v>
struct generator_bits<subtract_with_carry_01<RealType, w, s, r, v> > {
static std::size_t value() { return w; }
};
}
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_SUBTRACT_WITH_CARRY_HPP
@@ -1,45 +0,0 @@
/* boost random/taus88.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org/libs/random for documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_TAUS88_HPP
#define ACTIV_BOOST_RANDOM_TAUS88_HPP
#include <ActivBoost/random/linear_feedback_shift.hpp>
#include <ActivBoost/random/xor_combine.hpp>
namespace Boost {
namespace random {
/**
* The specialization taus88 was suggested in
*
* @blockquote
* "Maximally Equidistributed Combined Tausworthe Generators",
* Pierre L'Ecuyer, Mathematics of Computation, Volume 65,
* Number 213, January 1996, Pages 203-213
* @endblockquote
*/
typedef xor_combine_engine<
xor_combine_engine<
linear_feedback_shift_engine<uint32_t, 32, 31, 13, 12>, 0,
linear_feedback_shift_engine<uint32_t, 32, 29, 2, 4>, 0>, 0,
linear_feedback_shift_engine<uint32_t, 32, 28, 3, 17>, 0> taus88;
} // namespace random
using random::taus88;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_TAUS88_HPP
-107
View File
@@ -1,107 +0,0 @@
/* boost random/traits.hpp header file
*
* Copyright John Maddock 2015
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* These traits classes serve two purposes: they are designed to mostly
* work out of the box for multiprecision types (ie number types that are
* C++ class types and not integers or floats from type-traits point of view),
* they are also a potential point of specialization for user-defined
* number types.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_TRAITS_HPP
#define ACTIV_BOOST_RANDOM_TRAITS_HPP
#include <ActivBoost/type_traits/integral_constant.hpp>
#include <ActivBoost/type_traits/is_signed.hpp>
#include <ActivBoost/type_traits/is_integral.hpp>
#include <ActivBoost/type_traits/make_unsigned.hpp>
#include <limits>
namespace Boost {
namespace random {
namespace traits {
// \cond show_private
template <class T, bool intrinsic>
struct make_unsigned_imp
{
typedef typename Boost::make_unsigned<T>::type type;
};
template <class T>
struct make_unsigned_imp<T, false>
{
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_signed == false);
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
typedef T type;
};
// \endcond
/** \brief Converts the argument type T to an unsigned type.
*
* This trait has a single member `type` which is the unsigned type corresponding to T.
* Note that
* if T is signed, then member `type` *should define a type with one more bit precision than T*. For built-in
* types this trait defaults to `Boost::make_unsigned<T>::type`. For user defined types it simply asserts that
* the argument type T is an unsigned integer (using std::numeric_limits).
* User defined specializations may be provided for other cases.
*/
template <class T>
struct make_unsigned
// \cond show_private
: public make_unsigned_imp < T, Boost::is_integral<T>::value >
// \endcond
{};
// \cond show_private
template <class T, bool intrinsic>
struct make_unsigned_or_unbounded_imp
{
typedef typename Boost::make_unsigned<T>::type type;
};
template <class T>
struct make_unsigned_or_unbounded_imp<T, false>
{
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
ACTIV_BOOST_STATIC_ASSERT((std::numeric_limits<T>::is_signed == false) || (std::numeric_limits<T>::is_bounded == false));
ACTIV_BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_integer == true);
typedef T type;
};
// \endcond
/** \brief Converts the argument type T to either an unsigned type or an unbounded integer type.
*
* This trait has a single member `type` which is either the unsigned type corresponding to T or an unbounded
* integer type. This trait is used to generate types suitable for the calculation of a range: as a result
* if T is signed, then member `type` *should define a type with one more bit precision than T*. For built-in
* types this trait defaults to `Boost::make_unsigned<T>::type`. For user defined types it simply asserts that
* the argument type T is either an unbounded integer, or an unsigned one (using std::numeric_limits).
* User defined specializations may be provided for other cases.
*/
template <class T>
struct make_unsigned_or_unbounded
// \cond show_private
: public make_unsigned_or_unbounded_imp < T, Boost::is_integral<T>::value >
// \endcond
{};
/** \brief Traits class that indicates whether type T is an integer
*/
template <class T>
struct is_integral
: public integral_constant<bool, Boost::is_integral<T>::value || (std::numeric_limits<T>::is_integer)>
{};
/** \brief Traits class that indicates whether type T is a signed integer
*/
template <class T> struct is_signed
: public integral_constant<bool, Boost::is_signed<T>::value || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer && std::numeric_limits<T>::is_signed)>
{};
}
}
}
#endif
@@ -1,232 +0,0 @@
/* boost random/triangle_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <ios>
#include <istream>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/uniform_01.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of @c triangle_distribution model a \random_distribution.
* A @c triangle_distribution has three parameters, @c a, @c b, and @c c,
* which are the smallest, the most probable and the largest values of
* the distribution respectively.
*/
template<class RealType = double>
class triangle_distribution
{
public:
typedef RealType input_type;
typedef RealType result_type;
class param_type
{
public:
typedef triangle_distribution distribution_type;
/** Constructs the parameters of a @c triangle_distribution. */
explicit param_type(RealType a_arg = RealType(0.0),
RealType b_arg = RealType(0.5),
RealType c_arg = RealType(1.0))
: _a(a_arg), _b(b_arg), _c(c_arg)
{
ACTIV_BOOST_ASSERT(_a <= _b && _b <= _c);
}
/** Returns the minimum value of the distribution. */
RealType a() const { return _a; }
/** Returns the mode of the distribution. */
RealType b() const { return _b; }
/** Returns the maximum value of the distribution. */
RealType c() const { return _c; }
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._a << " " << parm._b << " " << parm._c;
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
double a_in, b_in, c_in;
if(is >> a_in >> std::ws >> b_in >> std::ws >> c_in) {
if(a_in <= b_in && b_in <= c_in) {
parm._a = a_in;
parm._b = b_in;
parm._c = c_in;
} else {
is.setstate(std::ios_base::failbit);
}
}
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._a == rhs._a && lhs._b == rhs._b && lhs._c == rhs._c; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _a;
RealType _b;
RealType _c;
};
/**
* Constructs a @c triangle_distribution with the parameters
* @c a, @c b, and @c c.
*
* Preconditions: a <= b <= c.
*/
explicit triangle_distribution(RealType a_arg = RealType(0.0),
RealType b_arg = RealType(0.5),
RealType c_arg = RealType(1.0))
: _a(a_arg), _b(b_arg), _c(c_arg)
{
ACTIV_BOOST_ASSERT(_a <= _b && _b <= _c);
init();
}
/** Constructs a @c triangle_distribution from its parameters. */
explicit triangle_distribution(const param_type& parm)
: _a(parm.a()), _b(parm.b()), _c(parm.c())
{
init();
}
// compiler-generated copy ctor and assignment operator are fine
/** Returns the @c a parameter of the distribution */
result_type a() const { return _a; }
/** Returns the @c b parameter of the distribution */
result_type b() const { return _b; }
/** Returns the @c c parameter of the distribution */
result_type c() const { return _c; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _a; }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _c; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_a, _b, _c); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_a = parm.a();
_b = parm.b();
_c = parm.c();
init();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/**
* Returns a random variate distributed according to the
* triangle distribution.
*/
template<class Engine>
result_type operator()(Engine& eng)
{
using std::sqrt;
result_type u = uniform_01<result_type>()(eng);
if( u <= q1 )
return _a + p1*sqrt(u);
else
return _c - d3*sqrt(d2*u-d1);
}
/**
* Returns a random variate distributed according to the
* triangle distribution with parameters specified by param.
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm)
{ return triangle_distribution(parm)(eng); }
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, triangle_distribution, td)
{
os << td.param();
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, triangle_distribution, td)
{
param_type parm;
if(is >> parm) {
td.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will produce identical
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(triangle_distribution, lhs, rhs)
{ return lhs._a == rhs._a && lhs._b == rhs._b && lhs._c == rhs._c; }
/**
* Returns true if the two distributions may produce different
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(triangle_distribution)
private:
/// \cond show_private
void init()
{
using std::sqrt;
d1 = _b - _a;
d2 = _c - _a;
d3 = sqrt(_c - _b);
q1 = d1 / d2;
p1 = sqrt(d1 * d2);
}
/// \endcond
RealType _a, _b, _c;
RealType d1, d2, d3, q1, p1;
};
} // namespace random
using random::triangle_distribution;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_TRIANGLE_DISTRIBUTION_HPP
@@ -1,257 +0,0 @@
/* boost random/uniform_01.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_01_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_01_HPP
#include <iostream>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/static_assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/ptr_helper.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
namespace random {
#ifdef ACTIV_BOOST_RANDOM_DOXYGEN
/**
* The distribution function uniform_01 models a \random_distribution.
* On each invocation, it returns a random floating-point value
* uniformly distributed in the range [0..1).
*
* The template parameter RealType shall denote a float-like value type
* with support for binary operators +, -, and /.
*
* Note: The current implementation is buggy, because it may not fill
* all of the mantissa with random bits. I'm unsure how to fill a
* (to-be-invented) @c Boost::bigfloat class with random bits efficiently.
* It's probably time for a traits class.
*/
template<class RealType = double>
class uniform_01
{
public:
typedef RealType input_type;
typedef RealType result_type;
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const;
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const;
void reset();
template<class Engine>
result_type operator()(Engine& eng);
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os, const new_uniform_01&)
{
return os;
}
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, new_uniform_01&)
{
return is;
}
#endif
};
#else
namespace detail {
template<class RealType>
class new_uniform_01
{
public:
typedef RealType input_type;
typedef RealType result_type;
// compiler-generated copy ctor and copy assignment are fine
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
void reset() { }
template<class Engine>
result_type operator()(Engine& eng) {
for (;;) {
typedef typename Engine::result_type base_result;
result_type factor = result_type(1) /
(result_type(base_result((eng.max)()-(eng.min)())) +
result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0));
result_type result = result_type(base_result(eng() - (eng.min)())) * factor;
if (result < result_type(1))
return result;
}
}
#ifndef ACTIV_BOOST_RANDOM_NO_STREAM_OPERATORS
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os, const new_uniform_01&)
{
return os;
}
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, new_uniform_01&)
{
return is;
}
#endif
};
template<class UniformRandomNumberGenerator, class RealType>
class backward_compatible_uniform_01
{
typedef Boost::random::detail::ptr_helper<UniformRandomNumberGenerator> traits;
public:
typedef UniformRandomNumberGenerator base_type;
typedef RealType result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
#if !defined(ACTIV_BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS)
ACTIV_BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
#endif
explicit backward_compatible_uniform_01(typename traits::rvalue_type rng)
: _rng(rng),
_factor(result_type(1) /
(result_type((base().max)()-(base().min)()) +
result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0)))
{
}
// compiler-generated copy ctor and copy assignment are fine
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
typename traits::value_type& base() { return traits::ref(_rng); }
const typename traits::value_type& base() const { return traits::ref(_rng); }
void reset() { }
result_type operator()() {
for (;;) {
result_type result = result_type(base()() - (base().min)()) * _factor;
if (result < result_type(1))
return result;
}
}
#if !defined(ACTIV_BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(ACTIV_BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os, const backward_compatible_uniform_01& u)
{
os << u._rng;
return os;
}
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, backward_compatible_uniform_01& u)
{
is >> u._rng;
return is;
}
#endif
private:
typedef typename traits::value_type::result_type base_result;
UniformRandomNumberGenerator _rng;
result_type _factor;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class UniformRandomNumberGenerator, class RealType>
const bool backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType>::has_fixed_range;
#endif
template<class UniformRandomNumberGenerator, bool is_number = std::numeric_limits<UniformRandomNumberGenerator>::is_specialized>
struct select_uniform_01
{
template<class RealType>
struct apply
{
typedef backward_compatible_uniform_01<UniformRandomNumberGenerator, RealType> type;
};
};
template<class Num>
struct select_uniform_01<Num, true>
{
template<class RealType>
struct apply
{
typedef new_uniform_01<Num> type;
};
};
}
// Because it is so commonly used: uniform distribution on the real [0..1)
// range. This allows for specializations to avoid a costly int -> float
// conversion plus float multiplication
template<class UniformRandomNumberGenerator = double, class RealType = double>
class uniform_01
: public detail::select_uniform_01<UniformRandomNumberGenerator>::ACTIV_BOOST_NESTED_TEMPLATE apply<RealType>::type
{
typedef typename detail::select_uniform_01<UniformRandomNumberGenerator>::ACTIV_BOOST_NESTED_TEMPLATE apply<RealType>::type impl_type;
typedef Boost::random::detail::ptr_helper<UniformRandomNumberGenerator> traits;
public:
uniform_01() {}
explicit uniform_01(typename traits::rvalue_type rng)
: impl_type(rng)
{
}
#if !defined(ACTIV_BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(ACTIV_BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_01& u)
{
os << static_cast<const impl_type&>(u);
return os;
}
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, uniform_01& u)
{
is >> static_cast<impl_type&>(u);
return is;
}
#endif
};
#endif
} // namespace random
using random::uniform_01;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_UNIFORM_01_HPP
@@ -1,99 +0,0 @@
/* boost random/uniform_int.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-04-08 added min<max assertion (N. Becker)
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_INT_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_INT_HPP
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/uniform_int_distribution.hpp>
namespace Boost {
/**
* The distribution function uniform_int models a \random_distribution.
* On each invocation, it returns a random integer value uniformly
* distributed in the set of integer numbers {min, min+1, min+2, ..., max}.
*
* The template parameter IntType shall denote an integer-like value type.
*
* This class is deprecated. Please use @c uniform_int_distribution in
* new code.
*/
template<class IntType = int>
class uniform_int : public random::uniform_int_distribution<IntType>
{
typedef random::uniform_int_distribution<IntType> base_type;
public:
class param_type : public base_type::param_type
{
public:
typedef uniform_int distribution_type;
/**
* Constructs the parameters of a uniform_int distribution.
*
* Requires: min <= max
*/
explicit param_type(IntType min_arg = 0, IntType max_arg = 9)
: base_type::param_type(min_arg, max_arg)
{}
};
/**
* Constructs a uniform_int object. @c min and @c max are
* the parameters of the distribution.
*
* Requires: min <= max
*/
explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9)
: base_type(min_arg, max_arg)
{}
/** Constructs a uniform_int distribution from its parameters. */
explicit uniform_int(const param_type& parm)
: base_type(parm)
{}
/** Returns the parameters of the distribution */
param_type param() const { return param_type(this->a(), this->b()); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm) { this->base_type::param(parm); }
// Codergear seems to have trouble with a using declaration here
template<class Engine>
IntType operator()(Engine& eng) const
{
return static_cast<const base_type&>(*this)(eng);
}
template<class Engine>
IntType operator()(Engine& eng, const param_type& parm) const
{
return static_cast<const base_type&>(*this)(eng, parm);
}
template<class Engine>
IntType operator()(Engine& eng, IntType n) const
{
ACTIV_BOOST_ASSERT(n > 0);
return static_cast<const base_type&>(*this)(eng, param_type(0, n - 1));
}
};
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_UNIFORM_INT_HPP
@@ -1,419 +0,0 @@
/* boost random/uniform_int_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-04-08 added min<max assertion (N. Becker)
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
#include <iosfwd>
#include <ios>
#include <istream>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/uniform_int_float.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/random/traits.hpp>
#include <ActivBoost/type_traits/integral_constant.hpp>
#ifdef ACTIV_BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
#include <ActivBoost/type_traits/conditional.hpp>
#endif
namespace Boost {
namespace random {
namespace detail {
#ifdef ACTIV_BOOST_MSVC
#pragma warning(push)
// disable division by zero warning, since we can't
// actually divide by zero.
#pragma warning(disable:4723)
#endif
template<class Engine, class T>
T generate_uniform_int(
Engine& eng, T min_value, T max_value,
Boost::true_type /** is_integral<Engine::result_type> */)
{
typedef T result_type;
typedef typename Boost::random::traits::make_unsigned_or_unbounded<T>::type range_type;
typedef typename Engine::result_type base_result;
// ranges are always unsigned or unbounded
typedef typename Boost::random::traits::make_unsigned_or_unbounded<base_result>::type base_unsigned;
const range_type range = random::detail::subtract<result_type>()(max_value, min_value);
const base_result bmin = (eng.min)();
const base_unsigned brange =
random::detail::subtract<base_result>()((eng.max)(), (eng.min)());
if(range == 0) {
return min_value;
} else if(brange == range) {
// this will probably never happen in real life
// basically nothing to do; just take care we don't overflow / underflow
base_unsigned v = random::detail::subtract<base_result>()(eng(), bmin);
return random::detail::add<base_unsigned, result_type>()(v, min_value);
} else if(brange < range) {
// use rejection method to handle things like 0..3 --> 0..4
for(;;) {
// concatenate several invocations of the base RNG
// take extra care to avoid overflows
// limit == floor((range+1)/(brange+1))
// Therefore limit*(brange+1) <= range+1
range_type limit;
if(range == (std::numeric_limits<range_type>::max)()) {
limit = range/(range_type(brange)+1);
if(range % (range_type(brange)+1) == range_type(brange))
++limit;
} else {
limit = (range+1)/(range_type(brange)+1);
}
// We consider "result" as expressed to base (brange+1):
// For every power of (brange+1), we determine a random factor
range_type result = range_type(0);
range_type mult = range_type(1);
// loop invariants:
// result < mult
// mult <= range
while(mult <= limit) {
// Postcondition: result <= range, thus no overflow
//
// limit*(brange+1)<=range+1 def. of limit (1)
// eng()-bmin<=brange eng() post. (2)
// and mult<=limit. loop condition (3)
// Therefore mult*(eng()-bmin+1)<=range+1 by (1),(2),(3) (4)
// Therefore mult*(eng()-bmin)+mult<=range+1 rearranging (4) (5)
// result<mult loop invariant (6)
// Therefore result+mult*(eng()-bmin)<range+1 by (5), (6) (7)
//
// Postcondition: result < mult*(brange+1)
//
// result<mult loop invariant (1)
// eng()-bmin<=brange eng() post. (2)
// Therefore result+mult*(eng()-bmin) <
// mult+mult*(eng()-bmin) by (1) (3)
// Therefore result+(eng()-bmin)*mult <
// mult+mult*brange by (2), (3) (4)
// Therefore result+(eng()-bmin)*mult <
// mult*(brange+1) by (4)
result += static_cast<range_type>(static_cast<range_type>(random::detail::subtract<base_result>()(eng(), bmin)) * mult);
// equivalent to (mult * (brange+1)) == range+1, but avoids overflow.
if(mult * range_type(brange) == range - mult + 1) {
// The destination range is an integer power of
// the generator's range.
return(result);
}
// Postcondition: mult <= range
//
// limit*(brange+1)<=range+1 def. of limit (1)
// mult<=limit loop condition (2)
// Therefore mult*(brange+1)<=range+1 by (1), (2) (3)
// mult*(brange+1)!=range+1 preceding if (4)
// Therefore mult*(brange+1)<range+1 by (3), (4) (5)
//
// Postcondition: result < mult
//
// See the second postcondition on the change to result.
mult *= range_type(brange)+range_type(1);
}
// loop postcondition: range/mult < brange+1
//
// mult > limit loop condition (1)
// Suppose range/mult >= brange+1 Assumption (2)
// range >= mult*(brange+1) by (2) (3)
// range+1 > mult*(brange+1) by (3) (4)
// range+1 > (limit+1)*(brange+1) by (1), (4) (5)
// (range+1)/(brange+1) > limit+1 by (5) (6)
// limit < floor((range+1)/(brange+1)) by (6) (7)
// limit==floor((range+1)/(brange+1)) def. of limit (8)
// not (2) reductio (9)
//
// loop postcondition: (range/mult)*mult+(mult-1) >= range
//
// (range/mult)*mult + range%mult == range identity (1)
// range%mult < mult def. of % (2)
// (range/mult)*mult+mult > range by (1), (2) (3)
// (range/mult)*mult+(mult-1) >= range by (3) (4)
//
// Note that the maximum value of result at this point is (mult-1),
// so after this final step, we generate numbers that can be
// at least as large as range. We have to really careful to avoid
// overflow in this final addition and in the rejection. Anything
// that overflows is larger than range and can thus be rejected.
// range/mult < brange+1 -> no endless loop
range_type result_increment =
generate_uniform_int(
eng,
static_cast<range_type>(0),
static_cast<range_type>(range/mult),
Boost::true_type());
if(std::numeric_limits<range_type>::is_bounded && ((std::numeric_limits<range_type>::max)() / mult < result_increment)) {
// The multiplcation would overflow. Reject immediately.
continue;
}
result_increment *= mult;
// unsigned integers are guaranteed to wrap on overflow.
result += result_increment;
if(result < result_increment) {
// The addition overflowed. Reject.
continue;
}
if(result > range) {
// Too big. Reject.
continue;
}
return random::detail::add<range_type, result_type>()(result, min_value);
}
} else { // brange > range
#ifdef ACTIV_BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
typedef typename conditional<
std::numeric_limits<range_type>::is_specialized && std::numeric_limits<base_unsigned>::is_specialized
&& (std::numeric_limits<range_type>::digits >= std::numeric_limits<base_unsigned>::digits),
range_type, base_unsigned>::type mixed_range_type;
#else
typedef base_unsigned mixed_range_type;
#endif
mixed_range_type bucket_size;
// it's safe to add 1 to range, as long as we cast it first,
// because we know that it is less than brange. However,
// we do need to be careful not to cause overflow by adding 1
// to brange. We use mixed_range_type throughout for mixed
// arithmetic between base_unsigned and range_type - in the case
// that range_type has more bits than base_unsigned it is always
// safe to use range_type for this albeit it may be more effient
// to use base_unsigned. The latter is a narrowing conversion though
// which may be disallowed if range_type is a multiprecision type
// and there are no explicit converison operators.
if(brange == (std::numeric_limits<base_unsigned>::max)()) {
bucket_size = static_cast<mixed_range_type>(brange) / (static_cast<mixed_range_type>(range)+1);
if(static_cast<mixed_range_type>(brange) % (static_cast<mixed_range_type>(range)+1) == static_cast<mixed_range_type>(range)) {
++bucket_size;
}
} else {
bucket_size = static_cast<mixed_range_type>(brange + 1) / (static_cast<mixed_range_type>(range)+1);
}
for(;;) {
mixed_range_type result =
random::detail::subtract<base_result>()(eng(), bmin);
result /= bucket_size;
// result and range are non-negative, and result is possibly larger
// than range, so the cast is safe
if(result <= static_cast<mixed_range_type>(range))
return random::detail::add<mixed_range_type, result_type>()(result, min_value);
}
}
}
#ifdef ACTIV_BOOST_MSVC
#pragma warning(pop)
#endif
template<class Engine, class T>
inline T generate_uniform_int(
Engine& eng, T min_value, T max_value,
Boost::false_type /** is_integral<Engine::result_type> */)
{
uniform_int_float<Engine> wrapper(eng);
return generate_uniform_int(wrapper, min_value, max_value, Boost::true_type());
}
template<class Engine, class T>
inline T generate_uniform_int(Engine& eng, T min_value, T max_value)
{
typedef typename Engine::result_type base_result;
return generate_uniform_int(eng, min_value, max_value,
Boost::random::traits::is_integral<base_result>());
}
}
/**
* The class template uniform_int_distribution models a \random_distribution.
* On each invocation, it returns a random integer value uniformly
* distributed in the set of integers {min, min+1, min+2, ..., max}.
*
* The template parameter IntType shall denote an integer-like value type.
*/
template<class IntType = int>
class uniform_int_distribution
{
public:
typedef IntType input_type;
typedef IntType result_type;
class param_type
{
public:
typedef uniform_int_distribution distribution_type;
/**
* Constructs the parameters of a uniform_int_distribution.
*
* Requires min <= max
*/
explicit param_type(
IntType min_arg = 0,
IntType max_arg = (std::numeric_limits<IntType>::max)())
: _min(min_arg), _max(max_arg)
{
ACTIV_BOOST_ASSERT(_min <= _max);
}
/** Returns the minimum value of the distribution. */
IntType a() const { return _min; }
/** Returns the maximum value of the distribution. */
IntType b() const { return _max; }
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._min << " " << parm._max;
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
IntType min_in, max_in;
if(is >> min_in >> std::ws >> max_in) {
if(min_in <= max_in) {
parm._min = min_in;
parm._max = max_in;
} else {
is.setstate(std::ios_base::failbit);
}
}
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._min == rhs._min && lhs._max == rhs._max; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
IntType _min;
IntType _max;
};
/**
* Constructs a uniform_int_distribution. @c min and @c max are
* the parameters of the distribution.
*
* Requires: min <= max
*/
explicit uniform_int_distribution(
IntType min_arg = 0,
IntType max_arg = (std::numeric_limits<IntType>::max)())
: _min(min_arg), _max(max_arg)
{
ACTIV_BOOST_ASSERT(min_arg <= max_arg);
}
/** Constructs a uniform_int_distribution from its parameters. */
explicit uniform_int_distribution(const param_type& parm)
: _min(parm.a()), _max(parm.b()) {}
/** Returns the minimum value of the distribution */
IntType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
/** Returns the maximum value of the distribution */
IntType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
/** Returns the minimum value of the distribution */
IntType a() const { return _min; }
/** Returns the maximum value of the distribution */
IntType b() const { return _max; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_min, _max); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_min = parm.a();
_max = parm.b();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Returns an integer uniformly distributed in the range [min, max]. */
template<class Engine>
result_type operator()(Engine& eng) const
{ return detail::generate_uniform_int(eng, _min, _max); }
/**
* Returns an integer uniformly distributed in the range
* [param.a(), param.b()].
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm) const
{ return detail::generate_uniform_int(eng, parm.a(), parm.b()); }
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_int_distribution, ud)
{
os << ud.param();
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_int_distribution, ud)
{
param_type parm;
if(is >> parm) {
ud.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will produce identical sequences
* of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_int_distribution, lhs, rhs)
{ return lhs._min == rhs._min && lhs._max == rhs._max; }
/**
* Returns true if the two distributions may produce different sequences
* of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_int_distribution)
private:
IntType _min;
IntType _max;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_UNIFORM_INT_HPP
@@ -1,288 +0,0 @@
/* boost random/uniform_on_sphere.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
#include <vector>
#include <algorithm> // std::transform
#include <functional> // std::bind2nd, std::divides
#include <ActivBoost/assert.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/normal_distribution.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of class template uniform_on_sphere model a
* \random_distribution. Such a distribution produces random
* numbers uniformly distributed on the unit sphere of arbitrary
* dimension @c dim. The @c Cont template parameter must be a STL-like
* container type with begin and end operations returning non-const
* ForwardIterators of type @c Cont::iterator.
*/
template<class RealType = double, class Cont = std::vector<RealType> >
class uniform_on_sphere
{
public:
typedef RealType input_type;
typedef Cont result_type;
class param_type
{
public:
typedef uniform_on_sphere distribution_type;
/**
* Constructs the parameters of a uniform_on_sphere
* distribution, given the dimension of the sphere.
*/
explicit param_type(int dim_arg = 2) : _dim(dim_arg)
{
ACTIV_BOOST_ASSERT(_dim >= 0);
}
/** Returns the dimension of the sphere. */
int dim() const { return _dim; }
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._dim;
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._dim;
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._dim == rhs._dim; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
int _dim;
};
/**
* Constructs a @c uniform_on_sphere distribution.
* @c dim is the dimension of the sphere.
*
* Requires: dim >= 0
*/
explicit uniform_on_sphere(int dim_arg = 2)
: _container(dim_arg), _dim(dim_arg) { }
/**
* Constructs a @c uniform_on_sphere distribution from its parameters.
*/
explicit uniform_on_sphere(const param_type& parm)
: _container(parm.dim()), _dim(parm.dim()) { }
// compiler-generated copy ctor and assignment operator are fine
/** Returns the dimension of the sphere. */
int dim() const { return _dim; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_dim); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_dim = parm.dim();
_container.resize(_dim);
}
/**
* Returns the smallest value that the distribution can produce.
* Note that this is required to approximate the standard library's
* requirements. The behavior is defined according to lexicographical
* comparison so that for a container type of std::vector,
* dist.min() <= x <= dist.max() where x is any value produced
* by the distribution.
*/
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{
result_type result(_dim);
if(_dim != 0) {
result.front() = RealType(-1.0);
}
return result;
}
/**
* Returns the largest value that the distribution can produce.
* Note that this is required to approximate the standard library's
* requirements. The behavior is defined according to lexicographical
* comparison so that for a container type of std::vector,
* dist.min() <= x <= dist.max() where x is any value produced
* by the distribution.
*/
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{
result_type result(_dim);
if(_dim != 0) {
result.front() = RealType(1.0);
}
return result;
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() {}
/**
* Returns a point uniformly distributed over the surface of
* a sphere of dimension dim().
*/
template<class Engine>
const result_type & operator()(Engine& eng)
{
using std::sqrt;
switch(_dim)
{
case 0: break;
case 1:
{
if(uniform_01<RealType>()(eng) < 0.5) {
*_container.begin() = -1;
} else {
*_container.begin() = 1;
}
break;
}
case 2:
{
uniform_01<RealType> uniform;
RealType sqsum;
RealType x, y;
do {
x = uniform(eng) * 2 - 1;
y = uniform(eng) * 2 - 1;
sqsum = x*x + y*y;
} while(sqsum == 0 || sqsum > 1);
RealType mult = 1/sqrt(sqsum);
typename Cont::iterator iter = _container.begin();
*iter = x * mult;
iter++;
*iter = y * mult;
break;
}
case 3:
{
uniform_01<RealType> uniform;
RealType sqsum;
RealType x, y;
do {
x = uniform(eng) * 2 - 1;
y = uniform(eng) * 2 - 1;
sqsum = x*x + y*y;
} while(sqsum > 1);
RealType mult = 2 * sqrt(1 - sqsum);
typename Cont::iterator iter = _container.begin();
*iter = x * mult;
++iter;
*iter = y * mult;
++iter;
*iter = 2 * sqsum - 1;
break;
}
default:
{
detail::unit_normal_distribution<RealType> normal;
RealType sqsum;
do {
sqsum = 0;
for(typename Cont::iterator it = _container.begin();
it != _container.end();
++it) {
RealType val = normal(eng);
*it = val;
sqsum += val * val;
}
} while(sqsum == 0);
// for all i: result[i] /= sqrt(sqsum)
RealType inverse_distance = 1 / sqrt(sqsum);
for(typename Cont::iterator it = _container.begin();
it != _container.end();
++it) {
*it *= inverse_distance;
}
}
}
return _container;
}
/**
* Returns a point uniformly distributed over the surface of
* a sphere of dimension param.dim().
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm) const
{
return uniform_on_sphere(parm)(eng);
}
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_on_sphere, sd)
{
os << sd._dim;
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_on_sphere, sd)
{
is >> sd._dim;
sd._container.resize(sd._dim);
return is;
}
/**
* Returns true if the two distributions will produce identical
* sequences of values, given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_on_sphere, lhs, rhs)
{ return lhs._dim == rhs._dim; }
/**
* Returns true if the two distributions may produce different
* sequences of values, given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_on_sphere)
private:
result_type _container;
int _dim;
};
} // namespace random
using random::uniform_on_sphere;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_UNIFORM_ON_SPHERE_HPP
@@ -1,82 +0,0 @@
/* boost random/uniform_real.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-04-08 added min<max assertion (N. Becker)
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_REAL_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_REAL_HPP
#include <ActivBoost/assert.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/uniform_real_distribution.hpp>
namespace Boost {
/**
* The distribution function uniform_real models a random distribution.
* On each invocation, it returns a random floating-point value uniformly
* distributed in the range [min..max).
*
* This class is deprecated. Please use @c uniform_real_distribution in
* new code.
*/
template<class RealType = double>
class uniform_real : public random::uniform_real_distribution<RealType>
{
typedef random::uniform_real_distribution<RealType> base_type;
public:
class param_type : public base_type::param_type
{
public:
typedef uniform_real distribution_type;
/**
* Constructs the parameters of a uniform_real distribution.
*
* Requires: min <= max
*/
explicit param_type(RealType min_arg = RealType(0.0),
RealType max_arg = RealType(1.0))
: base_type::param_type(min_arg, max_arg)
{}
};
/**
* Constructs a uniform_real object. @c min and @c max are the
* parameters of the distribution.
*
* Requires: min <= max
*/
explicit uniform_real(RealType min_arg = RealType(0.0),
RealType max_arg = RealType(1.0))
: base_type(min_arg, max_arg)
{
ACTIV_BOOST_ASSERT(min_arg < max_arg);
}
/** Constructs a uniform_real distribution from its parameters. */
explicit uniform_real(const param_type& parm)
: base_type(parm)
{}
/** Returns the parameters of the distribution */
param_type param() const { return param_type(this->a(), this->b()); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm) { this->base_type::param(parm); }
};
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_UNIFORM_REAL_HPP
@@ -1,240 +0,0 @@
/* boost random/uniform_real_distribution.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
#include <iosfwd>
#include <ios>
#include <istream>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/type_traits/is_integral.hpp>
namespace Boost {
namespace random {
namespace detail {
template<class Engine, class T>
T generate_uniform_real(
Engine& eng, T min_value, T max_value,
Boost::false_type /** is_integral<Engine::result_type> */)
{
for(;;) {
typedef T result_type;
result_type numerator = static_cast<T>(eng() - (eng.min)());
result_type divisor = static_cast<T>((eng.max)() - (eng.min)());
ACTIV_BOOST_ASSERT(divisor > 0);
ACTIV_BOOST_ASSERT(numerator >= 0 && numerator <= divisor);
T result = numerator / divisor * (max_value - min_value) + min_value;
if(result < max_value) return result;
}
}
template<class Engine, class T>
T generate_uniform_real(
Engine& eng, T min_value, T max_value,
Boost::true_type /** is_integral<Engine::result_type> */)
{
for(;;) {
typedef T result_type;
typedef typename Engine::result_type base_result;
result_type numerator = static_cast<T>(subtract<base_result>()(eng(), (eng.min)()));
result_type divisor = static_cast<T>(subtract<base_result>()((eng.max)(), (eng.min)())) + 1;
ACTIV_BOOST_ASSERT(divisor > 0);
ACTIV_BOOST_ASSERT(numerator >= 0 && numerator <= divisor);
T result = numerator / divisor * (max_value - min_value) + min_value;
if(result < max_value) return result;
}
}
template<class Engine, class T>
inline T generate_uniform_real(Engine& eng, T min_value, T max_value)
{
if(max_value / 2 - min_value / 2 > (std::numeric_limits<T>::max)() / 2)
return 2 * generate_uniform_real(eng, T(min_value / 2), T(max_value / 2));
typedef typename Engine::result_type base_result;
return generate_uniform_real(eng, min_value, max_value,
Boost::is_integral<base_result>());
}
}
/**
* The class template uniform_real_distribution models a \random_distribution.
* On each invocation, it returns a random floating-point value uniformly
* distributed in the range [min..max).
*/
template<class RealType = double>
class uniform_real_distribution
{
public:
typedef RealType input_type;
typedef RealType result_type;
class param_type
{
public:
typedef uniform_real_distribution distribution_type;
/**
* Constructs the parameters of a uniform_real_distribution.
*
* Requires min <= max
*/
explicit param_type(RealType min_arg = RealType(0.0),
RealType max_arg = RealType(1.0))
: _min(min_arg), _max(max_arg)
{
ACTIV_BOOST_ASSERT(_min < _max);
}
/** Returns the minimum value of the distribution. */
RealType a() const { return _min; }
/** Returns the maximum value of the distribution. */
RealType b() const { return _max; }
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._min << " " << parm._max;
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
RealType min_in, max_in;
if(is >> min_in >> std::ws >> max_in) {
if(min_in <= max_in) {
parm._min = min_in;
parm._max = max_in;
} else {
is.setstate(std::ios_base::failbit);
}
}
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._min == rhs._min && lhs._max == rhs._max; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _min;
RealType _max;
};
/**
* Constructs a uniform_real_distribution. @c min and @c max are
* the parameters of the distribution.
*
* Requires: min <= max
*/
explicit uniform_real_distribution(
RealType min_arg = RealType(0.0),
RealType max_arg = RealType(1.0))
: _min(min_arg), _max(max_arg)
{
ACTIV_BOOST_ASSERT(min_arg < max_arg);
}
/** Constructs a uniform_real_distribution from its parameters. */
explicit uniform_real_distribution(const param_type& parm)
: _min(parm.a()), _max(parm.b()) {}
/** Returns the minimum value of the distribution */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
/** Returns the maximum value of the distribution */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
/** Returns the minimum value of the distribution */
RealType a() const { return _min; }
/** Returns the maximum value of the distribution */
RealType b() const { return _max; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_min, _max); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_min = parm.a();
_max = parm.b();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Returns a value uniformly distributed in the range [min, max). */
template<class Engine>
result_type operator()(Engine& eng) const
{ return detail::generate_uniform_real(eng, _min, _max); }
/**
* Returns a value uniformly distributed in the range
* [param.a(), param.b()).
*/
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm) const
{ return detail::generate_uniform_real(eng, parm.a(), parm.b()); }
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_real_distribution, ud)
{
os << ud.param();
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_real_distribution, ud)
{
param_type parm;
if(is >> parm) {
ud.param(parm);
}
return is;
}
/**
* Returns true if the two distributions will produce identical sequences
* of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_real_distribution, lhs, rhs)
{ return lhs._min == rhs._min && lhs._max == rhs._max; }
/**
* Returns true if the two distributions may produce different sequences
* of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_real_distribution)
private:
RealType _min;
RealType _max;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_UNIFORM_INT_HPP
@@ -1,306 +0,0 @@
/* boost random/uniform_smallint.hpp header file
*
* Copyright Jens Maurer 2000-2001
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
* Revision history
* 2001-04-08 added min<max assertion (N. Becker)
* 2001-02-18 moved to individual header files
*/
#ifndef ACTIV_BOOST_RANDOM_UNIFORM_SMALLINT_HPP
#define ACTIV_BOOST_RANDOM_UNIFORM_SMALLINT_HPP
#include <istream>
#include <iosfwd>
#include <ActivBoost/assert.hpp>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/type_traits/is_integral.hpp>
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/detail/signed_unsigned_tools.hpp>
#include <ActivBoost/random/uniform_01.hpp>
#include <ActivBoost/detail/workaround.hpp>
#ifdef ACTIV_BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
#include <ActivBoost/type_traits/conditional.hpp>
#endif
namespace Boost {
namespace random {
// uniform integer distribution on a small range [min, max]
/**
* The distribution function uniform_smallint models a \random_distribution.
* On each invocation, it returns a random integer value uniformly distributed
* in the set of integer numbers {min, min+1, min+2, ..., max}. It assumes
* that the desired range (max-min+1) is small compared to the range of the
* underlying source of random numbers and thus makes no attempt to limit
* quantization errors.
*
* Let \f$r_{\mathtt{out}} = (\mbox{max}-\mbox{min}+1)\f$ the desired range of
* integer numbers, and
* let \f$r_{\mathtt{base}}\f$ be the range of the underlying source of random
* numbers. Then, for the uniform distribution, the theoretical probability
* for any number i in the range \f$r_{\mathtt{out}}\f$ will be
* \f$\displaystyle p_{\mathtt{out}}(i) = \frac{1}{r_{\mathtt{out}}}\f$.
* Likewise, assume a uniform distribution on \f$r_{\mathtt{base}}\f$ for
* the underlying source of random numbers, i.e.
* \f$\displaystyle p_{\mathtt{base}}(i) = \frac{1}{r_{\mathtt{base}}}\f$.
* Let \f$p_{\mathtt{out\_s}}(i)\f$ denote the random
* distribution generated by @c uniform_smallint. Then the sum over all
* i in \f$r_{\mathtt{out}}\f$ of
* \f$\displaystyle
* \left(\frac{p_{\mathtt{out\_s}}(i)}{p_{\mathtt{out}}(i)} - 1\right)^2\f$
* shall not exceed
* \f$\displaystyle \frac{r_{\mathtt{out}}}{r_{\mathtt{base}}^2}
* (r_{\mathtt{base}} \mbox{ mod } r_{\mathtt{out}})
* (r_{\mathtt{out}} - r_{\mathtt{base}} \mbox{ mod } r_{\mathtt{out}})\f$.
*
* The template parameter IntType shall denote an integer-like value type.
*
* @xmlnote
* The property above is the square sum of the relative differences
* in probabilities between the desired uniform distribution
* \f$p_{\mathtt{out}}(i)\f$ and the generated distribution
* \f$p_{\mathtt{out\_s}}(i)\f$.
* The property can be fulfilled with the calculation
* \f$(\mbox{base\_rng} \mbox{ mod } r_{\mathtt{out}})\f$, as follows:
* Let \f$r = r_{\mathtt{base}} \mbox{ mod } r_{\mathtt{out}}\f$.
* The base distribution on \f$r_{\mathtt{base}}\f$ is folded onto the
* range \f$r_{\mathtt{out}}\f$. The numbers i < r have assigned
* \f$\displaystyle
* \left\lfloor\frac{r_{\mathtt{base}}}{r_{\mathtt{out}}}\right\rfloor+1\f$
* numbers of the base distribution, the rest has only \f$\displaystyle
* \left\lfloor\frac{r_{\mathtt{base}}}{r_{\mathtt{out}}}\right\rfloor\f$.
* Therefore,
* \f$\displaystyle p_{\mathtt{out\_s}}(i) =
* \left(\left\lfloor\frac{r_{\mathtt{base}}}
* {r_{\mathtt{out}}}\right\rfloor+1\right) /
* r_{\mathtt{base}}\f$ for i < r and \f$\displaystyle p_{\mathtt{out\_s}}(i) =
* \left\lfloor\frac{r_{\mathtt{base}}}
* {r_{\mathtt{out}}}\right\rfloor/r_{\mathtt{base}}\f$ otherwise.
* Substituting this in the
* above sum formula leads to the desired result.
* @endxmlnote
*
* Note: The upper bound for
* \f$(r_{\mathtt{base}} \mbox{ mod } r_{\mathtt{out}})
* (r_{\mathtt{out}} - r_{\mathtt{base}} \mbox{ mod } r_{\mathtt{out}})\f$ is
* \f$\displaystyle \frac{r_{\mathtt{out}}^2}{4}\f$. Regarding the upper bound
* for the square sum of the relative quantization error of
* \f$\displaystyle \frac{r_\mathtt{out}^3}{4r_{\mathtt{base}}^2}\f$, it
* seems wise to either choose \f$r_{\mathtt{base}}\f$ so that
* \f$r_{\mathtt{base}} > 10r_{\mathtt{out}}^2\f$ or ensure that
* \f$r_{\mathtt{base}}\f$ is
* divisible by \f$r_{\mathtt{out}}\f$.
*/
template<class IntType = int>
class uniform_smallint
{
public:
typedef IntType input_type;
typedef IntType result_type;
class param_type
{
public:
typedef uniform_smallint distribution_type;
/** constructs the parameters of a @c uniform_smallint distribution. */
param_type(IntType min_arg = 0, IntType max_arg = 9)
: _min(min_arg), _max(max_arg)
{
ACTIV_BOOST_ASSERT(_min <= _max);
}
/** Returns the minimum value. */
IntType a() const { return _min; }
/** Returns the maximum value. */
IntType b() const { return _max; }
/** Writes the parameters to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{
os << parm._min << " " << parm._max;
return os;
}
/** Reads the parameters from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{
is >> parm._min >> std::ws >> parm._max;
return is;
}
/** Returns true if the two sets of parameters are equal. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._min == rhs._min && lhs._max == rhs._max; }
/** Returns true if the two sets of parameters are different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
IntType _min;
IntType _max;
};
/**
* Constructs a @c uniform_smallint. @c min and @c max are the
* lower and upper bounds of the output range, respectively.
*/
explicit uniform_smallint(IntType min_arg = 0, IntType max_arg = 9)
: _min(min_arg), _max(max_arg) {}
/**
* Constructs a @c uniform_smallint from its parameters.
*/
explicit uniform_smallint(const param_type& parm)
: _min(parm.a()), _max(parm.b()) {}
/** Returns the minimum value of the distribution. */
result_type a() const { return _min; }
/** Returns the maximum value of the distribution. */
result_type b() const { return _max; }
/** Returns the minimum value of the distribution. */
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
/** Returns the maximum value of the distribution. */
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_min, _max); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_min = parm.a();
_max = parm.b();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Returns a value uniformly distributed in the range [min(), max()]. */
template<class Engine>
result_type operator()(Engine& eng) const
{
typedef typename Engine::result_type base_result;
return generate(eng, Boost::random::traits::is_integral<base_result>());
}
/** Returns a value uniformly distributed in the range [param.a(), param.b()]. */
template<class Engine>
result_type operator()(Engine& eng, const param_type& parm) const
{ return uniform_smallint(parm)(eng); }
/** Writes the distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_smallint, ud)
{
os << ud._min << " " << ud._max;
return os;
}
/** Reads the distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_smallint, ud)
{
is >> ud._min >> std::ws >> ud._max;
return is;
}
/**
* Returns true if the two distributions will produce identical
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_smallint, lhs, rhs)
{ return lhs._min == rhs._min && lhs._max == rhs._max; }
/**
* Returns true if the two distributions may produce different
* sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_smallint)
private:
// \cond show_private
template<class Engine>
result_type generate(Engine& eng, Boost::true_type) const
{
// equivalent to (eng() - eng.min()) % (_max - _min + 1) + _min,
// but guarantees no overflow.
typedef typename Engine::result_type base_result;
typedef typename Boost::random::traits::make_unsigned<base_result>::type base_unsigned;
typedef typename Boost::random::traits::make_unsigned_or_unbounded<result_type>::type range_type;
#ifdef ACTIV_BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
typedef typename conditional<
std::numeric_limits<range_type>::is_specialized && std::numeric_limits<base_unsigned>::is_specialized
&& (std::numeric_limits<range_type>::digits >= std::numeric_limits<base_unsigned>::digits),
range_type, base_unsigned>::type mixed_range_type;
#else
typedef base_unsigned mixed_range_type;
#endif
range_type range = random::detail::subtract<result_type>()(_max, _min);
base_unsigned base_range =
random::detail::subtract<base_result>()((eng.max)(), (eng.min)());
base_unsigned val =
random::detail::subtract<base_result>()(eng(), (eng.min)());
if(range >= base_range) {
return Boost::random::detail::add<range_type, result_type>()(
static_cast<range_type>(val), _min);
} else {
// This involves mixed arithmetic between the base generators range
// type, and the result_type's range type. mixed_range_type is
// normally the same as base_unsigned which is the most efficient
// option, but requires a narrowing explcit cast if result_type
// is a multiprecision type. If no such casts are available then use
// multiprecision arithmetic throughout instead.
mixed_range_type modulus = static_cast<mixed_range_type>(range)+1;
return Boost::random::detail::add<range_type, result_type>()(
static_cast<mixed_range_type>(val) % modulus, _min);
}
}
template<class Engine>
result_type generate(Engine& eng, Boost::false_type) const
{
typedef typename Engine::result_type base_result;
typedef typename Boost::random::traits::make_unsigned<result_type>::type range_type;
range_type range = random::detail::subtract<result_type>()(_max, _min);
base_result val = Boost::uniform_01<base_result>()(eng);
// what is the worst that can possibly happen here?
// base_result may not be able to represent all the values in [0, range]
// exactly. If this happens, it will cause round off error and we
// won't be able to produce all the values in the range. We don't
// care about this because the user has already told us not to by
// using uniform_smallint. However, we do need to be careful
// to clamp the result, or floating point rounding can produce
// an out of range result.
range_type offset = static_cast<range_type>(val * (static_cast<base_result>(range) + 1));
if(offset > range) return _max;
return Boost::random::detail::add<range_type, result_type>()(offset , _min);
}
// \endcond
result_type _min;
result_type _max;
};
} // namespace random
using random::uniform_smallint;
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_UNIFORM_SMALLINT_HPP
@@ -1,122 +0,0 @@
/* boost random/variate_generator.hpp header file
*
* Copyright Jens Maurer 2002
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_RANDOM_GENERATOR_HPP
#define ACTIV_BOOST_RANDOM_RANDOM_GENERATOR_HPP
#include <ActivBoost/random/detail/ptr_helper.hpp>
#include <ActivBoost/random/detail/disable_warnings.hpp>
namespace Boost {
/// \cond hide_private_members
namespace random {
///\endcond
/**
* A random variate generator is used to join a random number
* generator together with a random number distribution.
* Boost.Random provides a vast choice of \generators as well
* as \distributions.
*
* The argument for the template parameter Engine shall be of
* the form U, U&, or U*, where U models a
* \uniform_random_number_generator. Then, the member
* engine_value_type names U (not the pointer or reference to U).
*
* Specializations of @c variate_generator satisfy the
* requirements of CopyConstructible. They also satisfy the
* requirements of Assignable unless the template parameter
* Engine is of the form U&.
*
* The complexity of all functions specified in this section
* is constant. No function described in this section except
* the constructor throws an exception.
*/
template<class Engine, class Distribution>
class variate_generator
{
private:
typedef Boost::random::detail::ptr_helper<Engine> helper_type;
public:
typedef typename helper_type::value_type engine_value_type;
typedef Engine engine_type;
typedef Distribution distribution_type;
typedef typename Distribution::result_type result_type;
/**
* Constructs a @c variate_generator object with the associated
* \uniform_random_number_generator eng and the associated
* \random_distribution d.
*
* Throws: If and what the copy constructor of Engine or
* Distribution throws.
*/
variate_generator(Engine e, Distribution d)
: _eng(e), _dist(d) { }
/** Returns: distribution()(engine()) */
result_type operator()() { return _dist(engine()); }
/**
* Returns: distribution()(engine(), value).
*/
template<class T>
result_type operator()(const T& value) { return _dist(engine(), value); }
/**
* Returns: A reference to the associated uniform random number generator.
*/
engine_value_type& engine() { return helper_type::ref(_eng); }
/**
* Returns: A reference to the associated uniform random number generator.
*/
const engine_value_type& engine() const { return helper_type::ref(_eng); }
/** Returns: A reference to the associated \random_distribution. */
distribution_type& distribution() { return _dist; }
/**
* Returns: A reference to the associated random distribution.
*/
const distribution_type& distribution() const { return _dist; }
/**
* Precondition: distribution().min() is well-formed
*
* Returns: distribution().min()
*/
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
/**
* Precondition: distribution().max() is well-formed
*
* Returns: distribution().max()
*/
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
private:
Engine _eng;
distribution_type _dist;
};
} // namespace random
using random::variate_generator;
} // namespace Boost
#include <ActivBoost/random/detail/enable_warnings.hpp>
#endif // ACTIV_BOOST_RANDOM_RANDOM_GENERATOR_HPP
@@ -1,177 +0,0 @@
/* boost random/weibull_distribution.hpp header file
*
* Copyright Steven Watanabe 2010
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*/
#ifndef ACTIV_BOOST_RANDOM_WEIBULL_DISTRIBUTION_HPP
#define ACTIV_BOOST_RANDOM_WEIBULL_DISTRIBUTION_HPP
#include <ActivBoost/config/no_tr1/cmath.hpp>
#include <iosfwd>
#include <istream>
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/random/detail/operators.hpp>
#include <ActivBoost/random/uniform_01.hpp>
namespace Boost {
namespace random {
/**
* The Weibull distribution is a real valued distribution with two
* parameters a and b, producing values >= 0.
*
* It has \f$\displaystyle p(x) = \frac{a}{b}\left(\frac{x}{b}\right)^{a-1}e^{-\left(\frac{x}{b}\right)^a}\f$.
*/
template<class RealType = double>
class weibull_distribution {
public:
typedef RealType result_type;
typedef RealType input_type;
class param_type {
public:
typedef weibull_distribution distribution_type;
/**
* Constructs a @c param_type from the "a" and "b" parameters
* of the distribution.
*
* Requires: a > 0 && b > 0
*/
explicit param_type(RealType a_arg = 1.0, RealType b_arg = 1.0)
: _a(a_arg), _b(b_arg)
{}
/** Returns the "a" parameter of the distribtuion. */
RealType a() const { return _a; }
/** Returns the "b" parameter of the distribution. */
RealType b() const { return _b; }
/** Writes a @c param_type to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
{ os << parm._a << ' ' << parm._b; return os; }
/** Reads a @c param_type from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
{ is >> parm._a >> std::ws >> parm._b; return is; }
/** Returns true if the two sets of parameters are the same. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
{ return lhs._a == rhs._a && lhs._b == rhs._b; }
/** Returns true if the two sets of parameters are the different. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
private:
RealType _a;
RealType _b;
};
/**
* Constructs a @c weibull_distribution from its "a" and "b" parameters.
*
* Requires: a > 0 && b > 0
*/
explicit weibull_distribution(RealType a_arg = 1.0, RealType b_arg = 1.0)
: _a(a_arg), _b(b_arg)
{}
/** Constructs a @c weibull_distribution from its parameters. */
explicit weibull_distribution(const param_type& parm)
: _a(parm.a()), _b(parm.b())
{}
/**
* Returns a random variate distributed according to the
* @c weibull_distribution.
*/
template<class URNG>
RealType operator()(URNG& urng) const
{
using std::pow;
using std::log;
return _b*pow(-log(1 - uniform_01<RealType>()(urng)), 1/_a);
}
/**
* Returns a random variate distributed accordint to the Weibull
* distribution with parameters specified by @c param.
*/
template<class URNG>
RealType operator()(URNG& urng, const param_type& parm) const
{
return weibull_distribution(parm)(urng);
}
/** Returns the "a" parameter of the distribution. */
RealType a() const { return _a; }
/** Returns the "b" parameter of the distribution. */
RealType b() const { return _b; }
/** Returns the smallest value that the distribution can produce. */
RealType min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
/** Returns the largest value that the distribution can produce. */
RealType max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const
{ return std::numeric_limits<RealType>::infinity(); }
/** Returns the parameters of the distribution. */
param_type param() const { return param_type(_a, _b); }
/** Sets the parameters of the distribution. */
void param(const param_type& parm)
{
_a = parm.a();
_b = parm.b();
}
/**
* Effects: Subsequent uses of the distribution do not depend
* on values produced by any engine prior to invoking reset.
*/
void reset() { }
/** Writes a @c weibull_distribution to a @c std::ostream. */
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, weibull_distribution, wd)
{
os << wd.param();
return os;
}
/** Reads a @c weibull_distribution from a @c std::istream. */
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, weibull_distribution, wd)
{
param_type parm;
if(is >> parm) {
wd.param(parm);
}
return is;
}
/**
* Returns true if the two instances of @c weibull_distribution will
* return identical sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(weibull_distribution, lhs, rhs)
{ return lhs._a == rhs._a && lhs._b == rhs._b; }
/**
* Returns true if the two instances of @c weibull_distribution will
* return different sequences of values given equal generators.
*/
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(weibull_distribution)
private:
RealType _a;
RealType _b;
};
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_WEIBULL_DISTRIBUTION_HPP
@@ -1,210 +0,0 @@
/* boost random/xor_combine.hpp header file
*
* Copyright Jens Maurer 2002
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org for most recent version including documentation.
*
* $Id$
*
*/
#ifndef ACTIV_BOOST_RANDOM_XOR_COMBINE_HPP
#define ACTIV_BOOST_RANDOM_XOR_COMBINE_HPP
#include <istream>
#include <iosfwd>
#include <cassert>
#include <algorithm> // for std::min and std::max
#include <ActivBoost/config.hpp>
#include <ActivBoost/limits.hpp>
#include <ActivBoost/cstdint.hpp> // uint32_t
#include <ActivBoost/random/detail/config.hpp>
#include <ActivBoost/random/detail/seed.hpp>
#include <ActivBoost/random/detail/seed_impl.hpp>
#include <ActivBoost/random/detail/operators.hpp>
namespace Boost {
namespace random {
/**
* Instantiations of @c xor_combine_engine model a
* \pseudo_random_number_generator. To produce its output it
* invokes each of the base generators, shifts their results
* and xors them together.
*/
template<class URNG1, int s1, class URNG2, int s2>
class xor_combine_engine
{
public:
typedef URNG1 base1_type;
typedef URNG2 base2_type;
typedef typename base1_type::result_type result_type;
ACTIV_BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
ACTIV_BOOST_STATIC_CONSTANT(int, shift1 = s1);
ACTIV_BOOST_STATIC_CONSTANT(int, shift2 = s2);
/**
* Constructors a @c xor_combine_engine by default constructing
* both base generators.
*/
xor_combine_engine() : _rng1(), _rng2() { }
/** Constructs a @c xor_combine by copying two base generators. */
xor_combine_engine(const base1_type & rng1, const base2_type & rng2)
: _rng1(rng1), _rng2(rng2) { }
/**
* Constructs a @c xor_combine_engine, seeding both base generators
* with @c v.
*
* @xmlwarning
* The exact algorithm used by this function may change in the future.
* @endxmlwarning
*/
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(xor_combine_engine,
result_type, v)
{ seed(v); }
/**
* Constructs a @c xor_combine_engine, seeding both base generators
* with values produced by @c seq.
*/
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(xor_combine_engine,
SeedSeq, seq)
{ seed(seq); }
/**
* Constructs a @c xor_combine_engine, seeding both base generators
* with values from the iterator range [first, last) and changes
* first to point to the element after the last one used. If there
* are not enough elements in the range to seed both generators,
* throws @c std::invalid_argument.
*/
template<class It> xor_combine_engine(It& first, It last)
: _rng1(first, last), _rng2( /* advanced by other call */ first, last) { }
/** Calls @c seed() for both base generators. */
void seed() { _rng1.seed(); _rng2.seed(); }
/** @c seeds both base generators with @c v. */
ACTIV_BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(xor_combine_engine, result_type, v)
{ _rng1.seed(v); _rng2.seed(v); }
/** @c seeds both base generators with values produced by @c seq. */
ACTIV_BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(xor_combine_engine, SeedSeq, seq)
{ _rng1.seed(seq); _rng2.seed(seq); }
/**
* seeds both base generators with values from the iterator
* range [first, last) and changes first to point to the element
* after the last one used. If there are not enough elements in
* the range to seed both generators, throws @c std::invalid_argument.
*/
template<class It> void seed(It& first, It last)
{
_rng1.seed(first, last);
_rng2.seed(first, last);
}
/** Returns the first base generator. */
const base1_type& base1() const { return _rng1; }
/** Returns the second base generator. */
const base2_type& base2() const { return _rng2; }
/** Returns the next value of the generator. */
result_type operator()()
{
return (_rng1() << s1) ^ (_rng2() << s2);
}
/** Fills a range with random values */
template<class Iter>
void generate(Iter first, Iter last)
{ detail::generate_from_int(*this, first, last); }
/** Advances the state of the generator by @c z. */
void discard(Boost::uintmax_t z)
{
_rng1.discard(z);
_rng2.discard(z);
}
/** Returns the smallest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (URNG1::min)()<(URNG2::min)()?(URNG1::min)():(URNG2::min)(); }
/** Returns the largest value that the generator can produce. */
static ACTIV_BOOST_CONSTEXPR result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION ()
{ return (URNG1::max)()>(URNG2::max)()?(URNG1::max)():(URNG2::max)(); }
/**
* Writes the textual representation of the generator to a @c std::ostream.
*/
ACTIV_BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, xor_combine_engine, s)
{
os << s._rng1 << ' ' << s._rng2;
return os;
}
/**
* Reads the textual representation of the generator from a @c std::istream.
*/
ACTIV_BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, xor_combine_engine, s)
{
is >> s._rng1 >> std::ws >> s._rng2;
return is;
}
/** Returns true if the two generators will produce identical sequences. */
ACTIV_BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(xor_combine_engine, x, y)
{ return x._rng1 == y._rng1 && x._rng2 == y._rng2; }
/** Returns true if the two generators will produce different sequences. */
ACTIV_BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(xor_combine_engine)
private:
base1_type _rng1;
base2_type _rng2;
};
#ifndef ACTIV_BOOST_NO_INCLASS_MEMBER_INITIALIZATION
// A definition is required even for integral static constants
template<class URNG1, int s1, class URNG2, int s2>
const bool xor_combine_engine<URNG1, s1, URNG2, s2>::has_fixed_range;
template<class URNG1, int s1, class URNG2, int s2>
const int xor_combine_engine<URNG1, s1, URNG2, s2>::shift1;
template<class URNG1, int s1, class URNG2, int s2>
const int xor_combine_engine<URNG1, s1, URNG2, s2>::shift2;
#endif
/// \cond show_private
/** Provided for backwards compatibility. */
template<class URNG1, int s1, class URNG2, int s2,
typename URNG1::result_type v = 0>
class xor_combine : public xor_combine_engine<URNG1, s1, URNG2, s2>
{
typedef xor_combine_engine<URNG1, s1, URNG2, s2> base_type;
public:
typedef typename base_type::result_type result_type;
xor_combine() {}
xor_combine(result_type val) : base_type(val) {}
template<class It>
xor_combine(It& first, It last) : base_type(first, last) {}
xor_combine(const URNG1 & rng1, const URNG2 & rng2)
: base_type(rng1, rng2) { }
result_type min ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (std::min)((this->base1().min)(), (this->base2().min)()); }
result_type max ACTIV_BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (std::max)((this->base1().min)(), (this->base2().max)()); }
};
/// \endcond
} // namespace random
} // namespace Boost
#endif // ACTIV_BOOST_RANDOM_XOR_COMBINE_HPP