aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
Dirichlet_inl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief a class for sampling w.r.t. Dirichlet distributions
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 
28 namespace gum {
29 
30  // default constructor
31  INLINE Dirichlet::Dirichlet(const param_type& params, unsigned int seed) :
34  }
35 
36  // copy constructor
40  }
41 
42  // move constructor
47  }
48 
49  // destructor
52  ;
53  }
54 
55  // copy operator
56  INLINE Dirichlet& Dirichlet::operator=(const Dirichlet& from) {
57  if (&from != this) {
61  }
62  return *this;
63  }
64 
65  // move operator
67  if (&from != this) {
71  }
72  return *this;
73  }
74 
75  // returns a sample from the Dirichlet distribution
77  Size size = Size(_params_.size());
79  float sum = 0.0f;
80  while (sum == 0.0f) {
81  for (Idx i = 0; i < size; ++i) {
84  sum += res[i];
85  }
86  }
87  for (Idx i = 0; i < size; ++i) {
88  res[i] /= sum;
89  }
90  return res;
91  }
92 
93  // returns a sample from the Dirichlet distribution
95  Size size = Size(parm.size());
97  float sum = 0.0f;
98  while (sum == 0.0f) {
99  for (Idx i = 0; i < size; ++i) {
101  res[i] = _gamma_(_generator_);
102  sum += res[i];
103  }
104  }
105  for (Idx i = 0; i < size; ++i) {
106  res[i] /= sum;
107  }
108  return res;
109  }
110 
111  // returns the parameters of the distribution
112  INLINE const Dirichlet::param_type& Dirichlet::param() const noexcept { return _params_; }
113 
114  // sets the parameters of the distribution
116 
117  // Returns the greatest lower bound of the range of values possibly returned
118  INLINE float Dirichlet::min() const noexcept { return 0.0f; }
119 
120  // Returns the lowest higher bound of the range of values possibly returned
121  INLINE float Dirichlet::max() const noexcept { return 1.0f; }
122 
123 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643