aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
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 
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 
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:60
bool operator!=(const IBayesNet< GUM_SCALAR > &from) const
GUM_SCALAR minParam() const
Virtual base class for PGMs using a DAG.
Definition: DAGmodel.h:47
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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:626
GUM_SCALAR maxNonOneParam() const
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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) ...