aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
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
 
bool hasSameStructure (const DAGmodel &other)
 
double log10DomainSize () const
 
Constructors and Destructor
 BayesNet ()
 Default constructor. More...
 
 BayesNet (std::string name)
 Default constructor. More...
 
virtual ~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 clear ()
 clear the whole Bayes net * 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...
 
NodeId addSUM (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...
 
Variable manipulation methods.
const DAGdag () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
virtual Size size () const final
 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...
 
const NodeGraphPartnodes () const final
 Returns a constant reference to the dag of this Bayes Net. More...
 
bool exists (NodeId node) const final
 Return true if this node exists in this graphical model. More...
 
Variable manipulation methods.
bool exists (const std::string &name) const
 Return true if this graphical model is empty. More...
 
virtual bool empty () const
 Return true if this graphical model is empty. More...
 
std::vector< std::string > names (const std::vector< NodeId > &ids) const
 transform a vector of NodeId in a vector of names More...
 
std::vector< std::string > names (const NodeSet &ids) const
 transform a NodeSet in a vector of names More...
 
std::vector< NodeIdids (const std::vector< std::string > &names) const
 transform a vector of names into a vector of nodeId More...
 
NodeSet nodeset (const std::vector< std::string > &names) const
 transform a vector of names into a NodeSet More...
 
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model. More...
 
Arc manipulation methods.
const ArcSetarcs () const
 return true if the arc tail->head exists in the DAGmodel More...
 
bool existsArc (const NodeId tail, const NodeId head) const
 return true if the arc tail->head exists in the DAGmodel More...
 
bool existsArc (const std::string &nametail, const std::string &namehead) const
 return true if the arc tail->head exists in the DAGmodel 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
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet parents (const NodeSet &ids) const
 returns the parents of a set of nodes More...
 
NodeSet parents (const std::vector< std::string > &names) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet family (const NodeId id) const
 returns the parents of a node and the node More...
 
NodeSet family (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel 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
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet children (const NodeSet &ids) const
 returns the children of a set of nodes More...
 
NodeSet children (const std::vector< std::string > &names) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet descendants (const NodeId id) const
 returns the set of nodes with directed path outgoing from a given node More...
 
NodeSet descendants (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
NodeSet ancestors (const NodeId id) const
 returns the set of nodes with directed path ingoing to a given node More...
 
NodeSet ancestors (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel More...
 
Graphical methods
UndiGraph moralizedAncestralGraph (const NodeSet &nodes) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
UndiGraph moralizedAncestralGraph (const std::vector< std::string > &nodenames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
bool isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const final
 check if node X and node Y are independent given nodes Z More...
 
bool isIndependent (const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const final
 check if nodes X and nodes Y are independent given nodes Z More...
 
bool isIndependent (const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
bool isIndependent (const std::vector< std::string > &Xnames, const std::vector< std::string > &Ynames, const std::vector< std::string > &Znames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More...
 
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...
 
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this GraphicalModel. More...
 
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this GraphicalModel. More...
 
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this GraphicalModel. More...
 

Static Public Member Functions

static BayesNet< GUM_SCALAR > fastPrototype (const std::string &dotlike, Size domainSize=2)
 Create a Bayesian network with a dot-like syntax which specifies: 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_n) = \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, it's domain cannot change. But it arcs are added, the data in its CPT are 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 77 of file BayesNet.h.

Constructor & Destructor Documentation

◆ BayesNet() [1/3]

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

Default constructor.

Definition at line 178 of file BayesNet_tpl.h.

178  : IBayesNet< GUM_SCALAR >() {
179  GUM_CONSTRUCTOR(BayesNet);
180  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:178

◆ BayesNet() [2/3]

template<typename GUM_SCALAR >
INLINE gum::BayesNet< GUM_SCALAR >::BayesNet ( std::string  name)
explicit

Default constructor.

Parameters
nameThe BayesNet's name.

Definition at line 183 of file BayesNet_tpl.h.

183  : IBayesNet< GUM_SCALAR >(name) {
184  GUM_CONSTRUCTOR(BayesNet);
185  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:178

◆ ~BayesNet()

template<typename GUM_SCALAR >
gum::BayesNet< GUM_SCALAR >::~BayesNet ( )
finalvirtual

Destructor.

Definition at line 209 of file BayesNet_tpl.h.

209  {
210  GUM_DESTRUCTOR(BayesNet);
211  for (const auto p: _probaMap_) {
212  delete p.second;
213  }
214  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:178
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

◆ BayesNet() [3/3]

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

Copy constructor.

Definition at line 188 of file BayesNet_tpl.h.

188  :
189  IBayesNet< GUM_SCALAR >(source), _varMap_(source._varMap_) {
190  GUM_CONS_CPY(BayesNet);
191 
192  _copyPotentials_(source);
193  }
BayesNet()
Default constructor.
Definition: BayesNet_tpl.h:178
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:635
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647

Member Function Documentation

◆ _clearPotentials_()

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

clear all potentials

Definition at line 624 of file BayesNet_tpl.h.

624  {
625  // Removing previous potentials
626  for (const auto& elt: _probaMap_) {
627  delete elt.second;
628  }
629 
630  _probaMap_.clear();
631  }
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

◆ _copyPotentials_()

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 635 of file BayesNet_tpl.h.

635  {
636  // Copying potentials
637 
638  for (const auto src: source._probaMap_) {
639  // First we build the node's CPT
640  Potential< GUM_SCALAR >* copy_array = new Potential< GUM_SCALAR >();
641  copy_array->beginMultipleChanges();
642  for (gum::Idx i = 0; i < src.second->nbrDim(); i++) {
643  (*copy_array) << variableFromName(src.second->variable(i).name());
644  }
645  copy_array->endMultipleChanges();
646  copy_array->copyFrom(*(src.second));
647 
648  // We add the CPT to the CPT hashmap
649  _probaMap_.insert(src.first, copy_array);
650  }
651  }
const DiscreteVariable & variableFromName(const std::string &name) const final
Returns a variable given its name in the gum::BayesNet.
Definition: BayesNet_tpl.h:308
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
Size Idx
Type for indexes.
Definition: types.h:52

◆ _unsafeChangePotential_()

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 687 of file BayesNet_tpl.h.

687  {
688  delete _probaMap_[id];
689  _probaMap_[id] = newPot;
690  }
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

◆ add() [1/5]

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 246 of file BayesNet_tpl.h.

246  {
247  auto ptr = new MultiDimArray< GUM_SCALAR >();
248  try {
249  return add(var, ptr);
250  } catch (Exception&) {
251  delete ptr;
252  throw;
253  }
254  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ add() [2/5]

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 257 of file BayesNet_tpl.h.

257  {
258  if (nbrmod < 2) {
259  GUM_ERROR(OperationNotAllowed,
260  "Variable " << name << "needs more than " << nbrmod << " modalities")
261  }
262 
263  RangeVariable v(name, name, 0, nbrmod - 1);
264  return add(v);
265  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ add() [3/5]

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 268 of file BayesNet_tpl.h.

269  {
270  NodeId proposedId = dag().nextNodeId();
271 
272  return add(var, aContent, proposedId);
273  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246
NodeId nextNodeId() const
returns a new node id, not yet used by any node
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ add() [4/5]

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 276 of file BayesNet_tpl.h.

276  {
277  auto ptr = new MultiDimArray< GUM_SCALAR >();
278 
279  try {
280  return add(var, ptr, id);
281 
282  } catch (Exception&) {
283  delete ptr;
284  throw;
285  }
286  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ add() [5/5]

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 289 of file BayesNet_tpl.h.

291  {
292  _varMap_.insert(id, var);
293  this->dag_.addNodeWithId(id);
294 
295  auto cpt = new Potential< GUM_SCALAR >(aContent);
296  (*cpt) << variable(id);
297  _probaMap_.insert(id, cpt);
298  return id;
299  }
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:217
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
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:313
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647

◆ addAMPLITUDE()

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

Others aggregators.

Definition at line 462 of file BayesNet_tpl.h.

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

◆ addAND()

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 467 of file BayesNet_tpl.h.

467  {
468  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an AND has to be boolean")
469 
470  return add(var, new aggregator::And< GUM_SCALAR >());
471  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addArc() [1/2]

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.
DuplicateElementif the arc already exists

Definition at line 356 of file BayesNet_tpl.h.

356  {
357  if (this->dag_.existsArc(tail, head)) {
358  GUM_ERROR(DuplicateElement, "The arc (" << tail << "," << head << ") already exists.")
359  }
360 
361  this->dag_.addArc(tail, head);
362  // Add parent in the child's CPT
363  (*(_probaMap_[head])) << variable(tail);
364  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Definition: DAG_inl.h:42
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addArc() [2/2]

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

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

Exceptions
gum::DuplicateElementif the arc already exists

Definition at line 367 of file BayesNet_tpl.h.

367  {
368  try {
369  addArc(this->idFromName(tail), this->idFromName(head));
370  } catch (DuplicateElement) {
371  GUM_ERROR(DuplicateElement, "The arc " << tail << "->" << head << " already exists.")
372  }
373  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:356
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:302
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addCOUNT()

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

Others aggregators.

Definition at line 474 of file BayesNet_tpl.h.

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

◆ addEXISTS()

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

Others aggregators.

Definition at line 479 of file BayesNet_tpl.h.

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

◆ addFORALL()

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

Others aggregators.

Definition at line 486 of file BayesNet_tpl.h.

486  {
487  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an EXISTS has to be boolean")
488 
489  return add(var, new aggregator::Forall< GUM_SCALAR >(value));
490  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addLogit() [1/2]

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 567 of file BayesNet_tpl.h.

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

◆ addLogit() [2/2]

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 547 of file BayesNet_tpl.h.

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

◆ addMAX()

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

Others aggregators.

Definition at line 493 of file BayesNet_tpl.h.

493  {
494  return add(var, new aggregator::Max< GUM_SCALAR >());
495  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ addMEDIAN()

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

Others aggregators.

Definition at line 498 of file BayesNet_tpl.h.

498  {
499  return add(var, new aggregator::Median< GUM_SCALAR >());
500  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ addMIN()

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

Others aggregators.

Definition at line 503 of file BayesNet_tpl.h.

503  {
504  return add(var, new aggregator::Min< GUM_SCALAR >());
505  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ addNoisyAND() [1/2]

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 560 of file BayesNet_tpl.h.

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

◆ addNoisyAND() [2/2]

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 541 of file BayesNet_tpl.h.

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

◆ addNoisyOR() [1/2]

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 523 of file BayesNet_tpl.h.

524  {
525  return addNoisyORCompound(var, external_weight);
526  }
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:529

◆ addNoisyOR() [2/2]

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 553 of file BayesNet_tpl.h.

555  {
556  return addNoisyORCompound(var, external_weight, id);
557  }
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:529

◆ addNoisyORCompound() [1/2]

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 529 of file BayesNet_tpl.h.

530  {
531  return add(var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight));
532  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ addNoisyORCompound() [2/2]

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 574 of file BayesNet_tpl.h.

576  {
577  return add(var, new MultiDimNoisyORCompound< GUM_SCALAR >(external_weight), id);
578  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ addNoisyORNet() [1/2]

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 535 of file BayesNet_tpl.h.

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

◆ addNoisyORNet() [2/2]

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 581 of file BayesNet_tpl.h.

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

◆ addOR()

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 508 of file BayesNet_tpl.h.

508  {
509  if (var.domainSize() > 2) GUM_ERROR(SizeError, "an OR has to be boolean")
510 
511  return add(var, new aggregator::Or< GUM_SCALAR >());
512  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addSUM()

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

Others aggregators.

Definition at line 515 of file BayesNet_tpl.h.

515  {
516  return add(var, new aggregator::Sum< GUM_SCALAR >());
517  }
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
Definition: BayesNet_tpl.h:246

◆ addWeightedArc() [1/2]

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 588 of file BayesNet_tpl.h.

588  {
589  auto* CImodel = dynamic_cast< const MultiDimICIModel< GUM_SCALAR >* >(cpt(head).content());
590 
591  if (CImodel != 0) {
592  // or is OK
593  addArc(tail, head);
594 
595  CImodel->causalWeight(variable(tail), causalWeight);
596  } else {
597  GUM_ERROR(InvalidArc,
598  "Head variable (" << variable(head).name() << ") is not a CIModel variable !")
599  }
600  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:356
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:313
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addWeightedArc() [2/2]

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 620 of file BayesNet.h.

620  {
621  addWeightedArc(idFromName(tail), idFromName(head), causalWeight);
622  };
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:588
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:302

◆ ancestors() [1/2]

INLINE NodeSet gum::DAGmodel::ancestors ( const NodeId  id) const
inherited

returns the set of nodes with directed path ingoing to a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is ingoing to the given node.

Parameters
idthe node which is the head of a directed path with the returned nodes
namethe name of the node which is the head of a directed path with the returned nodes

Definition at line 96 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

96 { return dag().ancestors(id); }
NodeSet ancestors(NodeId id) const
returns the set of nodes with directed path ingoing to a given node
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ ancestors() [2/2]

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

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 98 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

98  {
99  return ancestors(idFromName(name));
100  }
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
Definition: DAGmodel_inl.h:96
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ arcs()

INLINE const ArcSet & gum::DAGmodel::arcs ( ) const
inherited

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 43 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

43 { return dag_.arcs(); }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:

◆ beginTopologyTransformation()

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 610 of file BayesNet_tpl.h.

610  {
611  for (const auto node: nodes())
612  _probaMap_[node]->beginMultipleChanges();
613  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

◆ changePotential() [1/2]

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 667 of file BayesNet_tpl.h.

667  {
668  if (cpt(id).nbrDim() != newPot->nbrDim()) {
669  GUM_ERROR(OperationNotAllowed,
670  "cannot exchange potentials with different "
671  "dimensions for variable with id "
672  << id)
673  }
674 
675  for (Idx i = 0; i < cpt(id).nbrDim(); i++) {
676  if (&cpt(id).variable(i) != &(newPot->variable(i))) {
677  GUM_ERROR(OperationNotAllowed,
678  "cannot exchange potentials because, for variable with id "
679  << id << ", dimension " << i << " differs. ")
680  }
681  }
682 
683  _unsafeChangePotential_(id, newPot);
684  }
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:313
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:687
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ changePotential() [2/2]

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

Definition at line 693 of file BayesNet_tpl.h.

694  {
695  changePotential(idFromName(name), newPot);
696  }
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:667
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:302

◆ changeVariableLabel() [1/2]

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 227 of file BayesNet_tpl.h.

229  {
230  if (variable(id).varType() != VarType::Labelized)
231  GUM_ERROR(NotFound, "Variable " << id << " is not a LabelizedVariable.")
232 
233  LabelizedVariable* var
234  = dynamic_cast< LabelizedVariable* >(const_cast< DiscreteVariable* >(&variable(id)));
235 
236  var->changeLabel(var->posLabel(old_label), new_label);
237  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ changeVariableLabel() [2/2]

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 346 of file BayesNet.h.

348  {
349  changeVariableLabel(idFromName(name), old_label, new_label);
350  }
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:227
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:302

◆ changeVariableName() [1/2]

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 222 of file BayesNet_tpl.h.

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

◆ changeVariableName() [2/2]

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 327 of file BayesNet.h.

327  {
328  changeVariableName(idFromName(name), new_name);
329  }
void changeVariableName(NodeId id, const std::string &new_name)
Changes a variable&#39;s name in the gum::BayesNet.
Definition: BayesNet_tpl.h:222
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:302

◆ children() [1/4]

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 nodes returned may be empty if no node is outgoing from the given node.

Parameters
idthe node which is the tail of an arc with the returned nodes
namethe name of the node which is the tail of an arc with the returned nodes

Definition at line 65 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

65 { return dag_.children(id); }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ children() [2/4]

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

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 66 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

66  {
67  return dag_.children(idFromName(name));
68  }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ children() [3/4]

INLINE NodeSet gum::DAGmodel::children ( const NodeSet ids) const
inherited

returns the children of a set of nodes

Definition at line 70 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

70 { return dag_.children(ids); }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ children() [4/4]

INLINE NodeSet gum::DAGmodel::children ( const std::vector< std::string > &  names) const
inherited

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 72 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

72  {
73  return children(nodeset(names));
74  }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:65
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
+ Here is the call graph for this function:

◆ clear()

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

clear the whole Bayes net *

Definition at line 346 of file BayesNet_tpl.h.

346  {
347  if (!this->empty()) {
348  auto l = this->nodes();
349  for (const auto no: l) {
350  this->erase(no);
351  }
352  }
353  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
virtual bool empty() const
Return true if this graphical model is empty.
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
Definition: BayesNet_tpl.h:328

◆ completeInstantiation()

INLINE Instantiation gum::GraphicalModel::completeInstantiation ( ) const
inherited

Get an instantiation over all the variables of the model.

Definition at line 84 of file graphicalModel_inl.h.

84  {
85  Instantiation I;
86 
87  for (const auto node: nodes())
88  I << variable(node);
89 
90  return I;
91  }
virtual const NodeGraphPart & nodes() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.

◆ cpt() [1/2]

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 313 of file BayesNet_tpl.h.

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

◆ cpt() [2/2]

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 164 of file BayesNet.h.

164  {
165  return cpt(idFromName(name));
166  };
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:313
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:302

◆ dag()

INLINE const DAG & gum::DAGmodel::dag ( ) const
inherited

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

Definition at line 35 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

35 { return dag_; }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ descendants() [1/2]

INLINE NodeSet gum::DAGmodel::descendants ( const NodeId  id) const
inherited

returns the set of nodes with directed path outgoing from a given node

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

Parameters
idthe node which is the tail of a directed path with the returned nodes
namethe name of the node which is the tail of a directed path with the returned nodes

Definition at line 90 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

90 { return dag().descendants(id); }
NodeSet descendants(NodeId id) const
returns the set of nodes with directed path outgoing from a given node
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ descendants() [2/2]

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

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 92 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

92  {
93  return descendants(idFromName(name));
94  }
NodeSet descendants(const NodeId id) const
returns the set of nodes with directed path outgoing from a given node
Definition: DAGmodel_inl.h:90
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ dim()

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 78 of file IBayesNet_tpl.h.

78  {
79  Size dim = 0;
80 
81  for (auto node: nodes()) {
82  Size q = 1;
83 
84  for (auto parent: parents(node))
85  q *= variable(parent).domainSize();
86 
87  dim += (variable(node).domainSize() - 1) * q;
88  }
89 
90  return dim;
91  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:53
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.
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
Definition: IBayesNet_tpl.h:78
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ empty()

INLINE bool gum::GraphicalModel::empty ( ) const
virtualinherited

Return true if this graphical model is empty.

Definition at line 94 of file graphicalModel_inl.h.

94 { return size() == 0; }
virtual Size size() const =0
Returns the number of variables in this Directed Graphical Model.

◆ endTopologyTransformation()

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 617 of file BayesNet_tpl.h.

617  {
618  for (const auto node: nodes())
619  _probaMap_[node]->endMultipleChanges();
620  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650

◆ erase() [1/3]

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 328 of file BayesNet_tpl.h.

328  {
329  if (_varMap_.exists(varId)) {
330  // Reduce the variable child's CPT
331  const NodeSet& children = this->children(varId);
332 
333  for (const auto c: children) {
334  _probaMap_[c]->erase(variable(varId));
335  }
336 
337  delete _probaMap_[varId];
338 
339  _probaMap_.erase(varId);
340  _varMap_.erase(varId);
341  this->dag_.eraseNode(varId);
342  }
343  }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:65
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool exists(NodeId id) const
Return true if id matches a node.
void erase(NodeId id)
Removes a var and it&#39;s id of this mapping. The pointer is deleted.
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:67

◆ erase() [2/3]

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 279 of file BayesNet.h.

279 { 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:302
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
Definition: BayesNet_tpl.h:328

◆ erase() [3/3]

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 323 of file BayesNet_tpl.h.

323  {
324  erase(_varMap_.get(var));
325  }
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:328
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.

◆ eraseArc() [1/3]

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 376 of file BayesNet_tpl.h.

376  {
377  if (_varMap_.exists(arc.tail()) && _varMap_.exists(arc.head())) {
378  NodeId head = arc.head(), tail = arc.tail();
379  this->dag_.eraseArc(arc);
380  // Remove parent from child's CPT
381  (*(_probaMap_[head])) >> variable(tail);
382  }
383  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
bool exists(NodeId id) const
Return true if id matches a node.
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable&#39;s id and their CPT.
Definition: BayesNet.h:650
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ eraseArc() [2/3]

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 386 of file BayesNet_tpl.h.

386  {
387  eraseArc(Arc(tail, head));
388  }
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head&#39;s CTP.
Definition: BayesNet_tpl.h:376

◆ eraseArc() [3/3]

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 426 of file BayesNet.h.

426  {
427  eraseArc(idFromName(tail), idFromName(head));
428  }
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:302
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head&#39;s CTP.
Definition: BayesNet_tpl.h:376

◆ exists() [1/2]

INLINE bool gum::DAGmodel::exists ( NodeId  node) const
finalvirtualinherited

Return true if this node exists in this graphical model.

Implements gum::GraphicalModel.

Definition at line 82 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

82 { return dag_.exists(node); }
bool exists(const NodeId id) const
alias for existsNode
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ exists() [2/2]

bool gum::GraphicalModel::exists ( const std::string &  name) const
inlineinherited

Return true if this graphical model is empty.

Definition at line 112 of file graphicalModel.h.

112 { return exists(idFromName(name)); };
virtual bool exists(NodeId node) const =0
Return true if this node exists in this graphical model.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.

◆ existsArc() [1/2]

INLINE bool gum::DAGmodel::existsArc ( const NodeId  tail,
const NodeId  head 
) const
inherited

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 45 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

45  {
46  return dag_.existsArc(tail, head);
47  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
+ Here is the call graph for this function:

◆ existsArc() [2/2]

INLINE bool gum::DAGmodel::existsArc ( const std::string &  nametail,
const std::string &  namehead 
) const
inherited

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 49 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

49  {
50  return existsArc(idFromName(nametail), idFromName(namehead));
51  }
bool existsArc(const NodeId tail, const NodeId head) const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:45
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ family() [1/2]

INLINE NodeSet gum::DAGmodel::family ( const NodeId  id) const
inherited

returns the parents of a node and the node

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

Parameters
idthe node which is the head of an arc with the returned nodes
namethe name of the node the node which is the head of an arc with the returned nodes

Definition at line 59 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

59 { return dag_.family(id); }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ family() [2/2]

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

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 61 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

61  {
62  return dag_.family(idFromName(name));
63  }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ fastPrototype()

template<typename GUM_SCALAR >
BayesNet< GUM_SCALAR > gum::BayesNet< GUM_SCALAR >::fastPrototype ( const std::string &  dotlike,
Size  domainSize = 2 
)
static

Create a Bayesian network with a dot-like syntax which specifies:

  • the structure "a->b->c;b->d<-e;".
  • the type of the variables with different syntax:

Note that if the dot-like string contains such a specification more than once for a 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 145 of file BayesNet_tpl.h.

146  {
148 
149 
150  for (const auto& chaine: split(dotlike, ";")) {
151  NodeId lastId = 0;
152  bool notfirst = false;
153  for (const auto& souschaine: split(chaine, "->")) {
154  bool forward = true;
155  for (const auto& node: split(souschaine, "<-")) {
156  auto idVar = build_node(bn, node, domainSize);
157  if (notfirst) {
158  if (forward) {
159  bn.addArc(lastId, idVar);
160  forward = false;
161  } else {
162  bn.addArc(idVar, lastId);
163  }
164  } else {
165  notfirst = true;
166  forward = false;
167  }
168  lastId = idVar;
169  }
170  }
171  }
172  bn.generateCPTs();
173  bn.setProperty("name", "fastPrototype");
174  return bn;
175  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:356
Class representing a Bayesian network.
Definition: BayesNet.h:77
NodeId build_node(gum::BayesNet< GUM_SCALAR > &bn, std::string node, gum::Size default_domain_size)
Definition: BayesNet_tpl.h:63
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this GraphicalModel.
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:654
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ generateCPT() [1/2]

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 660 of file BayesNet_tpl.h.

660  {
661  SimpleCPTGenerator< GUM_SCALAR > generator;
662 
663  generator.generateCPT(cpt(node).pos(variable(node)), cpt(node));
664  }
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:313

◆ generateCPT() [2/2]

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

Definition at line 630 of file BayesNet.h.

630 { generateCPT(idFromName(name)); };
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
Definition: BayesNet_tpl.h:660
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:302

◆ generateCPTs()

template<typename GUM_SCALAR >
INLINE void gum::BayesNet< GUM_SCALAR >::generateCPTs ( ) const

randomly generates CPTs for a given structure

Definition at line 654 of file BayesNet_tpl.h.

654  {
655  for (const auto node: nodes())
656  generateCPT(node);
657  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
Definition: BayesNet_tpl.h:660

◆ hasSameStructure()

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 69 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

69  {
70  if (this == &other) return true;
71 
72  if (size() != other.size()) return false;
73 
74  if (sizeArcs() != other.sizeArcs()) return false;
75 
76  for (const auto& nid: nodes()) {
77  try {
78  other.idFromName(variable(nid).name());
79  } catch (NotFound) { return false; }
80  }
81 
82  for (const auto& arc: arcs()) {
83  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
84  other.idFromName(variable(arc.head()).name()))))
85  return false;
86  }
87 
88  return true;
89  }
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:43
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:41
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:38
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
+ Here is the call graph for this function:

◆ idFromName()

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 302 of file BayesNet_tpl.h.

302  {
303  return _varMap_.idFromName(name);
304  }
NodeId idFromName(const std::string &name) const
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647

◆ ids()

INLINE std::vector< NodeId > gum::GraphicalModel::ids ( const std::vector< std::string > &  names) const
inherited

transform a vector of names into a vector of nodeId

Returns
the vector of names

Definition at line 117 of file graphicalModel_inl.h.

117  {
118  std::vector< NodeId > res;
119  const VariableNodeMap& v = variableNodeMap();
120  std::transform(names.cbegin(),
121  names.cend(),
122  std::back_inserter(res),
123  [v](const std::string& n) { return v.idFromName(n); });
124  return res;
125  }
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

◆ isIndependent() [1/4]

INLINE bool gum::DAGmodel::isIndependent ( NodeId  X,
NodeId  Y,
const NodeSet Z 
) const
finalvirtualinherited

check if node X and node Y are independent given nodes Z

Implements gum::GraphicalModel.

Definition at line 113 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

113  {
114  return dag().dSeparation(X, Y, Z);
115  }
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation) ...
Definition: DAG.cpp:105
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ isIndependent() [2/4]

INLINE bool gum::DAGmodel::isIndependent ( const NodeSet X,
const NodeSet Y,
const NodeSet Z 
) const
finalvirtualinherited

check if nodes X and nodes Y are independent given nodes Z

Implements gum::GraphicalModel.

Definition at line 117 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

117  {
118  return dag().dSeparation(X, Y, Z);
119  }
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation) ...
Definition: DAG.cpp:105
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ isIndependent() [3/4]

bool gum::DAGmodel::isIndependent ( const std::string &  Xname,
const std::string &  Yname,
const std::vector< std::string > &  Znames 
) const
inlineinherited

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 185 of file DAGmodel.h.

187  {
188  return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
189  };
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z
Definition: DAGmodel_inl.h:113

◆ isIndependent() [4/4]

bool gum::DAGmodel::isIndependent ( const std::vector< std::string > &  Xnames,
const std::vector< std::string > &  Ynames,
const std::vector< std::string > &  Znames 
) const
inlineinherited

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 191 of file DAGmodel.h.

193  {
194  return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
195  };
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z
Definition: DAGmodel_inl.h:113

◆ jointProbability()

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 207 of file IBayesNet_tpl.h.

207  {
208  auto value = (GUM_SCALAR)1.0;
209 
210  GUM_SCALAR tmp;
211 
212  for (auto node: nodes()) {
213  if ((tmp = cpt(node)[i]) == (GUM_SCALAR)0) { return (GUM_SCALAR)0; }
214 
215  value *= tmp;
216  }
217 
218  return value;
219  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.

◆ log10DomainSize()

INLINE double gum::GraphicalModel::log10DomainSize ( ) const
inherited

Definition at line 73 of file graphicalModel_inl.h.

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 NodeGraphPart & nodes() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.

◆ log2JointProbability()

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 225 of file IBayesNet_tpl.h.

225  {
226  auto value = (GUM_SCALAR)0.0;
227 
228  GUM_SCALAR tmp;
229 
230  for (auto node: nodes()) {
231  if ((tmp = cpt(node)[i]) == (GUM_SCALAR)0) {
232  return (GUM_SCALAR)(-std::numeric_limits< double >::infinity());
233  }
234 
235  value += std::log2(cpt(node)[i]);
236  }
237 
238  return value;
239  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Potential< GUM_SCALAR > log2(const Potential< GUM_SCALAR > &arg)
Definition: potential.h:590

◆ maxNonOneParam()

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
Warning
can return one if no other value in the CPTs than one....

Definition at line 134 of file IBayesNet_tpl.h.

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

◆ maxParam()

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 114 of file IBayesNet_tpl.h.

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

◆ maxVarDomainSize()

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

Definition at line 94 of file IBayesNet_tpl.h.

94  {
95  Size res = 0;
96  for (auto node: nodes()) {
97  auto v = variable(node).domainSize();
98  if (v > res) { res = v; }
99  }
100  return res;
101  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
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.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ minimalCondSet() [1/2]

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

Definition at line 332 of file IBayesNet_tpl.h.

332  {
333  if (soids.contains(target)) return NodeSet({target});
334 
335  NodeSet res;
336  NodeSet alreadyVisitedUp;
337  NodeSet alreadyVisitedDn;
338  alreadyVisitedDn << target;
339  alreadyVisitedUp << target;
340 
341  for (auto fath: dag_.parents(target))
342  _minimalCondSetVisitUp_(fath, soids, res, alreadyVisitedUp, alreadyVisitedDn);
343  for (auto chil: dag_.children(target))
344  _minimalCondSetVisitDn_(chil, soids, res, alreadyVisitedUp, alreadyVisitedDn);
345  return res;
346  }
void _minimalCondSetVisitUp_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
void _minimalCondSetVisitDn_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222

◆ minimalCondSet() [2/2]

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

Definition at line 349 of file IBayesNet_tpl.h.

350  {
351  NodeSet res;
352  for (auto node: targets) {
353  res += minimalCondSet(node, soids);
354  }
355  return res;
356  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const

◆ minNonZeroParam()

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
Warning
can return 0 if no other value in the CPTs than 0...

Definition at line 124 of file IBayesNet_tpl.h.

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

◆ minParam()

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 104 of file IBayesNet_tpl.h.

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

◆ moralGraph()

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 55 of file DAGmodel.cpp.

References gum::Set< Key, Alloc >::emplace().

55  {
56  if (clear || (_mutableMoralGraph_ == nullptr)) { // we have to call dag().moralGraph()
57  if (_mutableMoralGraph_ == nullptr) {
58  _mutableMoralGraph_ = new UndiGraph();
59  } else {
60  // clear is True , __mutableMoralGraph exists
62  }
64  }
65 
66  return *_mutableMoralGraph_;
67  }
void clear() override
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:42
UndiGraph moralGraph() const
build a UndiGraph by moralizing the dag
Definition: DAG.cpp:55
UndiGraph * _mutableMoralGraph_
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:230
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ moralizedAncestralGraph() [1/2]

INLINE UndiGraph gum::DAGmodel::moralizedAncestralGraph ( const NodeSet nodes) const
inherited

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 109 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

109  {
111  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAG.cpp:79
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ moralizedAncestralGraph() [2/2]

INLINE UndiGraph gum::DAGmodel::moralizedAncestralGraph ( const std::vector< std::string > &  nodenames) const
inherited

build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

Parameters
nodesthe set of nodeId
nodenamesthe vector of names of nodes
Returns
the moralized ancestral graph

Definition at line 104 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

104  {
105  return moralizedAncestralGraph(nodeset(nodenames));
106  }
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAGmodel_inl.h:109
+ Here is the call graph for this function:

◆ names() [1/2]

INLINE std::vector< std::string > gum::GraphicalModel::names ( const std::vector< NodeId > &  ids) const
inherited

transform a vector of NodeId in a vector of names

Returns
the vector of names

Definition at line 97 of file graphicalModel_inl.h.

97  {
98  std::vector< std::string > res;
99  const VariableNodeMap& v = variableNodeMap();
100  std::transform(ids.cbegin(), ids.cend(), std::back_inserter(res), [v](NodeId n) {
101  return v[n].name();
102  });
103  return res;
104  }
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ names() [2/2]

INLINE std::vector< std::string > gum::GraphicalModel::names ( const NodeSet ids) const
inherited

transform a NodeSet in a vector of names

Returns
the vector of names

Definition at line 107 of file graphicalModel_inl.h.

107  {
108  const VariableNodeMap& v = variableNodeMap();
109  std::vector< std::string > res;
110  for (auto n: ids) {
111  res.push_back(v.name(n));
112  }
113  return res;
114  }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

◆ nodeId()

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 241 of file BayesNet_tpl.h.

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

◆ nodes()

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

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

Implements gum::GraphicalModel.

Definition at line 84 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

84 { return (NodeGraphPart&)dag_; }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ nodeset()

NodeSet gum::GraphicalModel::nodeset ( const std::vector< std::string > &  names) const
inherited

transform a vector of names into a NodeSet

Returns
NodeSet

Definition at line 58 of file graphicalModel.cpp.

References gum::Set< Key, Alloc >::emplace().

58  {
59  NodeSet res;
60  for (const auto& name: names) {
61  res.insert(idFromName(name));
62  }
63  return res;
64  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ operator!=()

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 286 of file IBayesNet_tpl.h.

286  {
287  return !this->operator==(from);
288  }
bool operator==(const IBayesNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !

◆ operator=()

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 196 of file BayesNet_tpl.h.

196  {
197  if (this != &source) {
199  _varMap_ = source._varMap_;
200 
202  _copyPotentials_(source);
203  }
204 
205  return *this;
206  }
void _clearPotentials_()
clear all potentials
Definition: BayesNet_tpl.h:624
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Definition: IBayesNet_tpl.h:66
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:635
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647

◆ operator==()

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 242 of file IBayesNet_tpl.h.

242  {
243  if (size() != from.size()) { return false; }
244 
245  if (sizeArcs() != from.sizeArcs()) { return false; }
246 
247  // alignment of variables between the 2 BNs
248  Bijection< const DiscreteVariable*, const DiscreteVariable* > alignment;
249 
250  for (auto node: nodes()) {
251  try {
252  alignment.insert(&variable(node), &from.variableFromName(variable(node).name()));
253  } catch (NotFound&) {
254  // a name is not found in from
255  return false;
256  }
257  }
258 
259  for (auto node: nodes()) {
260  NodeId fromnode = from.idFromName(variable(node).name());
261 
262  if (cpt(node).nbrDim() != from.cpt(fromnode).nbrDim()) { return false; }
263 
264  if (cpt(node).domainSize() != from.cpt(fromnode).domainSize()) { return false; }
265 
266  Instantiation i(cpt(node));
267  Instantiation j(from.cpt(fromnode));
268 
269  for (i.setFirst(); !i.end(); i.inc()) {
270  for (Idx indice = 0; indice < cpt(node).nbrDim(); ++indice) {
271  const DiscreteVariable* p = &(i.variable(indice));
272  j.chgVal(*(alignment.second(p)), i.val(*p));
273  }
274 
275  if (std::pow(cpt(node).get(i) - from.cpt(fromnode).get(j), (GUM_SCALAR)2)
276  > (GUM_SCALAR)1e-6) {
277  return false;
278  }
279  }
280  }
281 
282  return true;
283  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:41
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:38
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ parents() [1/4]

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 nodes returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node which is the head of an arc with the returned nodes
namethe name of the node the node which is the head of an arc with the returned nodes

Definition at line 53 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

53 { return dag_.parents(id); }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ parents() [2/4]

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

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 55 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

55  {
56  return parents(idFromName(name));
57  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:53
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ parents() [3/4]

INLINE NodeSet gum::DAGmodel::parents ( const NodeSet ids) const
inherited

returns the parents of a set of nodes

Definition at line 76 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

76 { return dag_.children(ids); }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ parents() [4/4]

INLINE NodeSet gum::DAGmodel::parents ( const std::vector< std::string > &  names) const
inherited

return true if the arc tail->head exists in the DAGmodel

Parameters
tailthe nodeId (or the name) of the tail in tail->head
headthe nodeId (or the name) of the head in tail->head
Returns
true if the arc exists

Definition at line 78 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

78  {
79  return parents(nodeset(names));
80  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:53
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet
+ Here is the call graph for this function:

◆ property()

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

Return the value of the property name of this GraphicalModel.

Exceptions
NotFoundRaised if no name property is found.

Definition at line 38 of file graphicalModel_inl.h.

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

◆ propertyWithDefault()

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

Return the value of the property name of this GraphicalModel.

return byDefault if the property name is not found

Definition at line 57 of file graphicalModel_inl.h.

58  {
59  try {
60  return _properties_()[name];
61  } catch (NotFound&) { return byDefault; }
62  }
HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...

◆ reverseArc() [1/3]

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 453 of file BayesNet_tpl.h.

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

◆ reverseArc() [2/3]

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 459 of file BayesNet.h.

459  {
460  reverseArc(idFromName(tail), idFromName(head));
461  }
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:302
void reverseArc(NodeId tail, NodeId head)
Reverses an arc while preserving the same joint distribution.
Definition: BayesNet_tpl.h:453

◆ reverseArc() [3/3]

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 391 of file BayesNet_tpl.h.

391  {
392  // check that the arc exists
393  if (!_varMap_.exists(arc.tail()) || !_varMap_.exists(arc.head()) || !dag().existsArc(arc)) {
394  GUM_ERROR(InvalidArc, "a non-existing arc cannot be reversed")
395  }
396 
397  NodeId tail = arc.tail(), head = arc.head();
398 
399  // check that the reversal does not induce a cycle
400  try {
401  DAG d = dag();
402  d.eraseArc(arc);
403  d.addArc(head, tail);
404  } catch (Exception&) {
405  GUM_ERROR(InvalidArc, "this arc reversal would induce a directed cycle")
406  }
407 
408  // with the same notations as Shachter (1986), "evaluating influence
409  // diagrams", p.878, we shall first compute the product of probabilities:
410  // pi_j^old (x_j | x_c^old(j) ) * pi_i^old (x_i | x_c^old(i) )
411  Potential< GUM_SCALAR > prod{cpt(tail) * cpt(head)};
412 
413  // modify the topology of the graph: add to tail all the parents of head
414  // and add to head all the parents of tail
416  NodeSet new_parents;
417  for (const auto node: this->parents(tail))
418  new_parents.insert(node);
419  for (const auto node: this->parents(head))
420  new_parents.insert(node);
421  // remove arc (head, tail)
422  eraseArc(arc);
423 
424  // add the necessary arcs to the tail
425  for (const auto p: new_parents) {
426  if ((p != tail) && !dag().existsArc(p, tail)) { addArc(p, tail); }
427  }
428 
429  addArc(head, tail);
430  // add the necessary arcs to the head
431  new_parents.erase(tail);
432 
433  for (const auto p: new_parents) {
434  if ((p != head) && !dag().existsArc(p, head)) { addArc(p, head); }
435  }
436 
438 
439  // update the conditional distributions of head and tail
440  Set< const DiscreteVariable* > del_vars;
441  del_vars << &(variable(tail));
442  Potential< GUM_SCALAR > new_cpt_head = prod.margSumOut(del_vars).putFirst(&variable(head));
443 
444  auto& cpt_head = const_cast< Potential< GUM_SCALAR >& >(cpt(head));
445  cpt_head = std::move(new_cpt_head);
446 
447  Potential< GUM_SCALAR > new_cpt_tail{(prod / cpt_head).putFirst(&variable(tail))};
448  auto& cpt_tail = const_cast< Potential< GUM_SCALAR >& >(cpt(tail));
449  cpt_tail = std::move(new_cpt_tail);
450  }
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head&#39;s CPT.
Definition: BayesNet_tpl.h:356
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:53
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool exists(NodeId id) const
Return true if id matches a node.
bool existsArc(const NodeId tail, const NodeId head) const
return true if the arc tail->head exists in the DAGmodel
Definition: DAGmodel_inl.h:45
void beginTopologyTransformation()
When inserting/removing arcs, node CPTs change their dimension with a cost in time.
Definition: BayesNet_tpl.h:610
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:313
void endTopologyTransformation()
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
Definition: BayesNet_tpl.h:617
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head&#39;s CTP.
Definition: BayesNet_tpl.h:376

◆ setProperty()

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

Add or change a property of this GraphicalModel.

Definition at line 65 of file graphicalModel_inl.h.

65  {
66  try {
67  _properties_()[name] = value;
68  } catch (NotFound&) { _properties_().insert(name, value); }
69  }
HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 38 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

38 { return dag().size(); }
Size size() const
alias for sizeNodes
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ sizeArcs()

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

Returns the number of arcs in this Directed Graphical Model.

Definition at line 41 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

41 { return dag_.sizeArcs(); }
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:222
+ Here is the call graph for this function:

◆ toDot()

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 165 of file IBayesNet_tpl.h.

165  {
166  std::stringstream output;
167  output << "digraph \"";
168 
169  std::string bn_name;
170 
171  try {
172  bn_name = this->property("name");
173  } catch (NotFound&) { bn_name = "no_name"; }
174 
175  output << bn_name << "\" {" << std::endl;
176  output << " graph [bgcolor=transparent,label=\"" << bn_name << "\"];" << std::endl;
177  output << " node [style=filled fillcolor=\"#ffffaa\"];" << std::endl << std::endl;
178 
179  for (auto node: nodes())
180  output << "\"" << variable(node).name() << "\" [comment=\"" << node << ":"
181  << variable(node).toStringWithDescription() << "\"];" << std::endl;
182 
183  output << std::endl;
184 
185  std::string tab = " ";
186 
187  for (auto node: nodes()) {
188  if (children(node).size() > 0) {
189  for (auto child: children(node)) {
190  output << tab << "\"" << variable(node).name() << "\" -> "
191  << "\"" << variable(child).name() << "\";" << std::endl;
192  }
193  } else if (parents(node).size() == 0) {
194  output << tab << "\"" << variable(node).name() << "\";" << std::endl;
195  }
196  }
197 
198  output << "}" << std::endl;
199 
200  return output.str();
201  }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:65
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:53
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:38
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 std::string & name() const
returns the name of the variable
const std::string & property(const std::string &name) const
Return the value of the property name of this GraphicalModel.

◆ topologicalOrder()

INLINE 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 86 of file DAGmodel_inl.h.

References gum::Set< Key, Alloc >::emplace().

86  {
87  return dag().topologicalOrder(clear);
88  }
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
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35
+ Here is the call graph for this function:

◆ toString()

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 144 of file IBayesNet_tpl.h.

144  {
145  Size param = 0;
146  double dSize = log10DomainSize();
147 
148  for (auto node: nodes())
149  param += cpt(node).content()->realSize();
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 << ", dim: " << param << "}";
160 
161  return s.str();
162  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:84
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:38
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
double log10DomainSize() const
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35

◆ variable() [1/2]

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 217 of file BayesNet_tpl.h.

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

◆ variable() [2/2]

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 309 of file BayesNet.h.

309  {
310  return variable(idFromName(name));
311  };
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition: BayesNet_tpl.h:217
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:302

◆ variableFromName()

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 308 of file BayesNet_tpl.h.

308  {
309  return _varMap_.variableFromName(name);
310  }
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647
const DiscreteVariable & variableFromName(const std::string &name) const

◆ variableNodeMap()

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 318 of file BayesNet_tpl.h.

318  {
319  return _varMap_;
320  }
VariableNodeMap _varMap_
the map between variable and id
Definition: BayesNet.h:647

Friends And Related Function Documentation

◆ BayesNetFactory< GUM_SCALAR >

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

Definition at line 78 of file BayesNet.h.

Member Data Documentation

◆ _probaMap_

template<typename GUM_SCALAR>
NodeProperty< Potential< GUM_SCALAR >* > gum::BayesNet< GUM_SCALAR >::_probaMap_
private

Mapping between the variable's id and their CPT.

Definition at line 650 of file BayesNet.h.

◆ _varMap_

template<typename GUM_SCALAR>
VariableNodeMap gum::BayesNet< GUM_SCALAR >::_varMap_
private

the map between variable and id

Definition at line 647 of file BayesNet.h.

◆ dag_

DAG gum::DAGmodel::dag_
protectedinherited

The DAG of this Directed Graphical Model.

Definition at line 222 of file DAGmodel.h.


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