aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
MarkovNet.h
Go to the documentation of this file.
1 
30 #ifndef GUM_MARKOV_NET_H
31 #define GUM_MARKOV_NET_H
32 
33 #include <utility>
34 
35 #include <agrum/agrum.h>
36 
38 
39 #include <agrum/MN/IMarkovNet.h>
41 
42 namespace gum {
43 
70  template < typename GUM_SCALAR >
71  class MarkovNet: public IMarkovNet< GUM_SCALAR > {
72  public:
95  static MarkovNet< GUM_SCALAR > fastPrototype(const std::string& dotlike,
96  Size domainSize = 2);
97 
98  // ===========================================================================
100  // ===========================================================================
102 
106  MarkovNet();
107 
113  explicit MarkovNet(std::string name);
114 
118  virtual ~MarkovNet() final;
119 
123  MarkovNet(const MarkovNet< GUM_SCALAR >& source);
124 
126  // ===========================================================================
128  // ===========================================================================
130 
137  MarkovNet< GUM_SCALAR >& operator=(const MarkovNet< GUM_SCALAR >& source);
138 
140  // ===========================================================================
142  // ===========================================================================
144 
152  virtual const Potential< GUM_SCALAR >&
153  factor(const NodeSet& varIds) const final;
154 
159  virtual const FactorTable<GUM_SCALAR>& factors() const final;
160 
166  virtual const VariableNodeMap& variableNodeMap() const final;
167 
182  NodeId add(const DiscreteVariable& var);
183 
195  NodeId add(const std::string& name, unsigned int nbrmod);
196 
214  NodeId add(const DiscreteVariable& var, NodeId id);
215 
231  NodeId add(const DiscreteVariable& var,
232  MultiDimImplementation< GUM_SCALAR >* aContent,
233  NodeId id);
234 
238  void clear();
239 
250  void erase(NodeId varId);
251 
255  void erase(const std::string& name) { erase(idFromName(name)); };
256 
267  void erase(const DiscreteVariable& var);
268 
279  const DiscreteVariable& variable(NodeId id) const final;
280 
287  const DiscreteVariable& variable(const std::string& name) const {
288  return variable(idFromName(name));
289  };
290 
300  void changeVariableName(NodeId id, const std::string& new_name);
301 
305  void changeVariableName(const std::string& name, const std::string& new_name) {
306  changeVariableName(idFromName(name), new_name);
307  }
308 
319  void changeVariableLabel(NodeId id,
320  const std::string& old_label,
321  const std::string& new_label);
322 
326  void changeVariableLabel(const std::string& name,
327  const std::string& old_label,
328  const std::string& new_label) {
329  changeVariableLabel(idFromName(name), old_label, new_label);
330  }
331 
340  NodeId nodeId(const DiscreteVariable& var) const final;
341 
350  NodeId idFromName(const std::string& name) const final;
351 
361  const DiscreteVariable& variableFromName(const std::string& name) const final;
363 
364  // ===========================================================================
366  // ===========================================================================
368 
379  const Potential< GUM_SCALAR >& addFactor(const NodeSet& vars);
380  const Potential< GUM_SCALAR >&
381  addFactor(const std::vector< std::string >& varnames);
382  const Potential< GUM_SCALAR >&
383  addFactor(const Potential<GUM_SCALAR>& factor);
384 
390  void eraseFactor(const NodeSet& vars);
392 
393 
395  void generateFactors() const;
396 
398  void generateFactor(const NodeSet& vars) const;
399 
404  void changeFactor(const NodeSet& vars, Potential< GUM_SCALAR >* newPot);
405 
406  private:
408  void __clearFactors();
409 
411  void __copyFactors(const MarkovNet< GUM_SCALAR >& source);
412 
414  VariableNodeMap __varMap;
415 
417  FactorTable<GUM_SCALAR> __factors;
418 
420  // HashTable< const NodeSet,Potential< GUM_SCALAR >* > __factorMap;
421 
426  void _unsafeChangePotential(const NodeSet& vars,
427  Potential< GUM_SCALAR >* newPot);
428 
429  public:
434  };
435 
437  template < typename GUM_SCALAR >
438  std::ostream& operator<<(std::ostream& output,
439  const MarkovNet< GUM_SCALAR >& bn);
440 
441 
442 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
443  extern template class MarkovNet< double >;
444 #endif
445 
446 } /* namespace gum */
447 
448 #include <agrum/MN/MarkovNet_tpl.h>
449 
450 #endif /* GUM_MARKOV_NET_H */
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
STL namespace.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Definition: agrum.h:25
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
double log10DomainSize() const
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
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: UGmodel_inl.h:53
const UndiGraph & graph() const
Returns a constant reference to the dag of this Bayes Net.
Definition: UGmodel_inl.h:36
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: UGmodel_inl.h:39
HashTable< NodeSet, const Potential< GUM_SCALAR > *> FactorTable
Definition: IMarkovNet.h:44