aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber > Class Template Reference

<agrum/BN/generator/SimpleMCayesNetGenerator.h> More...

#include <maxParentsMCBayesNetGenerator.h>

+ Inheritance diagram for gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >:
+ Collaboration diagram for gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >:

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...
 

Detailed Description

template<typename GUM_SCALAR, template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
class gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >

<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.

Warning
Be Careful when entering the parameters, high Values may cause the density of the Bayesian network to be too high resulting in the failure of most of the inference Methods.

Definition at line 89 of file maxParentsMCBayesNetGenerator.h.

Constructor & Destructor Documentation

◆ MaxParentsMCBayesNetGenerator() [1/2]

template<typename GUM_SCALAR , template< class > class ICPTGenerator, template< class > class ICPTDisturber>
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.

Parameters
nbrNodesThe number of nodes in the generated BN.
maxArcsThe maximum number of Arcs.
maxModalityEach DRV has from 2 to maxModality modalities
maxParentsThe number of maximum parents for each node imposed on the generator
iterationThe number of iterations wanted to repeat the algorithm
pprobability for the change of the state (see useof p and q" )
qprobability for the change of the state (see useof p and q" )

Definition at line 48 of file maxParentsMCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

54  :
55  MCBG(nbrNodes, maxArcs, maxModality, iteration, p, q) {
56  if (maxParents == 0)
57  GUM_ERROR(OperationNotAllowed,
58  "maxParents must be at least equal to 1 to have a connexe graph");
59 
61  GUM_CONSTRUCTOR(MaxParentsMCBayesNetGenerator);
62  }
Size nbrNodes() const
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
Size maxArcs() const
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
MaxParentsMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxParents=1, Idx iteration=5000, Idx p=30, Idx q=40)
Constructor.
Size maxParents() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ MaxParentsMCBayesNetGenerator() [2/2]

template<typename GUM_SCALAR , template< class > class ICPTGenerator, template< class > class ICPTDisturber>
INLINE gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::MaxParentsMCBayesNetGenerator ( BayesNet< GUM_SCALAR >  bayesNet,
Size  maxParents = 2,
Idx  iteration = 5000,
Idx  p = 30,
Idx  q = 40 
)
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.

Parameters
bayesNetthe IBayesNet used as reference to fill the parameters nbrNodes, maxArcs and maxModality
maxParentsThe number of maximum parents for each node imposed on the generator
iterationThe number of iterations wanted to repeat the algorithm
pprobability for the change of the state (see useof p and q" )
qprobability for the change of the state (see useof p and q" )

Definition at line 71 of file maxParentsMCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

75  :
76  MCBG(bayesNet, iteration, p, q) {
78  GUM_CONSTRUCTOR(MaxParentsMCBayesNetGenerator);
79  }
MaxParentsMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxParents=1, Idx iteration=5000, Idx p=30, Idx q=40)
Constructor.
Size maxParents() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
+ Here is the call graph for this function:

◆ ~MaxParentsMCBayesNetGenerator()

template<typename GUM_SCALAR , template< class > class ICPTGenerator, template< class > class ICPTDisturber>
INLINE gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::~MaxParentsMCBayesNetGenerator ( )
final

Destructor.

Definition at line 89 of file maxParentsMCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

89  {
90  GUM_DESTRUCTOR(MaxParentsMCBayesNetGenerator);
91  }
MaxParentsMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxParents=1, Idx iteration=5000, Idx p=30, Idx q=40)
Constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ AorR__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::AorR__ ( )
protectedinherited

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().

294  {
295  NodeId i, j;
296  chooseNodes__(i, j);
297  const DAG dag__ = this->bayesNet_.dag();
298 
299  if (dag__.existsArc(i, j)) {
300  eraseArc__(i, j);
301 
302  return;
303  } else
304  insertArc__(i, j);
305  }
void eraseArc__(NodeId i, NodeId j, bool mustbeconnex=true)
The function that will remove the arc between node i and node j.
void chooseNodes__(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
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...
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ AR__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::AR__ ( )
protectedinherited

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().

312  {
313  NodeId i, j, head, tail;
314  chooseNodes__(i, j);
315  const DAG dag__ = this->bayesNet_.dag();
316 
317  if (dag__.existsArc(i, j) || dag__.existsArc(j, i)) {
318  return;
319  } else {
320  Idx per = randomValue(100);
321 
322  if (per < 50) {
323  head = i;
324  tail = j;
325  } else {
326  head = j;
327  tail = i;
328  }
329 
330  for (auto node: dag__.parents(j)) {
331  NodeSet excluded;
332  excluded.insert(j);
333 
334  if (connect__(node, i, excluded)) {
335  this->bayesNet_.eraseArc(node, j);
336  this->bayesNet_.addArc(head, tail);
337  return;
338  }
339  }
340 
341  for (auto node: dag__.children(j)) {
342  NodeSet excluded;
343  excluded.insert(j);
344 
345  if (connect__(node, i, excluded)) {
346  this->bayesNet_.eraseArc(j, node);
347  this->bayesNet_.addArc(head, tail);
348  return;
349  }
350  }
351  }
352  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void chooseNodes__(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
bool connect__(NodeId i, NodeId j)
The function that verify if node i and j are connected.
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ checkConditions__()

template<typename GUM_SCALAR , template< class > class ICPTGenerator, template< class > class ICPTDisturber>
bool gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::checkConditions__ ( )
finalprivatevirtual

function to holding the the specification wanted for the Bayesian markov.

Returns
boolean state that verify the conditions

Reimplemented from gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >.

Definition at line 99 of file maxParentsMCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

99  {
100  for (auto node: this->bayesNet_.nodes())
101  if (this->bayesNet_.parents(node).size() > maxParents_) return false;
102 
103  return MCBG::checkConditions__();
104  }
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ chooseCloseNodes__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::chooseCloseNodes__ ( NodeId i,
NodeId j 
)
protectedinherited

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().

451  {
452  NodeId temp = randomValue(this->bayesNet_.size());
453  Size co = 0;
454 
455  if (this->bayesNet_.parents(temp).size()) {
456  j = temp;
457  auto it = this->bayesNet_.parents(j).begin();
458  co = randomValue(this->bayesNet_.parents(j).size());
459 
460  while (co--) {
461  ++it;
462  }
463 
464  i = *it;
465  } else if (this->bayesNet_.children(temp).size()) {
466  i = temp;
467  auto it = this->bayesNet_.children(i).begin();
468  co = randomValue(this->bayesNet_.children(i).size());
469 
470  while (co--) {
471  ++it;
472  }
473 
474  j = *it;
475  } else {
476  GUM_ERROR(FatalError, "Sorry Misconstructed BN because of isolated node.");
477  }
478  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ chooseNodes__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::chooseNodes__ ( NodeId i,
NodeId j 
)
protectedinherited

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().

437  {
438  i = randomValue(this->bayesNet_.size());
439  j = randomValue(this->bayesNet_.size());
440 
441  while (i == j)
442  j = randomValue(this->bayesNet_.size());
443  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ connect__() [1/2]

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
bool gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::connect__ ( NodeId  i,
NodeId  j 
)
protectedinherited

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().

567  {
568  const DAG dag__ = this->bayesNet_.dag();
569 
570  if (dag__.existsArc(i, j) || dag__.existsArc(j, i))
571  return true;
572  else {
573  NodeSet excluded;
574  excluded.insert(i);
575 
576  for (auto par: dag__.parents(i)) {
577  if (!excluded.exists(par) && connect__(par, j, excluded)) return true;
578  }
579 
580  for (auto chi: dag__.children(i)) {
581  if (!excluded.exists(chi) && connect__(chi, j, excluded)) return true;
582  }
583 
584  return false;
585  }
586  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool connect__(NodeId i, NodeId j)
The function that verify if node i and j are connected.
BayesNet< GUM_SCALAR > bayesNet_
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ connect__() [2/2]

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
bool gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::connect__ ( NodeId  i,
NodeId  j,
NodeSet excluded 
)
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 593 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

596  {
597  const DAG dag__ = this->bayesNet_.dag();
598 
599  if (dag__.existsArc(i, j) || dag__.existsArc(j, i))
600  return true;
601  else {
602  excluded.insert(i);
603 
604  for (auto par: dag__.parents(i)) {
605  if (!excluded.exists(par) && connect__(par, j, excluded)) return true;
606  }
607 
608  for (auto chi: dag__.children(i)) {
609  if (!excluded.exists(chi) && connect__(chi, j, excluded)) return true;
610  }
611 
612  return false;
613  }
614  }
bool connect__(NodeId i, NodeId j)
The function that verify if node i and j are connected.
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ createPartTree__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
NodeId gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::createPartTree__ ( Size  BNSize,
Idx n 
)
protectedinherited

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().

511  {
512  Size nb_mod = 2 + randomValue(this->maxModality_ - 1);
513  std::stringstream strBuff;
514  strBuff << "n_" << n++;
515  NodeId root
516  = this->bayesNet_.add(LabelizedVariable(strBuff.str(), "", nb_mod));
517  Size maxNodes = BNSize - 1;
518  Size SubG = 0;
519 
520  while (maxNodes) {
521  SubG = randomValue(maxNodes) + 1;
522  maxNodes = maxNodes - SubG;
523  NodeId rootS = createPartTree__(SubG, n);
524  this->bayesNet_.addArc(root, rootS);
525  }
526 
527  return root;
528  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
NodeId createPartTree__(Size BNSize, Idx &n)
The internal function used by createTree__ that randomly generate a simple tree.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ createTree__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::createTree__ ( Size  BNSize)
protectedinherited

The function that randomly generate a simple tree.

Definition at line 486 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

487  {
488  Idx n = 0;
489  Size nb_mod = 2 + randomValue(this->maxModality_ - 1);
490  std::stringstream strBuff;
491  strBuff << "n_" << n++;
492  NodeId root
493  = this->bayesNet_.add(LabelizedVariable(strBuff.str(), "", nb_mod));
494  Size maxNodes = BNSize - 1;
495  Size SubG = 0;
496 
497  while (maxNodes) {
498  SubG = randomValue(maxNodes) + 1;
499  maxNodes = maxNodes - SubG;
500  NodeId rootS = createPartTree__(SubG, n);
501  this->bayesNet_.addArc(root, rootS);
502  }
503  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
NodeId createPartTree__(Size BNSize, Idx &n)
The internal function used by createTree__ that randomly generate a simple tree.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ directedPath__() [1/2]

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
bool gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::directedPath__ ( NodeId  tail,
NodeId  head 
)
protectedinherited

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().

622  {
623  const DAG dag__ = this->bayesNet_.dag();
624 
625  if (dag__.existsArc(tail, head))
626  return true;
627  else {
628  NodeSet excluded;
629  excluded.insert(tail);
630 
631  for (auto node: dag__.children(tail)) {
632  if (directedPath__(node, head, excluded)) return true;
633  }
634 
635  return false;
636  }
637  }
bool directedPath__(NodeId tail, NodeId head)
The function that verify if there is a oriented path from node i to node j.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
BayesNet< GUM_SCALAR > bayesNet_
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ directedPath__() [2/2]

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
bool gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::directedPath__ ( NodeId  tail,
NodeId  head,
NodeSet excluded 
)
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 645 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

645  {
646  const DAG dag__ = this->bayesNet_.dag();
647 
648  if (dag__.existsArc(tail, head))
649  return true;
650  else {
651  excluded.insert(tail);
652 
653  for (auto node: dag__.children(tail)) {
654  if (!excluded.exists(node) && directedPath__(node, head, excluded))
655  return true;
656  }
657 
658  return false;
659  }
660  }
bool directedPath__(NodeId tail, NodeId head)
The function that verify if there is a oriented path from node i to node j.
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ disturbBN()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN ( BayesNet< GUM_SCALAR > &  bayesNetinit,
Size  iteration = 0 
)
inherited

Change randomly the topology of a specific Bayesian networks.

Parameters
bayesNetinitIBayesNet to be modify
iterationThe number of iterations wanted to repeat the algorithm
Returns
null but modify inputed Bayesian network
Exceptions
OperationNotAllowif 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().

138  { // insert option for the variation
139  disturbing_ = true;
140  Size iter = iteration_;
141 
143 
144  this->bayesNet_ = bayesNetinit;
145 
146  if (checkConditions__()) {
147  LazyPropagation< GUM_SCALAR > inf(&bayesNetinit);
148  inf.makeInference();
149 
150  for (auto node: bayesNetinit.nodes()) {
151  auto pottemp = new Potential< GUM_SCALAR >();
152  pottemp->copy(inf.posterior(node));
153  hashMarginal_.insert(node, pottemp);
154  }
155 
156  bayesNettemp_ = this->bayesNet_;
157 
158  if (isPolytree__())
159  PMMx_poly__();
160  else
161  PMMx_multi__();
162 
163  bayesNetinit = (this->bayesNet_);
164 
165  while (hashMarginal_.size()) {
166  delete (hashMarginal_.begin().val());
167  hashMarginal_.erase(
168  hashMarginal_.beginSafe()); // safe iterator needed here.
169  }
170 
171  } else {
172  std::cout << this->bayesNet_.toDot() << std::endl;
173  GUM_ERROR(OperationNotAllowed,
174  "BN is not valid cause it does not respect constraint ");
175  }
176 
177  iteration_ = iter;
178  disturbing_ = false;
179  }
virtual bool checkConditions__()
The boolean function that will assert the respect of the constraint.
void PMMx_poly__()
In the case that the graph is a polytree, the function will, according to the probability p and q...
HashTable< NodeId, Potential< GUM_SCALAR > *> hashMarginal_
bool isPolytree__()
The function that verify if graph is a polytree.
void PMMx_multi__()
In the case that the graph is a multiconnected graph, the function will, according to the probability...
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
BayesNet< GUM_SCALAR > bayesNet_
BayesNet< GUM_SCALAR > bayesNettemp_
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ eraseArc__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::eraseArc__ ( NodeId  i,
NodeId  j,
bool  mustbeconnex = true 
)
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 408 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

411  {
412  if (disturbing_) {
413  const BayesNet< GUM_SCALAR > bayesNet(this->bayesNet_);
414  Potential< GUM_SCALAR > potj;
415  potj.copy(this->bayesNet_.cpt(j));
416  this->bayesNet_.eraseArc(i, j);
417 
418  if (connect__(i, j) || !mustbeconnex) {
419  auto marg = *hashMarginal_[i];
420 
421  this->disturbReducCPT(j, this->bayesNet_, potj, marg);
422  } else
423  this->bayesNet_.addArc(i, j);
424  } else {
425  this->bayesNet_.eraseArc(i, j);
426 
427  if (!connect__(i, j) && mustbeconnex) { this->bayesNet_.addArc(i, j); }
428  }
429  }
HashTable< NodeId, Potential< GUM_SCALAR > *> hashMarginal_
bool connect__(NodeId i, NodeId j)
The function that verify if node i and j are connected.
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ fillCPT()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::fillCPT ( )
inherited

function that insert random values in the CPT of each nodes according to the CPTGenerator.

Returns
null but modify inputed empty Bayesian network

Definition at line 64 of file IBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

64  {
65  for (auto node: bayesNet_.nodes())
66  this->generateCPT(bayesNet_.cpt(node).pos(bayesNet_.variable(node)),
67  bayesNet_.cpt(node));
68  }
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ generateBN()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::generateBN ( BayesNet< GUM_SCALAR > &  bayesNet)
overridevirtualinherited

Generates a random Bayesian network.

Parameters
bayesNetempty IBayesNet to generate.
Returns
null but modify inputed Bayesian network

Implements gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >.

Definition at line 114 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

115  {
117 
118  // this->bayesNet_ = bayesNet;
119  createTree__(this->nbrNodes_);
120  transformPoly__(this->nbrNodes_ / 2);
121  bayesNettemp_ = this->bayesNet_;
122  PMMx_poly__();
123 
124  this->fillCPT();
126 
127  bayesNet = this->bayesNet_;
128  }
void transformPoly__(Idx nbiter)
The function that randomly change the simple tree into a polytree.
void fillCPT()
function that insert random values in the CPT of each nodes according to the CPTGenerator.
void createTree__(Size BNSize)
The function that randomly generate a simple tree.
void PMMx_poly__()
In the case that the graph is a polytree, the function will, according to the probability p and q...
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator...
BayesNet< GUM_SCALAR > bayesNet_
BayesNet< GUM_SCALAR > bayesNettemp_
+ Here is the call graph for this function:

◆ insertArc__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::insertArc__ ( NodeId  i,
NodeId  j 
)
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 388 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

390  {
391  if (directedPath__(j, i)) return;
392 
393  if (disturbing_) {
394  auto potj = this->bayesNet_.cpt(j);
395  this->bayesNet_.addArc(i, j);
396 
397  this->disturbAugmCPT(j, this->bayesNet_, potj, (GUM_SCALAR)0.5);
398  } else
399  this->bayesNet_.addArc(i, j);
400  }
bool directedPath__(NodeId tail, NodeId head)
The function that verify if there is a oriented path from node i to node j.
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ isPolytree__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE bool gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::isPolytree__ ( )
protectedinherited

The function that verify if graph is a polytree.

Definition at line 555 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

555  {
556  const DAG dag__ = this->bayesNet_.dag();
557  return this->bayesNet_.size() - 1 == this->bayesNet_.sizeArcs();
558  }
BayesNet< GUM_SCALAR > bayesNet_
+ Here is the call graph for this function:

◆ iteration()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE Size gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::iteration ( ) const
inherited

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().

669  {
670  return iteration_;
671  }
+ Here is the call graph for this function:

◆ jump_multi__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::jump_multi__ ( )
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 374 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

374  {
375  NodeId i, j;
376  chooseNodes__(i, j);
377  const DAG dag__ = this->bayesNet_.dag();
378 
379  if (dag__.existsArc(i, j)) { eraseArc__(i, j); }
380  }
void eraseArc__(NodeId i, NodeId j, bool mustbeconnex=true)
The function that will remove the arc between node i and node j.
void chooseNodes__(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ jump_poly__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::jump_poly__ ( )
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 360 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

360  {
361  NodeId i, j;
362  chooseNodes__(i, j);
363  const DAG dag__ = this->bayesNet_.dag();
364 
365  if (!dag__.existsArc(i, j)) insertArc__(i, j);
366  }
void chooseNodes__(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
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...
BayesNet< GUM_SCALAR > bayesNet_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ maxArcs()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
INLINE Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxArcs ( ) const
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().

82  {
83  return maxArcs_;
84  }
+ Here is the call graph for this function:

◆ maxModality()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
INLINE Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxModality ( ) const
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().

72  {
73  return maxModality_;
74  }
+ Here is the call graph for this function:

◆ maxParents()

template<typename GUM_SCALAR , template< class > class ICPTGenerator, template< class > class ICPTDisturber>
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 113 of file maxParentsMCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

+ Here is the call graph for this function:

◆ nbrNodes()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
INLINE Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::nbrNodes ( ) const
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().

77  {
78  return nbrNodes_;
79  }
+ Here is the call graph for this function:

◆ p()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE Idx gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::p ( ) const
inherited

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().

679  {
680  return p_;
681  }
+ Here is the call graph for this function:

◆ PMMx_multi__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::PMMx_multi__ ( )
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 246 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

246  {
247  if (!iteration_--) return;
248 
249  Idx per = randomValue(100);
250 
251  if (per < p_ + q_) {
252  AorR__();
253 
254  if (checkConditions__()) {
255  if (isPolytree__()) {
256  if (per < p_) {
257  bayesNettemp_ = this->bayesNet_;
258  PMMx_poly__();
259  } else {
260  this->bayesNet_ = bayesNettemp_;
261  PMMx_multi__();
262  }
263  } else {
264  bayesNettemp_ = this->bayesNet_;
265  PMMx_multi__();
266  }
267  } else {
268  this->bayesNet_ = bayesNettemp_;
269  PMMx_multi__();
270  }
271  } else {
272  jump_multi__();
273 
274  if (checkConditions__()) {
275  bayesNettemp_ = this->bayesNet_;
276 
277  if (isPolytree__())
278  PMMx_poly__();
279  else
280  PMMx_multi__();
281 
282  } else {
283  this->bayesNet_ = bayesNettemp_;
284  PMMx_multi__();
285  }
286  }
287  }
void jump_multi__()
In the case that the graph is a multiconnect graph, the function will choose randomly two nodes and w...
void AorR__()
The function will add or remove a random arc in the graph using the functions insertArc__ and removeA...
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
virtual bool checkConditions__()
The boolean function that will assert the respect of the constraint.
void PMMx_poly__()
In the case that the graph is a polytree, the function will, according to the probability p and q...
bool isPolytree__()
The function that verify if graph is a polytree.
void PMMx_multi__()
In the case that the graph is a multiconnected graph, the function will, according to the probability...
BayesNet< GUM_SCALAR > bayesNet_
BayesNet< GUM_SCALAR > bayesNettemp_
+ Here is the call graph for this function:

◆ PMMx_poly__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::PMMx_poly__ ( )
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 200 of file MCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

200  {
201  if (!iteration_--) return;
202 
203  Idx per = randomValue(100);
204 
205  if (per < p_) {
206  AorR__();
207 
208  if (checkConditions__()) {
209  bayesNettemp_ = this->bayesNet_;
210  PMMx_multi__();
211  } else {
212  this->bayesNet_ = bayesNettemp_;
213  PMMx_poly__();
214  }
215  } else {
216  if (per < p_ + q_) {
217  AR__();
218 
219  if (!checkConditions__()) {
220  this->bayesNet_ = bayesNettemp_;
221  } else
222  bayesNettemp_ = this->bayesNet_;
223 
224  PMMx_poly__();
225  } else {
226  jump_poly__();
227 
228  if (checkConditions__()) {
229  bayesNettemp_ = this->bayesNet_;
230  PMMx_multi__();
231 
232  } else {
233  this->bayesNet_ = bayesNettemp_;
234  PMMx_poly__();
235  }
236  }
237  }
238  }
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...
void AorR__()
The function will add or remove a random arc in the graph using the functions insertArc__ and removeA...
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
virtual bool checkConditions__()
The boolean function that will assert the respect of the constraint.
void PMMx_poly__()
In the case that the graph is a polytree, the function will, according to the probability p and q...
void PMMx_multi__()
In the case that the graph is a multiconnected graph, the function will, according to the probability...
BayesNet< GUM_SCALAR > bayesNet_
BayesNet< GUM_SCALAR > bayesNettemp_
void AR__()
The function will remove and add a random arc changing the topology of the graph but asserting its co...
+ Here is the call graph for this function:

◆ q()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE Idx gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::q ( ) const
inherited

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().

689  {
690  return q_;
691  }
+ Here is the call graph for this function:

◆ setIteration()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setIteration ( Size  iteration)
inherited

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().

700  {
702  }
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator...
+ Here is the call graph for this function:

◆ setMaxArcs()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::setMaxArcs ( Size  maxArcs)
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().

106  {
107  if (maxArcs < nbrNodes_ - 1 || maxArcs > (nbrNodes_ * (nbrNodes_ - 1)) / 2)
108  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
109 
110  maxArcs_ = maxArcs;
111  }
Size maxArcs() const
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMaxModality()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::setMaxModality ( Size  maxModality)
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().

88  {
89  if (maxModality < 2)
90  GUM_ERROR(OperationNotAllowed,
91  " maxModality must be at least equal to two ");
92 
94  }
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMaxParents()

template<typename GUM_SCALAR , template< class > class ICPTGenerator, template< class > class ICPTDisturber>
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 123 of file maxParentsMCBayesNetGenerator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

123  {
124  if (maxParents == 0)
125  GUM_ERROR(OperationNotAllowed,
126  "maxParents must be at least equal to 1 to have a connexe graph");
127 
129  }
Size maxParents() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setNbrNodes()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::setNbrNodes ( Size  nbrNodes)
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().

97  {
98  if ((maxArcs_ < nbrNodes - 1) || (maxArcs_ > (nbrNodes * (nbrNodes - 1)) / 2))
99  GUM_ERROR(OperationNotAllowed, " nbrNodes value not possible ");
100 
102  }
Size nbrNodes() const
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setP()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setP ( Idx  p)
inherited

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().

709  {
710  p_ = p;
711 
712  if (p + q_ > 100)
713  GUM_ERROR(
714  OperationNotAllowed,
715  "the sum of the probabilities p and q must be at most equal to 100");
716  }
Idx p() const
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setQ()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
INLINE void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::setQ ( Idx  q)
inherited

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().

723  {
724  q_ = q;
725 
726  if (p_ + q > 100)
727  GUM_ERROR(
728  OperationNotAllowed,
729  "the sum of the probabilities p and q must be at most equal to 100");
730  }
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ transformPoly__()

template<typename GUM_SCALAR , template< typename > class ICPTGenerator, template< typename > class ICPTDisturber>
void gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::transformPoly__ ( Idx  nbiter)
protectedinherited

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().

537  {
538  while (nbiter--) {
539  NodeId i, j;
540  chooseCloseNodes__(i, j);
541  bayesNettemp_ = this->bayesNet_;
542  eraseArc__(i, j, false);
543  this->bayesNet_.addArc(j, i);
544 
545  if (!checkConditions__()) this->bayesNet_ = bayesNettemp_;
546  }
547  }
virtual bool checkConditions__()
The boolean function that will assert the respect of the constraint.
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.
BayesNet< GUM_SCALAR > bayesNet_
BayesNet< GUM_SCALAR > bayesNettemp_
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

Member Data Documentation

◆ bayesNet_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
BayesNet< GUM_SCALAR > gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::bayesNet_
protectedinherited

Definition at line 166 of file IBayesNetGenerator.h.

◆ bayesNettemp_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
BayesNet< GUM_SCALAR > gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::bayesNettemp_
protectedinherited

Definition at line 289 of file MCBayesNetGenerator.h.

◆ disturbing_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
bool gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbing_
protectedinherited

Definition at line 288 of file MCBayesNetGenerator.h.

◆ hashMarginal_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
HashTable< NodeId, Potential< GUM_SCALAR >* > gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::hashMarginal_
protectedinherited

Definition at line 290 of file MCBayesNetGenerator.h.

◆ iteration_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
Size gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::iteration_
protectedinherited

Definition at line 286 of file MCBayesNetGenerator.h.

◆ maxArcs_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxArcs_
protectedinherited

Definition at line 164 of file IBayesNetGenerator.h.

◆ maxModality_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxModality_
protectedinherited

Definition at line 165 of file IBayesNetGenerator.h.

◆ maxParents_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
Size gum::MaxParentsMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::maxParents_
protected

Definition at line 179 of file maxParentsMCBayesNetGenerator.h.

◆ nbrNodes_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator>
Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::nbrNodes_
protectedinherited

Definition at line 163 of file IBayesNetGenerator.h.

◆ p_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
Idx gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::p_
protectedinherited

Definition at line 287 of file MCBayesNetGenerator.h.

◆ q_

template<typename GUM_SCALAR , template< typename > class ICPTGenerator = SimpleCPTGenerator, template< typename > class ICPTDisturber = SimpleCPTDisturber>
Idx gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::q_
protectedinherited

Definition at line 287 of file MCBayesNetGenerator.h.


The documentation for this class was generated from the following files: