aGrUM  0.15.1
gum::Dirichlet Class Reference

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

#include <agrum/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 50 of file Dirichlet.h.

Member Typedef Documentation

◆ param_type

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

The parameter type.

Definition at line 53 of file Dirichlet.h.

◆ result_type

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

The type for the samples generated.

Definition at line 56 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 32 of file Dirichlet_inl.h.

32  :
34  GUM_CONSTRUCTOR(Dirichlet);
35  }
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:32
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
std::default_random_engine getRandomGenerator(unsigned int seed)
define a random_engine with correct seed
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

◆ Dirichlet() [2/3]

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

Copy constructor.

Parameters
fromThe distribution to copy.

Definition at line 38 of file Dirichlet_inl.h.

38  :
39  __generator(from.__generator), __gamma(from.__gamma),
40  __params(from.__params) {
41  GUM_CONS_CPY(Dirichlet);
42  }
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:32
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

◆ Dirichlet() [3/3]

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

Move constructor.

Parameters
fromThe distribution to move.

Definition at line 45 of file Dirichlet_inl.h.

45  :
46  __generator(std::move(from.__generator)), __gamma(std::move(from.__gamma)),
47  __params(std::move(from.__params)) {
48  GUM_CONS_MOV(Dirichlet);
49  }
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:32
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

◆ ~Dirichlet()

INLINE gum::Dirichlet::~Dirichlet ( )

Class destructor.

Definition at line 52 of file Dirichlet_inl.h.

52 { GUM_DESTRUCTOR(Dirichlet); }
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:32

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

126 { 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 123 of file Dirichlet_inl.h.

123 { 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 35 of file Dirichlet_tpl.h.

References __gamma.

35  {
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  }
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:56
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

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

References __gamma, __generator, and __params.

75  {
76  Size size = Size(__params.size());
77  result_type res(size);
78  float sum = 0.0f;
79  while (sum == 0.0f) {
80  for (Idx i = 0; i < size; ++i) {
81  __gamma.param(
82  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:175
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:56
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

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

References __gamma, and __generator.

95  {
96  Size size = Size(parm.size());
97  result_type res(size);
98  float sum = 0.0f;
99  while (sum == 0.0f) {
100  for (Idx i = 0; i < size; ++i) {
101  __gamma.param(std::gamma_distribution< float >::param_type(parm[i], 1));
102  res[i] = __gamma(__generator);
103  sum += res[i];
104  }
105  }
106  for (Idx i = 0; i < size; ++i) {
107  res[i] /= sum;
108  }
109  return res;
110  }
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:56
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

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

References __gamma, __generator, and __params.

55  {
56  if (&from != this) {
57  __generator = from.__generator;
58  __gamma = from.__gamma;
59  __params = from.__params;
60  }
61  return *this;
62  }
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

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

References __gamma, __generator, and __params.

65  {
66  if (&from != this) {
67  __generator = std::move(from.__generator);
68  __gamma = std::move(from.__gamma);
69  __params = std::move(from.__params);
70  }
71  return *this;
72  }
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:175
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:171
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

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

References __params.

113  {
114  return __params;
115  }
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

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

References __params.

118  {
119  __params = parm;
120  }
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:178

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

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

◆ __generator

std::default_random_engine gum::Dirichlet::__generator
private

The random engine used by the unform random distribution.

Definition at line 171 of file Dirichlet.h.

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

◆ __params

param_type gum::Dirichlet::__params
private

The parameters of the distribution.

Definition at line 178 of file Dirichlet.h.

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


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