aGrUM  0.16.0
IBayesNet.h
Go to the documentation of this file.
1 
30 #ifndef GUM_SIMPLE_BAYES_NET_H
31 #define GUM_SIMPLE_BAYES_NET_H
32 
33 #include <utility>
34 
35 #include <agrum/agrum.h>
36 
37 #include <agrum/core/hashTable.h>
38 
41 
42 namespace gum {
43 
44  template < typename GUM_SCALAR >
45  class BayesNetFactory;
46 
61  template < typename GUM_SCALAR >
62  class IBayesNet : public DAGmodel {
63  public:
64  // ===========================================================================
66  // ===========================================================================
68 
72  IBayesNet();
73  explicit IBayesNet(std::string name);
74 
78  virtual ~IBayesNet();
79 
83  IBayesNet(const IBayesNet< GUM_SCALAR >& source);
84 
89 
91  // ===========================================================================
93  // ===========================================================================
95 
101  virtual const Potential< GUM_SCALAR >& cpt(NodeId varId) const = 0;
102 
106  virtual const VariableNodeMap& variableNodeMap() const = 0;
107 
113  virtual const DiscreteVariable& variable(NodeId id) const = 0;
114 
120  virtual NodeId nodeId(const DiscreteVariable& var) const = 0;
121 
127  virtual NodeId idFromName(const std::string& name) const = 0;
128 
134  virtual const DiscreteVariable&
135  variableFromName(const std::string& name) const = 0;
137 
138  // ===========================================================================
140  // ===========================================================================
142 
147  GUM_SCALAR jointProbability(const Instantiation& i) const;
148 
153  GUM_SCALAR log2JointProbability(const Instantiation& i) const;
154 
157 
165  bool operator==(const IBayesNet< GUM_SCALAR >& from) const;
166 
168  bool operator!=(const IBayesNet< GUM_SCALAR >& from) const;
169 
180  Size dim() const;
181 
186  Size maxVarDomainSize() const;
187 
192  GUM_SCALAR minParam() const;
193 
198  GUM_SCALAR maxParam() const;
199 
204  GUM_SCALAR minNonZeroParam() const;
205 
210  GUM_SCALAR maxNonOneParam() const;
211 
213  virtual std::string toDot() const;
214 
216  std::string toString() const;
217 
218  /***
219  * @return the minimal subset of soids that conditions the target
220  *
221  * i.e. P(target| soids)=P(target|@return)
222  */
223  NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
224 
225 
226  /***
227  * @return the minimal subset of soids that conditions the targets
228  *
229  * i.e. P(targets| soids)=P(targets|@return)
230  */
231  NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
232 
233  private:
235  const NodeSet& soids,
236  NodeSet& minimal,
237  NodeSet& alreadyVisitedUp,
238  NodeSet& alreadyVisitedDn) const;
240  const NodeSet& soids,
241  NodeSet& minimal,
242  NodeSet& alreadyVisitedUp,
243  NodeSet& alreadyVisitedDn) const;
244  };
245 
246 
247 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
248  extern template class IBayesNet< double >;
249 #endif
250 
251 
253  template < typename GUM_SCALAR >
254  std::ostream& operator<<(std::ostream& output,
255  const IBayesNet< GUM_SCALAR >& bn);
256 
257 } /* namespace gum */
258 
259 #include <agrum/BN/IBayesNet_tpl.h>
260 
261 #endif /* GUM_SIMPLE_BAYES_NET_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
bool operator!=(const IBayesNet< GUM_SCALAR > &from) const
GUM_SCALAR minParam() const
Virtual base class for PGMs using a DAG.
Definition: DAGmodel.h:48
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:67
Base class for discrete random variable.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:62
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:605
GUM_SCALAR maxNonOneParam() const
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:74
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:79
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:83
std::string toString() const
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
IBayesNet()
Default constructor.
Definition: IBayesNet_tpl.h:49
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node from discrete var pointer.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size maxVarDomainSize() const
Definition: IBayesNet_tpl.h:95
Size NodeId
Type for node ids.
Definition: graphElements.h:98
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) ...