aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::Dirichlet Class Reference

A class for sampling w.r.t. More...

#include <agrum/tools/core/math/Dirichlet.h>

Public Member Functions

template<class URNG >
INLINE Dirichlet::result_type operator() (URNG &generator, const Dirichlet::param_type &parm)
 
Constructors / Destructors
 Dirichlet (const param_type &params, unsigned int seed=GUM_RANDOMSEED)
 Default constructor. More...
 
 Dirichlet (const Dirichlet &from)
 Copy constructor. More...
 
 Dirichlet (Dirichlet &&from)
 Move constructor. More...
 
 ~Dirichlet ()
 Class destructor. More...
 
Operators
Dirichletoperator= (const Dirichlet &from)
 Copy operator. More...
 
Dirichletoperator= (Dirichlet &&from)
 Move operator. More...
 
result_type operator() ()
 Returns a sample from the Dirichlet distribution. More...
 
result_type operator() (const param_type &p)
 Returns a sample from the Dirichlet distribution. More...
 
template<class URNG >
result_type operator() (URNG &generator, const param_type &p)
 Returns a sample from the Dirichlet distribution. More...
 
Accessors / Modifiers
const param_typeparam () const noexcept
 Returns the parameters of the distribution. More...
 
void param (const param_type &p)
 Sets the parameters of the distribution. More...
 
float min () const noexcept
 Returns the greatest lower bound of the range of values returned by gum::Dirichlet::operator()(). More...
 
float max () const noexcept
 Returns the lowest higher bound of the range of values returned by gum::Dirichlet::operator()(). More...
 

Public Types

using param_type = std::vector< float >
 The parameter type. More...
 
using result_type = std::vector< float >
 The type for the samples generated. More...
 

Detailed Description

A class for sampling w.r.t.

Dirichlet distributions.

Definition at line 49 of file Dirichlet.h.

Member Typedef Documentation

◆ param_type

using gum::Dirichlet::param_type = std::vector< float >

The parameter type.

Definition at line 52 of file Dirichlet.h.

◆ result_type

using gum::Dirichlet::result_type = std::vector< float >

The type for the samples generated.

Definition at line 55 of file Dirichlet.h.

Constructor & Destructor Documentation

◆ Dirichlet() [1/3]

INLINE gum::Dirichlet::Dirichlet ( const param_type params,
unsigned int  seed = GUM_RANDOMSEED 
)

Default constructor.

Parameters
paramsThe distribution parameters.
seedThe distribution seed.

Definition at line 31 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

31  :
33  GUM_CONSTRUCTOR(Dirichlet);
34  }
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:31
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
std::default_random_engine getRandomGenerator(unsigned int seed)
define a random_engine with correct seed
+ Here is the call graph for this function:

◆ Dirichlet() [2/3]

INLINE gum::Dirichlet::Dirichlet ( const Dirichlet from)

Copy constructor.

Parameters
fromThe distribution to copy.

Definition at line 37 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

37  :
38  _generator_(from._generator_), _gamma_(from._gamma_), _params_(from._params_) {
39  GUM_CONS_CPY(Dirichlet);
40  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:31
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
+ Here is the call graph for this function:

◆ Dirichlet() [3/3]

INLINE gum::Dirichlet::Dirichlet ( Dirichlet &&  from)

Move constructor.

Parameters
fromThe distribution to move.

Definition at line 43 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

43  :
44  _generator_(std::move(from._generator_)), _gamma_(std::move(from._gamma_)),
45  _params_(std::move(from._params_)) {
46  GUM_CONS_MOV(Dirichlet);
47  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:31
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
+ Here is the call graph for this function:

◆ ~Dirichlet()

INLINE gum::Dirichlet::~Dirichlet ( )

Class destructor.

Definition at line 50 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

50  {
51  GUM_DESTRUCTOR(Dirichlet);
52  ;
53  }
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:31
+ Here is the call graph for this function:

Member Function Documentation

◆ max()

INLINE float gum::Dirichlet::max ( ) const
noexcept

Returns the lowest higher bound of the range of values returned by gum::Dirichlet::operator()().

Returns
Returns the lowest higher bound of the range of values returned by gum::Dirichlet::operator()().

Definition at line 121 of file Dirichlet_inl.h.

121 { return 1.0f; }

◆ min()

INLINE float gum::Dirichlet::min ( ) const
noexcept

Returns the greatest lower bound of the range of values returned by gum::Dirichlet::operator()().

Returns
Returns the greatest lower bound of the range of values returned by gum::Dirichlet::operator()().

Definition at line 118 of file Dirichlet_inl.h.

118 { return 0.0f; }

◆ operator()() [1/4]

template<class URNG >
INLINE Dirichlet::result_type gum::Dirichlet::operator() ( URNG &  generator,
const Dirichlet::param_type parm 
)

Definition at line 33 of file Dirichlet_tpl.h.

References gum::Set< Key, Alloc >::emplace().

34  {
35  Size size = Size(parm.size());
36  result_type res(size);
37  float sum = 0.0f;
38  while (sum == 0.0f) {
39  for (Idx i = 0; i < size; ++i) {
40  _gamma_.param(std::gamma_distribution< float >::param_type(parm[i], 1));
41  res[i] = _gamma_(generator);
42  sum += res[i];
43  }
44  }
45  for (Idx i = 0; i < size; ++i) {
46  res[i] /= sum;
47  }
48  return res;
49  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:55
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ operator()() [2/4]

INLINE Dirichlet::result_type gum::Dirichlet::operator() ( )

Returns a sample from the Dirichlet distribution.

Returns
Returns a sample from the Dirichlet distribution.

Definition at line 76 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

76  {
77  Size size = Size(_params_.size());
78  result_type res(size);
79  float sum = 0.0f;
80  while (sum == 0.0f) {
81  for (Idx i = 0; i < size; ++i) {
82  _gamma_.param(std::gamma_distribution< float >::param_type(_params_[i], 1));
83  res[i] = _gamma_(_generator_);
84  sum += res[i];
85  }
86  }
87  for (Idx i = 0; i < size; ++i) {
88  res[i] /= sum;
89  }
90  return res;
91  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:55
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ operator()() [3/4]

INLINE Dirichlet::result_type gum::Dirichlet::operator() ( const param_type p)

Returns a sample from the Dirichlet distribution.

Parameters
pAn object representing the distribution's parameters, obtained by a call to gum::Dirichlet::param(const param_type&).

Definition at line 94 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

94  {
95  Size size = Size(parm.size());
96  result_type res(size);
97  float sum = 0.0f;
98  while (sum == 0.0f) {
99  for (Idx i = 0; i < size; ++i) {
100  _gamma_.param(std::gamma_distribution< float >::param_type(parm[i], 1));
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  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:55
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ operator()() [4/4]

template<class URNG >
result_type gum::Dirichlet::operator() ( URNG &  generator,
const param_type p 
)

Returns a sample from the Dirichlet distribution.

Parameters
generatorA uniform random number generator object, used as the source of randomness. URNG shall be a uniform random number generator type, such as one of the standard generator classes.
pAn object representing the distribution's parameters, obtained by a call to gum::Dirichlet::param(const param_type&).

◆ operator=() [1/2]

INLINE Dirichlet & gum::Dirichlet::operator= ( const Dirichlet from)

Copy operator.

Parameters
fromThe distribution to copy.
Returns
Returns this gum::Dirichlet distribution.

Definition at line 56 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

56  {
57  if (&from != this) {
58  _generator_ = from._generator_;
59  _gamma_ = from._gamma_;
60  _params_ = from._params_;
61  }
62  return *this;
63  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
+ Here is the call graph for this function:

◆ operator=() [2/2]

INLINE Dirichlet & gum::Dirichlet::operator= ( Dirichlet &&  from)

Move operator.

Parameters
fromThe distribution to move.
Returns
Returns this gum::Dirichlet distribution.

Definition at line 66 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

66  {
67  if (&from != this) {
68  _generator_ = std::move(from._generator_);
69  _gamma_ = std::move(from._gamma_);
70  _params_ = std::move(from._params_);
71  }
72  return *this;
73  }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:174
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
std::default_random_engine _generator_
The random engine used by the unform random distribution.
Definition: Dirichlet.h:170
+ Here is the call graph for this function:

◆ param() [1/2]

INLINE const Dirichlet::param_type & gum::Dirichlet::param ( ) const
noexcept

Returns the parameters of the distribution.

Returns
Returns the parameters of the distribution.

Definition at line 112 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

112 { return _params_; }
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
+ Here is the call graph for this function:

◆ param() [2/2]

INLINE void gum::Dirichlet::param ( const param_type p)

Sets the parameters of the distribution.

Parameters
pAn object representing the distribution's parameters, obtained by a call to member function param.

Definition at line 115 of file Dirichlet_inl.h.

References gum::Set< Key, Alloc >::emplace().

115 { _params_ = parm; }
param_type _params_
The parameters of the distribution.
Definition: Dirichlet.h:177
+ Here is the call graph for this function:

Member Data Documentation

◆ _gamma_

std::gamma_distribution< float > gum::Dirichlet::_gamma_
private

The gamma distribution used to compute the Dirichlet unnormalized samples.

Definition at line 174 of file Dirichlet.h.

◆ _generator_

std::default_random_engine gum::Dirichlet::_generator_
private

The random engine used by the unform random distribution.

Definition at line 170 of file Dirichlet.h.

◆ _params_

param_type gum::Dirichlet::_params_
private

The parameters of the distribution.

Definition at line 177 of file Dirichlet.h.


The documentation for this class was generated from the following files: