aGrUM  0.13.2
GibbsSampling_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES et Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 
29 #define GIBBS_SAMPLING_DEFAULT_EPSILON std::exp(-1.6)
30 #define GIBBS_SAMPLING_DEFAULT_MIN_EPSILON_RATE std::exp(-5)
31 #define GIBBS_SAMPLING_DEFAULT_BURNIN 300
32 
33 #define GIBBS_SAMPLING_POURCENT_DRAWN_SAMPLE 50 // percent drawn
34 #define GIBBS_SAMPLING_DRAWN_AT_RANDOM true
35 
36 namespace gum {
37 
39  template < typename GUM_SCALAR >
41  SamplingInference< GUM_SCALAR >(bn),
42  GibbsOperator< GUM_SCALAR >(
43  *bn,
44  &this->hardEvidence(),
45  1 + (bn->size() * GIBBS_SAMPLING_POURCENT_DRAWN_SAMPLE / 100),
47  GUM_CONSTRUCTOR(GibbsSampling);
48 
52  }
53 
55  template < typename GUM_SCALAR >
57  GUM_DESTRUCTOR(GibbsSampling);
58  }
59 
60 
61  template < typename GUM_SCALAR >
64  }
65 
66 
67  template < typename GUM_SCALAR >
70  if (this->burnIn() == 0) return Ip;
71 
72  float w = 1.0f;
73  Ip = _monteCarloSample();
74  for (Size i = 1; i < this->burnIn(); i++)
75  Ip = this->_draw(&w, Ip);
76 
77  return Ip;
78  }
79 
81 
82  template < typename GUM_SCALAR >
84  *w = 1.0;
86  }
87 } // namespace gum
~GibbsSampling() override
Destructor.
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
GibbsSampling(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
void setBurnIn(Size b)
Number of burn in for one iteration.
Definition: GibbsSampling.h:71
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:59
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
#define GIBBS_SAMPLING_DEFAULT_BURNIN
#define GIBBS_SAMPLING_DEFAULT_MIN_EPSILON_RATE
<agrum/BN/inference/gibbsSampling.h>
Definition: GibbsSampling.h:52
#define GIBBS_SAMPLING_DEFAULT_EPSILON
Instantiation nextSample(Instantiation prev)
draws next sample of Gibbs sampling
Size burnIn() const
Returns the number of burn in.
Definition: GibbsSampling.h:77
#define GIBBS_SAMPLING_POURCENT_DRAWN_SAMPLE
Instantiation _monteCarloSample()
draws a Monte Carlo sample
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
This file contains Gibbs sampling class definition.
Instantiation monteCarloSample()
draws a Monte Carlo sample
Instantiation _draw(float *w, Instantiation prev) override
draws a sample given previous one according to Gibbs sampling
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
#define GIBBS_SAMPLING_DRAWN_AT_RANDOM
Instantiation _burnIn() override
draws a defined number of samples without updating the estimators
class containing all variables and methods required for Gibbssampling
Definition: gibbsOperator.h:47