aGrUM  0.14.3
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 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
245  extern template class IBayesNet< double >;
246 #endif
247 
248 
250  template < typename GUM_SCALAR >
251  std::ostream& operator<<(std::ostream& output,
252  const IBayesNet< GUM_SCALAR >& bn);
253 
254 } /* namespace gum */
255 
256 #include <agrum/BN/IBayesNet_tpl.h>
257 
258 #endif /* GUM_SIMPLE_BAYES_NET_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
bool operator!=(const IBayesNet< GUM_SCALAR > &from) const
GUM_SCALAR minParam() const
Virtual base class for PGMs using a DAG.
Definition: DAGmodel.h:45
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Container used to map discrete variables with nodes.
virtual std::string toDot() const
GUM_SCALAR minNonZeroParam() const
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Definition: IBayesNet_tpl.h:64
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
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
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:583
GUM_SCALAR maxNonOneParam() const
Class representing probabilistic DAG model.
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.
virtual ~IBayesNet()
Destructor.
Definition: IBayesNet_tpl.h:71
GUM_SCALAR log2JointProbability(const Instantiation &i) const
Compute a parameter of the log joint probability for the BN (given an instantiation of the vars) ...
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
Definition: IBayesNet_tpl.h:76
void __minimalCondSetVisitUp(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
std::string toString() const
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
Template implementation of bns/bayesNet.h classes.
IBayesNet()
Default constructor.
Definition: IBayesNet_tpl.h:46
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node from discrete var pointer.
Class hash tables iterators.
Size maxVarDomainSize() const
Definition: IBayesNet_tpl.h:92
Size NodeId
Type for node ids.
Definition: graphElements.h:97
bool operator==(const IBayesNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !
void __minimalCondSetVisitDn(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
GUM_SCALAR maxParam() const
GUM_SCALAR jointProbability(const Instantiation &i) const
Compute a parameter of the joint probability for the BN (given an instantiation of the vars) ...