aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
loopySamplingInference.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 implements a Hybrid sampling class using LoopyBeliefPropagation
25  * and
26  * an approximate Inference method.
27  *
28  * @author Paul ALAM & Pierre-Henri WUILLEMIN(@LIP6)
29  */
30 
31 #ifndef GUM_LOOPY_INFERENCE_H
32 #define GUM_LOOPY_INFERENCE_H
33 #include <agrum/BN/inference/GibbsSampling.h>
34 #include <agrum/BN/inference/MonteCarloSampling.h>
35 #include <agrum/BN/inference/importanceSampling.h>
36 #include <agrum/BN/inference/tools/approximateInference.h>
37 #include <agrum/BN/inference/tools/marginalTargetedInference.h>
38 #include <agrum/BN/inference/weightedSampling.h>
39 
40 namespace gum {
41 
42  /**
43  * @class LoopySamplingInference LoopySamplingInference.h
44  *<agrum/BN/inference/loopySamplingInference.h>
45  * @brief class for making hybrid sampling inference with loopy belief
46  *propagation and an approximation inference method in Bayesian networks.
47  * @ingroup bn_approximation
48  *
49  * This class inherits of template class APPROX, which SHOULD be one of the 4
50  * approximate inference methods (MonteCarlo, Weighted, Importance, Gibbs).
51  * It makes the inference with respect to the inherited class' method, after
52  * having initialized the estimators with the posteriors obtained by running
53  * LoopyBeliefPropagation algorithm.
54  *
55  */
56 
57  template < typename GUM_SCALAR, template < typename > class APPROX >
58  class LoopySamplingInference: public APPROX< GUM_SCALAR > {
59  public:
60  /**
61  * Default constructor
62  */
63  explicit LoopySamplingInference(const IBayesNet< GUM_SCALAR >* bn);
64 
65  /**
66  * destructor
67  */
68  virtual ~LoopySamplingInference();
69 
70  /// makes the inference by generating samples w.r.t the mother class' sampling
71  /// method after initalizing estimators with loopy belief propagation
72  virtual void makeInference_();
73 
74  void setVirtualLBPSize(GUM_SCALAR vlbpsize) {
75  if (vlbpsize > 0) virtualLBPSize_ = vlbpsize;
76  };
77 
78  protected:
79  GUM_SCALAR virtualLBPSize_;
80  };
81 
82 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
83 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
84 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
85 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
86 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
87 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
88 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
89 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
90  extern template class LoopySamplingInference< float, WeightedSampling >;
91 # endif
92 # endif
93 # endif
94 # endif
95 # endif
96 # endif
97 # endif
98 #endif
99 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
100 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
101 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
102 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
103 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
104 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
105 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
106 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
107  extern template class LoopySamplingInference< double, WeightedSampling >;
108 # endif
109 # endif
110 # endif
111 # endif
112 # endif
113 # endif
114 # endif
115 #endif
116 
117 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
118 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
119 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
120 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
121 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
122 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
123 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
124 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
125  extern template class LoopySamplingInference< float, ImportanceSampling >;
126 # endif
127 # endif
128 # endif
129 # endif
130 # endif
131 # endif
132 # endif
133 #endif
134 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
135 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
136 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
137 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
138 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
139 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
140 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
141 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
142  extern template class LoopySamplingInference< double, ImportanceSampling >;
143 # endif
144 # endif
145 # endif
146 # endif
147 # endif
148 # endif
149 # endif
150 #endif
151 
152 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
153 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
154 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
155 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
156 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
157 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
158 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
159 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
160  extern template class LoopySamplingInference< float, MonteCarloSampling >;
161 # endif
162 # endif
163 # endif
164 # endif
165 # endif
166 # endif
167 # endif
168 #endif
169 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
170 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
171 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
172 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
173 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
174 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
175 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
176 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
177  extern template class LoopySamplingInference< double, MonteCarloSampling >;
178 # endif
179 # endif
180 # endif
181 # endif
182 # endif
183 # endif
184 # endif
185 #endif
186 
187 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
188 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
189 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
190 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
191 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
192 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
193 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
194 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
195  extern template class LoopySamplingInference< float, GibbsSampling >;
196 # endif
197 # endif
198 # endif
199 # endif
200 # endif
201 # endif
202 # endif
203 #endif
204 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
205 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
206 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
207 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
208 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
209 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
210 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
211 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
212  extern template class LoopySamplingInference< double, GibbsSampling >;
213 # endif
214 # endif
215 # endif
216 # endif
217 # endif
218 # endif
219 # endif
220 #endif
221 
222  template < typename GUM_SCALAR >
224  template < typename GUM_SCALAR >
226  template < typename GUM_SCALAR >
228  template < typename GUM_SCALAR >
230 } // namespace gum
231 
232 #include <agrum/BN/inference/loopySamplingInference_tpl.h>
233 #endif
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual ~LoopySamplingInference()
destructor
LoopySamplingInference(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
<agrum/BN/inference/loopySamplingInference.h>
void setVirtualLBPSize(GUM_SCALAR vlbpsize)
virtual void makeInference_()
makes the inference by generating samples w.r.t the mother class&#39; sampling method after initalizing e...