aGrUM  0.13.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,
196  const std::vector< NodeId >& evs);
197 
208  Potential< GUM_SCALAR > evidenceImpact(const std::string& target,
209  const std::vector< std::string >& evs);
210 
211  protected:
213 
214  virtual void _onMarginalTargetAdded(NodeId id) = 0;
215 
217 
218  virtual void _onMarginalTargetErased(NodeId id) = 0;
219 
221  virtual void _onAllMarginalTargetsAdded() = 0;
222 
224  virtual void _onAllMarginalTargetsErased() = 0;
225 
227  virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR >* bn);
228 
230 
231  virtual const Potential< GUM_SCALAR >& _posterior(NodeId id) = 0;
232 
233  protected:
234  void _setTargetedMode();
235  bool _isTargetedMode() const;
236 
237  private:
240 
243 
244 
245  /*/// remove all the marginal posteriors computed
246  void __invalidatePosteriors() noexcept;*/
247 
250  };
251 
252 
253 } // namespace gum
254 
255 
256 #include <agrum/BN/inference/tools/marginalTargetedInference_tpl.h>
257 
258 
259 #endif // GUM_BAYES_NET_MARGINAL_TARGETED_INFERENCE_H
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
virtual void _onMarginalTargetAdded(NodeId id)=0
fired after a new marginal target is inserted
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Potential< GUM_SCALAR > evidenceImpact(NodeId target, const std::vector< NodeId > &evs)
Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) ...
STL namespace.
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 const NodeSet & targets() const noexceptfinal
returns the list of marginal targets
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 void eraseAllTargets()
Clear all previously defined targets.
bool __targeted_mode
whether the actual targets are default
virtual const Size nbrTargets() const noexceptfinal
returns the number of marginal targets
MarginalTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
virtual void _onMarginalTargetErased(NodeId id)=0
fired before a marginal target is removed