aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
graphicalModelInference.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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,
224  const std::string& label) final;
225 
226  /// adds a new evidence on node id (might be soft or hard)
227  /**
228  * @throw UndefinedElement if id does not belong to the Bayesian network
229  * @throw InvalidArgument if id already has an evidence
230  * @throw FatalError if vals=[0,0,...,0]
231  * @throw InvalidArgument if the size of vals is different from the domain
232  * size of node id
233  */
234  virtual void addEvidence(NodeId id,
235  const std::vector< GUM_SCALAR >& vals) final;
236 
237  /// adds a new evidence on node named nodeName (might be soft or hard)
238  /**
239  * @throw UndefinedElement if id does not belong to the Bayesian network
240  * @throw InvalidArgument if nodeName already has an evidence
241  * @throw FatalError if vals=[0,0,...,0]
242  * @throw InvalidArgument if the size of vals is different from the domain
243  * size of node nodeName
244  */
245  virtual void addEvidence(const std::string& nodeName,
246  const std::vector< GUM_SCALAR >& vals) final;
247 
248  /// adds a new evidence on node id (might be soft or hard)
249  /**
250  * @throw UndefinedElement if the potential is defined over several nodes
251  * @throw UndefinedElement if the node on which the potential is defined
252  * does not belong to the Bayesian network
253  * @throw InvalidArgument if the node of the potential already has an
254  * evidence
255  * @throw FatalError if pot=[0,0,...,0]
256  */
257  virtual void addEvidence(const Potential< GUM_SCALAR >& pot) final;
258 
259  /// adds a new evidence on node id (might be soft or hard)
260  /**
261  * @throw UndefinedElement if the potential is defined over several nodes
262  * @throw UndefinedElement if the node on which the potential is defined
263  * does not belong to the Bayesian network
264  * @throw InvalidArgument if the node of the potential already has an
265  * evidence
266  * @throw FatalError if pot=[0,0,...,0]
267  */
268  virtual void addEvidence(Potential< GUM_SCALAR >&& pot) final;
269 
270  /// adds a new set of evidence
271  /**
272  * @throw UndefinedElement if some potential is defined over several nodes
273  * @throw UndefinedElement if the node on which some potential is defined
274  * does not belong to the Bayesian network
275  * @throw InvalidArgument if the node of some potential already has an
276  * evidence
277  * @throw FatalError if pot=[0,0,...,0]
278  */
279  virtual void
280  addSetOfEvidence(const Set< const Potential< GUM_SCALAR >* >& potset) final;
281 
282  /// adds a new list of evidence
283  /**
284  * @throw UndefinedElement if some potential is defined over several nodes
285  * @throw UndefinedElement if the node on which some potential is defined
286  * does not belong to the Bayesian network
287  * @throw InvalidArgument if the node of some potential already has an
288  * evidence
289  * @throw FatalError if pot=[0,0,...,0]
290  */
291  virtual void addListOfEvidence(
292  const List< const Potential< GUM_SCALAR >* >& potlist) final;
293 
294  /// change the value of an already existing hard evidence
295  /**
296  * @throw UndefinedElement if id does not belong to the Bayesian network
297  * @throw InvalidArgument if val is not a value for id
298  * @throw InvalidArgument if id does not already have an evidence
299  */
300  virtual void chgEvidence(NodeId id, const Idx val) final;
301 
302  /// change the value of an already existing hard evidence
303  /**
304  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
305  * @throw InvalidArgument if val is not a value for id
306  * @throw InvalidArgument if id does not already have an evidence
307  */
308  virtual void chgEvidence(const std::string& nodeName, const Idx val) final;
309 
310  /// change the value of an already existing hard evidence
311  /**
312  * @throw UndefinedElement if id does not belong to the Bayesian network
313  * @throw InvalidArgument if val is not a value for id
314  * @throw InvalidArgument if id does not already have an evidence
315  */
316  virtual void chgEvidence(NodeId id, const std::string& label) final;
317 
318  /// change the value of an already existing hard evidence
319  /**
320  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
321  * @throw InvalidArgument if val is not a value for id
322  * @throw InvalidArgument if id does not already have an evidence
323  */
324  virtual void chgEvidence(const std::string& nodeName,
325  const std::string& label) final;
326 
327  /// change the value of an already existing evidence (might be soft or hard)
328  /**
329  * @throw UndefinedElement if id does not belong to the Bayesian network
330  * @throw InvalidArgument if the node does not already have an evidence
331  * @throw FatalError if vals=[0,0,...,0]
332  * @throw InvalidArgument if the size of vals is different from the domain
333  * size of node id
334  */
335  virtual void chgEvidence(NodeId id,
336  const std::vector< GUM_SCALAR >& vals) final;
337 
338  /// change the value of an already existing evidence (might be soft or hard)
339  /**
340  * @throw UndefinedElement if nodeName does not belong to the Bayesian network
341  * @throw InvalidArgument if the node does not already have an evidence
342  * @throw FatalError if vals=[0,0,...,0]
343  * @throw InvalidArgument if the size of vals is different from the domain
344  * size of node id
345  */
346  virtual void chgEvidence(const std::string& nodeName,
347  const std::vector< GUM_SCALAR >& vals) final;
348 
349  /// change the value of an already existing evidence (might be soft or hard)
350  /**
351  * @throw UndefinedElement if the potential is defined over several nodes
352  * @throw UndefinedElement if the node on which the potential is defined
353  * does not belong to the Bayesian network
354  * @throw InvalidArgument if the node of the potential does not already
355  * have an evidence
356  * @throw FatalError if pot=[0,0,...,0]
357  */
358  virtual void chgEvidence(const Potential< GUM_SCALAR >& pot) final;
359 
360  /// removes all the evidence entered into the network
361  virtual void eraseAllEvidence() final;
362 
363  /// removed the evidence, if any, corresponding to node id
364  virtual void eraseEvidence(NodeId id) final;
365 
366  /// removed the evidence, if any, corresponding to node of name nodeName
367  virtual void eraseEvidence(const std::string& nodeName) final;
368 
369  /// indicates whether some node(s) have received evidence
370  virtual bool hasEvidence() const final;
371 
372  /// indicates whether node id has received an evidence
373  virtual bool hasEvidence(NodeId id) const final;
374 
375  /// indicates whether node id has received a hard evidence
376  virtual bool hasHardEvidence(NodeId id) const final;
377 
378  /// indicates whether node id has received a soft evidence
379  virtual bool hasSoftEvidence(NodeId id) const final;
380  /// indicates whether node id has received an evidence
381 
382  virtual bool hasEvidence(const std::string& nodeName) const final;
383 
384  /// indicates whether node id has received a hard evidence
385  virtual bool hasHardEvidence(const std::string& nodeName) const final;
386 
387  /// indicates whether node id has received a soft evidence
388  virtual bool hasSoftEvidence(const std::string& nodeName) const final;
389 
390  /// returns the number of evidence entered into the Bayesian network
391  virtual Size nbrEvidence() const final;
392 
393  /// returns the number of hard evidence entered into the Bayesian network
394  virtual Size nbrHardEvidence() const final;
395 
396  /// returns the number of soft evidence entered into the Bayesian network
397  virtual Size nbrSoftEvidence() const final;
398 
399  /// returns the set of evidence
400  const NodeProperty< const Potential< GUM_SCALAR >* >& evidence() const;
401 
402  /// returns the set of nodes with soft evidence
403  const NodeSet& softEvidenceNodes() const;
404 
405  /// returns the set of nodes with hard evidence
406  const NodeSet& hardEvidenceNodes() const;
407 
408  /// indicate for each node with hard evidence which value it took
409  const NodeProperty< Idx >& hardEvidence() const;
410 
411  /// @}
412 
413 
414  protected:
415  /// fired when the stage is changed
416  virtual void onStateChanged_() = 0;
417 
418  /// fired after a new evidence is inserted
419  virtual void onEvidenceAdded_(const NodeId id, bool isHardEvidence) = 0;
420 
421  /// fired before an evidence is removed
422  virtual void onEvidenceErased_(const NodeId id, bool isHardEvidence) = 0;
423 
424  /// fired before all the evidence are erased
425  virtual void onAllEvidenceErased_(bool contains_hard_evidence) = 0;
426 
427  /** @brief fired after an evidence is changed, in particular when its status
428  * (soft/hard) changes
429  *
430  * @param nodeId the node of the changed evidence
431  * @param hasChangedSoftHard true if the evidence has changed from Soft to
432  * Hard or from Hard to Soft
433  *
434  */
435  virtual void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard) = 0;
436 
437  /// fired after a new Bayes net has been assigned to the engine
438  virtual void onModelChanged_(const GraphicalModel* model) = 0;
439 
440  /// prepares inference when the latter is in OutdatedStructure state
441  /** Note that the values of evidence are not necessarily
442  * known and can be changed between updateOutdatedStructure_ and
443  * makeInference_. */
444  virtual void updateOutdatedStructure_() = 0;
445 
446  /// prepares inference when the latter is in OutdatedPotentials state
447  /** Note that the values of evidence are not necessarily
448  * known and can be changed between updateOutdatedPotentials_ and
449  * makeInference_. */
450  virtual void updateOutdatedPotentials_() = 0;
451 
452  /// called when the inference has to be performed effectively
453  /** Once the inference is done, fillPosterior_ can be called. */
454  virtual void makeInference_() = 0;
455 
456  /// put the inference into an outdated model structure state
457  /** OutdatedStructure: in this state, the inference is fully unprepared
458  * to be applied because some events changed the "logical" structure of the
459  * model: for instance a node received a hard evidence, which implies that
460  * its outgoing arcs can be removed from the model, hence involving a
461  * structural change in the model. As a consequence, the (incremental)
462  * inference (probably) needs a significant amount of preparation to be
463  * ready for the next inference. In a Lazy propagation, for instance, this
464  * step amounts to compute a new join tree, hence a new structure in which
465  * inference will be applied. Note that classes that inherit from
466  * graphicalModelInference may be smarter than graphicalModelInference and may,
467  * in some situations, find out that their data structures are still ok for
468  * inference and, therefore, only resort to perform the actions related to the
469  * OutdatedPotentials state. As an example, consider a LazyPropagation
470  * inference in Bayes Net A->B->C->D->E in which C has received hard evidence
471  * e_C and E is the only target. In this case, A and B are not needed for
472  * inference, the only potentials that matter are P(D|e_C) and P(E|D). So the
473  * smallest join tree needed for inference contains only one clique DE. Now,
474  * adding new evidence e_A on A has no impact on E given hard evidence e_C. In
475  * this case, LazyPropagation can be smart and not update its join tree.*/
477 
478  /** @brief puts the inference into an OutdatedPotentials state if it is
479  * not already in an OutdatedStructure state
480  *
481  * OutdatedPotentials: in this state, the structure of the model remains
482  * unchanged, only some potentials stored in it have changed. Therefore,
483  * the inference probably just needs to invalidate some already computed
484  * potentials to be ready. Only a light amount of preparation is needed to
485  * be able to perform inference.
486  */
488 
489 
490  private:
491  /// the current state of the inference (outdated/ready/done)
493 
494  /// the Bayes net on which we perform inferences
495  const GraphicalModel* model__{nullptr};
496 
497  /// the domain sizes of the random variables
499 
500  /// the set of evidence entered into the network
502 
503  /// assign to each node with a hard evidence the index of its observed value
505 
506  /// the set of nodes that received soft evidence
508 
509  /// the set of nodes that received hard evidence
511 
512 
513  /// create the internal structure for a hard evidence
515 
516  /// checks whether a potential corresponds to a hard evidence or not
517  bool isHardEvidence__(const Potential< GUM_SCALAR >& pot, Idx& val) const;
518 
519  /// computes the domain sizes of the random variables
520  void computeDomainSizes__();
521 
522  protected:
523  /// set the state of the inference engine and
524  /// call the notification onStateChanged_
525  /// when necessary (i.e. when the state has effectively changed).
526  virtual void setState_(const StateOfInference state) final;
527 
528  void setModel_(const GraphicalModel* model);
529 
530  /// assigns a model during the inference engine construction
531  void setModelDuringConstruction_(const GraphicalModel* model);
532 
533  bool hasNoModel_() const { return model__ == nullptr; };
534  };
535 } // namespace gum
536 
537 #include <agrum/tools/graphicalModels/inference/graphicalModelInference_tpl.h>
538 
539 
540 #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
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
void computeDomainSizes__()
computes the domain sizes of the random variables
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:669
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
NodeSet hard_evidence_nodes__
the set of nodes that received hard evidence
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
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
Potential< GUM_SCALAR > createHardEvidence__(NodeId id, Idx val) const
create the internal structure for a hard evidence
NodeSet soft_evidence_nodes__
the set of nodes that received soft evidence
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence
StateOfInference
current state of the inference
StateOfInference state__
the current state of the inference (outdated/ready/done)
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)
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)
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
NodeProperty< Size > domain_sizes__
the domain sizes of the random variables
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
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
virtual void chgEvidence(const Potential< GUM_SCALAR > &pot) final
change the value of an already existing evidence (might be soft or hard)
const GraphicalModel * model__
the Bayes net on which we perform inferences
void setOutdatedPotentialsState_()
puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure stat...
NodeProperty< Idx > hard_evidence__
assign to each node with a hard evidence the index of its observed value
NodeProperty< const Potential< GUM_SCALAR > *> evidence__
the set of evidence entered into the network
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