aGrUM  0.16.0
Dirichlet_tpl.h
Go to the documentation of this file.
1 
30 namespace gum {
31 
32  // returns a sample from the Dirichlet distribution
33  template < class URNG >
35  operator()(URNG& generator, const Dirichlet::param_type& parm) {
36  Size size = Size(parm.size());
37  result_type res(size);
38  float sum = 0.0f;
39  while (sum == 0.0f) {
40  for (Idx i = 0; i < size; ++i) {
41  __gamma.param(std::gamma_distribution< float >::param_type(parm[i], 1));
42  res[i] = __gamma(generator);
43  sum += res[i];
44  }
45  }
46  for (Idx i = 0; i < size; ++i) {
47  res[i] /= sum;
48  }
49  return res;
50  }
51 
52 } /* namespace gum */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::vector< float > param_type
The parameter type.
Definition: Dirichlet.h:53
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:56
result_type operator()()
Returns a sample from the Dirichlet distribution.
Definition: Dirichlet_inl.h:75
Size Idx
Type for indexes.
Definition: types.h:53
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48