aGrUM  0.16.0
MCBayesNetGenerator.h
Go to the documentation of this file.
1 
30 #ifndef GUM_MC_BAYES_NET_GENERATOR
31 #define GUM_MC_BAYES_NET_GENERATOR
32 
33 #include <agrum/agrum.h>
34 
35 #include <fstream>
36 #include <iostream>
37 #include <set>
38 #include <vector>
39 
40 #include <sstream>
41 
42 #ifdef HAVE_DIRENT_H
43 # include <dirent.h>
44 #else
45 # include <agrum/core/mvsc/dirent.h>
46 #endif
47 
48 #include <agrum/BN/BayesNet.h>
53 #include <agrum/core/hashTable.h>
56 
57 namespace gum {
157  template < typename GUM_SCALAR,
158  template < typename > class ICPTGenerator = SimpleCPTGenerator,
159  template < typename > class ICPTDisturber = SimpleCPTDisturber >
161  : public IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
162  , public ICPTDisturber< GUM_SCALAR > {
163  public:
164  // ############################################################################
166  // ############################################################################
168 
186  Size maxArcs,
187  Idx maxModality = 2,
188  Size iteration = 5000,
189  Idx p = 30,
190  Idx q = 40);
191 
207  Size iteration = 5000,
208  Idx p = 30,
209  Idx q = 40);
210 
215  ~MCBayesNetGenerator() override;
216 
218 
219  // ############################################################################
221  // ############################################################################
223 
228  void generateBN(BayesNet< GUM_SCALAR >& bayesNet) override;
229 
241  void disturbBN(BayesNet< GUM_SCALAR >& bayesNetinit, Size iteration = 0);
242 
244 
245  // ############################################################################
247  // ############################################################################
250 
256  Size iteration() const;
262  Idx p() const;
267  Idx q() const;
268 
270 
275  void setIteration(Size iteration);
279  void setP(Idx p);
283  void setQ(Idx q);
284 
286  protected:
292 
296  bool __isPolytree();
300  bool __connect(NodeId i, NodeId j);
305  bool __directedPath(NodeId tail, NodeId head);
311  void __insertArc(NodeId i, NodeId j);
318  void __eraseArc(NodeId i, NodeId j, bool mustbeconnex = true);
319 
330  void __PMMx_poly();
339  void __PMMx_multi();
346  void __jump_poly();
347 
355  void __jump_multi();
356 
362  void __AorR();
367  void __AR();
371  virtual bool __checkConditions();
372 
373  // NOT USED ? void __createDAG( Size BNSize, Size iniRoot );
374 
375  // NOT USED ? std::vector<Idx>* __createPartDAG( Size BNSize, Size iniRoot
376  // );
377 
386  bool __connect(NodeId i, NodeId j, NodeSet& excluded);
387 
393  bool __directedPath(NodeId tail, NodeId head, NodeSet& excluded);
394 
399  void __chooseNodes(NodeId& i, NodeId& j);
400 
404  void __chooseCloseNodes(NodeId& i, NodeId& j);
405 
410  void __transformPoly(Idx nbiter);
411 
415  void __createTree(Size BNSize);
416 
423  NodeId __createPartTree(Size BNSize, Idx& n);
424  };
425 
426 
427 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
428  extern template class MCBayesNetGenerator< double >;
429 #endif
430 
431 } /*namespace gum*/
432 
434 #endif // MCBAYESNETGENERATOR
Class representing a Bayesian Network.
Definition: BayesNet.h:78
MCBayesNetGenerator(Size nbrNodes, Size maxArcs, Idx maxModality=2, Size iteration=5000, Idx p=30, Idx q=40)
Constructor.
virtual bool __checkConditions()
The boolean function that will assert the respect of the constraint.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __PMMx_poly()
In the case that the graph is a polytree, the function will, according to the probability p and q...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
<agrum/BN/generator/MCayesNetGenerator.h>
Class for generating bayesian networks.
bool __connect(NodeId i, NodeId j)
The function that verify if node i and j are connected.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setQ(Idx q)
Modifies the value of the probability q imposed on the BayesNetGenerator.
Size nbrNodes() const
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
void __jump_multi()
In the case that the graph is a multiconnect graph, the function will choose randomly two nodes and w...
bool __isPolytree()
The function that verify if graph is a polytree.
void setP(Idx p)
Modifies the value of the probability p imposed on the BayesNetGenerator.
~MCBayesNetGenerator() override
Destructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size maxArcs() const
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
BayesNet< GUM_SCALAR > _bayesNettemp
void __transformPoly(Idx nbiter)
The function that randomly change the simple tree into a polytree.
void __jump_poly()
In the case that the graph is a polytree, the function will add a ramdom arc by the use of the functi...
NodeId __createPartTree(Size BNSize, Idx &n)
The internal function used by __createTree that randomly generate a simple tree.
void setIteration(Size iteration)
Modifies the value of the number of iterations impose on the BayesNetGenerator.
void disturbBN(BayesNet< GUM_SCALAR > &bayesNetinit, Size iteration=0)
Change randomly the topology of a specific bayesian networks.
void __chooseNodes(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
void __AR()
The function will remove and add a random arc changing the topology of the graph but asserting its co...
void __insertArc(NodeId i, NodeId j)
The function that will insert an arc between node i to node j, but only if there isn&#39;t any cycle crea...
void generateBN(BayesNet< GUM_SCALAR > &bayesNet) override
Generates a random bayesian network.
void __eraseArc(NodeId i, NodeId j, bool mustbeconnex=true)
The function that will remove the arc between node i and node j.
void __chooseCloseNodes(NodeId &i, NodeId &j)
The function that randomly choose two neighbours nodes of the graph.
Size Idx
Type for indexes.
Definition: types.h:53
void __AorR()
The function will add or remove a random arc in the graph using the functions __insertArc and __remov...
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator...
void __PMMx_multi()
In the case that the graph is a multiconnected graph, the function will, according to the probability...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool __directedPath(NodeId tail, NodeId head)
The function that verify if there is a oriented path from node i to node j.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __createTree(Size BNSize)
The function that randomly generate a simple tree.
Idx p() const
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
HashTable< NodeId, Potential< GUM_SCALAR > *> _hashMarginal