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