aGrUM  0.13.2
IBayesNet.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
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  ***************************************************************************/
27 #ifndef GUM_SIMPLE_BAYES_NET_H
28 #define GUM_SIMPLE_BAYES_NET_H
29 
30 #include <utility>
31 
32 #include <agrum/agrum.h>
33 
34 #include <agrum/core/hashTable.h>
35 
38 
39 namespace gum {
40 
41  template < typename GUM_SCALAR >
42  class BayesNetFactory;
43 
58  template < typename GUM_SCALAR >
59  class IBayesNet : public DAGmodel {
60  public:
61  // ===========================================================================
63  // ===========================================================================
65 
69  IBayesNet();
70  explicit IBayesNet(std::string name);
71 
75  virtual ~IBayesNet();
76 
80  IBayesNet(const IBayesNet< GUM_SCALAR >& source);
81 
86 
88  // ===========================================================================
90  // ===========================================================================
92 
98  virtual const Potential< GUM_SCALAR >& cpt(NodeId varId) const = 0;
99 
103  virtual const VariableNodeMap& variableNodeMap() const = 0;
104 
110  virtual const DiscreteVariable& variable(NodeId id) const = 0;
111 
117  virtual NodeId nodeId(const DiscreteVariable& var) const = 0;
118 
124  virtual NodeId idFromName(const std::string& name) const = 0;
125 
131  virtual const DiscreteVariable&
132  variableFromName(const std::string& name) const = 0;
134 
135  // ===========================================================================
137  // ===========================================================================
139 
144  GUM_SCALAR jointProbability(const Instantiation& i) const;
145 
150  GUM_SCALAR log2JointProbability(const Instantiation& i) const;
151 
154 
162  bool operator==(const IBayesNet< GUM_SCALAR >& from) const;
163 
165  bool operator!=(const IBayesNet< GUM_SCALAR >& from) const;
166 
177  Size dim() const;
178 
183  Size maxVarDomainSize() const;
184 
189  GUM_SCALAR minParam() const;
190 
195  GUM_SCALAR maxParam() const;
196 
201  GUM_SCALAR minNonZeroParam() const;
202 
207  GUM_SCALAR maxNonOneParam() const;
208 
210  virtual std::string toDot() const;
211 
213  std::string toString() const;
214 
215  /***
216  * @return the minimal subset of soids that conditions the target
217  *
218  * i.e. P(target| soids)=P(target|@return)
219  */
220  NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
221 
222 
223  /***
224  * @return the minimal subset of soids that conditions the targets
225  *
226  * i.e. P(targets| soids)=P(targets|@return)
227  */
228  NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
229 
230  private:
232  const NodeSet& soids,
233  NodeSet& minimal,
234  NodeSet& alreadyVisitedUp,
235  NodeSet& alreadyVisitedDn) const;
237  const NodeSet& soids,
238  NodeSet& minimal,
239  NodeSet& alreadyVisitedUp,
240  NodeSet& alreadyVisitedDn) const;
241  };
242 
243 
244  extern template class IBayesNet< float >;
245  extern template class IBayesNet< double >;
246 
247 
249  template < typename GUM_SCALAR >
250  std::ostream& operator<<(std::ostream& output,
251  const IBayesNet< GUM_SCALAR >& bn);
252 
253 } /* namespace gum */
254 
255 #include <agrum/BN/IBayesNet_tpl.h>
256 
257 #endif /* GUM_SIMPLE_BAYES_NET_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
GUM_SCALAR jointProbability(const Instantiation &i) const
Compute a parameter of the joint probability for the BN (given an instantiation of the vars) ...
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Virtual base class for PGMs using a DAG.
Definition: DAGmodel.h:45
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
void __minimalCondSetVisitDn(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
Definition: IBayesNet_tpl.h:76
bool operator==(const IBayesNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Container used to map discrete variables with nodes.
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Definition: IBayesNet_tpl.h:64
GUM_SCALAR maxNonOneParam() const
Base class for discrete random variable.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:59
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
GUM_SCALAR maxParam() const
virtual std::string toDot() const
bool operator!=(const IBayesNet< GUM_SCALAR > &from) const
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
GUM_SCALAR log2JointProbability(const Instantiation &i) const
Compute a parameter of the log joint probability for the BN (given an instantiation of the vars) ...
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
Header of the Potential class.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:573
Class representing probabilistic DAG model.
GUM_SCALAR minNonZeroParam() const
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
std::string toString() const
virtual const DiscreteVariable & variableFromName(const std::string &name) const =0
Getter by name.
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of thisBN.
GUM_SCALAR minParam() const
virtual ~IBayesNet()
Destructor.
Definition: IBayesNet_tpl.h:71
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
void __minimalCondSetVisitUp(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
Template implementation of bns/bayesNet.h classes.
IBayesNet()
Default constructor.
Definition: IBayesNet_tpl.h:46
Size maxVarDomainSize() const
Definition: IBayesNet_tpl.h:92
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node from discrete var pointer.
Class hash tables iterators.