![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
<agrum/BN/generator/SimpleMCayesNetGenerator.h> More...
#include <maxParentsMCBayesNetGenerator.h>
Public Member Functions | |
Constructors / Destructor | |
MaxParentsMCBayesNetGenerator (Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxParents=1, Idx iteration=5000, Idx p=30, Idx q=40) | |
Constructor. More... | |
MaxParentsMCBayesNetGenerator (BayesNet< GUM_SCALAR > bayesNet, Size maxParents=2, Idx iteration=5000, Idx p=30, Idx q=40) | |
Constructor. More... | |
~MaxParentsMCBayesNetGenerator () final | |
Destructor. More... | |
Getters | |
Size | maxParents () const |
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGenerator. More... | |
Setters | |
void | setMaxParents (Size maxParents) |
Modifies the value of the number of maximum parents imposed on the BayesNetGenerator. More... | |
BN generation methods | |
void | generateBN (BayesNet< GUM_SCALAR > &bayesNet) override |
Generates a random Bayesian network. More... | |
void | disturbBN (BayesNet< GUM_SCALAR > &bayesNetinit, Size iteration=0) |
Change randomly the topology of a specific Bayesian networks. More... | |
Getters | |
Size | iteration () const |
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator. More... | |
Idx | p () const |
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator. More... | |
Idx | q () const |
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator. More... | |
Setters | |
void | setIteration (Size iteration) |
Modifies the value of the number of iterations impose on the BayesNetGenerator. More... | |
void | setP (Idx p) |
Modifies the value of the probability p imposed on the BayesNetGenerator. More... | |
void | setQ (Idx q) |
Modifies the value of the probability q imposed on the BayesNetGenerator. More... | |
BN generation methods | |
void | fillCPT () |
function that insert random values in the CPT of each nodes according to the CPTGenerator. More... | |
Getters | |
Size | nbrNodes () const |
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator. More... | |
Size | maxArcs () const |
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator. More... | |
Size | maxModality () const |
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator. More... | |
Setters | |
void | setNbrNodes (Size nbrNodes) |
Modifies the value of the number of nodes imposed on the BayesGenerator. More... | |
void | setMaxArcs (Size maxArcs) |
Modifies the value of the number of nodes imposed on the BayesGenerator. More... | |
void | setMaxModality (Size maxModality) |
Modifies the value of the number of nodes imposed on the BayesGenerator. More... | |
Protected Attributes | |
Size | maxParents_ |
Size | iteration_ |
Idx | p_ |
Idx | q_ |
bool | disturbing_ |
BayesNet< GUM_SCALAR > | bayesNettemp_ |
HashTable< NodeId, Potential< GUM_SCALAR > *> | hashMarginal_ |
Size | nbrNodes_ |
Size | maxArcs_ |
Size | maxModality_ |
BayesNet< GUM_SCALAR > | bayesNet_ |
Protected Member Functions | |
bool | _isPolytree_ () |
The function that verify if graph is a polytree. More... | |
bool | _connect_ (NodeId i, NodeId j) |
The function that verify if node i and j are connected. More... | |
bool | _connect_ (NodeId i, NodeId j, NodeSet &excluded) |
The internal function used by the previous connect. More... | |
bool | _directedPath_ (NodeId tail, NodeId head) |
The function that verify if there is a oriented path from node i to node j. More... | |
bool | _directedPath_ (NodeId tail, NodeId head, NodeSet &excluded) |
The internal function used by the previous directedPath. More... | |
void | _insertArc_ (NodeId i, NodeId j) |
The function that will insert an arc between node i to node j, but only if there isn't any cycle created. More... | |
void | _eraseArc_ (NodeId i, NodeId j, bool mustbeconnex=true) |
The function that will remove the arc between node i and node j. More... | |
void | _PMMx_poly_ () |
In the case that the graph is a polytree, the function will, according to the probability p and q, choose which change of state must occure( AorR or AR or jump) then will assert that the imposed constraint are respected and if not, will return to the previous topology. More... | |
void | _PMMx_multi_ () |
In the case that the graph is a multiconnected graph, the function will, according to the probability p and q, choose which change of state must occure( AorR or jump) then will assert that the imposed constraint are respected and if not, will return to the previous topology. More... | |
void | _jump_poly_ () |
In the case that the graph is a polytree, the function will add a ramdom arc by the use of the function insertArc if the arc does not exist allready. More... | |
void | _jump_multi_ () |
In the case that the graph is a multiconnect graph, the function will choose randomly two nodes and will remove the arc between them by the use of the function insertArc if the arc exists. More... | |
void | _AorR_ () |
The function will add or remove a random arc in the graph using the functions insertArc and removeArc. More... | |
void | _AR_ () |
The function will remove and add a random arc changing the topology of the graph but asserting its connectivity. More... | |
void | _chooseNodes_ (NodeId &i, NodeId &j) |
The function that randomly choose two nodes of the graph. More... | |
void | _chooseCloseNodes_ (NodeId &i, NodeId &j) |
The function that randomly choose two neighbours nodes of the graph. More... | |
void | _transformPoly_ (Idx nbiter) |
The function that randomly change the simple tree into a polytree. More... | |
void | _createTree_ (Size BNSize) |
The function that randomly generate a simple tree. More... | |
NodeId | _createPartTree_ (Size BNSize, Idx &n) |
The internal function used by createTree that randomly generate a simple tree. More... | |
<agrum/BN/generator/SimpleMCayesNetGenerator.h>
Class for generating Bayesian networks with Markov chains.
This class is inherited from MCBayesNetGenerator and is an example of Markov Chain Bayesian network Generator that can be implemented. Here a constraint is added which is the maximum number of parents that a node can have. To create our own MCBayesNetGenerator with a specific constraint you must:
1) Create the class XXXXXXMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>.
2) Add a variable specific to the constraint (here maxParents_).
3) Verify in the function checkCondition_() the wanted constraint and then launch MCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>:: checkConditions() to verify the default constraint.
4) Define the getters and setters of the constraint variable.
5) And verify in the constructor that the constraint is not in contradiction with the generator here maxParent must be >= 1.
Definition at line 89 of file maxParentsMCBayesNetGenerator.h.
INLINE gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::MaxParentsMCBayesNetGenerator | ( | Size | nbrNodes, |
Size | maxArcs, | ||
Size | maxModality = 2 , |
||
Size | maxParents = 1 , |
||
Idx | iteration = 5000 , |
||
Idx | p = 30 , |
||
Idx | q = 40 |
||
) |
Constructor.
Use by default the SimpleCPTGenerator for generating the BNs CPT and the SimpleCPTDisturber to tweak the CPT when the dimension of the table changes.
nbrNodes | The number of nodes in the generated BN. |
maxArcs | The maximum number of Arcs. |
maxModality | Each DRV has from 2 to maxModality modalities |
maxParents | The number of maximum parents for each node imposed on the generator |
iteration | The number of iterations wanted to repeat the algorithm |
p | probability for the change of the state (see useof p and q" ) |
q | probability for the change of the state (see useof p and q" ) |
Definition at line 47 of file maxParentsMCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
explicit |
Constructor.
Use by default the SimpleCPTGenerator for generating the BNs CPT and the SimpleCPTDisturber to tweak the CPT when the dimension of the table changes.
bayesNet | the IBayesNet used as reference to fill the parameters nbrNodes, maxArcs and maxModality |
maxParents | The number of maximum parents for each node imposed on the generator |
iteration | The number of iterations wanted to repeat the algorithm |
p | probability for the change of the state (see useof p and q" ) |
q | probability for the change of the state (see useof p and q" ) |
Definition at line 69 of file maxParentsMCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
final |
Destructor.
Definition at line 86 of file maxParentsMCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function will add or remove a random arc in the graph using the functions insertArc and removeArc.
Definition at line 287 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function will remove and add a random arc changing the topology of the graph but asserting its connectivity.
Definition at line 305 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
finalprivatevirtual |
function to holding the the specification wanted for the Bayesian markov.
Reimplemented from gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >.
Definition at line 96 of file maxParentsMCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that randomly choose two neighbours nodes of the graph.
Definition at line 440 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that randomly choose two nodes of the graph.
Definition at line 426 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that verify if node i and j are connected.
Definition at line 552 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The internal function used by the previous connect.
It asserts the existence of an unoriented path between node i and node j avoiding passing through nodes listed in excluded.
Definition at line 580 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The internal function used by createTree that randomly generate a simple tree.
n : id number for node label
Definition at line 499 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that randomly generate a simple tree.
Definition at line 476 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that verify if there is a oriented path from node i to node j.
Definition at line 608 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The internal function used by the previous directedPath.
It asserts the existence of an oriented path between node i and node j avoiding passing through nodes listed in excluded.
Definition at line 631 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that will remove the arc between node i and node j.
If the boolean parameter mustbeconnex is true, the function will assert that the graph remain connected and will restore the arc otherwise.
Definition at line 397 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that will insert an arc between node i to node j, but only if there isn't any cycle created.
Definition at line 379 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that verify if graph is a polytree.
Definition at line 542 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
In the case that the graph is a multiconnect graph, the function will choose randomly two nodes and will remove the arc between them by the use of the function insertArc if the arc exists.
Definition at line 365 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
In the case that the graph is a polytree, the function will add a ramdom arc by the use of the function insertArc if the arc does not exist allready.
Definition at line 352 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
In the case that the graph is a multiconnected graph, the function will, according to the probability p and q, choose which change of state must occure( AorR or jump) then will assert that the imposed constraint are respected and if not, will return to the previous topology.
Definition at line 239 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
In the case that the graph is a polytree, the function will, according to the probability p and q, choose which change of state must occure( AorR or AR or jump) then will assert that the imposed constraint are respected and if not, will return to the previous topology.
Definition at line 194 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
The function that randomly change the simple tree into a polytree.
Definition at line 525 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Change randomly the topology of a specific Bayesian networks.
bayesNetinit | IBayesNet to be modify |
iteration | The number of iterations wanted to repeat the algorithm |
OperationNotAllow | if the initial state of the IBayesNet is not respecting the wanted conditions if iteration = 0, it is assumed that the number of iteration wanted is the same as the one specified in the constructor |
Definition at line 134 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
function that insert random values in the CPT of each nodes according to the CPTGenerator.
Definition at line 62 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
overridevirtualinherited |
Generates a random Bayesian network.
bayesNet | empty IBayesNet to generate. |
Implements gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >.
Definition at line 112 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator.
Definition at line 655 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
Definition at line 78 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
Definition at line 68 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Size gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::maxParents | ( | ) | const |
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGenerator.
Definition at line 109 of file maxParentsMCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
Definition at line 73 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
Definition at line 664 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
Definition at line 673 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Modifies the value of the number of iterations impose on the BayesNetGenerator.
Definition at line 683 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Modifies the value of the number of nodes imposed on the BayesGenerator.
Definition at line 98 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Modifies the value of the number of nodes imposed on the BayesGenerator.
Definition at line 83 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE void gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setMaxParents | ( | Size | maxParents | ) |
Modifies the value of the number of maximum parents imposed on the BayesNetGenerator.
Definition at line 118 of file maxParentsMCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Modifies the value of the number of nodes imposed on the BayesGenerator.
Definition at line 90 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Modifies the value of the probability p imposed on the BayesNetGenerator.
Definition at line 691 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Modifies the value of the probability q imposed on the BayesNetGenerator.
Definition at line 703 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
Definition at line 166 of file IBayesNetGenerator.h.
|
protectedinherited |
Definition at line 289 of file MCBayesNetGenerator.h.
|
protectedinherited |
Definition at line 288 of file MCBayesNetGenerator.h.
|
protectedinherited |
Definition at line 290 of file MCBayesNetGenerator.h.
|
protectedinherited |
Definition at line 286 of file MCBayesNetGenerator.h.
|
protectedinherited |
Definition at line 164 of file IBayesNetGenerator.h.
|
protectedinherited |
Definition at line 165 of file IBayesNetGenerator.h.
|
protected |
Definition at line 179 of file maxParentsMCBayesNetGenerator.h.
|
protectedinherited |
Definition at line 163 of file IBayesNetGenerator.h.
|
protectedinherited |
Definition at line 287 of file MCBayesNetGenerator.h.
|
protectedinherited |
Definition at line 287 of file MCBayesNetGenerator.h.