aGrUM  0.18.1
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 
202  GUM_SCALAR minNonZeroParam() const;
203 
209  GUM_SCALAR maxNonOneParam() const;
210 
212  virtual std::string toDot() const;
213 
215  std::string toString() const;
216 
217  /***
218  * @return the minimal subset of soids that conditions the target
219  *
220  * i.e. P(target| soids)=P(target|@return)
221  */
222  NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
223 
224 
225  /***
226  * @return the minimal subset of soids that conditions the targets
227  *
228  * i.e. P(targets| soids)=P(targets|@return)
229  */
230  NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
231 
232  private:
234  const NodeSet& soids,
235  NodeSet& minimal,
236  NodeSet& alreadyVisitedUp,
237  NodeSet& alreadyVisitedDn) const;
239  const NodeSet& soids,
240  NodeSet& minimal,
241  NodeSet& alreadyVisitedUp,
242  NodeSet& alreadyVisitedDn) const;
243  };
244 
245 
246 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
247  extern template class IBayesNet< double >;
248 #endif
249 
250 
252  template < typename GUM_SCALAR >
253  std::ostream& operator<<(std::ostream& output,
254  const IBayesNet< GUM_SCALAR >& bn);
255 
256 } /* namespace gum */
257 
258 #include <agrum/BN/IBayesNet_tpl.h>
259 
260 #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() & 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() & 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:631
GUM_SCALAR maxNonOneParam() const
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
void minimalCondSetVisitDn__(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) 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.
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
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
void minimalCondSetVisitUp__(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & 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() & 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 !
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) ...