aGrUM  0.14.2
marginalTargetedInference.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 #ifndef GUM_BAYES_NET_MARGINAL_TARGETED_INFERENCE_H
29 #define GUM_BAYES_NET_MARGINAL_TARGETED_INFERENCE_H
30 
31 #include <string>
32 
34 #include <agrum/agrum.h>
35 
36 
37 namespace gum {
38 
39 
53  template < typename GUM_SCALAR >
54  class MarginalTargetedInference
55  : public virtual BayesNetInference< GUM_SCALAR > {
56  public:
57  // ############################################################################
59  // ############################################################################
61 
63 
66  explicit MarginalTargetedInference(const IBayesNet< GUM_SCALAR >* bn);
67 
70 
72 
73 
74  // ############################################################################
76  // ############################################################################
78 
80 
94  virtual const Potential< GUM_SCALAR >& posterior(NodeId node);
95 
97 
112  virtual const Potential< GUM_SCALAR >& posterior(const std::string& nodeName);
113 
115 
116 
117  // ############################################################################
119  // ############################################################################
121 
123  virtual void eraseAllTargets();
124 
126  virtual void addAllTargets() final;
127 
129 
132  virtual void addTarget(NodeId target) final;
133 
135 
138  virtual void addTarget(const std::string& nodeName) final;
139 
141 
143  virtual void eraseTarget(NodeId target) final;
144 
146 
148  virtual void eraseTarget(const std::string& nodeName) final;
149 
151  virtual bool isTarget(NodeId node) const final;
152 
154  virtual bool isTarget(const std::string& nodeName) const final;
155 
157  virtual const Size nbrTargets() const noexcept final;
158 
160  virtual const NodeSet& targets() const noexcept final;
161 
163 
164  // ############################################################################
166  // ############################################################################
168 
173  virtual GUM_SCALAR H(NodeId X) final;
174 
179  virtual GUM_SCALAR H(const std::string& nodeName) final;
180 
182 
183 
195  Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet& evs);
196 
207  Potential< GUM_SCALAR > evidenceImpact(const std::string& target,
208  const std::vector< std::string >& evs);
209 
210  protected:
212 
213  virtual void _onMarginalTargetAdded(const NodeId id) = 0;
214 
216 
217  virtual void _onMarginalTargetErased(const NodeId id) = 0;
218 
220  virtual void _onAllMarginalTargetsAdded() = 0;
221 
223  virtual void _onAllMarginalTargetsErased() = 0;
224 
226  virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR >* bn);
227 
229 
230  virtual const Potential< GUM_SCALAR >& _posterior(NodeId id) = 0;
231 
232  protected:
233  void _setTargetedMode();
234  bool _isTargetedMode() const;
235 
236  private:
239 
242 
243 
244  /*/// remove all the marginal posteriors computed
245  void __invalidatePosteriors() noexcept;*/
246 
249  };
250 
251 
252 } // namespace gum
253 
254 
255 #include <agrum/BN/inference/tools/marginalTargetedInference_tpl.h>
256 
257 
258 #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
gum is the global namespace for all aGrUM entities
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
This file contains abstract class definitions for Bayesian networks inference classes.
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:45
bool __targeted_mode
whether the actual targets are default
Size NodeId
Type for node ids.
Definition: graphElements.h:97
MarginalTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor