aGrUM  0.14.2
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 47 of file Dirichlet.h.

Member Typedef Documentation

◆ param_type

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

The parameter type.

Definition at line 50 of file Dirichlet.h.

◆ result_type

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

The type for the samples generated.

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

29  :
31  GUM_CONSTRUCTOR(Dirichlet);
32  }
Dirichlet(const param_type &params, unsigned int seed=GUM_RANDOMSEED)
Default constructor.
Definition: Dirichlet_inl.h:29
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:168
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:175

◆ Dirichlet() [2/3]

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

Copy constructor.

Parameters
fromThe distribution to copy.

Definition at line 35 of file Dirichlet_inl.h.

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

◆ Dirichlet() [3/3]

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

Move constructor.

Parameters
fromThe distribution to move.

Definition at line 42 of file Dirichlet_inl.h.

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

◆ ~Dirichlet()

INLINE gum::Dirichlet::~Dirichlet ( )

Class destructor.

Definition at line 49 of file Dirichlet_inl.h.

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

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

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

120 { 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 32 of file Dirichlet_tpl.h.

References __gamma.

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

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

References __gamma, __generator, and __params.

72  {
73  Size size = Size(__params.size());
74  result_type res(size);
75  float sum = 0.0f;
76  while (sum == 0.0f) {
77  for (Idx i = 0; i < size; ++i) {
78  __gamma.param(
79  std::gamma_distribution< float >::param_type(__params[i], 1));
80  res[i] = __gamma(__generator);
81  sum += res[i];
82  }
83  }
84  for (Idx i = 0; i < size; ++i) {
85  res[i] /= sum;
86  }
87  return res;
88  }
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:172
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:53
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:168
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:175
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45

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

References __gamma, and __generator.

92  {
93  Size size = Size(parm.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(parm[i], 1));
99  res[i] = __gamma(__generator);
100  sum += res[i];
101  }
102  }
103  for (Idx i = 0; i < size; ++i) {
104  res[i] /= sum;
105  }
106  return res;
107  }
std::gamma_distribution< float > __gamma
The gamma distribution used to compute the Dirichlet unnormalized samples.
Definition: Dirichlet.h:172
std::vector< float > result_type
The type for the samples generated.
Definition: Dirichlet.h:53
std::default_random_engine __generator
The random engine used by the unform random distribution.
Definition: Dirichlet.h:168
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45

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

References __gamma, __generator, and __params.

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

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

References __gamma, __generator, and __params.

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

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

References __params.

110  {
111  return __params;
112  }
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:175

◆ 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 __params.

115  {
116  __params = parm;
117  }
param_type __params
The parameters of the distribution.
Definition: Dirichlet.h:175

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

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

◆ __params

param_type gum::Dirichlet::__params
private

The parameters of the distribution.

Definition at line 175 of file Dirichlet.h.

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


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