52#define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
55 template < GUM_Numeric GUM_SCALAR >
59 for (
auto node: bayesNet.
nodes())
68 template < GUM_Numeric GUM_SCALAR,
69 template <
typename >
class ICPTGenerator,
70 template <
typename >
class ICPTDisturber >
80 "the sum of the probabilities p and q must be at most equal to 100");
90 template <
typename >
class ICPTGenerator,
91 template <
typename >
class ICPTDisturber >
93 BayesNet< GUM_SCALAR > bayesNet,
98 (
Size)(bayesNet.sizeArcs() * 1.1),
107 template <
typename >
class ICPTGenerator,
108 template <
typename >
class ICPTDisturber >
114 template <
typename >
class ICPTGenerator,
115 template <
typename >
class ICPTDisturber >
117 BayesNet< GUM_SCALAR >& bayesNet) {
181 template <
typename >
class ICPTGenerator,
182 template <
typename >
class ICPTDisturber >
191 template <
typename >
class ICPTGenerator,
192 template <
typename >
class ICPTDisturber >
203 tmp_dag = this->
dag_;
207 this->
dag_ = tmp_dag;
214 this->
dag_ = tmp_dag;
216 tmp_dag = this->
dag_;
222 tmp_dag = this->
dag_;
226 this->dag_ = tmp_dag;
234 template <
typename >
class ICPTGenerator,
235 template <
typename >
class ICPTDisturber >
248 tmp_dag = this->
dag_;
252 this->
dag_ = tmp_dag;
255 tmp_dag = this->
dag_;
258 this->
dag_ = tmp_dag;
263 tmp_dag = this->
dag_;
269 this->dag_ = tmp_dag;
275 template < GUM_Numeric GUM_SCALAR,
276 template <
typename >
class ICPTGenerator,
277 template <
typename >
class ICPTDisturber >
281 if (this->
dag_.existsArc(i, j)) {
285 }
else _insertArc_(i, j);
288 template < GUM_Numeric GUM_SCALAR,
289 template <
typename >
class ICPTGenerator,
290 template <
typename >
class ICPTDisturber >
295 if (this->
dag_.existsArc(i, j) || this->dag_.existsArc(j, i)) {
308 for (
auto node: this->
dag_.parents(j)) {
313 this->
dag_.eraseArc(
Arc(node, j));
314 this->
dag_.addArc(head, tail);
319 for (
auto node: this->dag_.children(j)) {
324 this->
dag_.eraseArc(
Arc{j, node});
325 this->
dag_.addArc(head, tail);
333 template <
typename >
class ICPTGenerator,
334 template <
typename >
class ICPTDisturber >
343 template <
typename >
class ICPTGenerator,
344 template <
typename >
class ICPTDisturber >
353 template <
typename >
class ICPTGenerator,
354 template <
typename >
class ICPTDisturber >
365 this->
dag_.addArc(i, j);
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 < GUM_Numeric GUM_SCALAR,
395 template <
typename >
class ICPTGenerator,
396 template <
typename >
class ICPTDisturber >
399 if (this->
dag_.size() < 3) {
410 template <
typename >
class ICPTGenerator,
411 template <
typename >
class ICPTDisturber >
418 if (this->
dag_.parents(temp).size()) {
420 auto it = this->
dag_.parents(j).begin();
428 }
else if (this->dag_.children(temp).size()) {
430 auto it = this->dag_.children(i).begin();
439 GUM_ERROR(FatalError,
"Sorry Misconstructed BN because of isolated node.")
444 template <
typename >
class ICPTGenerator,
445 template <
typename >
class ICPTDisturber >
449 Size maxNodes = BNSize - 1;
454 maxNodes = maxNodes - SubG;
456 this->
dag_.addArc(root, rootS);
461 template <
typename >
class ICPTGenerator,
462 template <
typename >
class ICPTDisturber >
473 Size maxNodes = BNSize - 1;
478 maxNodes = maxNodes - SubG;
480 this->
dag_.addArc(root, rootS);
488 template <
typename >
class ICPTGenerator,
489 template <
typename >
class ICPTDisturber >
495 auto dag_tmp = this->
dag_;
497 this->
dag_.addArc(j, i);
504 template <
typename >
class ICPTGenerator,
505 template <
typename >
class ICPTDisturber >
507 return this->
dag_.size() - 1 == this->
dag_.sizeArcs();
511 template <
typename >
class ICPTGenerator,
512 template <
typename >
class ICPTDisturber >
515 if (this->
dag_.existsArc(i, j) || this->dag_.existsArc(j, i))
return true;
520 for (
auto par: this->
dag_.parents(i)) {
524 for (
auto chi: this->
dag_.children(i)) {
533 template <
typename >
class ICPTGenerator,
534 template <
typename >
class ICPTDisturber >
539 if (this->
dag_.existsArc(i, j) || this->dag_.existsArc(j, i))
return true;
543 for (
auto par: this->
dag_.parents(i)) {
547 for (
auto chi: this->
dag_.children(i)) {
556 template <
typename >
class ICPTGenerator,
557 template <
typename >
class ICPTDisturber >
561 if (this->
dag_.existsArc(tail, head))
return true;
566 for (
auto node: this->
dag_.children(tail)) {
575 template <
typename >
class ICPTGenerator,
576 template <
typename >
class ICPTDisturber >
581 if (this->
dag_.existsArc(tail, head))
return true;
585 for (
auto node: this->
dag_.children(tail)) {
594 template <
typename >
class ICPTGenerator,
595 template <
typename >
class ICPTDisturber >
601 template <
typename >
class ICPTGenerator,
602 template <
typename >
class ICPTDisturber >
608 template <
typename >
class ICPTGenerator,
609 template <
typename >
class ICPTDisturber >
615 template <
typename >
class ICPTGenerator,
616 template <
typename >
class ICPTDisturber >
623 template <
typename >
class ICPTGenerator,
624 template <
typename >
class ICPTDisturber >
630 "the sum of the probabilities p and q must be at most equal to 100");
634 template <
typename >
class ICPTGenerator,
635 template <
typename >
class ICPTDisturber >
641 "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(std::string_view name) const
Returns a gum::DiscreteVariable given its name in the gum::BayesNet.
const NodeGraphPart & nodes() const final
Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding vari...
virtual Size domainSize() const =0
void fromDAG(BayesNet< GUM_SCALAR > &bayesNet)
void fillCPT(BayesNet< GUM_SCALAR > &bn) const
Idx p() const
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
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 _chooseCloseNodes_(NodeId &i, NodeId &j)
The function that randomly choose two neighbours nodes of the graph.
bool _connect_(NodeId i, NodeId j)
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 generateBN(BayesNet< GUM_SCALAR > &bayesNet) override
Generates a random Bayesian network.
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.
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
void _insertArc_(NodeId i, NodeId j)
virtual bool _checkConditions_()
The boolean function that will assert the respect of the constraint.
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator.
void setIteration(Size iteration)
Modifies the value of the number of iterations impose on the BayesNetGenerator.
void _chooseNodes_(NodeId &i, NodeId &j)
The function that randomly choose two nodes of the graph.
void _eraseArc_(NodeId i, NodeId j, bool mustbeconnex=true)
The function that will remove the arc between node i and node j.
~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.
Complete concept for GUM_SCALAR template parameter.
#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)