32 # define IBNG IBayesNetGenerator 34 # define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator > 37 template <
typename GUM_SCALAR >
41 for (
auto node : bayesNet.
nodes())
50 template <
typename GUM_SCALAR,
62 IBNG(nbrNodes, maxArcs, maxModality),
63 _bayesNettemp(), _hashMarginal() {
67 "the sum of the probabilities p and q must be at most equal to 100");
77 template <
typename GUM_SCALAR,
88 (
Size)(bayesNet.sizeArcs() * 1.1),
97 template <
typename GUM_SCALAR,
100 template <
typename >
101 class ICPTDisturber >
107 template <
typename GUM_SCALAR,
108 template <
typename >
110 template <
typename >
111 class ICPTDisturber >
129 template <
typename GUM_SCALAR,
130 template <
typename >
132 template <
typename >
133 class ICPTDisturber >
148 for (
auto node : bayesNetinit.
nodes()) {
170 std::cout << this->
_bayesNet.toDot() << std::endl;
172 "BN is not valid cause it does not respect constraint ");
179 template <
typename GUM_SCALAR,
180 template <
typename >
182 template <
typename >
183 class ICPTDisturber >
192 template <
typename GUM_SCALAR,
193 template <
typename >
195 template <
typename >
196 class ICPTDisturber >
238 template <
typename GUM_SCALAR,
239 template <
typename >
241 template <
typename >
242 class ICPTDisturber >
287 template <
typename GUM_SCALAR,
288 template <
typename >
290 template <
typename >
291 class ICPTDisturber >
305 template <
typename GUM_SCALAR,
306 template <
typename >
308 template <
typename >
309 class ICPTDisturber >
328 for (
auto node : __dag.
parents(j)) {
339 for (
auto node : __dag.
children(j)) {
352 template <
typename GUM_SCALAR,
353 template <
typename >
355 template <
typename >
356 class ICPTDisturber >
366 template <
typename GUM_SCALAR,
367 template <
typename >
369 template <
typename >
370 class ICPTDisturber >
380 template <
typename GUM_SCALAR,
381 template <
typename >
383 template <
typename >
384 class ICPTDisturber >
394 this->disturbAugmCPT(j, this->
_bayesNet, potj, (GUM_SCALAR)0.5);
399 template <
typename GUM_SCALAR,
400 template <
typename >
402 template <
typename >
403 class ICPTDisturber >
416 this->disturbReducCPT(j, this->
_bayesNet, potj, marg);
426 template <
typename GUM_SCALAR,
427 template <
typename >
429 template <
typename >
430 class ICPTDisturber >
440 template <
typename GUM_SCALAR,
441 template <
typename >
443 template <
typename >
444 class ICPTDisturber >
450 if (this->
_bayesNet.parents(temp).size()) {
452 auto it = this->
_bayesNet.parents(j).begin();
460 }
else if (this->
_bayesNet.children(temp).size()) {
462 auto it = this->
_bayesNet.children(i).begin();
475 template <
typename GUM_SCALAR,
476 template <
typename >
478 template <
typename >
479 class ICPTDisturber >
485 std::stringstream strBuff;
486 strBuff <<
"n_" << n++;
489 Size maxNodes = BNSize - 1;
494 maxNodes = maxNodes - SubG;
500 template <
typename GUM_SCALAR,
501 template <
typename >
503 template <
typename >
504 class ICPTDisturber >
508 std::stringstream strBuff;
509 strBuff <<
"n_" << n++;
512 Size maxNodes = BNSize - 1;
517 maxNodes = maxNodes - SubG;
526 template <
typename GUM_SCALAR,
527 template <
typename >
529 template <
typename >
530 class ICPTDisturber >
544 template <
typename GUM_SCALAR,
545 template <
typename >
547 template <
typename >
548 class ICPTDisturber >
555 template <
typename GUM_SCALAR,
556 template <
typename >
558 template <
typename >
559 class ICPTDisturber >
570 for (
auto par : __dag.
parents(i)) {
574 for (
auto chi : __dag.
children(i)) {
582 template <
typename GUM_SCALAR,
583 template <
typename >
585 template <
typename >
586 class ICPTDisturber >
596 for (
auto par : __dag.
parents(i)) {
600 for (
auto chi : __dag.
children(i)) {
608 template <
typename GUM_SCALAR,
609 template <
typename >
611 template <
typename >
612 class ICPTDisturber >
623 for (
auto node : __dag.
children(tail)) {
631 template <
typename GUM_SCALAR,
632 template <
typename >
634 template <
typename >
635 class ICPTDisturber >
645 for (
auto node : __dag.
children(tail)) {
654 template <
typename GUM_SCALAR,
655 template <
typename >
657 template <
typename >
658 class ICPTDisturber >
665 template <
typename GUM_SCALAR,
666 template <
typename >
668 template <
typename >
669 class ICPTDisturber >
675 template <
typename GUM_SCALAR,
676 template <
typename >
678 template <
typename >
679 class ICPTDisturber >
685 template <
typename GUM_SCALAR,
686 template <
typename >
688 template <
typename >
689 class ICPTDisturber >
695 template <
typename GUM_SCALAR,
696 template <
typename >
698 template <
typename >
699 class ICPTDisturber >
707 "the sum of the probabilities p and q must be at most equal to 100");
709 template <
typename GUM_SCALAR,
710 template <
typename >
712 template <
typename >
713 class ICPTDisturber >
721 "the sum of the probabilities p and q must be at most equal to 100");
aGrUM's Potential is a multi-dimensional array with tensor operators.
Class representing a Bayesian Network.
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.
void __PMMx_poly()
In the case that the graph is a polytree, the function will, according to the probability p and q...
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
<agrum/BN/generator/MCayesNetGenerator.h>
void fillCPT()
function that insert random values in the CPT of each nodes according to the CPTGenerator.
gum::Size getMaxModality(gum::BayesNet< GUM_SCALAR > &bayesNet)
bool __connect(NodeId i, NodeId j)
The function that verify if node i and j are connected.
void setQ(Idx q)
Modifies the value of the probability q imposed on the BayesNetGenerator.
gum is the global namespace for all aGrUM entities
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included...
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.
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual Size domainSize() const =0
void setP(Idx p)
Modifies the value of the probability p imposed on the BayesNetGenerator.
~MCBayesNetGenerator() override
Destructor.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
BayesNet< GUM_SCALAR > _bayesNet
BayesNet< GUM_SCALAR > _bayesNettemp
void __transformPoly(Idx nbiter)
The function that randomly change the simple tree into a polytree.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
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.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
virtual const Potential< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
void __AR()
The function will remove and add a random arc changing the topology of the graph but asserting its co...
<agrum/BN/inference/lazyPropagation.h>
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 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.
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...
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.
Class for generating bayesian networks.using MC algorithm cf.
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.
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
HashTable< NodeId, Potential< GUM_SCALAR > *> _hashMarginal