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

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

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

Public Types

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

Public Member Functions

Constructors / Destructors
 Dirichlet (const param_type &params)
 Default constructor.
 Dirichlet (const Dirichlet &from)
 Copy constructor.
 Dirichlet (Dirichlet &&from)
 Move constructor.
 ~Dirichlet ()
 Class destructor.
Operators
Dirichletoperator= (const Dirichlet &from)
 Copy operator.
Dirichletoperator= (Dirichlet &&from)
 Move operator.
result_type operator() ()
 Returns a sample from the Dirichlet distribution.
result_type operator() (const param_type &p)
 Returns a sample from the Dirichlet distribution.
Accessors / Modifiers
const param_typeparam () const noexcept
 Returns the parameters of the distribution.
void param (const param_type &p)
 Sets the parameters of the distribution.
float min () const noexcept
 Returns the greatest lower bound of the range of values returned by gum::Dirichlet::operator()().
float max () const noexcept
 Returns the lowest higher bound of the range of values returned by gum::Dirichlet::operator()().

Private Attributes

std::gamma_distribution< float > _gamma_
 The gamma distribution used to compute the Dirichlet unnormalized samples.
param_type _params_
 The parameters of the distribution.

Detailed Description

A class for sampling w.r.t.

Dirichlet distributions.

Definition at line 69 of file Dirichlet.h.

Member Typedef Documentation

◆ param_type

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

The parameter type.

Definition at line 72 of file Dirichlet.h.

◆ result_type

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

The type for the samples generated.

Definition at line 75 of file Dirichlet.h.

Constructor & Destructor Documentation

◆ Dirichlet() [1/3]

INLINE gum::Dirichlet::Dirichlet ( const param_type & params)

Default constructor.

Parameters
paramsThe distribution parameters.
seedThe distribution seed.

Definition at line 51 of file Dirichlet_inl.h.

51 : _params_(params) {
52 GUM_CONSTRUCTOR(Dirichlet);
53 }
Dirichlet(const param_type &params)
Default constructor.
param_type _params_
The parameters of the distribution.
Definition Dirichlet.h:182

References Dirichlet(), and _params_.

Referenced by Dirichlet(), Dirichlet(), Dirichlet(), ~Dirichlet(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dirichlet() [2/3]

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

Copy constructor.

Parameters
fromThe distribution to copy.

Definition at line 56 of file Dirichlet_inl.h.

56 :
57 _gamma_(from._gamma_), _params_(from._params_) {
58 GUM_CONS_CPY(Dirichlet);
59 }
std::gamma_distribution< float > _gamma_
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition Dirichlet.h:179

References Dirichlet(), _gamma_, and _params_.

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 62 of file Dirichlet_inl.h.

62 :
63 _gamma_(std::move(from._gamma_)), _params_(std::move(from._params_)) {
64 GUM_CONS_MOV(Dirichlet);
65 }

References Dirichlet(), _gamma_, and _params_.

Here is the call graph for this function:

◆ ~Dirichlet()

INLINE gum::Dirichlet::~Dirichlet ( )

Class destructor.

Definition at line 68 of file Dirichlet_inl.h.

68 {
69 GUM_DESTRUCTOR(Dirichlet);
70 ;
71 }

References Dirichlet().

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 137 of file Dirichlet_inl.h.

137{ 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 134 of file Dirichlet_inl.h.

134{ return 0.0f; }

◆ operator()() [1/2]

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 92 of file Dirichlet_inl.h.

92 {
93 Size size = Size(_params_.size());
94 result_type res(size);
95 float sum = 0.0f;
96 while (sum == 0.0f) {
97 for (Idx i = 0; i < size; ++i) {
98 _gamma_.param(std::gamma_distribution< float >::param_type(_params_[i], 1));
99 res[i] = _gamma_(gum::randomGenerator());
100 sum += res[i];
101 }
102 }
103 for (Idx i = 0; i < size; ++i) {
104 res[i] /= sum;
105 }
106 return res;
107 }
std::vector< float > result_type
The type for the samples generated.
Definition Dirichlet.h:75
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
std::mt19937 & randomGenerator()
define a random_engine with correct seed

References _gamma_, _params_, and gum::randomGenerator().

Here is the call graph for this function:

◆ operator()() [2/2]

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 110 of file Dirichlet_inl.h.

110 {
111 Size size = Size(parm.size());
112 result_type res(size);
113 float sum = 0.0f;
114 while (sum == 0.0f) {
115 for (Idx i = 0; i < size; ++i) {
116 _gamma_.param(std::gamma_distribution< float >::param_type(parm[i], 1));
117 res[i] = _gamma_(gum::randomGenerator());
118 sum += res[i];
119 }
120 }
121 for (Idx i = 0; i < size; ++i) {
122 res[i] /= sum;
123 }
124 return res;
125 }

References _gamma_, and gum::randomGenerator().

Here is the call graph for this function:

◆ 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 74 of file Dirichlet_inl.h.

74 {
75 if (&from != this) {
76 _gamma_ = from._gamma_;
77 _params_ = from._params_;
78 }
79 return *this;
80 }

References Dirichlet(), _gamma_, and _params_.

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 83 of file Dirichlet_inl.h.

83 {
84 if (&from != this) {
85 _gamma_ = std::move(from._gamma_);
86 _params_ = std::move(from._params_);
87 }
88 return *this;
89 }

References Dirichlet(), _gamma_, and _params_.

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 128 of file Dirichlet_inl.h.

128{ return _params_; }

References _params_.

◆ 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 131 of file Dirichlet_inl.h.

131{ _params_ = parm; }

References _params_.

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 179 of file Dirichlet.h.

Referenced by Dirichlet(), Dirichlet(), operator()(), operator()(), operator=(), and operator=().

◆ _params_

param_type gum::Dirichlet::_params_
private

The parameters of the distribution.

Definition at line 182 of file Dirichlet.h.

Referenced by Dirichlet(), Dirichlet(), Dirichlet(), operator()(), operator=(), operator=(), param(), and param().


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