aGrUM  0.13.2
gum::BayesNet< GUM_SCALAR > Class Template Reference

Class representing a Bayesian Network. More...

#include <agrum/BN/BayesNet.h>

+ Inheritance diagram for gum::BayesNet< GUM_SCALAR >:
+ Collaboration diagram for gum::BayesNet< GUM_SCALAR >:

Public Member Functions

NodeId addNoisyAND (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
 Add a variable, its associate node and a noisyAND implementation. More...
 
NodeId addNoisyAND (const DiscreteVariable &var, GUM_SCALAR external_weight)
 Add a variable, its associate node and a noisyAND implementation. More...
 
NodeId addLogit (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
 Add a variable, its associate node and a Logit implementation. More...
 
NodeId addLogit (const DiscreteVariable &var, GUM_SCALAR external_weight)
 Add a variable, its associate node and a Logit implementation. More...
 
NodeId addOR (const DiscreteVariable &var)
 Add a variable, it's associate node and an OR implementation. More...
 
NodeId addAND (const DiscreteVariable &var)
 Add a variable, it's associate node and an AND implementation. More...
 
void addWeightedArc (NodeId tail, NodeId head, GUM_SCALAR causalWeight)
 Add an arc in the BN, and update arc.head's CPT. More...
 
void addWeightedArc (const std::string &tail, const std::string &head, GUM_SCALAR causalWeight)
 Add an arc in the BN, and update arc.head's CPT. More...
 
void generateCPTs () const
 randomly generates CPTs for a given structure More...
 
void generateCPT (NodeId node) const
 randomly generate CPT for a given node in a given structure More...
 
void generateCPT (const std::string &name) const
 
void changePotential (NodeId id, Potential< GUM_SCALAR > *newPot)
 change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId. More...
 
void changePotential (const std::string &name, Potential< GUM_SCALAR > *newPot)
 
bool operator== (const IBayesNet< GUM_SCALAR > &from) const
 This operator compares 2 BNs ! More...
 
bool operator!= (const IBayesNet< GUM_SCALAR > &from) const
 
Size dim () const
 Returns the dimension (the number of free parameters) in this bayes net. More...
 
Size maxVarDomainSize () const
 
GUM_SCALAR minParam () const
 
GUM_SCALAR maxParam () const
 
GUM_SCALAR minNonZeroParam () const
 
GUM_SCALAR maxNonOneParam () const
 
virtual std::string toDot () const
 
std::string toString () const
 
NodeSet minimalCondSet (NodeId target, const NodeSet &soids) const
 
NodeSet minimalCondSet (const NodeSet &targets, const NodeSet &soids) const
 
double log10DomainSize () const
 
bool hasSameStructure (const DAGmodel &other)
 
Constructors and Destructor
 BayesNet ()
 Default constructor. More...
 
 BayesNet (std::string name)
 Default constructor. More...
 
 ~BayesNet () final
 Destructor. More...
 
 BayesNet (const BayesNet< GUM_SCALAR > &source)
 Copy constructor. More...
 
Operators
BayesNet< GUM_SCALAR > & operator= (const BayesNet< GUM_SCALAR > &source)
 Copy operator. More...
 
Variable manipulation methods
const Potential< GUM_SCALAR > & cpt (NodeId varId) const final
 Returns the CPT of a variable. More...
 
const Potential< GUM_SCALAR > & cpt (const std::string &name) const
 Returns the CPT of a variable. More...
 
const VariableNodeMapvariableNodeMap () const final
 Returns a map between variables and nodes of this gum::BayesNet. More...
 
NodeId add (const DiscreteVariable &var)
 Add a variable to the gum::BayesNet. More...
 
NodeId add (const std::string &name, unsigned int nbrmod)
 Shortcut for add(gum::LabelizedVariable(name,name,nbrmod)) More...
 
NodeId add (const DiscreteVariable &var, MultiDimImplementation< GUM_SCALAR > *aContent)
 Add a variable to the gum::BayesNet. More...
 
NodeId add (const DiscreteVariable &var, NodeId id)
 Add a variable to the gum::BayesNet. More...
 
NodeId add (const DiscreteVariable &var, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id)
 Add a variable to the gum::BayesNet. More...
 
void erase (NodeId varId)
 Remove a variable from the gum::BayesNet. More...
 
void erase (const std::string &name)
 Removes a variable from the gum::BayesNet. More...
 
void erase (const DiscreteVariable &var)
 Remove a variable from the gum::BayesNet. More...
 
const DiscreteVariablevariable (NodeId id) const final
 Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet. More...
 
const DiscreteVariablevariable (const std::string &name) const
 Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet. More...
 
void changeVariableName (NodeId id, const std::string &new_name)
 Changes a variable's name in the gum::BayesNet. More...
 
void changeVariableName (const std::string &name, const std::string &new_name)
 Changes a variable's name. More...
 
void changeVariableLabel (NodeId id, const std::string &old_label, const std::string &new_label)
 Changes a variable's label in the gum::BayesNet. More...
 
void changeVariableLabel (const std::string &name, const std::string &old_label, const std::string &new_label)
 Changes a variable's name. More...
 
NodeId nodeId (const DiscreteVariable &var) const final
 Returns a variable's id in the gum::BayesNet. More...
 
NodeId idFromName (const std::string &name) const final
 Returns a variable's id given its name in the gum::BayesNet. More...
 
const DiscreteVariablevariableFromName (const std::string &name) const final
 Returns a variable given its name in the gum::BayesNet. More...
 
Arc manipulation methods.
void addArc (NodeId tail, NodeId head)
 Add an arc in the BN, and update arc.head's CPT. More...
 
void addArc (const std::string &tail, const std::string &head)
 Add an arc in the BN, and update arc.head's CPT. More...
 
void eraseArc (const Arc &arc)
 Removes an arc in the BN, and update head's CTP. More...
 
void eraseArc (NodeId tail, NodeId head)
 Removes an arc in the BN, and update head's CTP. More...
 
void eraseArc (const std::string &tail, const std::string &head)
 Removes an arc in the BN, and update head's CTP. More...
 
void beginTopologyTransformation ()
 When inserting/removing arcs, node CPTs change their dimension with a cost in time. More...
 
void endTopologyTransformation ()
 terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions. More...
 
void reverseArc (NodeId tail, NodeId head)
 Reverses an arc while preserving the same joint distribution. More...
 
void reverseArc (const std::string &tail, const std::string &head)
 Reverses an arc while preserving the same joint distribution. More...
 
void reverseArc (const Arc &arc)
 Reverses an arc while preserving the same joint distribution. More...
 
Accessors for nodes with CI or logical implementation
NodeId addNoisyOR (const DiscreteVariable &var, GUM_SCALAR external_weight)
 Add a variable, it's associate node and a gum::noisyOR implementation. More...
 
NodeId addNoisyORNet (const DiscreteVariable &var, GUM_SCALAR external_weight)
 Add a variable, it's associate node and a gum::noisyOR implementation. More...
 
NodeId addNoisyORCompound (const DiscreteVariable &var, GUM_SCALAR external_weight)
 Add a variable, it's associate node and a gum::noisyOR implementation. More...
 
NodeId addNoisyOR (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
 Add a variable, its associate node and a noisyOR implementation. More...
 
NodeId addNoisyORNet (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
 Add a variable, its associate node and a noisyOR implementation. More...
 
NodeId addNoisyORCompound (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
 Add a variable, its associate node and a noisyOR implementation. More...
 
NodeId addAMPLITUDE (const DiscreteVariable &var)
 Others aggregators. More...
 
NodeId addCOUNT (const DiscreteVariable &var, Idx value=1)
 Others aggregators. More...
 
NodeId addEXISTS (const DiscreteVariable &var, Idx value=1)
 Others aggregators. More...
 
NodeId addFORALL (const DiscreteVariable &var, Idx value=1)
 Others aggregators. More...
 
NodeId addMAX (const DiscreteVariable &var)
 Others aggregators. More...
 
NodeId addMEDIAN (const DiscreteVariable &var)
 Others aggregators. More...
 
NodeId addMIN (const DiscreteVariable &var)
 Others aggregators. More...
 
Joint Probability manipulation methods
GUM_SCALAR jointProbability (const Instantiation &i) const
 Compute a parameter of the joint probability for the BN (given an instantiation of the vars) More...
 
GUM_SCALAR log2JointProbability (const Instantiation &i) const
 Compute a parameter of the log joint probability for the BN (given an instantiation of the vars) More...
 
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this DAGModel. More...
 
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this DAGModel. More...
 
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this DAGModel. More...
 
Variable manipulation methods.
const DAGdag () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
Size size () const
 Returns the number of variables in this Directed Graphical Model. More...
 
Size sizeArcs () const
 Returns the number of arcs in this Directed Graphical Model. More...
 
bool empty () const
 Retursn true if this Directed Graphical Model is empty. More...
 
const NodeGraphPartnodes () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
virtual Instantiation completeInstantiation () const final
 Get an instantiation over all the variables of the model. More...
 
Arc manipulation methods.
const ArcSetarcs () const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
const NodeSetchildren (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
Graphical methods
const UndiGraphmoralGraph (bool clear=true) const
 The node's id are coherent with the variables and nodes of the topology. More...
 
const Sequence< NodeId > & topologicalOrder (bool clear=true) const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology. More...
 

Static Public Member Functions

static BayesNet< GUM_SCALAR > fastPrototype (const std::string &dotlike, Size domainSize=2)
 Create a bn with a dotlike syntax : 'a->b->c;b->d;'. More...
 

Protected Attributes

DAG _dag
 The DAG of this Directed Graphical Model. More...
 

Friends

class BayesNetFactory< GUM_SCALAR >
 

Detailed Description

template<typename GUM_SCALAR>
class gum::BayesNet< GUM_SCALAR >

Class representing a Bayesian Network.

Bayesian Networks are a probabilistic graphical model in which nodes are random variables and the probability distribution is defined by the product:

\(P(X_1, \ldots, X_2) = \prod_{i=1}^{n} P(X_i | \pi(X_i))\),

where \(\pi(X_i)\) is the parent of \(X_i\).

The probability distribution can be represented as a directed acyclic graph (DAG) where:

  • Nodes are discrete random variables.
  • An arc A -> B represent a dependency between variables A and B, i.e. B conditional probability distribution is defined as \(P(B| \pi(B)\).

After a variable is added to the BN, if it's domain size changes, then the data in it's CPT is lost.

You should look a the gum::BayesNetFactory class which can help build Bayesian Networks.

You can print a BayesNet using gum::operator<<(std::ostream&, const BayesNet<GUM_SCALAR>&).

Definition at line 76 of file BayesNet.h.

Constructor & Destructor Documentation

template<typename GUM_SCALAR >
INLINE gum::BayesNet< GUM_SCALAR >::BayesNet ( )

Default constructor.

Definition at line 147 of file BayesNet_tpl.h.

147  : IBayesNet< GUM_SCALAR >() {
148  GUM_CONSTRUCTOR(BayesNet);
149  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:147
template<typename GUM_SCALAR >
INLINE gum::BayesNet< GUM_SCALAR >::BayesNet ( std::string  name)
explicit

Default constructor.

Parameters
nameThe BayesNet's name.

Definition at line 152 of file BayesNet_tpl.h.

152  :
153  IBayesNet< GUM_SCALAR >(name) {
154  GUM_CONSTRUCTOR(BayesNet);
155  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:147
template<typename GUM_SCALAR >
gum::BayesNet< GUM_SCALAR >::~BayesNet ( )
final

Destructor.

Definition at line 180 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap.

180  {
181  GUM_DESTRUCTOR(BayesNet);
182  for (const auto p : __probaMap) {
183  delete p.second;
184  }
185  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:147
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
template<typename GUM_SCALAR>
gum::BayesNet< GUM_SCALAR >::BayesNet ( const BayesNet< GUM_SCALAR > &  source)

Copy constructor.

Definition at line 158 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__copyPotentials(), and gum::BayesNet< GUM_SCALAR >::operator=().

158  :
159  IBayesNet< GUM_SCALAR >(source), __varMap(source.__varMap) {
160  GUM_CONS_CPY(BayesNet);
161 
162  __copyPotentials(source);
163  }
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:147
void __copyPotentials(const BayesNet< GUM_SCALAR > &source)
copy of potentials from a BN to another, using names of vars as ref.
Definition: BayesNet_tpl.h:606

+ Here is the call graph for this function:

Member Function Documentation

template<typename GUM_SCALAR >
void gum::BayesNet< GUM_SCALAR >::__clearPotentials ( )
private

clear all potentials

Definition at line 595 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap.

Referenced by gum::BayesNet< double >::generateCPT(), and gum::BayesNet< GUM_SCALAR >::operator=().

595  {
596  // Removing previous potentials
597  for (const auto& elt : __probaMap) {
598  delete elt.second;
599  }
600 
601  __probaMap.clear();
602  }
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::__copyPotentials ( const BayesNet< GUM_SCALAR > &  source)
private

copy of potentials from a BN to another, using names of vars as ref.

Definition at line 606 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges(), gum::MultiDimContainer< GUM_SCALAR >::copyFrom(), gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges(), and gum::BayesNet< GUM_SCALAR >::variableFromName().

Referenced by gum::BayesNet< GUM_SCALAR >::BayesNet(), gum::BayesNet< double >::generateCPT(), and gum::BayesNet< GUM_SCALAR >::operator=().

607  {
608  // Copying potentials
609 
610  for (const auto src : source.__probaMap) {
611  // First we build the node's CPT
612  Potential< GUM_SCALAR >* copy_array = new Potential< GUM_SCALAR >();
613  copy_array->beginMultipleChanges();
614  for (gum::Idx i = 0; i < src.second->nbrDim(); i++) {
615  (*copy_array) << variableFromName(src.second->variable(i).name());
616  }
617  copy_array->endMultipleChanges();
618  copy_array->copyFrom(*(src.second));
619 
620  // We add the CPT to the CPT's hashmap
621  __probaMap.insert(src.first, copy_array);
622  }
623  }
const DiscreteVariable & variableFromName(const std::string &name) const final
Returns a variable given its name in the gum::BayesNet.
Definition: BayesNet_tpl.h:296
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::_unsafeChangePotential ( NodeId  id,
Potential< GUM_SCALAR > *  newPot 
)
private

change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.

Warning
no verification of dimensions are performer
See also
changePotential

Definition at line 659 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap.

Referenced by gum::BayesNet< GUM_SCALAR >::changePotential().

660  {
661  delete __probaMap[id];
662  __probaMap[id] = newPot;
663  }
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add ( const DiscreteVariable var)

Add a variable to the gum::BayesNet.

Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.

The variable is added by copy to the gum::BayesNet. The variable's gum::Potential implementation will be a gum::MultiDimArray.

Parameters
varThe variable added by copy.
Returns
Returns the variable's id in the gum::BayesNet.
Exceptions
DuplicateLabelRaised if variable.name() is already used in this gum::BayesNet.

Definition at line 219 of file BayesNet_tpl.h.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::learning::genericBNLearner::Database::__BNVars(), gum::BayesNet< GUM_SCALAR >::add(), gum::BayesNet< GUM_SCALAR >::addAMPLITUDE(), gum::BayesNet< GUM_SCALAR >::addAND(), gum::BayesNet< GUM_SCALAR >::addCOUNT(), gum::BayesNet< GUM_SCALAR >::addEXISTS(), gum::BayesNet< GUM_SCALAR >::addFORALL(), gum::BayesNet< GUM_SCALAR >::addLogit(), gum::BayesNet< GUM_SCALAR >::addMAX(), gum::BayesNet< GUM_SCALAR >::addMEDIAN(), gum::BayesNet< GUM_SCALAR >::addMIN(), gum::BayesNet< GUM_SCALAR >::addNoisyAND(), gum::BayesNet< GUM_SCALAR >::addNoisyORCompound(), gum::BayesNet< GUM_SCALAR >::addNoisyORNet(), gum::BayesNet< GUM_SCALAR >::addOR(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::build_node(), gum::BayesNet< double >::cpt(), and gum::learning::DAG2BNLearner::createBN().

219  {
220  auto ptr = new MultiDimArray< GUM_SCALAR >();
221  NodeId res = 0;
222 
223  try {
224  res = add(var, ptr);
225 
226  } catch (Exception&) {
227  delete ptr;
228  throw;
229  }
230 
231  return res;
232  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add ( const std::string &  name,
unsigned int  nbrmod 
)

Shortcut for add(gum::LabelizedVariable(name,name,nbrmod))

Add a gum::LabelizedVariable to the gum::BayesNet

This method is just a shortcut for a often used pattern

Exceptions
DuplicateLabelRaised if variable.name() is already used in this gum::BayesNet.
NotAllowedif nbrmod<2

Definition at line 235 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add(), and GUM_ERROR.

236  {
237  if (nbrmod < 2) {
238  GUM_ERROR(OperationNotAllowed,
239  "Variable " << name << "needs more than " << nbrmod
240  << " modalities");
241  }
242 
243  LabelizedVariable v(name, name, nbrmod);
244  return add(v);
245  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add ( const DiscreteVariable var,
MultiDimImplementation< GUM_SCALAR > *  aContent 
)

Add a variable to the gum::BayesNet.

Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.

The variable is added by copy to the gum::BayesNet.

Parameters
varThe variable added by copy.
aContentThe gum::MultiDimImplementation to use for this variable's gum::Potential implementation.
Returns
Returns the variable's id in the gum::BayesNet.
Exceptions
DuplicateLabelRaised if variable.name() is already used in this gum::BayesNet.

Definition at line 248 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add(), gum::DAGmodel::dag(), and gum::NodeGraphPart::nextNodeId().

249  {
250  NodeId proposedId = dag().nextNodeId();
251  NodeId res = 0;
252 
253  res = add(var, aContent, proposedId);
254 
255  return res;
256  }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219
NodeId nextNodeId() const
returns a new node id, not yet used by any node

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add ( const DiscreteVariable var,
NodeId  id 
)

Add a variable to the gum::BayesNet.

Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.

The variable is added by copy to the gum::BayesNet. The variable's gum::Potential implementation will be a gum::MultiDimArray.

Parameters
varThe variable added by copy.
idThe variable's forced gum::NodeId in the gum::BayesNet.
Returns
Returns the variable's id in the gum::BayesNet.
Exceptions
DuplicateElementRaised id is already used.
DuplicateLabelRaised if variable.name() is already used in this gum::BayesNet.

Definition at line 259 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

260  {
261  auto ptr = new MultiDimArray< GUM_SCALAR >();
262  NodeId res = 0;
263 
264  try {
265  res = add(var, ptr, id);
266 
267  } catch (Exception&) {
268  delete ptr;
269  throw;
270  }
271 
272  return res;
273  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
NodeId gum::BayesNet< GUM_SCALAR >::add ( const DiscreteVariable var,
MultiDimImplementation< GUM_SCALAR > *  aContent,
NodeId  id 
)

Add a variable to the gum::BayesNet.

Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.

Parameters
varThe variable added by copy.
aContentThe gum::MultiDimImplementation to use for this variable's gum::Potential implementation.
idThe variable's forced gum::NodeId in the gum::BayesNet.
Returns
Returns the variable's id in the gum::BayesNet.
Exceptions
DuplicateElementRaised id is already used.
DuplicateLabelRaised if variable.name() is already used in this gum::BayesNet.

Definition at line 277 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, gum::BayesNet< GUM_SCALAR >::__varMap, gum::DAGmodel::_dag, gum::NodeGraphPart::addNodeWithId(), gum::BayesNet< GUM_SCALAR >::cpt(), gum::VariableNodeMap::insert(), and gum::BayesNet< GUM_SCALAR >::variable().

279  {
280  __varMap.insert(id, var);
281  this->_dag.addNodeWithId(id);
282 
283  auto cpt = new Potential< GUM_SCALAR >(aContent);
284  (*cpt) << variable(id);
285  __probaMap.insert(id, cpt);
286  return id;
287  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:302

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addAMPLITUDE ( const DiscreteVariable var)

Others aggregators.

Definition at line 429 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

429  {
430  return add(var, new aggregator::Amplitude< GUM_SCALAR >());
431  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addAND ( const DiscreteVariable var)

Add a variable, it's associate node and an AND implementation.

The id of the new variable is automatically generated.

Warning
AND is implemented as a gum::aggregator::And which means that if parents are not boolean, all value>1 is True
Parameters
varThe variable added by copy.
Returns
the id of the added variable.
Exceptions
SizeErrorif variable.domainSize()>2

Definition at line 434 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add(), gum::DiscreteVariable::domainSize(), and GUM_ERROR.

Referenced by gum::BayesNet< double >::reverseArc().

434  {
435  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an AND has to be boolean");
436 
437  return add(var, new aggregator::And< GUM_SCALAR >());
438  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::addArc ( NodeId  tail,
NodeId  head 
)

Add an arc in the BN, and update arc.head's CPT.

Parameters
headand
tailas NodeId
Exceptions
InvalidEdgeIf arc.tail and/or arc.head are not in the BN.

Definition at line 335 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, gum::DAGmodel::_dag, gum::DAG::addArc(), and gum::BayesNet< GUM_SCALAR >::variable().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::BayesNet< double >::addArc(), gum::BayesNet< GUM_SCALAR >::addWeightedArc(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::BayesNet< double >::changeVariableLabel(), gum::learning::DAG2BNLearner::createBN(), gum::BayesNet< GUM_SCALAR >::fastPrototype(), and gum::BayesNet< GUM_SCALAR >::reverseArc().

335  {
336  this->_dag.addArc(tail, head);
337  // Add parent in the child's CPT
338  (*(__probaMap[head])) << variable(tail);
339  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:40
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::addArc ( const std::string &  tail,
const std::string &  head 
)
inline

Add an arc in the BN, and update arc.head's CPT.

Definition at line 389 of file BayesNet.h.

389  {
390  addArc(idFromName(tail), idFromName(head));
391  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:335
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:290
template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addCOUNT ( const DiscreteVariable var,
Idx  value = 1 
)

Others aggregators.

Definition at line 441 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

442  {
443  return add(var, new aggregator::Count< GUM_SCALAR >(value));
444  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addEXISTS ( const DiscreteVariable var,
Idx  value = 1 
)

Others aggregators.

Definition at line 447 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add(), gum::DiscreteVariable::domainSize(), and GUM_ERROR.

Referenced by gum::BayesNet< double >::reverseArc().

448  {
449  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean");
450 
451  return add(var, new aggregator::Exists< GUM_SCALAR >(value));
452  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addFORALL ( const DiscreteVariable var,
Idx  value = 1 
)

Others aggregators.

Definition at line 455 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add(), gum::DiscreteVariable::domainSize(), and GUM_ERROR.

Referenced by gum::BayesNet< double >::reverseArc().

456  {
457  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean");
458 
459  return add(var, new aggregator::Forall< GUM_SCALAR >(value));
460  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addLogit ( const DiscreteVariable var,
GUM_SCALAR  external_weight,
NodeId  id 
)

Add a variable, its associate node and a Logit implementation.

Parameters
varThe variable added by copy
external_weightsee gum::MultiDimLogit
idproposed gum::nodeId for the variable
Warning
give an id should be reserved for rare and specific situations !!!
Returns
the id of the added variable.

Definition at line 533 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

535  {
536  return add(var, new MultiDimLogit< GUM_SCALAR >(external_weight), id);
537  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addLogit ( const DiscreteVariable var,
GUM_SCALAR  external_weight 
)

Add a variable, its associate node and a Logit implementation.

The id of the new variable is automatically generated.

Parameters
varThe variable added by copy.
external_weightsee gum::MultiDimLogit
Returns
the id of the added variable.

Definition at line 513 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

514  {
515  return add(var, new MultiDimLogit< GUM_SCALAR >(external_weight));
516  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addMAX ( const DiscreteVariable var)

Others aggregators.

Definition at line 463 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

463  {
464  return add(var, new aggregator::Max< GUM_SCALAR >());
465  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addMEDIAN ( const DiscreteVariable var)

Others aggregators.

Definition at line 468 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

468  {
469  return add(var, new aggregator::Median< GUM_SCALAR >());
470  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addMIN ( const DiscreteVariable var)

Others aggregators.

Definition at line 473 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

473  {
474  return add(var, new aggregator::Min< GUM_SCALAR >());
475  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyAND ( const DiscreteVariable var,
GUM_SCALAR  external_weight,
NodeId  id 
)

Add a variable, its associate node and a noisyAND implementation.

Parameters
varThe variable added by copy
external_weightsee gum::MultiDimNoisyAND
idproposed gum::nodeId for the variable
Warning
give an id should be reserved for rare and specific situations !!!
Returns
the id of the added variable.

Definition at line 526 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

528  {
529  return add(var, new MultiDimNoisyAND< GUM_SCALAR >(external_weight), id);
530  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyAND ( const DiscreteVariable var,
GUM_SCALAR  external_weight 
)

Add a variable, its associate node and a noisyAND implementation.

The id of the new variable is automatically generated.

Parameters
varThe variable added by copy.
external_weightsee gum::MultiDimNoisyAND
Returns
the id of the added variable.

Definition at line 507 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

508  {
509  return add(var, new MultiDimNoisyAND< GUM_SCALAR >(external_weight));
510  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyOR ( const DiscreteVariable var,
GUM_SCALAR  external_weight 
)

Add a variable, it's associate node and a gum::noisyOR implementation.

The id of the new variable is automatically generated. Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the gum::BayesNet::addNoisyOR as an alias for gum::BayesNet::addNoisyORCompound

Parameters
varThe variable added by copy.
external_weightsee ref gum::MultiDimNoisyORNet,gum::MultiDimNoisyORCompound
Returns
the id of the added variable.

Definition at line 489 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::addNoisyORCompound().

Referenced by gum::BayesNet< double >::reverseArc().

490  {
491  return addNoisyORCompound(var, external_weight);
492  }
NodeId addNoisyORCompound(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it&#39;s associate node and a gum::noisyOR implementation.
Definition: BayesNet_tpl.h:495

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyOR ( const DiscreteVariable var,
GUM_SCALAR  external_weight,
NodeId  id 
)

Add a variable, its associate node and a noisyOR implementation.

Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.

Parameters
varThe variable added by copy.
external_weightsee gum::MultiDimNoisyORNet, gum::MultiDimNoisyORCompound
idThe chosen id
Warning
give an id should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id is already used

Definition at line 519 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::addNoisyORCompound().

521  {
522  return addNoisyORCompound(var, external_weight, id);
523  }
NodeId addNoisyORCompound(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it&#39;s associate node and a gum::noisyOR implementation.
Definition: BayesNet_tpl.h:495

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORCompound ( const DiscreteVariable var,
GUM_SCALAR  external_weight 
)

Add a variable, it's associate node and a gum::noisyOR implementation.

The id of the new variable is automatically generated. Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the gum::BayesNet::addNoisyOR as an alias for gum::BayesNet::addNoisyORCompound

Parameters
varThe variable added by copy.
external_weightsee ref gum::MultiDimNoisyORNet,gum::MultiDimNoisyORCompound
Returns
the id of the added variable.

Definition at line 495 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< GUM_SCALAR >::addNoisyOR(), and gum::BayesNet< double >::reverseArc().

496  {
497  return add(var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight));
498  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORCompound ( const DiscreteVariable var,
GUM_SCALAR  external_weight,
NodeId  id 
)

Add a variable, its associate node and a noisyOR implementation.

Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.

Parameters
varThe variable added by copy.
external_weightsee gum::MultiDimNoisyORNet, gum::MultiDimNoisyORCompound
idThe chosen id
Warning
give an id should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id is already used

Definition at line 540 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

541  {
542  return add(
543  var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight), id);
544  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORNet ( const DiscreteVariable var,
GUM_SCALAR  external_weight 
)

Add a variable, it's associate node and a gum::noisyOR implementation.

The id of the new variable is automatically generated. Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the gum::BayesNet::addNoisyOR as an alias for gum::BayesNet::addNoisyORCompound

Parameters
varThe variable added by copy.
external_weightsee ref gum::MultiDimNoisyORNet,gum::MultiDimNoisyORCompound
Returns
the id of the added variable.

Definition at line 501 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

Referenced by gum::BayesNet< double >::reverseArc().

502  {
503  return add(var, new MultiDimNoisyORNet< GUM_SCALAR >(external_weight));
504  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORNet ( const DiscreteVariable var,
GUM_SCALAR  external_weight,
NodeId  id 
)

Add a variable, its associate node and a noisyOR implementation.

Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.

Parameters
varThe variable added by copy.
external_weightsee gum::MultiDimNoisyORNet, gum::MultiDimNoisyORCompound
idThe chosen id
Warning
give an id should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id is already used

Definition at line 547 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add().

549  {
550  return add(var, new MultiDimNoisyORNet< GUM_SCALAR >(external_weight), id);
551  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addOR ( const DiscreteVariable var)

Add a variable, it's associate node and an OR implementation.

The id of the new variable is automatically generated.

Warning
OR is implemented as a gum::aggregator::Or which means that if parents are not boolean, all value>1 is True
Parameters
varThe variable added by copy.
Returns
the id of the added variable.
Exceptions
SizeErrorif variable.domainSize()>2

Definition at line 478 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::add(), gum::DiscreteVariable::domainSize(), and GUM_ERROR.

Referenced by gum::BayesNet< double >::reverseArc().

478  {
479  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an OR has to be boolean");
480 
481  return add(var, new aggregator::Or< GUM_SCALAR >());
482  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:219
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::addWeightedArc ( NodeId  tail,
NodeId  head,
GUM_SCALAR  causalWeight 
)

Add an arc in the BN, and update arc.head's CPT.

Parameters
headand
tailas NodeId
causalWeightsee gum::MultiDimICIModel
Exceptions
InvalidArcIf arc.tail and/or arc.head are not in the BN.
InvalidArcIf variable in arc.head is not a NoisyOR variable.

Definition at line 554 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::addArc(), gum::BayesNet< GUM_SCALAR >::cpt(), GUM_ERROR, and gum::BayesNet< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< double >::addWeightedArc(), and gum::BayesNet< double >::reverseArc().

556  {
557  auto* CImodel =
558  dynamic_cast< const MultiDimICIModel< GUM_SCALAR >* >(cpt(head).content());
559 
560  if (CImodel != 0) {
561  // or is OK
562  addArc(tail, head);
563 
564  CImodel->causalWeight(variable(tail), causalWeight);
565  } else {
566  GUM_ERROR(InvalidArc,
567  "Head variable (" << variable(head).name()
568  << ") is not a CIModel variable !");
569  }
570  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:335
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:302
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::addWeightedArc ( const std::string &  tail,
const std::string &  head,
GUM_SCALAR  causalWeight 
)
inline

Add an arc in the BN, and update arc.head's CPT.

Parameters
headand
tailas std::string
causalWeightsee gum::MultiDimICIModel
NotFoundif no node with sun names is found
Exceptions
InvalidArcIf arc.tail and/or arc.head are not in the BN.
InvalidArcIf variable in arc.head is not a NoisyOR variable.

Definition at line 616 of file BayesNet.h.

618  {
619  addWeightedArc(idFromName(tail), idFromName(head), causalWeight);
620  };
void addWeightedArc(NodeId tail, NodeId head, GUM_SCALAR causalWeight)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:554
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:290
INLINE const ArcSet & gum::DAGmodel::arcs ( ) const
inherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 102 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::arcs().

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::DAGmodel::__moralGraph(), gum::MarkovBlanket::hasSameStructure(), and gum::DAGmodel::hasSameStructure().

102 { return _dag.arcs(); }
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNet< GUM_SCALAR >::beginTopologyTransformation ( )

When inserting/removing arcs, node CPTs change their dimension with a cost in time.

begin Multiple Change for all CPTs

These functions delay the CPTs change to be done just once at the end of a sequence of topology modification. begins a sequence of insertions/deletions of arcs without changing the dimensions of the CPTs.

Definition at line 581 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, and gum::DAGmodel::nodes().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::learning::DAG2BNLearner::createBN(), gum::BayesNet< double >::eraseArc(), and gum::BayesNet< GUM_SCALAR >::reverseArc().

581  {
582  for (const auto node : nodes())
583  __probaMap[node]->beginMultipleChanges();
584  }
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::changePotential ( NodeId  id,
Potential< GUM_SCALAR > *  newPot 
)

change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.

Exceptions
NotAllowedif newPot has not the same signature as __probaMap[NodeId]

Definition at line 638 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::_unsafeChangePotential(), gum::BayesNet< GUM_SCALAR >::cpt(), GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< GUM_SCALAR >::changePotential(), and gum::BayesNet< double >::generateCPT().

639  {
640  if (cpt(id).nbrDim() != newPot->nbrDim()) {
641  GUM_ERROR(OperationNotAllowed,
642  "cannot exchange potentials with different "
643  "dimensions for variable with id "
644  << id);
645  }
646 
647  for (Idx i = 0; i < cpt(id).nbrDim(); i++) {
648  if (&cpt(id).variable(i) != &(newPot->variable(i))) {
649  GUM_ERROR(OperationNotAllowed,
650  "cannot exchange potentials because, for variable with id "
651  << id << ", dimension " << i << " differs. ");
652  }
653  }
654 
655  _unsafeChangePotential(id, newPot);
656  }
void _unsafeChangePotential(NodeId id, Potential< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
Definition: BayesNet_tpl.h:659
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:302
unsigned long Idx
Type for indexes.
Definition: types.h:43
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::changePotential ( const std::string &  name,
Potential< GUM_SCALAR > *  newPot 
)

Definition at line 666 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::changePotential(), and gum::BayesNet< GUM_SCALAR >::idFromName().

667  {
668  changePotential(idFromName(name), newPot);
669  }
void changePotential(NodeId id, Potential< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
Definition: BayesNet_tpl.h:638
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:290

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::changeVariableLabel ( NodeId  id,
const std::string &  old_label,
const std::string &  new_label 
)

Changes a variable's label in the gum::BayesNet.

This will change the gum::LabelizedVariable names in the gum::BayesNet.

Exceptions
DuplicateLabelRaised if new_label is already used in this gum::LabelizedVariable.
NotFoundRaised if no variable matches id or if the variable is not a LabelizedVariable

Definition at line 201 of file BayesNet_tpl.h.

References gum::LabelizedVariable::changeLabel(), GUM_ERROR, gum::Labelized, gum::LabelizedVariable::posLabel(), and gum::BayesNet< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< double >::changeVariableLabel(), and gum::BayesNet< double >::changeVariableName().

202  {
203  if (variable(id).varType() != VarType::Labelized) {
204  GUM_ERROR(NotFound, "Variable " << id << " is not a LabelizedVariable.");
205  }
206  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(
207  const_cast< DiscreteVariable* >(&variable(id)));
208 
209  var->changeLabel(var->posLabel(old_label), new_label);
210  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::changeVariableLabel ( const std::string &  name,
const std::string &  old_label,
const std::string &  new_label 
)
inline

Changes a variable's name.

Definition at line 334 of file BayesNet.h.

336  {
337  changeVariableLabel(idFromName(name), old_label, new_label);
338  }
void changeVariableLabel(NodeId id, const std::string &old_label, const std::string &new_label)
Changes a variable&#39;s label in the gum::BayesNet.
Definition: BayesNet_tpl.h:201
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:290
template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::changeVariableName ( NodeId  id,
const std::string &  new_name 
)

Changes a variable's name in the gum::BayesNet.

This will change the gum::DiscreteVariable names in the gum::BayesNet.

Exceptions
DuplicateLabelRaised if newName is already used in this gum::BayesNet.
NotFoundRaised if no variable matches id.

Definition at line 195 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, and gum::VariableNodeMap::changeName().

Referenced by gum::BayesNet< double >::changeVariableName(), and gum::BayesNet< double >::variable().

196  {
197  __varMap.changeName(id, new_name);
198  }
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
void changeName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::changeVariableName ( const std::string &  name,
const std::string &  new_name 
)
inline

Changes a variable's name.

Definition at line 313 of file BayesNet.h.

313  {
314  changeVariableName(idFromName(name), new_name);
315  }
void changeVariableName(NodeId id, const std::string &new_name)
Changes a variable&#39;s name in the gum::BayesNet.
Definition: BayesNet_tpl.h:195
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:290
INLINE const NodeSet & gum::DAGmodel::children ( const NodeId  id) const
inherited

returns the set of nodes with arc outgoing from a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of the arcs returned

Definition at line 109 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::children().

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::BayesNet< GUM_SCALAR >::erase(), gum::DAGmodel::parents(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toDot().

109  {
110  return _dag.children(id);
111  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const NodeSet& gum::DAGmodel::children ( const std::string &  name) const
inlineinherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 162 of file DAGmodel.h.

References gum::DAGmodel::hasSameStructure(), gum::DAGmodel::idFromName(), gum::DAGmodel::log10DomainSize(), gum::DAGmodel::moralGraph(), gum::DAGmodel::operator=(), gum::DAGmodel::parents(), and gum::DAGmodel::topologicalOrder().

162  {
163  return parents(idFromName(name));
164  };
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104

+ Here is the call graph for this function:

INLINE Instantiation gum::DAGmodel::completeInstantiation ( ) const
finalvirtualinherited

Get an instantiation over all the variables of the model.

Definition at line 84 of file DAGmodel_inl.h.

References gum::DAGmodel::dag(), and gum::DAGmodel::variable().

84  {
85  Instantiation I;
86 
87  for (const auto node : dag())
88  I << variable(node);
89 
90  return I;
91  }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::BayesNet< GUM_SCALAR >::cpt ( NodeId  varId) const
finalvirtual

Returns the CPT of a variable.

Parameters
varIdA variable's id in the gum::BayesNet.
Returns
The variable's CPT.
Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 302 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::BayesNet< GUM_SCALAR >::add(), gum::BayesNet< GUM_SCALAR >::addWeightedArc(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::BayesNet< GUM_SCALAR >::changePotential(), gum::BayesNet< double >::cpt(), gum::learning::DAG2BNLearner::createBN(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbAugmCPT(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbReducCPT(), gum::BayesNet< GUM_SCALAR >::generateCPT(), gum::BayesNet< GUM_SCALAR >::reverseArc(), and gum::credal::CredalNet< GUM_SCALAR >::toString().

302  {
303  return *(__probaMap[varId]);
304  }
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
const Potential< GUM_SCALAR >& gum::BayesNet< GUM_SCALAR >::cpt ( const std::string &  name) const
inline

Returns the CPT of a variable.

Definition at line 153 of file BayesNet.h.

153  {
154  return cpt(idFromName(name));
155  };
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:302
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:290
template<typename GUM_SCALAR >
Size gum::IBayesNet< GUM_SCALAR >::dim ( ) const
inherited

Returns the dimension (the number of free parameters) in this bayes net.

\( dim(G)=\sum_{i \in nodes} ((r_i-1)\cdot q_i) \) where \( r_i \) is the number of instantiations of node \( i \) and \( q_i \) is the number of instantiations of its parents.

Definition at line 76 of file IBayesNet_tpl.h.

References gum::DiscreteVariable::domainSize(), gum::DAGmodel::nodes(), gum::DAGmodel::parents(), and gum::IBayesNet< GUM_SCALAR >::variable().

76  {
77  Size dim = 0;
78 
79  for (auto node : nodes()) {
80  Size q = 1;
81 
82  for (auto parent : parents(node))
83  q *= variable(parent).domainSize();
84 
85  dim += (variable(node).domainSize() - 1) * q;
86  }
87 
88  return dim;
89  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
Definition: IBayesNet_tpl.h:76
virtual Size domainSize() const =0
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

INLINE bool gum::DAGmodel::empty ( ) const
inherited

Retursn true if this Directed Graphical Model is empty.

Definition at line 97 of file DAGmodel_inl.h.

References gum::DAGmodel::size().

97 { return size() == 0; }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNet< GUM_SCALAR >::endTopologyTransformation ( )

terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.

end Multiple Change for all CPTs

Definition at line 588 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, and gum::DAGmodel::nodes().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::learning::DAG2BNLearner::createBN(), gum::BayesNet< double >::eraseArc(), and gum::BayesNet< GUM_SCALAR >::reverseArc().

588  {
589  for (const auto node : nodes())
590  __probaMap[node]->endMultipleChanges();
591  }
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNet< GUM_SCALAR >::erase ( NodeId  varId)

Remove a variable from the gum::BayesNet.

Removes the corresponding variable from the gum::BayesNet and from all of it's children gum::Potential.

If no variable matches the given id, then nothing is done.

Parameters
varIdThe variable's id to remove.

Definition at line 317 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, gum::BayesNet< GUM_SCALAR >::__varMap, gum::DAGmodel::_dag, gum::DAGmodel::children(), gum::VariableNodeMap::erase(), gum::DiGraph::eraseNode(), gum::VariableNodeMap::exists(), and gum::BayesNet< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< double >::cpt(), gum::BayesNet< double >::erase(), and gum::BayesNet< GUM_SCALAR >::erase().

317  {
318  if (__varMap.exists(varId)) {
319  // Reduce the variable child's CPT
320  const NodeSet& children = this->children(varId);
321 
322  for (const auto c : children) {
323  __probaMap[c]->erase(variable(varId));
324  }
325 
326  delete __probaMap[varId];
327 
328  __probaMap.erase(varId);
329  __varMap.erase(varId);
330  this->_dag.eraseNode(varId);
331  }
332  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:109
void erase(NodeId id)
Removes a var and it&#39;s id of this mapping. The pointer is deleted.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
bool exists(NodeId id) const
Return true if id matches a node.
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::erase ( const std::string &  name)
inline

Removes a variable from the gum::BayesNet.

Definition at line 265 of file BayesNet.h.

Referenced by gum::BayesNet< double >::erase().

265 { erase(idFromName(name)); };
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:290
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
Definition: BayesNet_tpl.h:317

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::erase ( const DiscreteVariable var)

Remove a variable from the gum::BayesNet.

Removes the corresponding variable from the gum::BayesNet and from all of it's children gum::Potential.

If no variable matches the given variable, then nothing is done.

Parameters
varA reference on the variable to remove.

Definition at line 312 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, gum::BayesNet< GUM_SCALAR >::erase(), and gum::VariableNodeMap::get().

312  {
313  erase(__varMap.get(var));
314  }
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
Definition: BayesNet_tpl.h:317

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::eraseArc ( const Arc arc)

Removes an arc in the BN, and update head's CTP.

If (tail, head) doesn't exist, the nothing happens.

Parameters
arcThe arc removed.

Definition at line 342 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__probaMap, gum::BayesNet< GUM_SCALAR >::__varMap, gum::DAGmodel::_dag, gum::ArcGraphPart::eraseArc(), gum::VariableNodeMap::exists(), gum::Arc::head(), gum::Arc::tail(), and gum::BayesNet< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< double >::addArc(), gum::BayesNet< GUM_SCALAR >::eraseArc(), gum::BayesNet< double >::eraseArc(), and gum::BayesNet< GUM_SCALAR >::reverseArc().

342  {
343  if (__varMap.exists(arc.tail()) && __varMap.exists(arc.head())) {
344  NodeId head = arc.head(), tail = arc.tail();
345  this->_dag.eraseArc(arc);
346  // Remove parent froms child's CPT
347  (*(__probaMap[head])) >> variable(tail);
348  }
349  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
NodeProperty< Potential< GUM_SCALAR > * > __probaMap
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
bool exists(NodeId id) const
Return true if id matches a node.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::eraseArc ( NodeId  tail,
NodeId  head 
)

Removes an arc in the BN, and update head's CTP.

If (tail, head) doesn't exist, the nothing happens.

Parameters
headand
tailas NodeId

Definition at line 352 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::eraseArc().

352  {
353  eraseArc(Arc(tail, head));
354  }
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head&#39;s CTP.
Definition: BayesNet_tpl.h:342

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::eraseArc ( const std::string &  tail,
const std::string &  head 
)
inline

Removes an arc in the BN, and update head's CTP.

Definition at line 413 of file BayesNet.h.

413  {
414  eraseArc(idFromName(tail), idFromName(head));
415  }
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:290
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head&#39;s CTP.
Definition: BayesNet_tpl.h:342
template<typename GUM_SCALAR >
BayesNet< GUM_SCALAR > gum::BayesNet< GUM_SCALAR >::fastPrototype ( const std::string &  dotlike,
Size  domainSize = 2 
)
static

Create a bn with a dotlike syntax : 'a->b->c;b->d;'.

The domain size maybe specified using 'a[10]' or using 'a{yes|maybe|no}'. Note that if the dotlike string contains such a specification for an already defined variable, the first specification will be used.

Parameters
dotlikethe string containing the specification
domainSizethe default domain size for variables
Returns
the resulting bayesian network

Definition at line 115 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::addArc(), gum::build_node(), gum::BayesNet< GUM_SCALAR >::generateCPTs(), and gum::split().

116  {
118 
119 
120  for (const auto& chaine : split(dotlike, ";")) {
121  NodeId lastId = 0;
122  bool notfirst = false;
123  for (const auto& souschaine : split(chaine, "->")) {
124  bool forward = true;
125  for (const auto& node : split(souschaine, "<-")) {
126  auto idVar = build_node(bn, node, domainSize);
127  if (notfirst) {
128  if (forward) {
129  bn.addArc(lastId, idVar);
130  forward = false;
131  } else {
132  bn.addArc(idVar, lastId);
133  }
134  } else {
135  notfirst = true;
136  forward = false;
137  }
138  lastId = idVar;
139  }
140  }
141  }
142  bn.generateCPTs();
143  return bn;
144  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:335
Class representing a Bayesian Network.
Definition: BayesNet.h:76
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
NodeId build_node(gum::BayesNet< GUM_SCALAR > &bn, std::string node, gum::Size domainSize)
Definition: BayesNet_tpl.h:57
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
void generateCPTs() const
randomly generates CPTs for a given structure
Definition: BayesNet_tpl.h:626

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::generateCPT ( NodeId  node) const

randomly generate CPT for a given node in a given structure

Definition at line 631 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::cpt(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), and gum::BayesNet< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< double >::addWeightedArc(), gum::BayesNet< double >::generateCPT(), and gum::BayesNet< GUM_SCALAR >::generateCPTs().

631  {
632  SimpleCPTGenerator< GUM_SCALAR > generator;
633 
634  generator.generateCPT(cpt(node).pos(variable(node)), cpt(node));
635  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:302

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::generateCPT ( const std::string &  name) const
inline

Definition at line 628 of file BayesNet.h.

628  {
629  generateCPT(idFromName(name));
630  };
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
Definition: BayesNet_tpl.h:631
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:290
template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::generateCPTs ( ) const

randomly generates CPTs for a given structure

Definition at line 626 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::generateCPT(), and gum::DAGmodel::nodes().

Referenced by gum::BayesNet< double >::addWeightedArc(), and gum::BayesNet< GUM_SCALAR >::fastPrototype().

626  {
627  for (const auto node : nodes())
628  generateCPT(node);
629  }
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
Definition: BayesNet_tpl.h:631
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool gum::DAGmodel::hasSameStructure ( const DAGmodel other)
inherited
Returns
true if all the named node are the same and all the named arcs are the same

Definition at line 118 of file DAGmodel.cpp.

References gum::DAGmodel::arcs(), gum::Set< Key, Alloc >::exists(), gum::DAGmodel::idFromName(), gum::DAGmodel::nodes(), gum::DAGmodel::size(), gum::DAGmodel::sizeArcs(), and gum::DAGmodel::variable().

Referenced by gum::DAGmodel::children().

118  {
119  if (this == &other) return true;
120 
121  if (size() != other.size()) return false;
122 
123  if (sizeArcs() != other.sizeArcs()) return false;
124 
125  for (const auto& nid : nodes()) {
126  try {
127  other.idFromName(variable(nid).name());
128  } catch (NotFound) { return false; }
129  }
130 
131  for (const auto& arc : arcs()) {
132  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
133  other.idFromName(variable(arc.head()).name()))))
134  return false;
135  }
136 
137  return true;
138  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:102
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:100
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::idFromName ( const std::string &  name) const
finalvirtual

Returns a variable's id given its name in the gum::BayesNet.

Parameters
nameThe variable's name from which the gum::NodeId is returned.
Returns
Returns the variable gum::NodeId in the gum::BayesNet.
Exceptions
NotFoundRaised if name does not match a variable in the gum::BayesNet.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 290 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, and gum::VariableNodeMap::idFromName().

Referenced by gum::BayesNet< double >::addArc(), gum::BayesNet< double >::addWeightedArc(), gum::build_node(), gum::BayesNet< GUM_SCALAR >::changePotential(), gum::BayesNet< double >::changeVariableLabel(), gum::BayesNet< double >::changeVariableName(), gum::BayesNet< double >::cpt(), gum::BayesNet< double >::erase(), gum::BayesNet< double >::eraseArc(), gum::BayesNet< double >::generateCPT(), gum::BayesNet< double >::reverseArc(), and gum::BayesNet< double >::variable().

290  {
291  return __varMap.idFromName(name);
292  }
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
NodeId idFromName(const std::string &name) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::jointProbability ( const Instantiation i) const
inherited

Compute a parameter of the joint probability for the BN (given an instantiation of the vars)

Warning
a variable not present in the instantiation is assumed to be instantiated to 0.

Definition at line 217 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

217  {
218  auto value = (GUM_SCALAR)1.0;
219 
220  GUM_SCALAR tmp;
221 
222  for (auto node : nodes()) {
223  if ((tmp = cpt(node)[i]) == (GUM_SCALAR)0) { return (GUM_SCALAR)0; }
224 
225  value *= tmp;
226  }
227 
228  return value;
229  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

INLINE double gum::DAGmodel::log10DomainSize ( ) const
inherited
Returns
Returns the log10 domain size of the joint probabilty for the Directed Graphical Model

Definition at line 73 of file DAGmodel_inl.h.

References gum::DAGmodel::nodes(), and gum::DAGmodel::variable().

Referenced by gum::DAGmodel::children(), gum::InfluenceDiagram< GUM_SCALAR >::toString(), and gum::IBayesNet< GUM_SCALAR >::toString().

73  {
74  double dSize = 0.0;
75 
76  for (const auto node : nodes()) {
77  dSize += std::log10(variable(node).domainSize());
78  }
79 
80  return dSize;
81  }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::log2JointProbability ( const Instantiation i) const
inherited

Compute a parameter of the log joint probability for the BN (given an instantiation of the vars)

Compute a parameter of the joint probability for the BN (given an instantiation of the vars)

Warning
a variable not present in the instantiation is assumed to be instantiated to 0.

Definition at line 236 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

236  {
237  auto value = (GUM_SCALAR)0.0;
238 
239  GUM_SCALAR tmp;
240 
241  for (auto node : nodes()) {
242  if ((tmp = cpt(node)[i]) == (GUM_SCALAR)0) {
243  return (GUM_SCALAR)(-std::numeric_limits< double >::infinity());
244  }
245 
246  value += log2(cpt(node)[i]);
247  }
248 
249  return value;
250  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::maxNonOneParam ( ) const
inherited
Returns
the biggest value (not equal to 1) in the CPTs of *this

Definition at line 132 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

132  {
133  GUM_SCALAR res = 0.0;
134  for (auto node : nodes()) {
135  auto v = cpt(node).maxNonOne();
136  if (v > res) { res = v; }
137  }
138  return res;
139  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::maxParam ( ) const
inherited
Returns
the biggest value in the CPTs of *this

Definition at line 112 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

112  {
113  GUM_SCALAR res = 1.0;
114  for (auto node : nodes()) {
115  auto v = cpt(node).max();
116  if (v > res) { res = v; }
117  }
118  return res;
119  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
Size gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize ( ) const
inherited
Returns
the biggest domainSize among the variables of *this

Definition at line 92 of file IBayesNet_tpl.h.

References gum::DiscreteVariable::domainSize(), gum::DAGmodel::nodes(), and gum::IBayesNet< GUM_SCALAR >::variable().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize().

92  {
93  Size res = 0;
94  for (auto node : nodes()) {
95  auto v = variable(node).domainSize();
96  if (v > res) { res = v; }
97  }
98  return res;
99  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
virtual Size domainSize() const =0
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
NodeSet gum::IBayesNet< GUM_SCALAR >::minimalCondSet ( NodeId  target,
const NodeSet soids 
) const
inherited

Definition at line 352 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitDn(), gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitUp(), gum::DAGmodel::_dag, gum::ArcGraphPart::children(), gum::Set< Key, Alloc >::contains(), and gum::ArcGraphPart::parents().

Referenced by gum::IBayesNet< GUM_SCALAR >::minimalCondSet().

353  {
354  if (soids.contains(target)) return NodeSet({target});
355 
356  NodeSet res;
357  NodeSet alreadyVisitedUp;
358  NodeSet alreadyVisitedDn;
359  alreadyVisitedDn << target;
360  alreadyVisitedUp << target;
361 
362  for (auto fath : _dag.parents(target))
364  fath, soids, res, alreadyVisitedUp, alreadyVisitedDn);
365  for (auto chil : _dag.children(target))
367  chil, soids, res, alreadyVisitedUp, alreadyVisitedDn);
368  return res;
369  }
void __minimalCondSetVisitDn(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
void __minimalCondSetVisitUp(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
NodeSet gum::IBayesNet< GUM_SCALAR >::minimalCondSet ( const NodeSet targets,
const NodeSet soids 
) const
inherited

Definition at line 372 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::minimalCondSet().

373  {
374  NodeSet res;
375  for (auto node : targets) {
376  res += minimalCondSet(node, soids);
377  }
378  return res;
379  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::minNonZeroParam ( ) const
inherited
Returns
the smallest value (not equal to 0) in the CPTs of *this

Definition at line 122 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize().

122  {
123  GUM_SCALAR res = 1.0;
124  for (auto node : nodes()) {
125  auto v = cpt(node).minNonZero();
126  if (v < res) { res = v; }
127  }
128  return res;
129  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::minParam ( ) const
inherited
Returns
the smallest value in the CPTs of *this

Definition at line 102 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

102  {
103  GUM_SCALAR res = 1.0;
104  for (auto node : nodes()) {
105  auto v = cpt(node).min();
106  if (v < res) { res = v; }
107  }
108  return res;
109  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

const UndiGraph & gum::DAGmodel::moralGraph ( bool  clear = true) const
inherited

The node's id are coherent with the variables and nodes of the topology.

Parameters
clearIf false returns the previously created moral graph.

Definition at line 98 of file DAGmodel.cpp.

References gum::DAGmodel::__moralGraph(), gum::DAGmodel::__mutableMoralGraph, and gum::UndiGraph::clear().

Referenced by gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), and gum::DAGmodel::children().

98  {
99  if (clear
100  || (__mutableMoralGraph == nullptr)) { // we have to call _moralGraph
101  if (__mutableMoralGraph == nullptr) {
102  __mutableMoralGraph = new UndiGraph();
103  } else {
104  // clear is True ,__mutableMoralGraph exists
106  }
107 
108  __moralGraph();
109  }
110 
111  return *__mutableMoralGraph;
112  }
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:40
UndiGraph * __mutableMoralGraph
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:208
void __moralGraph() const
Returns the moral graph of this DAGModel.
Definition: DAGmodel.cpp:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNet< GUM_SCALAR >::nodeId ( const DiscreteVariable var) const
finalvirtual

Returns a variable's id in the gum::BayesNet.

Parameters
varThe variable from which the gum::NodeId is returned.
Returns
Returns the gum::DiscreteVariable gum::NodeId in the gum::BayesNet.
Exceptions
NotFoundIf var is not in the gum::BayesNet.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 214 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, and gum::VariableNodeMap::get().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), and gum::BayesNet< double >::changeVariableLabel().

214  {
215  return __varMap.get(var);
216  }
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE const NodeGraphPart & gum::DAGmodel::nodes ( ) const
inherited

Returns a constant reference to the dag of this Bayes Net.

Definition at line 113 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::credal::CredalNet< GUM_SCALAR >::__sort_varType(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNet< GUM_SCALAR >::beginTopologyTransformation(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::IBayesNet< GUM_SCALAR >::dim(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::BayesNet< GUM_SCALAR >::endTopologyTransformation(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::BayesNet< GUM_SCALAR >::generateCPTs(), gum::getMaxModality(), gum::DAGmodel::hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::jointProbability(), gum::DAGmodel::log10DomainSize(), gum::IBayesNet< GUM_SCALAR >::log2JointProbability(), gum::IBayesNet< GUM_SCALAR >::maxNonOneParam(), gum::IBayesNet< GUM_SCALAR >::maxParam(), gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize(), gum::IBayesNet< GUM_SCALAR >::minNonZeroParam(), gum::IBayesNet< GUM_SCALAR >::minParam(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toString(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

113  {
114  return (NodeGraphPart&)_dag;
115  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
template<typename GUM_SCALAR>
bool gum::IBayesNet< GUM_SCALAR >::operator!= ( const IBayesNet< GUM_SCALAR > &  from) const
inherited
Returns
Returns false if the src and this are equal.

Definition at line 300 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::operator==().

300  {
301  return !this->operator==(from);
302  }
bool operator==(const IBayesNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
BayesNet< GUM_SCALAR > & gum::BayesNet< GUM_SCALAR >::operator= ( const BayesNet< GUM_SCALAR > &  source)

Copy operator.

Parameters
sourceThe copied BayesNet.
Returns
The copy of source.

Definition at line 167 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__clearPotentials(), gum::BayesNet< GUM_SCALAR >::__copyPotentials(), gum::BayesNet< GUM_SCALAR >::__varMap, and gum::IBayesNet< GUM_SCALAR >::operator=().

Referenced by gum::BayesNet< GUM_SCALAR >::BayesNet().

167  {
168  if (this != &source) {
170  __varMap = source.__varMap;
171 
173  __copyPotentials(source);
174  }
175 
176  return *this;
177  }
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Definition: IBayesNet_tpl.h:64
void __copyPotentials(const BayesNet< GUM_SCALAR > &source)
copy of potentials from a BN to another, using names of vars as ref.
Definition: BayesNet_tpl.h:606
void __clearPotentials()
clear all potentials
Definition: BayesNet_tpl.h:595

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
bool gum::IBayesNet< GUM_SCALAR >::operator== ( const IBayesNet< GUM_SCALAR > &  from) const
inherited

This operator compares 2 BNs !

Warning
To identify nodes between BNs, it is assumed that they share the same name.
Returns
true if the src and this are equal.

Definition at line 253 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), gum::Instantiation::end(), gum::IBayesNet< GUM_SCALAR >::idFromName(), gum::Instantiation::inc(), gum::BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::insert(), gum::DAGmodel::nodes(), gum::BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::second(), gum::Instantiation::setFirst(), gum::DAGmodel::size(), gum::DAGmodel::sizeArcs(), gum::Instantiation::val(), gum::IBayesNet< GUM_SCALAR >::variable(), gum::Instantiation::variable(), and gum::IBayesNet< GUM_SCALAR >::variableFromName().

Referenced by gum::IBayesNet< GUM_SCALAR >::operator!=().

253  {
254  if (size() != from.size()) { return false; }
255 
256  if (sizeArcs() != from.sizeArcs()) { return false; }
257 
258  // alignment of variables between the 2 BNs
259  Bijection< const DiscreteVariable*, const DiscreteVariable* > alignment;
260 
261  for (auto node : nodes()) {
262  try {
263  alignment.insert(&variable(node),
264  &from.variableFromName(variable(node).name()));
265  } catch (NotFound&) {
266  // a name is not found in from
267  return false;
268  }
269  }
270 
271  for (auto node : nodes()) {
272  NodeId fromnode = from.idFromName(variable(node).name());
273 
274  if (cpt(node).nbrDim() != from.cpt(fromnode).nbrDim()) { return false; }
275 
276  if (cpt(node).domainSize() != from.cpt(fromnode).domainSize()) {
277  return false;
278  }
279 
280  Instantiation i(cpt(node));
281  Instantiation j(from.cpt(fromnode));
282 
283  for (i.setFirst(); !i.end(); i.inc()) {
284  for (Idx indice = 0; indice < cpt(node).nbrDim(); ++indice) {
285  const DiscreteVariable* p = &(i.variable(indice));
286  j.chgVal(*(alignment.second(p)), i.val(*p));
287  }
288 
289  if (std::pow(cpt(node).get(i) - from.cpt(fromnode).get(j), (GUM_SCALAR)2)
290  > (GUM_SCALAR)1e-6) {
291  return false;
292  }
293  }
294  }
295 
296  return true;
297  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:100
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE const NodeSet & gum::DAGmodel::parents ( const NodeId  id) const
inherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 104 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::parents().

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::DAGmodel::children(), gum::IBayesNet< GUM_SCALAR >::dim(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::DAGmodel::parents(), gum::BayesNet< GUM_SCALAR >::reverseArc(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toDot().

104  {
105  return _dag.parents(id);
106  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const NodeSet& gum::DAGmodel::parents ( const std::string &  name) const
inlineinherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 153 of file DAGmodel.h.

References gum::DAGmodel::children(), gum::DAGmodel::idFromName(), and gum::DAGmodel::parents().

153  {
154  return parents(idFromName(name));
155  };
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104

+ Here is the call graph for this function:

INLINE const std::string & gum::DAGmodel::property ( const std::string &  name) const
inherited

Return the value of the property name of this DAGModel.

Exceptions
NotFoundRaised if no name property is found.

Definition at line 35 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties(), and GUM_ERROR.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toDot().

35  {
36  try {
37  return __properties()[name];
38  } catch (NotFound&) {
39  std::string msg = "The following property does not exists: ";
40  GUM_ERROR(NotFound, msg + name);
41  }
42  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:64
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE const std::string & gum::DAGmodel::propertyWithDefault ( const std::string &  name,
const std::string &  byDefault 
) const
inherited

Return the value of the property name of this DAGModel.

return byDefault if the property name is not found

Definition at line 46 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties().

47  {
48  try {
49  return __properties()[name];
50  } catch (NotFound&) { return byDefault; }
51  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:64

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::reverseArc ( NodeId  tail,
NodeId  head 
)

Reverses an arc while preserving the same joint distribution.

This method uses Shachter's 1986 algorithm for reversing an arc in the Bayes net while preserving the same joint distribution. By performing this reversal, we also add new arcs (required to not alter the joint distribution)

Exceptions
InvalidArcexception if the arc does not exist or if its reversal would induce a directed cycle.

Definition at line 420 of file BayesNet_tpl.h.

Referenced by gum::BayesNet< double >::eraseArc(), and gum::BayesNet< double >::reverseArc().

420  {
421  reverseArc(Arc(tail, head));
422  }
void reverseArc(NodeId tail, NodeId head)
Reverses an arc while preserving the same joint distribution.
Definition: BayesNet_tpl.h:420

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::BayesNet< GUM_SCALAR >::reverseArc ( const std::string &  tail,
const std::string &  head 
)
inline

Reverses an arc while preserving the same joint distribution.

This method uses Shachter's 1986 algorithm for reversing an arc in the Bayes net while preserving the same joint distribution. By performing this reversal, we also add new arcs (required to not alter the joint distribution)

Exceptions
InvalidArcexception if the arc does not exist or if its reversal would induce a directed cycle.

Definition at line 446 of file BayesNet.h.

446  {
447  reverseArc(idFromName(tail), idFromName(head));
448  }
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:290
void reverseArc(NodeId tail, NodeId head)
Reverses an arc while preserving the same joint distribution.
Definition: BayesNet_tpl.h:420
template<typename GUM_SCALAR >
void gum::BayesNet< GUM_SCALAR >::reverseArc ( const Arc arc)

Reverses an arc while preserving the same joint distribution.

This method uses Shachter's 1986 algorithm for reversing an arc in the Bayes net while preserving the same joint distribution. By performing this reversal, we also add new arcs (required to not alter the joint distribution)

Exceptions
InvalidArcexception if the arc does not exist or if its reversal would induce a directed cycle.

Definition at line 357 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, gum::DAG::addArc(), gum::BayesNet< GUM_SCALAR >::addArc(), gum::BayesNet< GUM_SCALAR >::beginTopologyTransformation(), gum::BayesNet< GUM_SCALAR >::cpt(), gum::DAGmodel::dag(), gum::BayesNet< GUM_SCALAR >::endTopologyTransformation(), gum::ArcGraphPart::eraseArc(), gum::BayesNet< GUM_SCALAR >::eraseArc(), gum::VariableNodeMap::exists(), gum::ArcGraphPart::existsArc(), GUM_ERROR, gum::Arc::head(), gum::Set< Key, Alloc >::insert(), gum::Potential< GUM_SCALAR >::margSumOut(), gum::DAGmodel::parents(), gum::Arc::tail(), and gum::BayesNet< GUM_SCALAR >::variable().

357  {
358  // check that the arc exsists
359  if (!__varMap.exists(arc.tail()) || !__varMap.exists(arc.head())
360  || !dag().existsArc(arc)) {
361  GUM_ERROR(InvalidArc, "a nonexisting arc cannot be reversed");
362  }
363 
364  NodeId tail = arc.tail(), head = arc.head();
365 
366  // check that the reversal does not induce a cycle
367  try {
368  DAG d = dag();
369  d.eraseArc(arc);
370  d.addArc(head, tail);
371  } catch (Exception&) {
372  GUM_ERROR(InvalidArc, "this arc reversal would induce a directed cycle");
373  }
374 
375  // with the same notations as Shachter (1986), "evaluating influence
376  // diagrams",
377  // p.878, we shall first compute the product of probabilities:
378  // pi_j^old (x_j | x_c^old(j) ) * pi_i^old (x_i | x_c^old(i) )
379  Potential< GUM_SCALAR > prod{cpt(tail) * cpt(head)};
380 
381  // modify the topology of the graph: add to tail all the parents of head
382  // and add to head all the parents of tail
384  NodeSet new_parents;
385  for (const auto node : this->parents(tail))
386  new_parents.insert(node);
387  for (const auto node : this->parents(head))
388  new_parents.insert(node);
389  // remove arc (head, tail)
390  eraseArc(arc);
391 
392  // add the necessary arcs to the tail
393  for (const auto p : new_parents) {
394  if ((p != tail) && !dag().existsArc(p, tail)) { addArc(p, tail); }
395  }
396 
397  addArc(head, tail);
398  // add the necessary arcs to the head
399  new_parents.erase(tail);
400 
401  for (const auto p : new_parents) {
402  if ((p != head) && !dag().existsArc(p, head)) { addArc(p, head); }
403  }
404 
406 
407  // update the conditional distributions of head and tail
408  Set< const DiscreteVariable* > del_vars;
409  del_vars << &(variable(tail));
410  Potential< GUM_SCALAR > new_cpt_head = prod.margSumOut(del_vars);
411  auto& cpt_head = const_cast< Potential< GUM_SCALAR >& >(cpt(head));
412  cpt_head = std::move(new_cpt_head);
413 
414  Potential< GUM_SCALAR > new_cpt_tail{prod / cpt_head};
415  auto& cpt_tail = const_cast< Potential< GUM_SCALAR >& >(cpt(tail));
416  cpt_tail = std::move(new_cpt_tail);
417  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:335
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
void beginTopologyTransformation()
When inserting/removing arcs, node CPTs change their dimension with a cost in time.
Definition: BayesNet_tpl.h:581
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:302
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104
bool exists(NodeId id) const
Return true if id matches a node.
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
void endTopologyTransformation()
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
Definition: BayesNet_tpl.h:588
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head&#39;s CTP.
Definition: BayesNet_tpl.h:342

+ Here is the call graph for this function:

INLINE void gum::DAGmodel::setProperty ( const std::string &  name,
const std::string &  value 
)
inherited

Add or change a property of this DAGModel.

Definition at line 54 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties(), and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::IBayesNet< GUM_SCALAR >::IBayesNet().

54  {
55  try {
56  __properties()[name] = value;
57  } catch (NotFound&) { __properties().insert(name, value); }
58  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:64
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE Size gum::DAGmodel::size ( ) const
inherited

Returns the number of variables in this Directed Graphical Model.

Definition at line 94 of file DAGmodel_inl.h.

References gum::DAGmodel::dag(), and gum::NodeGraphPart::size().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__initCNNets(), gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize(), gum::DAGmodel::empty(), gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toString().

94 { return dag().size(); }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
Size size() const
alias for sizeNodes

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

INLINE Size gum::DAGmodel::sizeArcs ( ) const
inherited

Returns the number of arcs in this Directed Graphical Model.

Definition at line 100 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::sizeArcs().

Referenced by gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), and gum::IBayesNet< GUM_SCALAR >::operator==().

100 { return _dag.sizeArcs(); }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
std::string gum::IBayesNet< GUM_SCALAR >::toDot ( ) const
virtualinherited
Returns
Returns a dot representation of this IBayesNet.

Reimplemented in gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.

Definition at line 172 of file IBayesNet_tpl.h.

References gum::DAGmodel::children(), gum::Variable::name(), gum::DAGmodel::nodes(), gum::DAGmodel::parents(), gum::DAGmodel::property(), gum::DAGmodel::size(), gum::DiscreteVariable::toStringWithDescription(), and gum::IBayesNet< GUM_SCALAR >::variable().

172  {
173  std::stringstream output;
174  output << "digraph \"";
175 
176  std::string bn_name;
177 
178  try {
179  bn_name = this->property("name");
180  } catch (NotFound&) { bn_name = "no_name"; }
181 
182  output << bn_name << "\" {" << std::endl;
183  output << " graph [bgcolor=transparent,label=\"" << bn_name << "\"];"
184  << std::endl;
185  output << " node [style=filled fillcolor=\"#ffffaa\"];" << std::endl
186  << std::endl;
187 
188  for (auto node : nodes())
189  output << "\"" << variable(node).name() << "\" [comment=\"" << node << ":"
190  << variable(node).toStringWithDescription() << "\"];" << std::endl;
191 
192  output << std::endl;
193 
194  std::string tab = " ";
195 
196  for (auto node : nodes()) {
197  if (children(node).size() > 0) {
198  for (auto child : children(node)) {
199  output << tab << "\"" << variable(node).name() << "\" -> "
200  << "\"" << variable(child).name() << "\";" << std::endl;
201  }
202  } else if (parents(node).size() == 0) {
203  output << tab << "\"" << variable(node).name() << "\";" << std::endl;
204  }
205  }
206 
207  output << "}" << std::endl;
208 
209  return output.str();
210  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:109
const std::string toStringWithDescription() const
string version of *this using description attribute instead of name.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104
const std::string & property(const std::string &name) const
Return the value of the property name of this DAGModel.
Definition: DAGmodel_inl.h:35
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113
const std::string & name() const
returns the name of the variable

+ Here is the call graph for this function:

const Sequence< NodeId > & gum::DAGmodel::topologicalOrder ( bool  clear = true) const
inherited

The topological order stays the same as long as no variable or arcs are added or erased src the topology.

Parameters
clearIf false returns the previously created topology.

Definition at line 114 of file DAGmodel.cpp.

References gum::DAGmodel::dag(), and gum::DiGraph::topologicalOrder().

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), gum::DAGmodel::children(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().

114  {
115  return this->dag().topologicalOrder(clear);
116  }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: diGraph.cpp:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE std::string gum::IBayesNet< GUM_SCALAR >::toString ( ) const
inherited
Returns
Returns a string representation of this IBayesNet.

Definition at line 142 of file IBayesNet_tpl.h.

References gum::IBayesNet< GUM_SCALAR >::cpt(), gum::DAGmodel::dag(), gum::DAGmodel::log10DomainSize(), gum::DAGmodel::nodes(), gum::DAGmodel::size(), and gum::ArcGraphPart::sizeArcs().

Referenced by gum::operator<<().

142  {
143  Size param = 0;
144  double dSize = log10DomainSize();
145 
146  for (auto node : nodes())
147  param += cpt(node).content()->realSize();
148 
149  double compressionRatio = log10(1.0 * param) - dSize;
150 
151  std::stringstream s;
152  s << "BN{nodes: " << size() << ", arcs: " << dag().sizeArcs() << ", ";
153 
154  if (dSize > 6)
155  s << "domainSize: 10^" << dSize;
156  else
157  s << "domainSize: " << std::round(std::pow(10.0, dSize));
158 
159  s << ", parameters: " << param << ", compression ratio: ";
160 
161  if (compressionRatio > -3)
162  s << trunc(100.0 - std::pow(10.0, compressionRatio + 2.0));
163  else
164  s << "100-10^" << compressionRatio + 2.0;
165 
166  s << "% }";
167 
168  return s.str();
169  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
double log10DomainSize() const
Definition: DAGmodel_inl.h:73
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::BayesNet< GUM_SCALAR >::variable ( NodeId  id) const
finalvirtual

Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.

Parameters
idThe variable's id to return.
Returns
Returns a constant reference of the gum::DiscreteVariable corresponding to id in the gum::BayesNet.
Exceptions
NotFoundRaised if id does not match a a variable in the gum::BayesNet.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 189 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, and gum::VariableNodeMap::get().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::BayesNet< GUM_SCALAR >::add(), gum::BayesNet< GUM_SCALAR >::addArc(), gum::BayesNet< GUM_SCALAR >::addWeightedArc(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNet< GUM_SCALAR >::changeVariableLabel(), gum::learning::genericBNLearner::Database::Database(), gum::BayesNet< GUM_SCALAR >::erase(), gum::BayesNet< double >::erase(), gum::BayesNet< GUM_SCALAR >::eraseArc(), gum::BayesNet< GUM_SCALAR >::generateCPT(), gum::getMaxModality(), gum::BayesNet< GUM_SCALAR >::reverseArc(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNet< double >::variable().

189  {
190  return __varMap.get(id);
191  }
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
const DiscreteVariable& gum::BayesNet< GUM_SCALAR >::variable ( const std::string &  name) const
inline

Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.

Definition at line 295 of file BayesNet.h.

295  {
296  return variable(idFromName(name));
297  };
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:189
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:290
template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::BayesNet< GUM_SCALAR >::variableFromName ( const std::string &  name) const
finalvirtual

Returns a variable given its name in the gum::BayesNet.

Parameters
nameThe variable's name in the gum::BayesNet.
Returns
Returns the gum::DiscreteVariable named name in the gum::BayesNet.
Exceptions
NotFoundRaised if name does not match a variable in the gum::BayesNet.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 296 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap, and gum::VariableNodeMap::variableFromName().

Referenced by gum::BayesNet< GUM_SCALAR >::__copyPotentials(), and gum::BayesNet< double >::changeVariableLabel().

296  {
297  return __varMap.variableFromName(name);
298  }
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647
const DiscreteVariable & variableFromName(const std::string &name) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const VariableNodeMap & gum::BayesNet< GUM_SCALAR >::variableNodeMap ( ) const
finalvirtual

Returns a map between variables and nodes of this gum::BayesNet.

Returns
Returns a constant reference to the gum::VariableNodeMap.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 307 of file BayesNet_tpl.h.

References gum::BayesNet< GUM_SCALAR >::__varMap.

Referenced by gum::BayesNet< double >::cpt(), and gum::learning::DAG2BNLearner::createBN().

307  {
308  return __varMap;
309  }
VariableNodeMap __varMap
the map between variable and id
Definition: BayesNet.h:647

+ Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename GUM_SCALAR>
friend class BayesNetFactory< GUM_SCALAR >
friend

Definition at line 77 of file BayesNet.h.

Member Data Documentation

DAG gum::DAGmodel::_dag
protectedinherited

The documentation for this class was generated from the following files: