aGrUM  0.20.2
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__),
39  params__(from.params__) {
40  GUM_CONS_CPY(Dirichlet);
41  }
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 44 of file Dirichlet_inl.h.

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

44  :
45  generator__(std::move(from.generator__)), gamma__(std::move(from.gamma__)),
46  params__(std::move(from.params__)) {
47  GUM_CONS_MOV(Dirichlet);
48  }
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 51 of file Dirichlet_inl.h.

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

51 { GUM_DESTRUCTOR(Dirichlet); }
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 125 of file Dirichlet_inl.h.

125 { 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 122 of file Dirichlet_inl.h.

122 { 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 34 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 74 of file Dirichlet_inl.h.

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

74  {
75  Size size = Size(params__.size());
76  result_type res(size);
77  float sum = 0.0f;
78  while (sum == 0.0f) {
79  for (Idx i = 0; i < size; ++i) {
80  gamma__.param(
81  std::gamma_distribution< float >::param_type(params__[i], 1));
82  res[i] = gamma__(generator__);
83  sum += res[i];
84  }
85  }
86  for (Idx i = 0; i < size; ++i) {
87  res[i] /= sum;
88  }
89  return res;
90  }
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 54 of file Dirichlet_inl.h.

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

54  {
55  if (&from != this) {
56  generator__ = from.generator__;
57  gamma__ = from.gamma__;
58  params__ = from.params__;
59  }
60  return *this;
61  }
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 64 of file Dirichlet_inl.h.

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

64  {
65  if (&from != this) {
66  generator__ = std::move(from.generator__);
67  gamma__ = std::move(from.gamma__);
68  params__ = std::move(from.params__);
69  }
70  return *this;
71  }
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  {
113  return params__;
114  }
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 117 of file Dirichlet_inl.h.

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

117  {
118  params__ = parm;
119  }
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: