51#define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
54 template <
typename GUM_SCALAR >
58 for (
auto node: bayesNet.
nodes())
67 template <
typename GUM_SCALAR,
68 template <
typename >
class ICPTGenerator,
69 template <
typename >
class ICPTDisturber >
79 "the sum of the probabilities p and q must be at most equal to 100");
88 template <
typename GUM_SCALAR,
89 template <
typename >
class ICPTGenerator,
90 template <
typename >
class ICPTDisturber >
92 BayesNet< GUM_SCALAR > bayesNet,
97 (
Size)(bayesNet.sizeArcs() * 1.1),
105 template <
typename GUM_SCALAR,
106 template <
typename >
class ICPTGenerator,
107 template <
typename >
class ICPTDisturber >
112 template <
typename GUM_SCALAR,
113 template <
typename >
class ICPTGenerator,
114 template <
typename >
class ICPTDisturber >
116 BayesNet< GUM_SCALAR >& bayesNet) {
179 template <
typename GUM_SCALAR,
180 template <
typename >
class ICPTGenerator,
181 template <
typename >
class ICPTDisturber >
189 template <
typename GUM_SCALAR,
190 template <
typename >
class ICPTGenerator,
191 template <
typename >
class ICPTDisturber >
202 tmp_dag = this->
dag_;
206 this->dag_ = tmp_dag;
212 if (!_checkConditions_()) {
213 this->dag_ = tmp_dag;
215 tmp_dag = this->dag_;
220 if (_checkConditions_()) {
221 tmp_dag = this->dag_;
225 this->dag_ = tmp_dag;
232 template <
typename GUM_SCALAR,
233 template <
typename >
class ICPTGenerator,
234 template <
typename >
class ICPTDisturber >
247 tmp_dag = this->
dag_;
251 this->dag_ = tmp_dag;
254 tmp_dag = this->dag_;
257 this->dag_ = tmp_dag;
261 if (_checkConditions_()) {
262 tmp_dag = this->dag_;
263 if (_isPolytree_()) {
268 this->dag_ = tmp_dag;
274 template <
typename GUM_SCALAR,
275 template <
typename >
class ICPTGenerator,
276 template <
typename >
class ICPTDisturber >
280 if (this->
dag_.existsArc(i, j)) {
287 template <
typename GUM_SCALAR,
288 template <
typename >
class ICPTGenerator,
289 template <
typename >
class ICPTDisturber >
294 if (this->
dag_.existsArc(i, j) || this->dag_.existsArc(j, i)) {
307 for (
auto node: this->dag_.parents(j)) {
313 this->
dag_.addArc(head, tail);
318 for (
auto node: this->
dag_.children(j)) {
324 this->dag_.addArc(head, tail);
331 template <
typename GUM_SCALAR,
332 template <
typename >
class ICPTGenerator,
333 template <
typename >
class ICPTDisturber >
341 template <
typename GUM_SCALAR,
342 template <
typename >
class ICPTGenerator,
343 template <
typename >
class ICPTDisturber >
351 template <
typename GUM_SCALAR,
352 template <
typename >
class ICPTGenerator,
353 template <
typename >
class ICPTDisturber >
365 this->
dag_.addArc(i, j);
368 template <
typename GUM_SCALAR,
369 template <
typename >
class ICPTGenerator,
370 template <
typename >
class ICPTDisturber >
388 this->
dag_.eraseArc(
Arc(i, j));
390 if (!
_connect_(i, j) && mustbeconnex) { this->
dag_.addArc(i, j); }
394 template <
typename GUM_SCALAR,
395 template <
typename >
class ICPTGenerator,
396 template <
typename >
class ICPTDisturber >
400 if (this->
dag_.size() < 3) {
410 template <
typename GUM_SCALAR,
411 template <
typename >
class ICPTGenerator,
412 template <
typename >
class ICPTDisturber >
419 if (this->
dag_.parents(temp).size()) {
421 auto it = this->
dag_.parents(j).begin();
429 }
else if (this->dag_.children(temp).size()) {
431 auto it = this->dag_.children(i).begin();
440 GUM_ERROR(FatalError,
"Sorry Misconstructed BN because of isolated node.")
444 template <
typename GUM_SCALAR,
445 template <
typename >
class ICPTGenerator,
446 template <
typename >
class ICPTDisturber >
450 Size maxNodes = BNSize - 1;
455 maxNodes = maxNodes - SubG;
457 this->
dag_.addArc(root, rootS);
461 template <
typename GUM_SCALAR,
462 template <
typename >
class ICPTGenerator,
463 template <
typename >
class ICPTDisturber >
474 Size maxNodes = BNSize - 1;
479 maxNodes = maxNodes - SubG;
481 this->
dag_.addArc(root, rootS);
488 template <
typename GUM_SCALAR,
489 template <
typename >
class ICPTGenerator,
490 template <
typename >
class ICPTDisturber >
496 auto dag_tmp = this->
dag_;
498 this->
dag_.addArc(j, i);
504 template <
typename GUM_SCALAR,
505 template <
typename >
class ICPTGenerator,
506 template <
typename >
class ICPTDisturber >
508 return this->
dag_.size() - 1 == this->
dag_.sizeArcs();
511 template <
typename GUM_SCALAR,
512 template <
typename >
class ICPTGenerator,
513 template <
typename >
class ICPTDisturber >
516 if (this->
dag_.existsArc(i, j) || this->dag_.existsArc(j, i))
return true;
521 for (
auto par: this->
dag_.parents(i)) {
525 for (
auto chi: this->
dag_.children(i)) {
533 template <
typename GUM_SCALAR,
534 template <
typename >
class ICPTGenerator,
535 template <
typename >
class ICPTDisturber >
540 if (this->
dag_.existsArc(i, j) || this->dag_.existsArc(j, i))
return true;
544 for (
auto par: this->
dag_.parents(i)) {
548 for (
auto chi: this->
dag_.children(i)) {
556 template <
typename GUM_SCALAR,
557 template <
typename >
class ICPTGenerator,
558 template <
typename >
class ICPTDisturber >
562 if (this->
dag_.existsArc(tail, head))
return true;
567 for (
auto node: this->
dag_.children(tail)) {
575 template <
typename GUM_SCALAR,
576 template <
typename >
class ICPTGenerator,
577 template <
typename >
class ICPTDisturber >
582 if (this->
dag_.existsArc(tail, head))
return true;
586 for (
auto node: this->
dag_.children(tail)) {
594 template <
typename GUM_SCALAR,
595 template <
typename >
class ICPTGenerator,
596 template <
typename >
class ICPTDisturber >
601 template <
typename GUM_SCALAR,
602 template <
typename >
class ICPTGenerator,
603 template <
typename >
class ICPTDisturber >
608 template <
typename GUM_SCALAR,
609 template <
typename >
class ICPTGenerator,
610 template <
typename >
class ICPTDisturber >
615 template <
typename GUM_SCALAR,
616 template <
typename >
class ICPTGenerator,
617 template <
typename >
class ICPTDisturber >
623 template <
typename GUM_SCALAR,
624 template <
typename >
class ICPTGenerator,
625 template <
typename >
class ICPTDisturber >
631 "the sum of the probabilities p and q must be at most equal to 100");
634 template <
typename GUM_SCALAR,
635 template <
typename >
class ICPTGenerator,
636 template <
typename >
class ICPTDisturber >
642 "the sum of the probabilities p and q must be at most equal to 100");
Class for generating Bayesian networks.using MC algorithm cf.
The base class for all directed edges.
Exception base for argument error.
Class representing a Bayesian network.
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
virtual Size domainSize() const =0
void fromDAG(BayesNet< GUM_SCALAR > &bayesNet)
void fillCPT(BayesNet< GUM_SCALAR > &bn) const
void _jump_multi_()
In the case that the graph is a multiconnect graph, the function will choose randomly two nodes and w...
void _createTree_(Size BNSize)
The function that randomly generate a simple tree.
bool _is_connected_(const NodeId i, const NodeId j, NodeSet &excluded)
NodeId _createPartTree_(Size BNSize, Idx &n)
The internal function used by createTree that randomly generate a simple tree.
void setQ(Idx q)
Modifies the value of the probability q imposed on the BayesNetGenerator.
void _transformPoly_(Idx nbiter)
The function that randomly change the simple tree into a polytree.
void _jump_poly_()
In the case that the graph is a polytree, the function will add a random arc by the use of the functi...
void _chooseCloseNodes_(NodeId &i, NodeId &j)
The function that randomly choose two neighbours nodes of the graph.
bool _connect_(NodeId i, NodeId j)
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 _PMMx_poly_()
In the case that the graph is a polytree, the function will, according to the probability p and q,...
bool _directedPath_(NodeId tail, NodeId head)
void _eraseArc_(NodeId i, NodeId j, bool mustbeconnex=true)
The function that will remove the arc between node i and node j.
void setIteration(Size iteration)
Modifies the value of the number of iterations impose on the BayesNetGenerator.
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
void generateBN(BayesNet< GUM_SCALAR > &bayesNet) override
Generates a random Bayesian network.
virtual bool _checkConditions_()
The boolean function that will assert the respect of the constraint.
MCBayesNetGenerator(Size nbrNodes, Size maxArcs, Idx maxModality=2, Size iteration=NB_INIT_ITERATIONS, Idx p=30, Idx q=40)
Constructor.
void setP(Idx p)
Modifies the value of the probability p imposed on the BayesNetGenerator.
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator.
void _Add_and_Remove_()
The function will remove and add a random arc changing the topology of the graph but asserting its co...
void _chooseNodes_(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
Idx p() const
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
~MCBayesNetGenerator() override
Destructor.
Exception : operation not allowed.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
Class used to compute response times for benchmark purposes.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
gum is the global namespace for all aGrUM entities
gum::Size getMaxModality(gum::BayesNet< GUM_SCALAR > &bayesNet)