aGrUM  0.14.2
MCBayesNetGenerator.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_MC_BAYES_NET_GENERATOR
28 #define GUM_MC_BAYES_NET_GENERATOR
29 
30 #include <agrum/agrum.h>
31 
32 #include <fstream>
33 #include <iostream>
34 #include <set>
35 #include <vector>
36 
37 #include <sstream>
38 
39 #ifdef HAVE_DIRENT_H
40 # include <dirent.h>
41 #else
42 # include <agrum/core/mvsc/dirent.h>
43 #endif
44 
45 #include <agrum/BN/BayesNet.h>
50 #include <agrum/core/hashTable.h>
53 
54 namespace gum {
154  template < typename GUM_SCALAR,
155  template < typename > class ICPTGenerator = SimpleCPTGenerator,
156  template < typename > class ICPTDisturber = SimpleCPTDisturber >
158  : public IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
159  , public ICPTDisturber< GUM_SCALAR > {
160  public:
161  // ############################################################################
163  // ############################################################################
165 
183  Size maxArcs,
184  Idx maxModality = 2,
185  Size iteration = 5000,
186  Idx p = 30,
187  Idx q = 40);
188 
204  Size iteration = 5000,
205  Idx p = 30,
206  Idx q = 40);
207 
212  ~MCBayesNetGenerator() override;
213 
215 
216  // ############################################################################
218  // ############################################################################
220 
225  void generateBN(BayesNet< GUM_SCALAR >& bayesNet) override;
226 
238  void disturbBN(BayesNet< GUM_SCALAR >& bayesNetinit, Size iteration = 0);
239 
241 
242  // ############################################################################
244  // ############################################################################
247 
253  Size iteration() const;
259  Idx p() const;
264  Idx q() const;
265 
267 
272  void setIteration(Size iteration);
276  void setP(Idx p);
280  void setQ(Idx q);
281 
283  protected:
289 
293  bool __isPolytree();
297  bool __connect(NodeId i, NodeId j);
302  bool __directedPath(NodeId tail, NodeId head);
308  void __insertArc(NodeId i, NodeId j);
315  void __eraseArc(NodeId i, NodeId j, bool mustbeconnex = true);
316 
327  void __PMMx_poly();
336  void __PMMx_multi();
343  void __jump_poly();
344 
352  void __jump_multi();
353 
359  void __AorR();
364  void __AR();
368  virtual bool __checkConditions();
369 
370  // NOT USED ? void __createDAG( Size BNSize, Size iniRoot );
371 
372  // NOT USED ? std::vector<Idx>* __createPartDAG( Size BNSize, Size iniRoot
373  // );
374 
383  bool __connect(NodeId i, NodeId j, NodeSet& excluded);
384 
390  bool __directedPath(NodeId tail, NodeId head, NodeSet& excluded);
391 
396  void __chooseNodes(NodeId& i, NodeId& j);
397 
401  void __chooseCloseNodes(NodeId& i, NodeId& j);
402 
407  void __transformPoly(Idx nbiter);
408 
412  void __createTree(Size BNSize);
413 
420  NodeId __createPartTree(Size BNSize, Idx& n);
421  };
422 
423 
424 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
425  extern template class MCBayesNetGenerator< double >;
426 #endif
427 
428 } /*namespace gum*/
429 
431 #endif // MCBAYESNETGENERATOR
Class representing a Bayesian Network.
Definition: BayesNet.h:76
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.
Abstract class for generating Conditional Probability Tables.
void __PMMx_poly()
In the case that the graph is a polytree, the function will, according to the probability p and q...
Source implementation of SimpleCPTDisturber.
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.
Class representing Bayesian networks.
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.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
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.
Header of the Potential class.
Source implementation of MCBayesNetGenerator.
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:50
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...
Implementation of a Shafer-Shenoy&#39;s-like version of lazy propagation for inference in Bayesian Networ...
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:45
Interface-like class for generating bayesian networks.
Base class for labelized discrete random variables.
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.
Class hash tables iterators.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
HashTable< NodeId, Potential< GUM_SCALAR > *> _hashMarginal