![]() |
aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
|
<agrum/BN/generator/MCayesNetGenerator.h> More...
#include <MCBayesNetGenerator.h>
Public Member Functions | |
Constructors / Destructor | |
MCBayesNetGenerator (Size nbrNodes, Size maxArcs, Idx maxModality=2, Size iteration=5000, Idx p=30, Idx q=40) | |
Constructor. More... | |
MCBayesNetGenerator (BayesNet< GUM_SCALAR > bayesNet, Size iteration=5000, Idx p=30, Idx q=40) | |
Constructor. More... | |
~MCBayesNetGenerator () override | |
Destructor. 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 | 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 | directedPath__ (NodeId tail, NodeId head) |
The function that verify if there is a oriented path from node i to node j. 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... | |
virtual bool | checkConditions__ () |
The boolean function that will assert the respect of the constraint. More... | |
bool | connect__ (NodeId i, NodeId j, NodeSet &excluded) |
The internal function used by the previous connect__. More... | |
bool | directedPath__ (NodeId tail, NodeId head, NodeSet &excluded) |
The internal function used by the previous directedPath__. 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/MCayesNetGenerator.h>
Class for generating Bayesian networks with Markov chains.
This class randomly generates a Bayesian network given 6 parameters: the number of nodes, the maximum number of arcs the and of iterations the maximum modality.
This Generation method require the use of two probability parameters(p, q) defining the choice of processes that will provoke the change of state. You can see in the graph below how the probabilities are used.
Definition at line 159 of file MCBayesNetGenerator.h.
gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::MCBayesNetGenerator | ( | Size | nbrNodes, |
Size | maxArcs, | ||
Idx | maxModality = 2 , |
||
Size | 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 |
iteration | The number of iterations wanted to repeat the algorithm |
p | probability for the change of the state (see use of p and q ) |
q | probability for the change of the state (see use of p and q ) |
Definition at line 58 of file MCBayesNetGenerator_tpl.h.
|
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 |
iteration | The number of iterations wanted to repeat the algorithm |
p | probability for the change of the state (see probability_p_q ) |
q | probability for the change of the state (see probability_p_q ) |
Definition at line 85 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
override |
Destructor.
Definition at line 105 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function will add or remove a random arc in the graph using the functions insertArc__ and removeArc__.
Definition at line 294 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function will remove and add a random arc changing the topology of the graph but asserting its connectivity.
Definition at line 312 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedvirtual |
The boolean function that will assert the respect of the constraint.
Reimplemented in gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >, and gum::MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >.
Definition at line 187 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that randomly choose two neighbours nodes of the graph.
Definition at line 451 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that randomly choose two nodes of the graph.
Definition at line 437 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that verify if node i and j are connected.
Definition at line 565 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 593 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The internal function used by createTree__ that randomly generate a simple tree.
n : id number for node label
Definition at line 511 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that randomly generate a simple tree.
Definition at line 486 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that verify if there is a oriented path from node i to node j.
Definition at line 622 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 645 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN | ( | BayesNet< GUM_SCALAR > & | bayesNetinit, |
Size | iteration = 0 |
||
) |
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 136 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 408 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 64 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
overridevirtual |
Generates a random Bayesian network.
bayesNet | empty IBayesNet to generate. |
Implements gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >.
Definition at line 114 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 388 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that verify if graph is a polytree.
Definition at line 555 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Size gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::iteration | ( | ) | const |
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator.
Definition at line 668 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 374 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 360 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 82 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 72 of file IBayesNetGenerator_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 77 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Idx gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::p | ( | ) | const |
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
Definition at line 679 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 246 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
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 200 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Idx gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::q | ( | ) | const |
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
Definition at line 689 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setIteration | ( | Size | iteration | ) |
Modifies the value of the number of iterations impose on the BayesNetGenerator.
Definition at line 699 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 106 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 87 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 97 of file IBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setP | ( | Idx | p | ) |
Modifies the value of the probability p imposed on the BayesNetGenerator.
Definition at line 709 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setQ | ( | Idx | q | ) |
Modifies the value of the probability q imposed on the BayesNetGenerator.
Definition at line 723 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protected |
The function that randomly change the simple tree into a polytree.
Definition at line 537 of file MCBayesNetGenerator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
Definition at line 166 of file IBayesNetGenerator.h.
|
protected |
Definition at line 289 of file MCBayesNetGenerator.h.
|
protected |
Definition at line 288 of file MCBayesNetGenerator.h.
|
protected |
Definition at line 290 of file MCBayesNetGenerator.h.
|
protected |
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.
|
protectedinherited |
Definition at line 163 of file IBayesNetGenerator.h.
|
protected |
Definition at line 287 of file MCBayesNetGenerator.h.
|
protected |
Definition at line 287 of file MCBayesNetGenerator.h.