aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
graphicalModelInference.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  * @file
23  * @brief This file contains abstract class definitions for graphical models
24  * inference classes.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Christophe GONZALES(@AMU)
27  */
28 #ifndef AGRUM_GRAPHICALMODELINFERENCE_H
29 #define AGRUM_GRAPHICALMODELINFERENCE_H
30 
31 
32 #include <agrum/tools/graphicalModels/graphicalModel.h>
33 #include <agrum/tools/multidim/potential.h>
34 #include <agrum/agrum.h>
35 
36 
37 namespace gum {
38 
39  /**
40  * @class GraphicalModelInference graphicalModelInference.h
41  * <agrum/tools/graphicalModels/graphicalModel.h>
42  * @brief A generic class for graphical model inference: handles evidence and the
43  * current state of the inference
44  * @ingroup gm_group
45  *
46  * The goal of the graphicalModelInference class is twofold:
47  * i) handling the common resources of graphical Model inference (model,
48  * soft/hard evidence); ii) propose a general high-level scheme for all the
49  * inference methods.
50  *
51  * A specialized inference just has to specify how to prepare inference, how
52  * to make inference and how to get the posteriors for nodes and set of nodes.
53  * The scheme for every inference derived from graphicalModelInference will be
54  * the same:
55  *
56  * 1- ie=SpecificInference(model); // state <- OutdatedStructure
57  * 2- set targets and evidence in ie
58  * 3- ie.prepareInference(); // state <- Ready4Inference
59  * 4.a- change values of evidence in ie // state <- OutdatedPotentials
60  * 4.b- change some hard evidence or targets // state <- OutdatedStructure
61  * 5- ie.makeInference(); // state <- Done
62  * 6- get posteriors
63  * 7- goto 2 or 4
64  *
65  * graphicalModelInference can be in one of 4 different states:
66  * - OutdatedStructure: in this state, the inference is fully unprepared
67  * to be applied because some events changed the "logical" structure of the
68  * model: for instance a node received a hard evidence, which implies that
69  * its outgoing arcs can be removed from the model, hence involving a
70  * structural change in the model.
71  * - OutdatedPotentials: in this state, the structure of the model remains
72  * unchanged, only some potentials stored in it have changed. Therefore,
73  * the inference probably just needs to invalidate some already computed
74  * potentials to be ready. Only a light amount of preparation is needed to
75  * be able to perform inference.
76  * - Ready4Inference: in this state, all the data structures are ready for
77  * inference. There just remains to perform the inference computations.
78  * - Done: the heavy computations of inference have been done. There might
79  * still remain a few light computations to perform to get the posterior
80  * potentials we need.
81  */
82 
83  template < typename GUM_SCALAR >
85  public:
86  /**
87  * current state of the inference
88  *
89  * graphicalModelInference can be in one of 4 different states:
90  * - OutdatedStructure: in this state, the inference is fully unprepared
91  * to be applied because some events changed the "logical" structure of the
92  * model: for instance a node received a hard evidence, which implies that
93  * its outgoing arcs can be removed from the model, hence involving a
94  * structural change in the model.
95  * - OutdatedPotentials: in this state, the structure of the model remains
96  * unchanged, only some potentials stored in it have changed. Therefore,
97  * the inference probably just needs to invalidate some already computed
98  * potentials to be ready. Only a light amount of preparation is needed to
99  * be able to perform inference.
100  * - Ready4Inference: in this state, all the data structures are ready for
101  * inference. There just remains to perform the inference computations.
102  * - Done: the heavy computations of inference have been done. There might
103  * still remain a few light computations to perform to get the posterior
104  * potentials we need.
105  */
106  enum class StateOfInference
107  {
111  Done
112  };
113 
114 
115  // ############################################################################
116  /// @name Constructors / Destructors
117  // ############################################################################
118  /// @{
119 
120  /// default constructor
121  /** @warning note that, by aGrUM's rule, the model is not copied but only
122  * referenced by the inference algorithm. */
123  explicit GraphicalModelInference(const GraphicalModel* model);
124 
125  /// default constructor with a null model (useful for virtual inheritance)
126  /** @warning graphicalModelInference is virtually inherited by
127  * MarginalTargetedInference. As a result, the lowest descendant of
128  * graphicalModelInference will create the latter. To avoid requiring
129  * developers to add in the constructors of their inference algorithms a call
130  * to graphicalModelInference( model ), we added constructor
131  * graphicalModelInference(),
132  * which will be called automatically by the lowest descendant. */
134 
135  /// destructor
136  virtual ~GraphicalModelInference();
137 
138  /// @}
139 
140 
141  // ############################################################################
142  /// @name Accessors / Modifiers
143  // ############################################################################
144  /// @{
145 
146  /// Returns a constant reference over the IBayesNet referenced by this class
147  /** @throws UndefinedElement is raised if no Bayes net has been assigned to
148  * the inference. */
149  virtual const GraphicalModel& model() const final;
150 
151  /// get the domain sizes of the random variables of the model
152  virtual const NodeProperty< Size >& domainSizes() const final;
153 
154  /// returns whether the inference object is in a ready state
155  virtual bool isInferenceReady() const noexcept final;
156  /// returns whether the inference object is in a OutdatedStructure state
157  virtual bool isInferenceOutdatedStructure() const noexcept final;
158  /// returns whether the inference object is in a OutdatedPotential state
159  virtual bool isInferenceOutdatedPotentials() const noexcept final;
160  /// returns whether the inference object is in a InferenceDone state
161  /** The inference object is in a done state when the posteriors can be
162  * retrieved without performing a new inference, i.e., all the heavy
163  * computations have already been performed. Typically, in a junction tree
164  * algorithm, this corresponds to a situation in which all the messages
165  * needed in the JT have been computed and sent. */
166  virtual bool isInferenceDone() const noexcept final;
167 
168 
169  /// prepare the internal inference structures for the next inference
170  virtual void prepareInference() final;
171 
172  /// perform the heavy computations needed to compute the targets' posteriors
173  /** In a Junction tree propagation scheme, for instance, the heavy
174  * computations are those of the messages sent in the JT. This is precisely
175  * what makeInference should compute. Later, the computations of the
176  * posteriors can be done "lightly" by multiplying and projecting those
177  * messages. */
178  virtual void makeInference() final;
179 
180  /// clears all the data structures allocated for the last inference
181  virtual void clear();
182 
183  /// returns the state of the inference engine
184  virtual StateOfInference state() const noexcept final;
185  /// @}
186 
187 
188  // ############################################################################
189  /// @name Evidence
190  // ############################################################################
191  /// @{
192 
193  /// adds a new hard evidence on node id
194  /**
195  * @throw UndefinedElement if id does not belong to the Bayesian network
196  * @throw InvalidArgument if val is not a value for id
197  * @throw InvalidArgument if id already has an evidence
198  */
199  virtual void addEvidence(NodeId id, const Idx val) final;
200 
201  /// adds a new hard evidence on node named nodeName
202  /**
203  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
204  * @throw InvalidArgument if val is not a value for id
205  * @throw InvalidArgument if nodeName already has an evidence
206  */
207  virtual void addEvidence(const std::string& nodeName, const Idx val) final;
208 
209  /// adds a new hard evidence on node id
210  /**
211  * @throw UndefinedElement if id does not belong to the Bayesian network
212  * @throw InvalidArgument if val is not a value for id
213  * @throw InvalidArgument if id already has an evidence
214  */
215  virtual void addEvidence(NodeId id, const std::string& label) final;
216 
217  /// adds a new hard evidence on node named nodeName
218  /**
219  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
220  * @throw InvalidArgument if val is not a value for id
221  * @throw InvalidArgument if nodeName already has an evidence
222  */
223  virtual void addEvidence(const std::string& nodeName, const std::string& label) final;
224 
225  /// adds a new evidence on node id (might be soft or hard)
226  /**
227  * @throw UndefinedElement if id does not belong to the Bayesian network
228  * @throw InvalidArgument if id already has an evidence
229  * @throw FatalError if vals=[0,0,...,0]
230  * @throw InvalidArgument if the size of vals is different from the domain
231  * size of node id
232  */
233  virtual void addEvidence(NodeId id, const std::vector< GUM_SCALAR >& vals) final;
234 
235  /// adds a new evidence on node named nodeName (might be soft or hard)
236  /**
237  * @throw UndefinedElement if id does not belong to the Bayesian network
238  * @throw InvalidArgument if nodeName already has an evidence
239  * @throw FatalError if vals=[0,0,...,0]
240  * @throw InvalidArgument if the size of vals is different from the domain
241  * size of node nodeName
242  */
243  virtual void addEvidence(const std::string& nodeName,
244  const std::vector< GUM_SCALAR >& vals) final;
245 
246  /// adds a new evidence on node id (might be soft or hard)
247  /**
248  * @throw UndefinedElement if the potential is defined over several nodes
249  * @throw UndefinedElement if the node on which the potential is defined
250  * does not belong to the Bayesian network
251  * @throw InvalidArgument if the node of the potential already has an
252  * evidence
253  * @throw FatalError if pot=[0,0,...,0]
254  */
255  virtual void addEvidence(const Potential< GUM_SCALAR >& pot) final;
256 
257  /// adds a new evidence on node id (might be soft or hard)
258  /**
259  * @throw UndefinedElement if the potential is defined over several nodes
260  * @throw UndefinedElement if the node on which the potential is defined
261  * does not belong to the Bayesian network
262  * @throw InvalidArgument if the node of the potential already has an
263  * evidence
264  * @throw FatalError if pot=[0,0,...,0]
265  */
266  virtual void addEvidence(Potential< GUM_SCALAR >&& pot) final;
267 
268  /// adds a new set of evidence
269  /**
270  * @throw UndefinedElement if some potential is defined over several nodes
271  * @throw UndefinedElement if the node on which some potential is defined
272  * does not belong to the Bayesian network
273  * @throw InvalidArgument if the node of some potential already has an
274  * evidence
275  * @throw FatalError if pot=[0,0,...,0]
276  */
277  virtual void addSetOfEvidence(const Set< const Potential< GUM_SCALAR >* >& potset) final;
278 
279  /// adds a new list of evidence
280  /**
281  * @throw UndefinedElement if some potential is defined over several nodes
282  * @throw UndefinedElement if the node on which some potential is defined
283  * does not belong to the Bayesian network
284  * @throw InvalidArgument if the node of some potential already has an
285  * evidence
286  * @throw FatalError if pot=[0,0,...,0]
287  */
288  virtual void addListOfEvidence(const List< const Potential< GUM_SCALAR >* >& potlist) final;
289 
290  /// change the value of an already existing hard evidence
291  /**
292  * @throw UndefinedElement if id does not belong to the Bayesian network
293  * @throw InvalidArgument if val is not a value for id
294  * @throw InvalidArgument if id does not already have an evidence
295  */
296  virtual void chgEvidence(NodeId id, const Idx val) final;
297 
298  /// change the value of an already existing hard evidence
299  /**
300  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
301  * @throw InvalidArgument if val is not a value for id
302  * @throw InvalidArgument if id does not already have an evidence
303  */
304  virtual void chgEvidence(const std::string& nodeName, const Idx val) final;
305 
306  /// change the value of an already existing hard evidence
307  /**
308  * @throw UndefinedElement if id does not belong to the Bayesian network
309  * @throw InvalidArgument if val is not a value for id
310  * @throw InvalidArgument if id does not already have an evidence
311  */
312  virtual void chgEvidence(NodeId id, const std::string& label) final;
313 
314  /// change the value of an already existing hard evidence
315  /**
316  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
317  * @throw InvalidArgument if val is not a value for id
318  * @throw InvalidArgument if id does not already have an evidence
319  */
320  virtual void chgEvidence(const std::string& nodeName, const std::string& label) final;
321 
322  /// change the value of an already existing evidence (might be soft or hard)
323  /**
324  * @throw UndefinedElement if id does not belong to the Bayesian network
325  * @throw InvalidArgument if the node does not already have an evidence
326  * @throw FatalError if vals=[0,0,...,0]
327  * @throw InvalidArgument if the size of vals is different from the domain
328  * size of node id
329  */
330  virtual void chgEvidence(NodeId id, const std::vector< GUM_SCALAR >& vals) final;
331 
332  /// change the value of an already existing evidence (might be soft or hard)
333  /**
334  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
335  * @throw InvalidArgument if the node does not already have an evidence
336  * @throw FatalError if vals=[0,0,...,0]
337  * @throw InvalidArgument if the size of vals is different from the domain
338  * size of node id
339  */
340  virtual void chgEvidence(const std::string& nodeName,
341  const std::vector< GUM_SCALAR >& vals) final;
342 
343  /// change the value of an already existing evidence (might be soft or hard)
344  /**
345  * @throw UndefinedElement if the potential is defined over several nodes
346  * @throw UndefinedElement if the node on which the potential is defined
347  * does not belong to the Bayesian network
348  * @throw InvalidArgument if the node of the potential does not already
349  * have an evidence
350  * @throw FatalError if pot=[0,0,...,0]
351  */
352  virtual void chgEvidence(const Potential< GUM_SCALAR >& pot) final;
353 
354  /// removes all the evidence entered into the network
355  virtual void eraseAllEvidence() final;
356 
357  /// removed the evidence, if any, corresponding to node id
358  virtual void eraseEvidence(NodeId id) final;
359 
360  /// removed the evidence, if any, corresponding to node of name nodeName
361  virtual void eraseEvidence(const std::string& nodeName) final;
362 
363  /// indicates whether some node(s) have received evidence
364  virtual bool hasEvidence() const final;
365 
366  /// indicates whether node id has received an evidence
367  virtual bool hasEvidence(NodeId id) const final;
368 
369  /// indicates whether node id has received a hard evidence
370  virtual bool hasHardEvidence(NodeId id) const final;
371 
372  /// indicates whether node id has received a soft evidence
373  virtual bool hasSoftEvidence(NodeId id) const final;
374  /// indicates whether node id has received an evidence
375 
376  virtual bool hasEvidence(const std::string& nodeName) const final;
377 
378  /// indicates whether node id has received a hard evidence
379  virtual bool hasHardEvidence(const std::string& nodeName) const final;
380 
381  /// indicates whether node id has received a soft evidence
382  virtual bool hasSoftEvidence(const std::string& nodeName) const final;
383 
384  /// returns the number of evidence entered into the Bayesian network
385  virtual Size nbrEvidence() const final;
386 
387  /// returns the number of hard evidence entered into the Bayesian network
388  virtual Size nbrHardEvidence() const final;
389 
390  /// returns the number of soft evidence entered into the Bayesian network
391  virtual Size nbrSoftEvidence() const final;
392 
393  /// returns the set of evidence
394  const NodeProperty< const Potential< GUM_SCALAR >* >& evidence() const;
395 
396  /// returns the set of nodes with soft evidence
397  const NodeSet& softEvidenceNodes() const;
398 
399  /// returns the set of nodes with hard evidence
400  const NodeSet& hardEvidenceNodes() const;
401 
402  /// indicate for each node with hard evidence which value it took
403  const NodeProperty< Idx >& hardEvidence() const;
404 
405  /// @}
406 
407 
408  protected:
409  /// fired when the stage is changed
410  virtual void onStateChanged_() = 0;
411 
412  /// fired after a new evidence is inserted
413  virtual void onEvidenceAdded_(const NodeId id, bool isHardEvidence) = 0;
414 
415  /// fired before an evidence is removed
416  virtual void onEvidenceErased_(const NodeId id, bool isHardEvidence) = 0;
417 
418  /// fired before all the evidence are erased
419  virtual void onAllEvidenceErased_(bool contains_hard_evidence) = 0;
420 
421  /** @brief fired after an evidence is changed, in particular when its status
422  * (soft/hard) changes
423  *
424  * @param nodeId the node of the changed evidence
425  * @param hasChangedSoftHard true if the evidence has changed from Soft to
426  * Hard or from Hard to Soft
427  *
428  */
429  virtual void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard) = 0;
430 
431  /// fired after a new Bayes net has been assigned to the engine
432  virtual void onModelChanged_(const GraphicalModel* model) = 0;
433 
434  /// prepares inference when the latter is in OutdatedStructure state
435  /** Note that the values of evidence are not necessarily
436  * known and can be changed between updateOutdatedStructure_ and
437  * makeInference_. */
438  virtual void updateOutdatedStructure_() = 0;
439 
440  /// prepares inference when the latter is in OutdatedPotentials state
441  /** Note that the values of evidence are not necessarily
442  * known and can be changed between updateOutdatedPotentials_ and
443  * makeInference_. */
444  virtual void updateOutdatedPotentials_() = 0;
445 
446  /// called when the inference has to be performed effectively
447  /** Once the inference is done, fillPosterior_ can be called. */
448  virtual void makeInference_() = 0;
449 
450  /// put the inference into an outdated model structure state
451  /** OutdatedStructure: in this state, the inference is fully unprepared
452  * to be applied because some events changed the "logical" structure of the
453  * model: for instance a node received a hard evidence, which implies that
454  * its outgoing arcs can be removed from the model, hence involving a
455  * structural change in the model. As a consequence, the (incremental)
456  * inference (probably) needs a significant amount of preparation to be
457  * ready for the next inference. In a Lazy propagation, for instance, this
458  * step amounts to compute a new join tree, hence a new structure in which
459  * inference will be applied. Note that classes that inherit from
460  * graphicalModelInference may be smarter than graphicalModelInference and may,
461  * in some situations, find out that their data structures are still ok for
462  * inference and, therefore, only resort to perform the actions related to the
463  * OutdatedPotentials state. As an example, consider a LazyPropagation
464  * inference in Bayes Net A->B->C->D->E in which C has received hard evidence
465  * e_C and E is the only target. In this case, A and B are not needed for
466  * inference, the only potentials that matter are P(D|e_C) and P(E|D). So the
467  * smallest join tree needed for inference contains only one clique DE. Now,
468  * adding new evidence e_A on A has no impact on E given hard evidence e_C. In
469  * this case, LazyPropagation can be smart and not update its join tree.*/
471 
472  /** @brief puts the inference into an OutdatedPotentials state if it is
473  * not already in an OutdatedStructure state
474  *
475  * OutdatedPotentials: in this state, the structure of the model remains
476  * unchanged, only some potentials stored in it have changed. Therefore,
477  * the inference probably just needs to invalidate some already computed
478  * potentials to be ready. Only a light amount of preparation is needed to
479  * be able to perform inference.
480  */
482 
483 
484  private:
485  /// the current state of the inference (outdated/ready/done)
487 
488  /// the Bayes net on which we perform inferences
489  const GraphicalModel* _model_{nullptr};
490 
491  /// the domain sizes of the random variables
493 
494  /// the set of evidence entered into the network
496 
497  /// assign to each node with a hard evidence the index of its observed value
499 
500  /// the set of nodes that received soft evidence
502 
503  /// the set of nodes that received hard evidence
505 
506 
507  /// create the internal structure for a hard evidence
509 
510  /// checks whether a potential corresponds to a hard evidence or not
511  bool _isHardEvidence_(const Potential< GUM_SCALAR >& pot, Idx& val) const;
512 
513  /// computes the domain sizes of the random variables
514  void _computeDomainSizes_();
515 
516  protected:
517  /// set the state of the inference engine and
518  /// call the notification onStateChanged_
519  /// when necessary (i.e. when the state has effectively changed).
520  virtual void setState_(const StateOfInference state) final;
521 
522  void setModel_(const GraphicalModel* model);
523 
524  /// assigns a model during the inference engine construction
525  void setModelDuringConstruction_(const GraphicalModel* model);
526 
527  bool hasNoModel_() const { return _model_ == nullptr; };
528  };
529 } // namespace gum
530 
531 #include <agrum/tools/graphicalModels/inference/graphicalModelInference_tpl.h>
532 
533 
534 #endif // AGRUM_GRAPHICALMODELINFERENCE_H
virtual void prepareInference() final
prepare the internal inference structures for the next inference
virtual const NodeProperty< Size > & domainSizes() const final
get the domain sizes of the random variables of the model
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void updateOutdatedPotentials_()=0
prepares inference when the latter is in OutdatedPotentials state
virtual void onAllEvidenceErased_(bool contains_hard_evidence)=0
fired before all the evidence are erased
Potential< GUM_SCALAR > _createHardEvidence_(NodeId id, Idx val) const
create the internal structure for a hard evidence
GraphicalModelInference()
default constructor with a null model (useful for virtual inheritance)
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void chgEvidence(const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
change the value of an already existing evidence (might be soft or hard)
virtual void updateOutdatedStructure_()=0
prepares inference when the latter is in OutdatedStructure state
virtual bool hasHardEvidence(const std::string &nodeName) const final
indicates whether node id has received a hard evidence
virtual void eraseEvidence(const std::string &nodeName) final
removed the evidence, if any, corresponding to node of name nodeName
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
void setOutdatedStructureState_()
put the inference into an outdated model structure state
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
virtual void onEvidenceAdded_(const NodeId id, bool isHardEvidence)=0
fired after a new evidence is inserted
virtual void addListOfEvidence(const List< const Potential< GUM_SCALAR > * > &potlist) final
adds a new list of evidence
virtual void addEvidence(const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
adds a new evidence on node named nodeName (might be soft or hard)
virtual bool hasSoftEvidence(const std::string &nodeName) const final
indicates whether node id has received a soft evidence
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
bool _isHardEvidence_(const Potential< GUM_SCALAR > &pot, Idx &val) const
checks whether a potential corresponds to a hard evidence or not
virtual void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard)=0
fired after an evidence is changed, in particular when its status (soft/hard) changes ...
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual void addSetOfEvidence(const Set< const Potential< GUM_SCALAR > * > &potset) final
adds a new set of evidence
virtual bool hasEvidence(const std::string &nodeName) const final
indicates whether node id has received an evidence
void _computeDomainSizes_()
computes the domain sizes of the random variables
virtual void onModelChanged_(const GraphicalModel *model)=0
fired after a new Bayes net has been assigned to the engine
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
void setModelDuringConstruction_(const GraphicalModel *model)
assigns a model during the inference engine construction
GraphicalModelInference(const GraphicalModel *model)
default constructor
virtual StateOfInference state() const noexcept final
returns the state of the inference engine
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence
StateOfInference
current state of the inference
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void addEvidence(const Potential< GUM_SCALAR > &pot) final
adds a new evidence on node id (might be soft or hard)
StateOfInference _state_
the current state of the inference (outdated/ready/done)
virtual void onStateChanged_()=0
fired when the stage is changed
virtual void chgEvidence(NodeId id, const std::vector< GUM_SCALAR > &vals) final
change the value of an already existing evidence (might be soft or hard)
void setModel_(const GraphicalModel *model)
virtual void makeInference_()=0
called when the inference has to be performed effectively
virtual void onEvidenceErased_(const NodeId id, bool isHardEvidence)=0
fired before an evidence is removed
virtual void addEvidence(Potential< GUM_SCALAR > &&pot) final
adds a new evidence on node id (might be soft or hard)
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
virtual void chgEvidence(const std::string &nodeName, const Idx val) final
change the value of an already existing hard evidence
virtual void addEvidence(NodeId id, const std::vector< GUM_SCALAR > &vals) final
adds a new evidence on node id (might be soft or hard)
virtual void addEvidence(const std::string &nodeName, const Idx val) final
adds a new hard evidence on node named nodeName
virtual void eraseEvidence(NodeId id) final
removed the evidence, if any, corresponding to node id
const NodeSet & softEvidenceNodes() const
returns the set of nodes with soft evidence
virtual Size nbrHardEvidence() const final
returns the number of hard evidence entered into the Bayesian network
virtual bool hasEvidence(NodeId id) const final
indicates whether node id has received an evidence
virtual bool isInferenceReady() const noexcept final
returns whether the inference object is in a ready state
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void clear()
clears all the data structures allocated for the last inference
NodeProperty< Size > _domain_sizes_
the domain sizes of the random variables
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual Size nbrSoftEvidence() const final
returns the number of soft evidence entered into the Bayesian network
const GraphicalModel * _model_
the Bayes net on which we perform inferences
virtual void chgEvidence(const Potential< GUM_SCALAR > &pot) final
change the value of an already existing evidence (might be soft or hard)
void setOutdatedPotentialsState_()
puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure stat...
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
const NodeProperty< const Potential< GUM_SCALAR > *> & evidence() const
returns the set of evidence
<agrum/tools/graphicalModels/graphicalModel.h>
virtual bool isInferenceOutdatedStructure() const noexcept final
returns whether the inference object is in a OutdatedStructure state
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
virtual Size nbrEvidence() const final
returns the number of evidence entered into the Bayesian network
virtual bool isInferenceOutdatedPotentials() const noexcept final
returns whether the inference object is in a OutdatedPotential state