aGrUM  0.16.0
marginalTargetedInference.h
Go to the documentation of this file.
1 
31 #ifndef GUM_BAYES_NET_MARGINAL_TARGETED_INFERENCE_H
32 #define GUM_BAYES_NET_MARGINAL_TARGETED_INFERENCE_H
33 
34 #include <string>
35 
37 #include <agrum/agrum.h>
38 
39 
40 namespace gum {
41 
42 
56  template < typename GUM_SCALAR >
57  class MarginalTargetedInference
58  : public virtual BayesNetInference< GUM_SCALAR > {
59  public:
60  // ############################################################################
62  // ############################################################################
64 
66 
69  explicit MarginalTargetedInference(const IBayesNet< GUM_SCALAR >* bn);
70 
73 
75 
76 
77  // ############################################################################
79  // ############################################################################
81 
83 
97  virtual const Potential< GUM_SCALAR >& posterior(NodeId node);
98 
100 
115  virtual const Potential< GUM_SCALAR >& posterior(const std::string& nodeName);
116 
118 
119 
120  // ############################################################################
122  // ############################################################################
124 
126  virtual void eraseAllTargets();
127 
129  virtual void addAllTargets() final;
130 
132 
135  virtual void addTarget(NodeId target) final;
136 
138 
141  virtual void addTarget(const std::string& nodeName) final;
142 
144 
146  virtual void eraseTarget(NodeId target) final;
147 
149 
151  virtual void eraseTarget(const std::string& nodeName) final;
152 
154  virtual bool isTarget(NodeId node) const final;
155 
157  virtual bool isTarget(const std::string& nodeName) const final;
158 
160  virtual const Size nbrTargets() const noexcept final;
161 
163  virtual const NodeSet& targets() const noexcept final;
164 
166 
167  // ############################################################################
169  // ############################################################################
171 
176  virtual GUM_SCALAR H(NodeId X) final;
177 
182  virtual GUM_SCALAR H(const std::string& nodeName) final;
183 
185 
186 
198  Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet& evs);
199 
210  Potential< GUM_SCALAR > evidenceImpact(const std::string& target,
211  const std::vector< std::string >& evs);
212 
213  protected:
215 
216  virtual void _onMarginalTargetAdded(const NodeId id) = 0;
217 
219 
220  virtual void _onMarginalTargetErased(const NodeId id) = 0;
221 
223  virtual void _onAllMarginalTargetsAdded() = 0;
224 
226  virtual void _onAllMarginalTargetsErased() = 0;
227 
229  virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR >* bn);
230 
232 
233  virtual const Potential< GUM_SCALAR >& _posterior(NodeId id) = 0;
234 
235  protected:
236  void _setTargetedMode();
237  bool _isTargetedMode() const;
238 
239  private:
242 
245 
246 
247  /*/// remove all the marginal posteriors computed
248  void __invalidatePosteriors() noexcept;*/
249 
252  };
253 
254 
255 } // namespace gum
256 
257 
258 #include <agrum/BN/inference/tools/marginalTargetedInference_tpl.h>
259 
260 
261 #endif // GUM_BAYES_NET_MARGINAL_TARGETED_INFERENCE_H
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)
fired after a new Bayes net has been assigned to the engine
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon&#39;s entropy of a node given the observation.
NodeSet __targets
the set of marginal targets
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void _onMarginalTargetAdded(const NodeId id)=0
fired after a new marginal target is inserted
STL namespace.
virtual const Size nbrTargets() const noexcept final
returns the number of marginal targets
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual void _onAllMarginalTargetsErased()=0
fired before a all marginal targets are removed
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
void __setAllMarginalTargets()
sets all the nodes of the Bayes net as targets
virtual void addAllTargets() final
adds all nodes as targets
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
virtual void _onMarginalTargetErased(const NodeId id)=0
fired before a marginal target is removed
Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) ...
virtual void _onAllMarginalTargetsAdded()=0
fired after all the nodes of the BN are added as marginal targets
virtual const Potential< GUM_SCALAR > & _posterior(NodeId id)=0
asks derived classes for the posterior of a given variable
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
virtual void eraseAllTargets()
Clear all previously defined targets.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
bool __targeted_mode
whether the actual targets are default
Size NodeId
Type for node ids.
Definition: graphElements.h:98
MarginalTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor