aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gibbsOperator.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief This file contains Gibbs sampling (for BNs) class definitions
25  *
26  * @author Paul ALAM & Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 
30 #ifndef GUM_GIBBS_OPERATOR_H
31 #define GUM_GIBBS_OPERATOR_H
32 
33 #include <agrum/BN/IBayesNet.h>
34 #include <agrum/tools/multidim/instantiation.h>
35 #include <agrum/tools/multidim/potential.h>
36 
37 namespace gum {
38 
39  /**
40  * @class GibbsOperator
41  * @headerfile gibbsOperator.h <agrum/BN/inference/gibbsOperator.h>
42  * @brief class containing all variables and methods required for Gibbssampling
43  *
44  * @ingroup bn_approximation
45  *
46  */
47 
48  template < typename GUM_SCALAR >
49  class GibbsOperator {
50  public:
51  /**
52  * constructor
53  */
54  GibbsOperator(const IBayesNet< GUM_SCALAR >& BN,
55  const NodeProperty< Idx >* hardEv,
56  Size nbr = 1,
57  bool atRandom = false);
58 
59  /**
60  * Destructor.
61  */
62  virtual ~GibbsOperator();
63 
64  /** Getters and setters*/
65  Size nbrDrawnVar() const { return nbr_; }
66 
67  void setNbrDrawnVar(Size nbr) { nbr_ = nbr; }
68 
69  bool isDrawnAtRandom() const { return atRandom_; }
70 
71  void setDrawnAtRandom(bool atRandom) { atRandom_ = atRandom; }
72 
73  /// draws a Monte Carlo sample
75 
76  /// draws next sample of Gibbs sampling
78 
79  protected:
84 
86  bool atRandom_;
87 
88  private:
89  void _updateSamplingNodes_();
90 
91  // adds a node to current instantiation
92  void _drawVarMonteCarlo_(NodeId nod, Instantiation* I);
93 
94  void _GibbsSample_(NodeId id, Instantiation* I);
95  };
96 
97 
98 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
99 
100  extern template class GibbsOperator< double >;
101 
102 #endif
103 
104 } // namespace gum
105 
106 #include <agrum/BN/inference/tools/gibbsOperator_tpl.h>
107 
108 #endif
bool isDrawnAtRandom() const
Definition: gibbsOperator.h:69
GibbsOperator(const IBayesNet< GUM_SCALAR > &BN, const NodeProperty< Idx > *hardEv, Size nbr=1, bool atRandom=false)
constructor
Size nbrDrawnVar() const
Getters and setters.
Definition: gibbsOperator.h:65
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
void _GibbsSample_(NodeId id, Instantiation *I)
change in Instantiation I a new drawn value for id
void setDrawnAtRandom(bool atRandom)
Definition: gibbsOperator.h:71
Instantiation nextSample(Instantiation prev)
draws next sample of Gibbs sampling
virtual ~GibbsOperator()
Destructor.
Instantiation monteCarloSample()
draws a Monte Carlo sample
void setNbrDrawnVar(Size nbr)
Definition: gibbsOperator.h:67
void _drawVarMonteCarlo_(NodeId nod, Instantiation *I)
const IBayesNet< GUM_SCALAR > & samplingBn_
Definition: gibbsOperator.h:81
const NodeProperty< Idx > * hardEv_
Definition: gibbsOperator.h:82
class containing all variables and methods required for Gibbssampling
Definition: gibbsOperator.h:49
Sequence< NodeId > samplingNodes_
Definition: gibbsOperator.h:83