32 #ifndef SHARK_RNG_DIRICHLET_H 33 #define SHARK_RNG_DIRICHLET_H 39 #include <boost/math/special_functions.hpp> 40 #include <boost/random.hpp> 45 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS 52 template<
class RealType=
double>
56 typedef RealType input_type;
57 typedef std::vector<RealType> result_type;
66 const std::vector<RealType>&
alphas()
const 73 template<
class Engine>
76 unsigned n = alphas_.size();
78 std::vector<double> x;
80 for(
size_t i=0; i<n; i++)
86 for(
size_t i=0; i<n; i++)
91 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS 92 template<
class CharT,
class Traits>
93 friend std::basic_ostream<CharT,Traits>&
97 for(
int i=0;i!=d.alphas_.size();++i)
102 template<
class CharT,
class Traits>
103 friend std::basic_istream<CharT,Traits>&
108 for(
int i=0;i!=size;++i)
112 d.alphas_.push_back(element);
118 std::vector<RealType> alphas_;
125 template<
typename RngType = shark::DefaultRngType>
126 class Dirichlet:
public boost::variate_generator<RngType*,Dirichlet_distribution<> >
129 typedef boost::variate_generator<RngType*,Dirichlet_distribution<> > Base;
138 explicit Dirichlet(RngType& rng,
size_t n=3,
double alpha=1)
152 using Base::operator();
161 return dist(Base::engine());
170 return dist(Base::engine());
176 const std::vector<double>
alphas()
const {
177 return Base::distribution().alphas();
184 void alphas(
const std::vector<double>& newAlphas) {
200 double p(
const std::vector<double> &x)
const 204 for(
int i=0; i<
alphas().size(); i++)
206 p *= pow(x[i],
alphas()[i]-1) / boost::math::tgamma(
alphas()[i]);
209 return p * boost::math::tgamma(sum);