aGrUM  0.17.2
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 
48 
52 
54 
57 
58 namespace gum {
59  template < typename GUM_SCALAR >
61  std::string node,
62  gum::Size default_domain_size) {
63  std::string name = node;
64  auto ds = default_domain_size;
65  long range_min = 0;
66  long range_max = long(ds) - 1;
67  std::vector< std::string > labels;
68  std::vector< GUM_SCALAR > ticks;
69 
70  if (*(node.rbegin()) == ']') {
71  auto posBrack = node.find('[');
72  if (posBrack != std::string::npos) {
73  name = node.substr(0, posBrack);
74  const auto& s_args = node.substr(posBrack + 1, node.size() - posBrack - 2);
75  const auto& args = split(s_args, ",");
76  if (args.size() == 0) { // n[]
77  GUM_ERROR(InvalidArgument, "Empty range for variable " << node)
78  } else if (args.size() == 1) { // n[4]
79  ds = static_cast< Size >(std::stoi(args[0]));
80  range_min = 0;
81  range_max = long(ds) - 1;
82  } else if (args.size() == 2) { // n[5,10]
83  range_min = std::stol(args[0]);
84  range_max = std::stol(args[1]);
85  if (1 + range_max - range_min < 2) {
86  GUM_ERROR(InvalidArgument, "Invalid range for variable " << node);
87  }
88  ds = static_cast< Size >(1 + range_max - range_min);
89  } else { // n[3.14,5,10,12]
90  for (const auto& tick: args) {
91  ticks.push_back(static_cast< GUM_SCALAR >(std::atof(tick.c_str())));
92  }
93  ds = static_cast< Size >(args.size() - 1);
94  }
95  }
96  } else if (*(node.rbegin()) == '}') { // node like "n{one|two|three}"
97  auto posBrack = node.find('{');
98  if (posBrack != std::string::npos) {
99  name = node.substr(0, posBrack);
100  labels = split(node.substr(posBrack + 1, node.size() - posBrack - 2), "|");
101  if (labels.size() < 2) {
102  GUM_ERROR(InvalidArgument, "Not enough labels in node " << node);
103  }
104  if (!hasUniqueElts(labels)) {
105  GUM_ERROR(InvalidArgument, "Duplicate labels in node " << node);
106  }
107  ds = static_cast< Size >(labels.size());
108  }
109  }
110 
111  if (ds == 0) {
112  GUM_ERROR(InvalidArgument, "No value for variable " << name << ".");
113  } else if (ds == 1) {
115  "Only one value for variable " << name
116  << " (2 at least are needed).");
117  }
118 
119  // now we add the node in the BN
120  NodeId idVar;
121  try {
122  idVar = bn.idFromName(name);
123  } catch (gum::NotFound&) {
124  if (!labels.empty()) {
125  idVar = bn.add(LabelizedVariable(name, name, labels));
126  } else if (!ticks.empty()) {
127  idVar = bn.add(DiscretizedVariable< GUM_SCALAR >(name, name, ticks));
128  } else {
129  idVar = bn.add(RangeVariable(name, name, range_min, range_max));
130  }
131  }
132 
133  return idVar;
134  }
135 
136  template < typename GUM_SCALAR >
138  BayesNet< GUM_SCALAR >::fastPrototype(const std::string& dotlike,
139  Size domainSize) {
141 
142 
143  for (const auto& chaine: split(dotlike, ";")) {
144  NodeId lastId = 0;
145  bool notfirst = false;
146  for (const auto& souschaine: split(chaine, "->")) {
147  bool forward = true;
148  for (const auto& node: split(souschaine, "<-")) {
149  auto idVar = build_node(bn, node, domainSize);
150  if (notfirst) {
151  if (forward) {
152  bn.addArc(lastId, idVar);
153  forward = false;
154  } else {
155  bn.addArc(idVar, lastId);
156  }
157  } else {
158  notfirst = true;
159  forward = false;
160  }
161  lastId = idVar;
162  }
163  }
164  }
165  bn.generateCPTs();
166  bn.setProperty("name", "fastPrototype");
167  return bn;
168  }
169 
170  template < typename GUM_SCALAR >
171  INLINE BayesNet< GUM_SCALAR >::BayesNet() : IBayesNet< GUM_SCALAR >() {
172  GUM_CONSTRUCTOR(BayesNet);
173  }
174 
175  template < typename GUM_SCALAR >
176  INLINE BayesNet< GUM_SCALAR >::BayesNet(std::string name) :
177  IBayesNet< GUM_SCALAR >(name) {
178  GUM_CONSTRUCTOR(BayesNet);
179  }
180 
181  template < typename GUM_SCALAR >
183  IBayesNet< GUM_SCALAR >(source), __varMap(source.__varMap) {
184  GUM_CONS_CPY(BayesNet);
185 
186  __copyPotentials(source);
187  }
188 
189  template < typename GUM_SCALAR >
192  if (this != &source) {
194  __varMap = source.__varMap;
195 
196  __clearPotentials();
197  __copyPotentials(source);
198  }
199 
200  return *this;
201  }
202 
203  template < typename GUM_SCALAR >
205  GUM_DESTRUCTOR(BayesNet);
206  for (const auto p: __probaMap) {
207  delete p.second;
208  }
209  }
210 
211  template < typename GUM_SCALAR >
212  INLINE const DiscreteVariable&
214  return __varMap.get(id);
215  }
216 
217  template < typename GUM_SCALAR >
218  INLINE void
220  const std::string& new_name) {
221  __varMap.changeName(id, new_name);
222  }
223 
224  template < typename GUM_SCALAR >
226  NodeId id, const std::string& old_label, const std::string& new_label) {
227  if (variable(id).varType() != VarType::Labelized) {
228  GUM_ERROR(NotFound, "Variable " << id << " is not a LabelizedVariable.");
229  }
230  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(
231  const_cast< DiscreteVariable* >(&variable(id)));
232 
233  var->changeLabel(var->posLabel(old_label), new_label);
234  }
235 
236 
237  template < typename GUM_SCALAR >
239  return __varMap.get(var);
240  }
241 
242  template < typename GUM_SCALAR >
244  auto ptr = new MultiDimArray< GUM_SCALAR >();
245  NodeId res = 0;
246 
247  try {
248  res = add(var, ptr);
249 
250  } catch (Exception&) {
251  delete ptr;
252  throw;
253  }
254 
255  return res;
256  }
257 
258  template < typename GUM_SCALAR >
259  INLINE NodeId BayesNet< GUM_SCALAR >::add(const std::string& name,
260  unsigned int nbrmod) {
261  if (nbrmod < 2) {
263  "Variable " << name << "needs more than " << nbrmod
264  << " modalities");
265  }
266 
267  RangeVariable v(name, name, 0, nbrmod - 1);
268  return add(v);
269  }
270 
271  template < typename GUM_SCALAR >
274  NodeId proposedId = dag().nextNodeId();
275  NodeId res = 0;
276 
277  res = add(var, aContent, proposedId);
278 
279  return res;
280  }
281 
282  template < typename GUM_SCALAR >
284  NodeId id) {
285  auto ptr = new MultiDimArray< GUM_SCALAR >();
286  NodeId res = 0;
287 
288  try {
289  res = add(var, ptr, id);
290 
291  } catch (Exception&) {
292  delete ptr;
293  throw;
294  }
295 
296  return res;
297  }
298 
299  template < typename GUM_SCALAR >
300  NodeId
303  NodeId id) {
304  __varMap.insert(id, var);
305  this->_dag.addNodeWithId(id);
306 
307  auto cpt = new Potential< GUM_SCALAR >(aContent);
308  (*cpt) << variable(id);
309  __probaMap.insert(id, cpt);
310  return id;
311  }
312 
313  template < typename GUM_SCALAR >
314  INLINE NodeId BayesNet< GUM_SCALAR >::idFromName(const std::string& name) const {
315  return __varMap.idFromName(name);
316  }
317 
318  template < typename GUM_SCALAR >
319  INLINE const DiscreteVariable&
320  BayesNet< GUM_SCALAR >::variableFromName(const std::string& name) const {
321  return __varMap.variableFromName(name);
322  }
323 
324  template < typename GUM_SCALAR >
325  INLINE const Potential< GUM_SCALAR >&
327  return *(__probaMap[varId]);
328  }
329 
330  template < typename GUM_SCALAR >
332  return __varMap;
333  }
334 
335  template < typename GUM_SCALAR >
337  erase(__varMap.get(var));
338  }
339 
340  template < typename GUM_SCALAR >
342  if (__varMap.exists(varId)) {
343  // Reduce the variable child's CPT
344  const NodeSet& children = this->children(varId);
345 
346  for (const auto c: children) {
347  __probaMap[c]->erase(variable(varId));
348  }
349 
350  delete __probaMap[varId];
351 
352  __probaMap.erase(varId);
353  __varMap.erase(varId);
354  this->_dag.eraseNode(varId);
355  }
356  }
357 
358  template < typename GUM_SCALAR >
360  if (!this->empty()) {
361  auto l = this->nodes();
362  for (const auto no: l) {
363  this->erase(no);
364  }
365  }
366  }
367 
368  template < typename GUM_SCALAR >
369  INLINE void BayesNet< GUM_SCALAR >::addArc(NodeId tail, NodeId head) {
370  if (this->_dag.existsArc(tail, head)) {
372  "The arc (" << tail << "," << head << ") already exists.")
373  }
374 
375  this->_dag.addArc(tail, head);
376  // Add parent in the child's CPT
377  (*(__probaMap[head])) << variable(tail);
378  }
379 
380  template < typename GUM_SCALAR >
381  INLINE void BayesNet< GUM_SCALAR >::addArc(const std::string& tail,
382  const std::string& head) {
383  try {
384  addArc(this->idFromName(tail), this->idFromName(head));
385  } catch (DuplicateElement) {
387  "The arc " << tail << "->" << head << " already exists.")
388  }
389  }
390 
391  template < typename GUM_SCALAR >
392  INLINE void BayesNet< GUM_SCALAR >::eraseArc(const Arc& arc) {
393  if (__varMap.exists(arc.tail()) && __varMap.exists(arc.head())) {
394  NodeId head = arc.head(), tail = arc.tail();
395  this->_dag.eraseArc(arc);
396  // Remove parent froms child's CPT
397  (*(__probaMap[head])) >> variable(tail);
398  }
399  }
400 
401  template < typename GUM_SCALAR >
403  eraseArc(Arc(tail, head));
404  }
405 
406  template < typename GUM_SCALAR >
408  // check that the arc exsists
409  if (!__varMap.exists(arc.tail()) || !__varMap.exists(arc.head())
410  || !dag().existsArc(arc)) {
411  GUM_ERROR(InvalidArc, "a nonexisting arc cannot be reversed");
412  }
413 
414  NodeId tail = arc.tail(), head = arc.head();
415 
416  // check that the reversal does not induce a cycle
417  try {
418  DAG d = dag();
419  d.eraseArc(arc);
420  d.addArc(head, tail);
421  } catch (Exception&) {
422  GUM_ERROR(InvalidArc, "this arc reversal would induce a directed cycle");
423  }
424 
425  // with the same notations as Shachter (1986), "evaluating influence
426  // diagrams",
427  // p.878, we shall first compute the product of probabilities:
428  // pi_j^old (x_j | x_c^old(j) ) * pi_i^old (x_i | x_c^old(i) )
429  Potential< GUM_SCALAR > prod{cpt(tail) * cpt(head)};
430 
431  // modify the topology of the graph: add to tail all the parents of head
432  // and add to head all the parents of tail
433  beginTopologyTransformation();
434  NodeSet new_parents;
435  for (const auto node: this->parents(tail))
436  new_parents.insert(node);
437  for (const auto node: this->parents(head))
438  new_parents.insert(node);
439  // remove arc (head, tail)
440  eraseArc(arc);
441 
442  // add the necessary arcs to the tail
443  for (const auto p: new_parents) {
444  if ((p != tail) && !dag().existsArc(p, tail)) { addArc(p, tail); }
445  }
446 
447  addArc(head, tail);
448  // add the necessary arcs to the head
449  new_parents.erase(tail);
450 
451  for (const auto p: new_parents) {
452  if ((p != head) && !dag().existsArc(p, head)) { addArc(p, head); }
453  }
454 
455  endTopologyTransformation();
456 
457  // update the conditional distributions of head and tail
459  del_vars << &(variable(tail));
460  Potential< GUM_SCALAR > new_cpt_head =
461  prod.margSumOut(del_vars).putFirst(&variable(head));
462 
463  auto& cpt_head = const_cast< Potential< GUM_SCALAR >& >(cpt(head));
464  cpt_head = std::move(new_cpt_head);
465 
466  Potential< GUM_SCALAR > new_cpt_tail{
467  (prod / cpt_head).putFirst(&variable(tail))};
468  auto& cpt_tail = const_cast< Potential< GUM_SCALAR >& >(cpt(tail));
469  cpt_tail = std::move(new_cpt_tail);
470  }
471 
472  template < typename GUM_SCALAR >
474  reverseArc(Arc(tail, head));
475  }
476 
477 
478  //==============================================
479  // Aggregators
480  //=============================================
481  template < typename GUM_SCALAR >
483  return add(var, new aggregator::Amplitude< GUM_SCALAR >());
484  }
485 
486  template < typename GUM_SCALAR >
488  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an AND has to be boolean");
489 
490  return add(var, new aggregator::And< GUM_SCALAR >());
491  }
492 
493  template < typename GUM_SCALAR >
495  Idx value) {
496  return add(var, new aggregator::Count< GUM_SCALAR >(value));
497  }
498 
499  template < typename GUM_SCALAR >
501  Idx value) {
502  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean");
503 
504  return add(var, new aggregator::Exists< GUM_SCALAR >(value));
505  }
506 
507  template < typename GUM_SCALAR >
509  Idx value) {
510  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean");
511 
512  return add(var, new aggregator::Forall< GUM_SCALAR >(value));
513  }
514 
515  template < typename GUM_SCALAR >
517  return add(var, new aggregator::Max< GUM_SCALAR >());
518  }
519 
520  template < typename GUM_SCALAR >
522  return add(var, new aggregator::Median< GUM_SCALAR >());
523  }
524 
525  template < typename GUM_SCALAR >
527  return add(var, new aggregator::Min< GUM_SCALAR >());
528  }
529 
530  template < typename GUM_SCALAR >
532  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an OR has to be boolean");
533 
534  return add(var, new aggregator::Or< GUM_SCALAR >());
535  }
536 
537 
538  //================================
539  // ICIModels
540  //================================
541  template < typename GUM_SCALAR >
543  GUM_SCALAR external_weight) {
544  return addNoisyORCompound(var, external_weight);
545  }
546 
547  template < typename GUM_SCALAR >
549  const DiscreteVariable& var, GUM_SCALAR external_weight) {
550  return add(var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight));
551  }
552 
553  template < typename GUM_SCALAR >
555  GUM_SCALAR external_weight) {
556  return add(var, new MultiDimNoisyORNet< GUM_SCALAR >(external_weight));
557  }
558 
559  template < typename GUM_SCALAR >
561  GUM_SCALAR external_weight) {
562  return add(var, new MultiDimNoisyAND< GUM_SCALAR >(external_weight));
563  }
564 
565  template < typename GUM_SCALAR >
567  GUM_SCALAR external_weight) {
568  return add(var, new MultiDimLogit< GUM_SCALAR >(external_weight));
569  }
570 
571  template < typename GUM_SCALAR >
573  GUM_SCALAR external_weight,
574  NodeId id) {
575  return addNoisyORCompound(var, external_weight, id);
576  }
577 
578  template < typename GUM_SCALAR >
580  GUM_SCALAR external_weight,
581  NodeId id) {
582  return add(var, new MultiDimNoisyAND< GUM_SCALAR >(external_weight), id);
583  }
584 
585  template < typename GUM_SCALAR >
587  GUM_SCALAR external_weight,
588  NodeId id) {
589  return add(var, new MultiDimLogit< GUM_SCALAR >(external_weight), id);
590  }
591 
592  template < typename GUM_SCALAR >
594  const DiscreteVariable& var, GUM_SCALAR external_weight, NodeId id) {
595  return add(
596  var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight), id);
597  }
598 
599  template < typename GUM_SCALAR >
601  GUM_SCALAR external_weight,
602  NodeId id) {
603  return add(var, new MultiDimNoisyORNet< GUM_SCALAR >(external_weight), id);
604  }
605 
606  template < typename GUM_SCALAR >
608  NodeId head,
609  GUM_SCALAR causalWeight) {
610  auto* CImodel =
611  dynamic_cast< const MultiDimICIModel< GUM_SCALAR >* >(cpt(head).content());
612 
613  if (CImodel != 0) {
614  // or is OK
615  addArc(tail, head);
616 
617  CImodel->causalWeight(variable(tail), causalWeight);
618  } else {
620  "Head variable (" << variable(head).name()
621  << ") is not a CIModel variable !");
622  }
623  }
624 
625  template < typename GUM_SCALAR >
626  INLINE std::ostream& operator<<(std::ostream& output,
627  const BayesNet< GUM_SCALAR >& bn) {
628  output << bn.toString();
629  return output;
630  }
631 
633  template < typename GUM_SCALAR >
635  for (const auto node: nodes())
636  __probaMap[node]->beginMultipleChanges();
637  }
638 
640  template < typename GUM_SCALAR >
642  for (const auto node: nodes())
643  __probaMap[node]->endMultipleChanges();
644  }
645 
647  template < typename GUM_SCALAR >
649  // Removing previous potentials
650  for (const auto& elt: __probaMap) {
651  delete elt.second;
652  }
653 
654  __probaMap.clear();
655  }
656 
658  template < typename GUM_SCALAR >
660  const BayesNet< GUM_SCALAR >& source) {
661  // Copying potentials
662 
663  for (const auto src: source.__probaMap) {
664  // First we build the node's CPT
666  copy_array->beginMultipleChanges();
667  for (gum::Idx i = 0; i < src.second->nbrDim(); i++) {
668  (*copy_array) << variableFromName(src.second->variable(i).name());
669  }
670  copy_array->endMultipleChanges();
671  copy_array->copyFrom(*(src.second));
672 
673  // We add the CPT to the CPT's hashmap
674  __probaMap.insert(src.first, copy_array);
675  }
676  }
677 
678  template < typename GUM_SCALAR >
680  for (const auto node: nodes())
681  generateCPT(node);
682  }
683 
684  template < typename GUM_SCALAR >
685  INLINE void BayesNet< GUM_SCALAR >::generateCPT(NodeId node) const {
687 
688  generator.generateCPT(cpt(node).pos(variable(node)), cpt(node));
689  }
690 
691  template < typename GUM_SCALAR >
693  Potential< GUM_SCALAR >* newPot) {
694  if (cpt(id).nbrDim() != newPot->nbrDim()) {
696  "cannot exchange potentials with different "
697  "dimensions for variable with id "
698  << id);
699  }
700 
701  for (Idx i = 0; i < cpt(id).nbrDim(); i++) {
702  if (&cpt(id).variable(i) != &(newPot->variable(i))) {
704  "cannot exchange potentials because, for variable with id "
705  << id << ", dimension " << i << " differs. ");
706  }
707  }
708 
709  _unsafeChangePotential(id, newPot);
710  }
711 
712  template < typename GUM_SCALAR >
714  NodeId id, Potential< GUM_SCALAR >* newPot) {
715  delete __probaMap[id];
716  __probaMap[id] = newPot;
717  }
718 
719  template < typename GUM_SCALAR >
720  void BayesNet< GUM_SCALAR >::changePotential(const std::string& name,
721  Potential< GUM_SCALAR >* newPot) {
722  changePotential(idFromName(name), newPot);
723  }
724 
725 } /* 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:369
Noisy OR representation.
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().
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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 () et 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:243
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:667
Class for discretized random variable.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Container used to map discrete variables with nodes.
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:171
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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:60
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
void clear()
clear the whole Bayes net *
Definition: BayesNet_tpl.h:359
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this GraphicalModel.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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 () et 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:138
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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:320
virtual Size domainSize() const =0
And aggregator.
Definition: and.h:55
Logit representation.
Definition: multiDimLogit.h:53
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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...
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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>
NodeProperty< Potential< GUM_SCALAR > *> __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:670
Noisy AND representation.
void generateCPTs() const
randomly generates CPTs for a given structure
Definition: BayesNet_tpl.h:679
Defines a discrete random variable over an integer interval.
Definition: rangeVariable.h:54
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:626
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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 () et Christophe GONZALES () info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
<agrum/tools/multidim/multiDimImplementation.h>
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Size Idx
Type for indexes.
Definition: types.h:53
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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:314
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et 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:615
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