aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
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: public virtual BayesNetInference< GUM_SCALAR > {
58  public:
59  // ############################################################################
61  // ############################################################################
63 
65 
68  explicit MarginalTargetedInference(const IBayesNet< GUM_SCALAR >* bn);
69 
72 
74 
75 
76  // ############################################################################
78  // ############################################################################
80 
82 
96  virtual const Potential< GUM_SCALAR >& posterior(NodeId node);
97 
99 
114  virtual const Potential< GUM_SCALAR >& posterior(const std::string& nodeName);
115 
117 
118 
119  // ############################################################################
121  // ############################################################################
123 
125  virtual void eraseAllTargets();
126 
128  virtual void addAllTargets() final;
129 
131 
134  virtual void addTarget(NodeId target) final;
135 
137 
140  virtual void addTarget(const std::string& nodeName) final;
141 
143 
145  virtual void eraseTarget(NodeId target) final;
146 
148 
150  virtual void eraseTarget(const std::string& nodeName) final;
151 
153  virtual bool isTarget(NodeId node) const final;
154 
156  virtual bool isTarget(const std::string& nodeName) const final;
157 
159  virtual const Size nbrTargets() const noexcept final;
160 
162  virtual const NodeSet& targets() const noexcept final;
163 
165 
166  // ############################################################################
168  // ############################################################################
170 
175  virtual GUM_SCALAR H(NodeId X) final;
176 
181  virtual GUM_SCALAR H(const std::string& nodeName) final;
182 
184 
185 
197  Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet& evs);
198 
209  Potential< GUM_SCALAR > evidenceImpact(const std::string& target,
210  const std::vector< std::string >& evs);
211 
212  protected:
214 
215  virtual void _onMarginalTargetAdded(const NodeId id) = 0;
216 
218 
219  virtual void _onMarginalTargetErased(const NodeId id) = 0;
220 
222  virtual void _onAllMarginalTargetsAdded() = 0;
223 
225  virtual void _onAllMarginalTargetsErased() = 0;
226 
228  virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR >* bn);
229 
231 
232  virtual const Potential< GUM_SCALAR >& _posterior(NodeId id) = 0;
233 
234  protected:
235  void _setTargetedMode();
236  bool _isTargetedMode() const;
237 
238  private:
241 
244 
245 
246  /*/// remove all the marginal posteriors computed
247  void __invalidatePosteriors() noexcept;*/
248 
251  };
252 
253 
254 } // namespace gum
255 
256 
257 #include <agrum/BN/inference/tools/marginalTargetedInference_tpl.h>
258 
259 
260 #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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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