aGrUM  0.18.1
a C++ library for (probabilistic) graphical models
BayesNet_tpl.h
Go to the documentation of this file.
1 
30 #include <limits>
31 #include <set>
32 
33 #include <agrum/BN/BayesNet.h>
34 
38 
49 
53 
55 
58 
59 namespace gum {
60  template < typename GUM_SCALAR >
62  std::string node,
63  gum::Size default_domain_size) {
64  std::string name = node;
65  auto ds = default_domain_size;
66  long range_min = 0;
67  long range_max = long(ds) - 1;
68  std::vector< std::string > labels;
69  std::vector< GUM_SCALAR > ticks;
70 
71  if (*(node.rbegin()) == ']') {
72  auto posBrack = node.find('[');
73  if (posBrack != std::string::npos) {
74  name = node.substr(0, posBrack);
75  const auto& s_args = node.substr(posBrack + 1, node.size() - posBrack - 2);
76  const auto& args = split(s_args, ",");
77  if (args.size() == 0) { // n[]
78  GUM_ERROR(InvalidArgument, "Empty range for variable " << node)
79  } else if (args.size() == 1) { // n[4]
80  ds = static_cast< Size >(std::stoi(args[0]));
81  range_min = 0;
82  range_max = long(ds) - 1;
83  } else if (args.size() == 2) { // n[5,10]
84  range_min = std::stol(args[0]);
85  range_max = std::stol(args[1]);
86  if (1 + range_max - range_min < 2) {
87  GUM_ERROR(InvalidArgument, "Invalid range for variable " << node);
88  }
89  ds = static_cast< Size >(1 + range_max - range_min);
90  } else { // n[3.14,5,10,12]
91  for (const auto& tick: args) {
92  ticks.push_back(static_cast< GUM_SCALAR >(std::atof(tick.c_str())));
93  }
94  ds = static_cast< Size >(args.size() - 1);
95  }
96  }
97  } else if (*(node.rbegin()) == '}') { // node like "n{one|two|three}"
98  auto posBrack = node.find('{');
99  if (posBrack != std::string::npos) {
100  name = node.substr(0, posBrack);
101  labels = split(node.substr(posBrack + 1, node.size() - posBrack - 2), "|");
102  if (labels.size() < 2) {
103  GUM_ERROR(InvalidArgument, "Not enough labels in node " << node);
104  }
105  if (!hasUniqueElts(labels)) {
106  GUM_ERROR(InvalidArgument, "Duplicate labels in node " << node);
107  }
108  ds = static_cast< Size >(labels.size());
109  }
110  }
111 
112  if (ds == 0) {
113  GUM_ERROR(InvalidArgument, "No value for variable " << name << ".");
114  } else if (ds == 1) {
116  "Only one value for variable " << name
117  << " (2 at least are needed).");
118  }
119 
120  // now we add the node in the BN
121  NodeId idVar;
122  try {
123  idVar = bn.idFromName(name);
124  } catch (gum::NotFound&) {
125  if (!labels.empty()) {
126  idVar = bn.add(LabelizedVariable(name, name, labels));
127  } else if (!ticks.empty()) {
128  idVar = bn.add(DiscretizedVariable< GUM_SCALAR >(name, name, ticks));
129  } else {
130  idVar = bn.add(RangeVariable(name, name, range_min, range_max));
131  }
132  }
133 
134  return idVar;
135  }
136 
137  template < typename GUM_SCALAR >
139  BayesNet< GUM_SCALAR >::fastPrototype(const std::string& dotlike,
140  Size domainSize) {
142 
143 
144  for (const auto& chaine: split(dotlike, ";")) {
145  NodeId lastId = 0;
146  bool notfirst = false;
147  for (const auto& souschaine: split(chaine, "->")) {
148  bool forward = true;
149  for (const auto& node: split(souschaine, "<-")) {
150  auto idVar = build_node(bn, node, domainSize);
151  if (notfirst) {
152  if (forward) {
153  bn.addArc(lastId, idVar);
154  forward = false;
155  } else {
156  bn.addArc(idVar, lastId);
157  }
158  } else {
159  notfirst = true;
160  forward = false;
161  }
162  lastId = idVar;
163  }
164  }
165  }
166  bn.generateCPTs();
167  bn.setProperty("name", "fastPrototype");
168  return bn;
169  }
170 
171  template < typename GUM_SCALAR >
172  INLINE BayesNet< GUM_SCALAR >::BayesNet() : IBayesNet< GUM_SCALAR >() {
173  GUM_CONSTRUCTOR(BayesNet);
174  }
175 
176  template < typename GUM_SCALAR >
177  INLINE BayesNet< GUM_SCALAR >::BayesNet(std::string name) :
178  IBayesNet< GUM_SCALAR >(name) {
179  GUM_CONSTRUCTOR(BayesNet);
180  }
181 
182  template < typename GUM_SCALAR >
184  IBayesNet< GUM_SCALAR >(source), varMap__(source.varMap__) {
185  GUM_CONS_CPY(BayesNet);
186 
187  copyPotentials__(source);
188  }
189 
190  template < typename GUM_SCALAR >
193  if (this != &source) {
195  varMap__ = source.varMap__;
196 
197  clearPotentials__();
198  copyPotentials__(source);
199  }
200 
201  return *this;
202  }
203 
204  template < typename GUM_SCALAR >
206  GUM_DESTRUCTOR(BayesNet);
207  for (const auto p: probaMap__) {
208  delete p.second;
209  }
210  }
211 
212  template < typename GUM_SCALAR >
213  INLINE const DiscreteVariable&
215  return varMap__.get(id);
216  }
217 
218  template < typename GUM_SCALAR >
219  INLINE void
221  const std::string& new_name) {
222  varMap__.changeName(id, new_name);
223  }
224 
225  template < typename GUM_SCALAR >
227  NodeId id, const std::string& old_label, const std::string& new_label) {
228  if (variable(id).varType() != VarType::Labelized) {
229  GUM_ERROR(NotFound, "Variable " << id << " is not a LabelizedVariable.");
230  }
231  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(
232  const_cast< DiscreteVariable* >(&variable(id)));
233 
234  var->changeLabel(var->posLabel(old_label), new_label);
235  }
236 
237 
238  template < typename GUM_SCALAR >
240  return varMap__.get(var);
241  }
242 
243  template < typename GUM_SCALAR >
245  auto ptr = new MultiDimArray< GUM_SCALAR >();
246  NodeId res = 0;
247 
248  try {
249  res = add(var, ptr);
250 
251  } catch (Exception&) {
252  delete ptr;
253  throw;
254  }
255 
256  return res;
257  }
258 
259  template < typename GUM_SCALAR >
260  INLINE NodeId BayesNet< GUM_SCALAR >::add(const std::string& name,
261  unsigned int nbrmod) {
262  if (nbrmod < 2) {
264  "Variable " << name << "needs more than " << nbrmod
265  << " modalities");
266  }
267 
268  RangeVariable v(name, name, 0, nbrmod - 1);
269  return add(v);
270  }
271 
272  template < typename GUM_SCALAR >
275  NodeId proposedId = dag().nextNodeId();
276  NodeId res = 0;
277 
278  res = add(var, aContent, proposedId);
279 
280  return res;
281  }
282 
283  template < typename GUM_SCALAR >
285  NodeId id) {
286  auto ptr = new MultiDimArray< GUM_SCALAR >();
287  NodeId res = 0;
288 
289  try {
290  res = add(var, ptr, id);
291 
292  } catch (Exception&) {
293  delete ptr;
294  throw;
295  }
296 
297  return res;
298  }
299 
300  template < typename GUM_SCALAR >
301  NodeId
304  NodeId id) {
305  varMap__.insert(id, var);
306  this->dag_.addNodeWithId(id);
307 
308  auto cpt = new Potential< GUM_SCALAR >(aContent);
309  (*cpt) << variable(id);
310  probaMap__.insert(id, cpt);
311  return id;
312  }
313 
314  template < typename GUM_SCALAR >
315  INLINE NodeId BayesNet< GUM_SCALAR >::idFromName(const std::string& name) const {
316  return varMap__.idFromName(name);
317  }
318 
319  template < typename GUM_SCALAR >
320  INLINE const DiscreteVariable&
321  BayesNet< GUM_SCALAR >::variableFromName(const std::string& name) const {
322  return varMap__.variableFromName(name);
323  }
324 
325  template < typename GUM_SCALAR >
326  INLINE const Potential< GUM_SCALAR >&
328  return *(probaMap__[varId]);
329  }
330 
331  template < typename GUM_SCALAR >
333  return varMap__;
334  }
335 
336  template < typename GUM_SCALAR >
338  erase(varMap__.get(var));
339  }
340 
341  template < typename GUM_SCALAR >
343  if (varMap__.exists(varId)) {
344  // Reduce the variable child's CPT
345  const NodeSet& children = this->children(varId);
346 
347  for (const auto c: children) {
348  probaMap__[c]->erase(variable(varId));
349  }
350 
351  delete probaMap__[varId];
352 
353  probaMap__.erase(varId);
354  varMap__.erase(varId);
355  this->dag_.eraseNode(varId);
356  }
357  }
358 
359  template < typename GUM_SCALAR >
361  if (!this->empty()) {
362  auto l = this->nodes();
363  for (const auto no: l) {
364  this->erase(no);
365  }
366  }
367  }
368 
369  template < typename GUM_SCALAR >
370  INLINE void BayesNet< GUM_SCALAR >::addArc(NodeId tail, NodeId head) {
371  if (this->dag_.existsArc(tail, head)) {
373  "The arc (" << tail << "," << head << ") already exists.")
374  }
375 
376  this->dag_.addArc(tail, head);
377  // Add parent in the child's CPT
378  (*(probaMap__[head])) << variable(tail);
379  }
380 
381  template < typename GUM_SCALAR >
382  INLINE void BayesNet< GUM_SCALAR >::addArc(const std::string& tail,
383  const std::string& head) {
384  try {
385  addArc(this->idFromName(tail), this->idFromName(head));
386  } catch (DuplicateElement) {
388  "The arc " << tail << "->" << head << " already exists.")
389  }
390  }
391 
392  template < typename GUM_SCALAR >
393  INLINE void BayesNet< GUM_SCALAR >::eraseArc(const Arc& arc) {
394  if (varMap__.exists(arc.tail()) && varMap__.exists(arc.head())) {
395  NodeId head = arc.head(), tail = arc.tail();
396  this->dag_.eraseArc(arc);
397  // Remove parent froms child's CPT
398  (*(probaMap__[head])) >> variable(tail);
399  }
400  }
401 
402  template < typename GUM_SCALAR >
404  eraseArc(Arc(tail, head));
405  }
406 
407  template < typename GUM_SCALAR >
409  // check that the arc exsists
410  if (!varMap__.exists(arc.tail()) || !varMap__.exists(arc.head())
411  || !dag().existsArc(arc)) {
412  GUM_ERROR(InvalidArc, "a nonexisting arc cannot be reversed");
413  }
414 
415  NodeId tail = arc.tail(), head = arc.head();
416 
417  // check that the reversal does not induce a cycle
418  try {
419  DAG d = dag();
420  d.eraseArc(arc);
421  d.addArc(head, tail);
422  } catch (Exception&) {
423  GUM_ERROR(InvalidArc, "this arc reversal would induce a directed cycle");
424  }
425 
426  // with the same notations as Shachter (1986), "evaluating influence
427  // diagrams",
428  // p.878, we shall first compute the product of probabilities:
429  // pi_j^old (x_j | x_c^old(j) ) * pi_i^old (x_i | x_c^old(i) )
430  Potential< GUM_SCALAR > prod{cpt(tail) * cpt(head)};
431 
432  // modify the topology of the graph: add to tail all the parents of head
433  // and add to head all the parents of tail
434  beginTopologyTransformation();
435  NodeSet new_parents;
436  for (const auto node: this->parents(tail))
437  new_parents.insert(node);
438  for (const auto node: this->parents(head))
439  new_parents.insert(node);
440  // remove arc (head, tail)
441  eraseArc(arc);
442 
443  // add the necessary arcs to the tail
444  for (const auto p: new_parents) {
445  if ((p != tail) && !dag().existsArc(p, tail)) { addArc(p, tail); }
446  }
447 
448  addArc(head, tail);
449  // add the necessary arcs to the head
450  new_parents.erase(tail);
451 
452  for (const auto p: new_parents) {
453  if ((p != head) && !dag().existsArc(p, head)) { addArc(p, head); }
454  }
455 
456  endTopologyTransformation();
457 
458  // update the conditional distributions of head and tail
460  del_vars << &(variable(tail));
461  Potential< GUM_SCALAR > new_cpt_head =
462  prod.margSumOut(del_vars).putFirst(&variable(head));
463 
464  auto& cpt_head = const_cast< Potential< GUM_SCALAR >& >(cpt(head));
465  cpt_head = std::move(new_cpt_head);
466 
467  Potential< GUM_SCALAR > new_cpt_tail{
468  (prod / cpt_head).putFirst(&variable(tail))};
469  auto& cpt_tail = const_cast< Potential< GUM_SCALAR >& >(cpt(tail));
470  cpt_tail = std::move(new_cpt_tail);
471  }
472 
473  template < typename GUM_SCALAR >
475  reverseArc(Arc(tail, head));
476  }
477 
478 
479  //==============================================
480  // Aggregators
481  //=============================================
482  template < typename GUM_SCALAR >
484  return add(var, new aggregator::Amplitude< GUM_SCALAR >());
485  }
486 
487  template < typename GUM_SCALAR >
489  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an AND has to be boolean");
490 
491  return add(var, new aggregator::And< GUM_SCALAR >());
492  }
493 
494  template < typename GUM_SCALAR >
496  Idx value) {
497  return add(var, new aggregator::Count< GUM_SCALAR >(value));
498  }
499 
500  template < typename GUM_SCALAR >
502  Idx value) {
503  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean");
504 
505  return add(var, new aggregator::Exists< GUM_SCALAR >(value));
506  }
507 
508  template < typename GUM_SCALAR >
510  Idx value) {
511  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean");
512 
513  return add(var, new aggregator::Forall< GUM_SCALAR >(value));
514  }
515 
516  template < typename GUM_SCALAR >
518  return add(var, new aggregator::Max< GUM_SCALAR >());
519  }
520 
521  template < typename GUM_SCALAR >
523  return add(var, new aggregator::Median< GUM_SCALAR >());
524  }
525 
526  template < typename GUM_SCALAR >
528  return add(var, new aggregator::Min< GUM_SCALAR >());
529  }
530 
531  template < typename GUM_SCALAR >
533  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an OR has to be boolean");
534 
535  return add(var, new aggregator::Or< GUM_SCALAR >());
536  }
537 
538  template < typename GUM_SCALAR >
540  return add(var, new aggregator::Sum< GUM_SCALAR >());
541  }
542 
543  //================================
544  // ICIModels
545  //================================
546  template < typename GUM_SCALAR >
548  GUM_SCALAR external_weight) {
549  return addNoisyORCompound(var, external_weight);
550  }
551 
552  template < typename GUM_SCALAR >
554  const DiscreteVariable& var, GUM_SCALAR external_weight) {
555  return add(var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight));
556  }
557 
558  template < typename GUM_SCALAR >
560  GUM_SCALAR external_weight) {
561  return add(var, new MultiDimNoisyORNet< GUM_SCALAR >(external_weight));
562  }
563 
564  template < typename GUM_SCALAR >
566  GUM_SCALAR external_weight) {
567  return add(var, new MultiDimNoisyAND< GUM_SCALAR >(external_weight));
568  }
569 
570  template < typename GUM_SCALAR >
572  GUM_SCALAR external_weight) {
573  return add(var, new MultiDimLogit< GUM_SCALAR >(external_weight));
574  }
575 
576  template < typename GUM_SCALAR >
578  GUM_SCALAR external_weight,
579  NodeId id) {
580  return addNoisyORCompound(var, external_weight, id);
581  }
582 
583  template < typename GUM_SCALAR >
585  GUM_SCALAR external_weight,
586  NodeId id) {
587  return add(var, new MultiDimNoisyAND< GUM_SCALAR >(external_weight), id);
588  }
589 
590  template < typename GUM_SCALAR >
592  GUM_SCALAR external_weight,
593  NodeId id) {
594  return add(var, new MultiDimLogit< GUM_SCALAR >(external_weight), id);
595  }
596 
597  template < typename GUM_SCALAR >
599  const DiscreteVariable& var, GUM_SCALAR external_weight, NodeId id) {
600  return add(
601  var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight), id);
602  }
603 
604  template < typename GUM_SCALAR >
606  GUM_SCALAR external_weight,
607  NodeId id) {
608  return add(var, new MultiDimNoisyORNet< GUM_SCALAR >(external_weight), id);
609  }
610 
611  template < typename GUM_SCALAR >
613  NodeId head,
614  GUM_SCALAR causalWeight) {
615  auto* CImodel =
616  dynamic_cast< const MultiDimICIModel< GUM_SCALAR >* >(cpt(head).content());
617 
618  if (CImodel != 0) {
619  // or is OK
620  addArc(tail, head);
621 
622  CImodel->causalWeight(variable(tail), causalWeight);
623  } else {
625  "Head variable (" << variable(head).name()
626  << ") is not a CIModel variable !");
627  }
628  }
629 
630  template < typename GUM_SCALAR >
631  INLINE std::ostream& operator<<(std::ostream& output,
632  const BayesNet< GUM_SCALAR >& bn) {
633  output << bn.toString();
634  return output;
635  }
636 
638  template < typename GUM_SCALAR >
640  for (const auto node: nodes())
641  probaMap__[node]->beginMultipleChanges();
642  }
643 
645  template < typename GUM_SCALAR >
647  for (const auto node: nodes())
648  probaMap__[node]->endMultipleChanges();
649  }
650 
652  template < typename GUM_SCALAR >
654  // Removing previous potentials
655  for (const auto& elt: probaMap__) {
656  delete elt.second;
657  }
658 
659  probaMap__.clear();
660  }
661 
663  template < typename GUM_SCALAR >
665  const BayesNet< GUM_SCALAR >& source) {
666  // Copying potentials
667 
668  for (const auto src: source.probaMap__) {
669  // First we build the node's CPT
671  copy_array->beginMultipleChanges();
672  for (gum::Idx i = 0; i < src.second->nbrDim(); i++) {
673  (*copy_array) << variableFromName(src.second->variable(i).name());
674  }
675  copy_array->endMultipleChanges();
676  copy_array->copyFrom(*(src.second));
677 
678  // We add the CPT to the CPT's hashmap
679  probaMap__.insert(src.first, copy_array);
680  }
681  }
682 
683  template < typename GUM_SCALAR >
685  for (const auto node: nodes())
686  generateCPT(node);
687  }
688 
689  template < typename GUM_SCALAR >
690  INLINE void BayesNet< GUM_SCALAR >::generateCPT(NodeId node) const {
692 
693  generator.generateCPT(cpt(node).pos(variable(node)), cpt(node));
694  }
695 
696  template < typename GUM_SCALAR >
698  Potential< GUM_SCALAR >* newPot) {
699  if (cpt(id).nbrDim() != newPot->nbrDim()) {
701  "cannot exchange potentials with different "
702  "dimensions for variable with id "
703  << id);
704  }
705 
706  for (Idx i = 0; i < cpt(id).nbrDim(); i++) {
707  if (&cpt(id).variable(i) != &(newPot->variable(i))) {
709  "cannot exchange potentials because, for variable with id "
710  << id << ", dimension " << i << " differs. ");
711  }
712  }
713 
714  unsafeChangePotential_(id, newPot);
715  }
716 
717  template < typename GUM_SCALAR >
719  NodeId id, Potential< GUM_SCALAR >* newPot) {
720  delete probaMap__[id];
721  probaMap__[id] = newPot;
722  }
723 
724  template < typename GUM_SCALAR >
725  void BayesNet< GUM_SCALAR >::changePotential(const std::string& name,
726  Potential< GUM_SCALAR >* newPot) {
727  changePotential(idFromName(name), newPot);
728  }
729 
730 } /* namespace gum */
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:370
Noisy OR representation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
Class representing a Bayesian Network.
Definition: BayesNet.h:78
virtual void beginMultipleChanges() final
Default implementation of MultiDimContainer::set().
Sum aggregator.
Definition: sum.h:52
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
void changeLabel(Idx pos, const std::string &aLabel) const
change a label for this index
bool hasUniqueElts(std::vector< T > const &x)
class LabelizedVariable
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
or aggregator
Definition: or.h:56
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:244
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
Class for discretized random variable.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Container used to map discrete variables with nodes.
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:172
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
NodeId build_node(gum::BayesNet< GUM_SCALAR > &bn, std::string node, gum::Size default_domain_size)
Definition: BayesNet_tpl.h:61
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
void clear()
clear the whole Bayes net *
Definition: BayesNet_tpl.h:360
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this GraphicalModel.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Base class for discrete random variable.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:62
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Definition: agrum.h:25
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
NodeId head() const
returns the head of the arc
static BayesNet< GUM_SCALAR > fastPrototype(const std::string &dotlike, Size domainSize=2)
Create a Bayesian network with a dot-like syntax which specifies:
Definition: BayesNet_tpl.h:139
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
forall aggregator
Definition: forall.h:55
const DiscreteVariable & variableFromName(const std::string &name) const final
Returns a variable given its name in the gum::BayesNet.
Definition: BayesNet_tpl.h:321
virtual Size domainSize() const =0
And aggregator.
Definition: and.h:55
Logit representation.
Definition: multiDimLogit.h:53
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
exists aggregator
Definition: exists.h:54
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
abstract class for Conditional Indepency Models
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
NodeProperty< Potential< GUM_SCALAR > *> probaMap__
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:671
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
Idx posLabel(const std::string &label) const
return the pos from label
Multidimensional matrix stored as an array in memory.
Definition: multiDimArray.h:54
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:43
<agrum/BN/generator/simpleCPTGenerator.h>
Noisy AND representation.
void generateCPTs() const
randomly generates CPTs for a given structure
Definition: BayesNet_tpl.h:684
Defines a discrete random variable over an integer interval.
Definition: rangeVariable.h:54
VariableNodeMap varMap__
the map between variable and id
Definition: BayesNet.h:668
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Basic copy of a MultiDimContainer.
INLINE std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:631
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Potential< GUM_SCALAR > margSumOut(const Set< const DiscreteVariable * > &del_vars) const
Projection using sum as operation (and implementation-optimized operations)
std::string toString() const
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
<agrum/tools/multidim/multiDimImplementation.h>
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Size Idx
Type for indexes.
Definition: types.h:53
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
max aggregator
Definition: max.h:54
median aggregator
Definition: median.h:60
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
NodeId idFromName(const std::string &name) const final
Returns a variable&#39;s id given its name in the gum::BayesNet.
Definition: BayesNet_tpl.h:315
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Base class for dag.
Definition: DAG.h:102
amplitude aggregator
Definition: amplitude.h:55
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
void generateCPT(const Idx &varId, const Potential< GUM_SCALAR > &cpt) override
Generates a CPT using floats.
min aggregator
Definition: min.h:53
NodeId tail() const
returns the tail of the arc
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
count aggregator
Definition: count.h:57