aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::InfluenceDiagram< GUM_SCALAR > Class Template Reference

Class representing an Influence Diagram. More...

#include <agrum/ID/influenceDiagram.h>

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

Public Member Functions

std::string toDot () const
 
std::string toString () const
 
void clear ()
 
bool hasSameStructure (const DAGmodel &other)
 
double log10DomainSize () const
 
Constructors / Destructors
 InfluenceDiagram ()
 Default constructor. More...
 
 ~InfluenceDiagram () override
 Destructor. More...
 
 InfluenceDiagram (const InfluenceDiagram< GUM_SCALAR > &source)
 Copy Constructor. More...
 
InfluenceDiagram< GUM_SCALAR > & operator= (const InfluenceDiagram< GUM_SCALAR > &source)
 Copy Operator. More...
 
Variable manipulation methods.
virtual const Potential< GUM_SCALAR > & cpt (NodeId varId) const
 Returns the CPT of a potential variable. More...
 
virtual const Potential< GUM_SCALAR > & cpt (std::string name) const final
 Returns the CPT of a potential variable. More...
 
virtual const Potential< GUM_SCALAR > & utility (NodeId varId) const
 Returns the utility table of a utility node. More...
 
virtual const Potential< GUM_SCALAR > & utility (std::string name) const final
 Returns the CPT of a potential variable. More...
 
const VariableNodeMapvariableNodeMap () const final
 Returns a constant reference to the VariableNodeMap of this Influence Diagram. More...
 
bool isUtilityNode (NodeId varId) const
 Returns true if node is a utility one. More...
 
bool isUtilityNode (const std::string &name) const
 Returns the CPT of a potential variable. More...
 
bool isDecisionNode (NodeId varId) const
 Returns true if node is a decision one. More...
 
bool isDecisionNode (const std::string &name) const
 Returns the CPT of a potential variable. More...
 
bool isChanceNode (NodeId varId) const
 Returns true if node is a chance one. More...
 
bool isChanceNode (const std::string &name) const
 Returns the CPT of a potential variable. More...
 
Size utilityNodeSize () const
 Returns the number of utility nodes. More...
 
Size chanceNodeSize () const
 Returns the number of chance nodes. More...
 
Size decisionNodeSize () const
 Returns the number of decision nodes. More...
 
const DiscreteVariablevariable (NodeId id) const final
 Returns a constant reference over a variable given it's node id. More...
 
NodeId nodeId (const DiscreteVariable &var) const final
 Return id node from discrete var pointer. More...
 
NodeId idFromName (const std::string &name) const final
 Getter by name. More...
 
const DiscreteVariablevariableFromName (const std::string &name) const final
 Getter by name. More...
 
NodeId add (const DiscreteVariable &variable, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT. More...
 
NodeId addChanceNode (const DiscreteVariable &variable, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT. More...
 
NodeId addUtilityNode (const DiscreteVariable &variable, NodeId id=0)
 Add a utility variable, it's associate node and it's UT. More...
 
NodeId addDecisionNode (const DiscreteVariable &variable, NodeId id=0)
 Add a decision variable. More...
 
NodeId addChanceNode (const DiscreteVariable &variable, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT. More...
 
NodeId addUtilityNode (const DiscreteVariable &variable, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT. More...
 
void erase (NodeId id)
 Erase a Variable from the network and remove the variable from all his children. More...
 
void erase (const std::string &name)
 Returns the CPT of a potential variable. More...
 
void erase (const DiscreteVariable &var)
 Erase a Variable from the network and remove the variable from all his children. More...
 
void changeVariableName (NodeId id, const std::string &new_name)
 we allow the user to change the name of a variable More...
 
void changeVariableName (const std::string &name, const std::string &new_name)
 Returns the CPT of a potential variable. More...
 
Arc manipulation methods.
void addArc (NodeId tail, NodeId head)
 Add an arc in the ID, and update diagram's potential nodes cpt if necessary. More...
 
void addArc (const std::string &tail, const std::string &head)
 Add an arc in the ID, and update diagram's potential nodes cpt if necessary. More...
 
void eraseArc (const Arc &arc)
 Removes an arc in the ID, and update diagram's potential nodes cpt if necessary. More...
 
void eraseArc (NodeId tail, NodeId head)
 Removes an arc in the ID, and update diagram's potential nodes cpt if necessary. More...
 
void eraseArc (const std::string &tail, const std::string &head)
 Add an arc in the ID, and update diagram's potential nodes cpt if necessary. More...
 
Decisions methods
bool decisionOrderExists () const
 True if a directed path exist with all decision nodes. More...
 
gum::DAGgetDecisionGraph () const
 Returns the temporal Graph. More...
 
std::vector< NodeIddecisionOrder () const
 Returns the sequence of decision nodes in the directed path. More...
 
bool existsPathBetween (NodeId src, NodeId dest) const
 Returns true if a path exists between two nodes. More...
 
bool existsPathBetween (const std::string &src, const std::string &dest) const
 True if a directed path exist with all decision nodes. More...
 
const List< NodeSet > & getPartialTemporalOrder (bool clear=true) const
 Returns partial temporal ordering. 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 InfluenceDiagram< GUM_SCALAR > fastPrototype (const std::string &dotlike, Size domainSize=2)
 Create an Influence Diagram with a dot-like syntax which specifies: More...
 

Protected Attributes

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

Protected Member Functions

virtual void moralGraph_ (UndiGraph &graph) const
 Returns the moral graph of this InfluenceDiagram. More...
 
void removeTables_ ()
 Removing ancient table. More...
 
void copyStructureAndTables_ (const InfluenceDiagram< GUM_SCALAR > &IDsource)
 Copying tables from another influence diagram. More...
 
NodeId addNode_ (const DiscreteVariable &variableType, NodeId DesiredId)
 Add a node. More...
 
Sequence< NodeIdgetChildrenDecision_ (NodeId parentDecision) const
 Returns the list of children decision for a given nodeId. More...
 

Detailed Description

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

Class representing an Influence Diagram.

Definition at line 53 of file influenceDiagram.h.

Constructor & Destructor Documentation

◆ InfluenceDiagram() [1/2]

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

Default constructor.

Definition at line 204 of file influenceDiagram_tpl.h.

204  : DAGmodel() {
205  GUM_CONSTRUCTOR(InfluenceDiagram);
206  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:29
InfluenceDiagram()
Default constructor.

◆ ~InfluenceDiagram()

template<typename GUM_SCALAR >
gum::InfluenceDiagram< GUM_SCALAR >::~InfluenceDiagram ( )
override

Destructor.

Definition at line 212 of file influenceDiagram_tpl.h.

212  {
213  GUM_DESTRUCTOR(InfluenceDiagram);
214  removeTables_();
215  }
void removeTables_()
Removing ancient table.
InfluenceDiagram()
Default constructor.

◆ InfluenceDiagram() [2/2]

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

Copy Constructor.

Definition at line 221 of file influenceDiagram_tpl.h.

222  {
223  GUM_CONS_CPY(InfluenceDiagram);
224  copyStructureAndTables_(source);
225  }
void copyStructureAndTables_(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
InfluenceDiagram()
Default constructor.

Member Function Documentation

◆ add()

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::add ( const DiscreteVariable variable,
NodeId  id = 0 
)

Add a chance variable, it's associate node and it's CPT.

The id of the new variable is automatically generated.

The implementation of the Potential is by default a MultiDimArray.

Parameters
variableThe variable added by copy.
idThe chosen id. If 0, the NodeGraphPart will choose.
Warning
give an id (not 0) should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id(<>0) is already used

Definition at line 501 of file influenceDiagram_tpl.h.

502  {
503  return addChanceNode(var, varId);
504  }
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.

◆ addArc() [1/2]

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

Add an arc in the ID, and update diagram's potential nodes cpt if necessary.

Parameters
headand
tailas NodeId
Exceptions
InvalidEdgeIf arc.tail and/or arc.head are not in the ID.
InvalidEdgeif tail is a utility node

Definition at line 681 of file influenceDiagram_tpl.h.

681  {
682  if (isUtilityNode(tail)) {
683  GUM_ERROR(InvalidArc, "Tail cannot be a utility node")
684  }
685 
686  dag_.addArc(tail, head);
687 
688  if (isChanceNode(head))
689  // Add parent in the child's CPT
690  (*(potentialMap__[head])) << variable(tail);
691  else if (isUtilityNode(head)) {
692  // Add parent in the child's UT
693  (*(utilityMap__[head])) << variable(tail);
694  }
695  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Definition: DAG_inl.h:42
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it&#39;s node id.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ addArc() [2/2]

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

Add an arc in the ID, and update diagram's potential nodes cpt if necessary.

Parameters
headand
tailas NodeId
Exceptions
InvalidEdgeIf arc.tail and/or arc.head are not in the ID.
InvalidEdgeif tail is a utility node

Definition at line 346 of file influenceDiagram.h.

346  {
347  addArc(idFromName(tail), idFromName(head));
348  }
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
NodeId idFromName(const std::string &name) const final
Getter by name.

◆ addChanceNode() [1/2]

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode ( const DiscreteVariable variable,
NodeId  id = 0 
)

Add a chance variable, it's associate node and it's CPT.

The id of the new variable is automatically generated.

The implementation of the Potential is by default a MultiDimArray.

Parameters
variableThe variable added by copy.
idThe chosen id. If 0, the NodeGraphPart will choose.
Warning
give an id (not 0) should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id(<>0) is already used

Definition at line 544 of file influenceDiagram_tpl.h.

545  {
546  auto newMultiDim = new MultiDimArray< GUM_SCALAR >();
547  NodeId res;
548 
549  try {
550  res = addChanceNode(var, newMultiDim, varId);
551  } catch (Exception&) {
552  delete newMultiDim;
553  throw;
554  }
555 
556  return res;
557  }
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ addChanceNode() [2/2]

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode ( const DiscreteVariable variable,
MultiDimImplementation< GUM_SCALAR > *  aContent,
NodeId  id = 0 
)

Add a chance variable, it's associate node and it's CPT.

The id of the new variable is automatically generated.

Parameters
variableThe variable added by copy.
aContentThe content used for the variable potential.
idThe chosen id. If 0, the NodeGraphPart will choose.
Warning
give an id (not 0) should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id(<>0) is already used

Definition at line 564 of file influenceDiagram_tpl.h.

567  {
568  NodeId proposedId = addNode_(var, DesiredId);
569 
570  auto varcpt = new Potential< GUM_SCALAR >(aContent);
571  (*varcpt) << variable(proposedId);
572  potentialMap__.insert(proposedId, varcpt);
573 
574  return proposedId;
575  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.
NodeId addNode_(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it&#39;s node id.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ addDecisionNode()

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addDecisionNode ( const DiscreteVariable variable,
NodeId  id = 0 
)

Add a decision variable.

The id of the new variable is automatically generated.

Parameters
variableThe variable added by copy.
idThe chosen id. If 0, the NodeGraphPart will choose.
Warning
give an id (not 0) should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
DuplicateElementif id(<>0) is already used

Definition at line 534 of file influenceDiagram_tpl.h.

535  {
536  return addNode_(var, varId);
537  }
NodeId addNode_(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.

◆ addNode_()

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addNode_ ( const DiscreteVariable variableType,
NodeId  DesiredId 
)
protected

Add a node.

Definition at line 609 of file influenceDiagram_tpl.h.

610  {
611  // None thread safe code!
612  NodeId proposedId;
613 
614  if (DesiredId == 0)
615  proposedId = dag_.nextNodeId();
616  else
617  proposedId = DesiredId;
618 
619  variableMap__.insert(proposedId, variableType);
620 
621  dag_.addNodeWithId(proposedId);
622 
623  // end critical section
624  return proposedId;
625  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
VariableNodeMap variableMap__
Mapping between id and variable.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
NodeId nextNodeId() const
returns a new node id, not yet used by any node
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ addUtilityNode() [1/2]

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode ( const DiscreteVariable variable,
NodeId  id = 0 
)

Add a utility variable, it's associate node and it's UT.

The id of the new variable is automatically generated.

The implementation of the Utility is by default a MultiDimArray.

Parameters
variableThe variable added by copy.
idThe chosen id. If 0, the NodeGraphPart will choose.
Warning
give an id (not 0) should be reserved for rare and specific situations !!!
Returns
the id of the added variable.
Exceptions
InvalidArgumentIf variable has more than one label
DuplicateElementif id(<>0) is already used

Definition at line 513 of file influenceDiagram_tpl.h.

514  {
515  auto newMultiDim = new MultiDimArray< GUM_SCALAR >();
516  NodeId res;
517 
518  try {
519  res = addUtilityNode(var, newMultiDim, varId);
520  } catch (Exception&) {
521  if (newMultiDim != nullptr) delete newMultiDim;
522  throw;
523  }
524 
525  return res;
526  }
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it&#39;s associate node and it&#39;s UT.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ addUtilityNode() [2/2]

template<typename GUM_SCALAR >
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode ( const DiscreteVariable variable,
MultiDimImplementation< GUM_SCALAR > *  aContent,
NodeId  id = 0 
)

Add a chance variable, it's associate node and it's CPT.

The id of the new variable is automatically generated.

Parameters
variableThe variable added by copy.
aContentThe content used for the variable utility.
idThe chosen id. If 0, the NodeGraphPart will choose.
Warning
give an id (not 0) should be reserved for rare and specific situations !!!
Exceptions
InvalidArgumentIf variable has more than one label
DuplicateElementif id(<>0) is already used

Definition at line 583 of file influenceDiagram_tpl.h.

586  {
587  if (var.domainSize() != 1) {
588  GUM_ERROR(InvalidArgument,
589  "Utility var have no state ( which implicates a "
590  "single label for data output reasons ).")
591  }
592 
593  NodeId proposedId = addNode_(var, DesiredId);
594 
595  auto varut = new Potential< GUM_SCALAR >(aContent);
596 
597  (*varut) << variable(proposedId);
598 
599  utilityMap__.insert(proposedId, varut);
600 
601  return proposedId;
602  }
NodeId addNode_(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it&#39;s node id.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ 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 112 of file DAGmodel_inl.h.

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

112  {
113  return dag().ancestors(id);
114  }
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 116 of file DAGmodel_inl.h.

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

116  {
117  return ancestors(idFromName(name));
118  }
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
Definition: DAGmodel_inl.h:112
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:225
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:

◆ chanceNodeSize()

template<typename GUM_SCALAR >
INLINE Size gum::InfluenceDiagram< GUM_SCALAR >::chanceNodeSize ( ) const

Returns the number of chance nodes.

Definition at line 442 of file influenceDiagram_tpl.h.

442  {
443  return potentialMap__.size();
444  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.

◆ changeVariableName() [1/2]

template<typename GUM_SCALAR >
INLINE void gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName ( NodeId  id,
const std::string &  new_name 
)

we allow the user to change the name of a variable

Exceptions
DuplicateLabelif this name already exists
NotFoundRaised if no nodes matches id.

Definition at line 668 of file influenceDiagram_tpl.h.

670  {
671  variableMap__.changeName(id, new_name);
672  }
VariableNodeMap variableMap__
Mapping between id and variable.
void changeName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable

◆ changeVariableName() [2/2]

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

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 326 of file influenceDiagram.h.

326  {
327  changeVariableName(idFromName(name), new_name);
328  }
NodeId idFromName(const std::string &name) const final
Getter by name.
void changeVariableName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable

◆ 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 70 of file DAGmodel_inl.h.

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

70  {
71  return dag_.children(id);
72  }
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:225
+ 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 73 of file DAGmodel_inl.h.

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

73  {
74  return dag_.children(idFromName(name));
75  }
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:225
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 77 of file DAGmodel_inl.h.

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

77  {
78  return dag_.children(ids);
79  }
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:225
+ 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 82 of file DAGmodel_inl.h.

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

82  {
83  return children(nodeset(names));
84  }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:70
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::InfluenceDiagram< GUM_SCALAR >::clear ( )

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 86 of file graphicalModel_inl.h.

86  {
87  Instantiation I;
88 
89  for (const auto node: nodes())
90  I << variable(node);
91 
92  return I;
93  }
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.

◆ copyStructureAndTables_()

template<typename GUM_SCALAR >
void gum::InfluenceDiagram< GUM_SCALAR >::copyStructureAndTables_ ( const InfluenceDiagram< GUM_SCALAR > &  IDsource)
protected

Copying tables from another influence diagram.

Definition at line 269 of file influenceDiagram_tpl.h.

270  {
271  for (auto node: IDsource.nodes()) {
272  if (IDsource.isChanceNode(node))
273  addChanceNode(IDsource.variable(node), node);
274  else if (IDsource.isUtilityNode(node))
275  addUtilityNode(IDsource.variable(node), node);
276  else // decision node
277  addDecisionNode(IDsource.variable(node), node);
278  }
279  // we add arc in the same order of the potentials
280  for (auto node: IDsource.nodes()) {
281  const auto& s = IDsource.variable(node).name();
282  if (IDsource.isChanceNode(node)) {
283  for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
284  addArc(IDsource.cpt(node).variable(par).name(), s);
285  } else if (IDsource.isUtilityNode(node)) {
286  for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
287  addArc(IDsource.utility(node).variable(par).name(), s);
288  } else { // decision node
289  // here the order does not depends on a Potential
290  for (NodeId par: IDsource.parents(node))
291  addArc(par, node);
292  }
293  }
294 
295  // Copying potentials
296  for (auto node: IDsource.nodes()) {
297  const auto& s = IDsource.variable(node).name();
298  if (IDsource.isChanceNode(node)) {
299  cpt(node).fillWith(IDsource.cpt(s));
300  } else if (IDsource.isUtilityNode(node)) {
301  utility(node).fillWith(IDsource.utility(s));
302  }
303  }
304  }
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it&#39;s associate node and it&#39;s UT.
NodeId addDecisionNode(const DiscreteVariable &variable, NodeId id=0)
Add a decision variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.

◆ cpt() [1/2]

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

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 389 of file influenceDiagram_tpl.h.

389  {
390  return *(potentialMap__[varId]);
391  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.

◆ cpt() [2/2]

template<typename GUM_SCALAR>
virtual const Potential< GUM_SCALAR >& gum::InfluenceDiagram< GUM_SCALAR >::cpt ( std::string  name) const
inlinefinalvirtual

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 131 of file influenceDiagram.h.

131  {
132  return cpt(idFromName(name));
133  };
NodeId idFromName(const std::string &name) const final
Getter by name.
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.

◆ 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:225
+ Here is the call graph for this function:

◆ decisionNodeSize()

template<typename GUM_SCALAR >
INLINE Size gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize ( ) const

Returns the number of decision nodes.

Definition at line 450 of file influenceDiagram_tpl.h.

450  {
451  return (size() - utilityMap__.size() - potentialMap__.size());
452  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:38
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ decisionOrder()

template<typename GUM_SCALAR >
std::vector< NodeId > gum::InfluenceDiagram< GUM_SCALAR >::decisionOrder ( ) const

Returns the sequence of decision nodes in the directed path.

Exceptions
NotFoundif such a path does not exist

Definition at line 883 of file influenceDiagram_tpl.h.

883  {
884  if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists") }
885 
886  std::vector< NodeId > decisionSequence;
887 
888  for (const auto elt: topologicalOrder(false))
889  if (isDecisionNode(elt)) decisionSequence.push_back(elt);
890 
891  return decisionSequence;
892  }
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool decisionOrderExists() const
True if a directed path exist with all decision nodes.
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: DAGmodel_inl.h:100
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ decisionOrderExists()

template<typename GUM_SCALAR >
bool gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists ( ) const

True if a directed path exist with all decision nodes.

Definition at line 754 of file influenceDiagram_tpl.h.

754  {
755  const Sequence< NodeId >& order = topologicalOrder(true);
756 
757  // Finding first decision node
758  Sequence< NodeId >::const_iterator orderIter = order.begin();
759 
760  while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
761  ++orderIter;
762 
763  if (orderIter == order.end()) return true;
764 
765  NodeId parentDecision = (*orderIter);
766  ++orderIter;
767 
768  // Checking path between decisions nodes
769  while (orderIter != order.end()) {
770  if (isDecisionNode(*orderIter)) {
771  if (!existsPathBetween(parentDecision, *orderIter)) return false;
772 
773  parentDecision = *orderIter;
774  }
775 
776  ++orderIter;
777  }
778 
779  return true;
780  }
SequenceIterator< NodeId > const_iterator
Definition: sequence.h:1035
iterator begin() const
Returns an unsafe begin iterator.
Definition: sequence_tpl.h:658
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
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: DAGmodel_inl.h:100
const iterator & end() const noexcept
Returns the unsafe end iterator.
Definition: sequence_tpl.h:665
Size NodeId
Type for node ids.
Definition: graphElements.h:97

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

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

104  {
105  return dag().descendants(id);
106  }
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 108 of file DAGmodel_inl.h.

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

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

◆ empty()

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

Return true if this graphical model is empty.

Definition at line 96 of file graphicalModel_inl.h.

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

◆ erase() [1/3]

template<typename GUM_SCALAR >
void gum::InfluenceDiagram< GUM_SCALAR >::erase ( NodeId  id)

Erase a Variable from the network and remove the variable from all his children.

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

Parameters
idThe id of the variable to erase.

Definition at line 633 of file influenceDiagram_tpl.h.

633  {
634  if (variableMap__.exists(varId)) {
635  // Reduce the variable child's CPT or Utility Table if necessary
636  for (const auto chi: dag_.children(varId))
637  if (isChanceNode(chi))
638  potentialMap__[chi]->erase(variable(varId));
639  else if (isUtilityNode(chi))
640  utilityMap__[chi]->erase(variable(varId));
641 
642  if (isChanceNode(varId)) {
643  delete potentialMap__[varId];
644  potentialMap__.erase(varId);
645  } else if (isUtilityNode(varId)) {
646  delete utilityMap__[varId];
647  utilityMap__.erase(varId);
648  }
649 
650  variableMap__.erase(varId);
651  dag_.eraseNode(varId);
652  }
653  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his children.
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
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.
VariableNodeMap variableMap__
Mapping between id and variable.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it&#39;s node id.
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:68
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ erase() [2/3]

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

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 310 of file influenceDiagram.h.

310 { erase(idFromName(name)); };
NodeId idFromName(const std::string &name) const final
Getter by name.
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his children.

◆ erase() [3/3]

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

Erase a Variable from the network and remove the variable from all his children.

If no variable matches, then nothing is done.

Parameters
varThe reference on the variable to remove.

Definition at line 661 of file influenceDiagram_tpl.h.

661  {
662  erase(variableMap__.get(var));
663  }
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his children.
VariableNodeMap variableMap__
Mapping between id and variable.
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::InfluenceDiagram< GUM_SCALAR >::eraseArc ( const Arc arc)

Removes an arc in the ID, and update diagram's potential nodes cpt if necessary.

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

Parameters
arcThe arc removed.

Definition at line 703 of file influenceDiagram_tpl.h.

703  {
704  if (dag_.existsArc(arc)) {
705  NodeId head = arc.head(), tail = arc.tail();
706  dag_.eraseArc(arc);
707 
708  if (isChanceNode(head))
709  // Removes parent in the child's CPT
710  (*(potentialMap__[head])) >> variable(tail);
711  else if (isUtilityNode(head))
712  // Removes parent in the child's UT
713  (*(utilityMap__[head])) >> variable(tail);
714  }
715  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it&#39;s node id.
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:97
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ eraseArc() [2/3]

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

Removes an arc in the ID, and update diagram's potential nodes cpt if necessary.

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

Parameters
headand
tailas NodeId

Definition at line 723 of file influenceDiagram_tpl.h.

723  {
724  eraseArc(Arc(tail, head));
725  }
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.

◆ eraseArc() [3/3]

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

Add an arc in the ID, and update diagram's potential nodes cpt if necessary.

Parameters
headand
tailas NodeId
Exceptions
InvalidEdgeIf arc.tail and/or arc.head are not in the ID.
InvalidEdgeif tail is a utility node

Definition at line 368 of file influenceDiagram.h.

368  {
369  eraseArc(idFromName(tail), idFromName(head));
370  }
NodeId idFromName(const std::string &name) const final
Getter by name.
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.

◆ 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 94 of file DAGmodel_inl.h.

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

94 { 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:225
+ 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  {
113  return exists(idFromName(name));
114  };
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:225
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().

50  {
51  return existsArc(idFromName(nametail), idFromName(namehead));
52  }
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:

◆ existsPathBetween() [1/2]

template<typename GUM_SCALAR >
bool gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween ( NodeId  src,
NodeId  dest 
) const

Returns true if a path exists between two nodes.

Definition at line 786 of file influenceDiagram_tpl.h.

787  {
788  List< NodeId > nodeFIFO;
789  // mark[node] contains 0 if not visited
790  // mark[node] = predecessor if visited
791  NodeProperty< int > mark = dag_.nodesProperty((int)-1);
792  NodeId current;
793 
794  mark[src] = (int)src;
795  nodeFIFO.pushBack(src);
796 
797  while (!nodeFIFO.empty()) {
798  current = nodeFIFO.front();
799  nodeFIFO.popFront();
800 
801  for (const auto new_one: dag_.children(current)) {
802  if (mark[new_one] != -1)
803  continue; // if this node is already marked, continue
804 
805  mark[new_one] = (int)current;
806 
807  if (new_one == dest) break; // if we reach *orderIter, stop.
808 
809  nodeFIFO.pushBack(new_one);
810  }
811  }
812 
813  if (mark[dest] == -1) return false;
814 
815  return true;
816  }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ existsPathBetween() [2/2]

template<typename GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween ( const std::string &  src,
const std::string &  dest 
) const
inline

True if a directed path exist with all decision nodes.

Definition at line 399 of file influenceDiagram.h.

399  {
400  return existsPathBetween(idFromName(src), idFromName(dest));
401  }
NodeId idFromName(const std::string &name) const final
Getter by name.
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.

◆ 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 62 of file DAGmodel_inl.h.

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

62  {
63  return dag_.family(id);
64  }
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:225
+ 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 66 of file DAGmodel_inl.h.

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

66  {
67  return dag_.family(idFromName(name));
68  }
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:225
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 >
InfluenceDiagram< GUM_SCALAR > gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype ( const std::string &  dotlike,
Size  domainSize = 2 
)
static

Create an Influence Diagram with a dot-like syntax which specifies:

  • the structure "a->*b->$c;b->d<-*e;".
  • the prefix of a variable can be :
    • nothing : chance node (a,d)
    • * : decision node (*b)
    • $ : utility node ($c) *
  • the type of the chance or decision 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 chance and decision variables
Returns
the resulting influence diagram

Definition at line 158 of file influenceDiagram_tpl.h.

159  {
161 
162  for (const auto& chaine: split(dotlike, ";")) {
163  NodeId lastId = 0;
164  bool notfirst = false;
165  for (const auto& souschaine: split(chaine, "->")) {
166  bool forward = true;
167  for (const auto& node: split(souschaine, "<-")) {
168  auto idVar = build_node_for_ID(infdiag, node, domainSize);
169  if (notfirst) {
170  if (forward) {
171  infdiag.addArc(lastId, idVar);
172  forward = false;
173  } else {
174  infdiag.addArc(idVar, lastId);
175  }
176  } else {
177  notfirst = true;
178  forward = false;
179  }
180  lastId = idVar;
181  }
182  }
183  }
184 
185  for (const auto n: infdiag.nodes()) {
186  if (infdiag.isChanceNode(n))
187  infdiag.cpt(n).randomCPT();
188  else if (infdiag.isUtilityNode(n)) {
189  infdiag.utility(n).random().scale(50).translate(-10);
190  }
191  }
192 
193  infdiag.setProperty("name", "fastPrototype");
194  return infdiag;
195  }
NodeId build_node_for_ID(gum::InfluenceDiagram< GUM_SCALAR > &infdiag, std::string node, gum::Size default_domain_size)
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:96
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
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.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
Class representing an Influence Diagram.

◆ getChildrenDecision_()

template<typename GUM_SCALAR >
Sequence< NodeId > gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_ ( NodeId  parentDecision) const
protected

Returns the list of children decision for a given nodeId.

Definition at line 844 of file influenceDiagram_tpl.h.

845  {
846  Sequence< NodeId > childrenSeq;
847 
848  List< NodeId > nodeFIFO;
849  NodeId current;
850 
851  // mark[node] contains false if not visited
852  // mark[node] contains true if visited
853  NodeProperty< bool > mark = dag_.nodesProperty(false);
854 
855  mark[parentDecision] = true;
856 
857  nodeFIFO.pushBack(parentDecision);
858 
859  while (!nodeFIFO.empty()) {
860  current = nodeFIFO.front();
861  nodeFIFO.popFront();
862 
863  for (const auto new_one: dag_.children(current)) {
864  if (mark[new_one]) continue; // if this node is already marked, continue
865 
866  mark[new_one] = true;
867 
868  if (!isDecisionNode(new_one))
869  nodeFIFO.pushBack(new_one);
870  else
871  childrenSeq.insert(new_one);
872  }
873  }
874 
875  return childrenSeq;
876  }
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:409

◆ getDecisionGraph()

template<typename GUM_SCALAR >
gum::DAG * gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph ( ) const

Returns the temporal Graph.

Definition at line 822 of file influenceDiagram_tpl.h.

822  {
823  auto temporalGraph = new gum::DAG();
824 
825  for (const auto node: dag_.nodes()) {
826  if (isDecisionNode(node)) {
827  if (!temporalGraph->existsNode(node)) temporalGraph->addNodeWithId(node);
828 
829  for (const auto chi: getChildrenDecision_(node)) {
830  if (!temporalGraph->existsNode(chi)) temporalGraph->addNodeWithId(chi);
831 
832  temporalGraph->addArc(node, chi);
833  }
834  }
835  }
836 
837  return temporalGraph;
838  }
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Sequence< NodeId > getChildrenDecision_(NodeId parentDecision) const
Returns the list of children decision for a given nodeId.
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
Base class for dag.
Definition: DAG.h:101

◆ getPartialTemporalOrder()

template<typename GUM_SCALAR >
const List< NodeSet > & gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder ( bool  clear = true) const

Returns partial temporal ordering.

Exceptions
NotFoundif such a sequence does not exist

Definition at line 900 of file influenceDiagram_tpl.h.

900  {
901  if (clear) {
902  temporalOrder__.clear();
903 
904  std::vector< NodeId > order = decisionOrder();
905  NodeSet nodeList = dag_.asNodeSet();
906 
907  for (auto i: order) {
908  NodeSet partialOrderedSet;
909 
910  for (const auto par: dag_.parents(i)) {
911  if (nodeList.contains(par) && isChanceNode(par)) {
912  partialOrderedSet.insert(par);
913  nodeList.erase(par);
914  }
915  }
916 
917  if (!partialOrderedSet.empty())
918  temporalOrder__.pushFront(partialOrderedSet);
919 
920  NodeSet decisionSet;
921 
922  decisionSet.insert(i);
923 
924  temporalOrder__.pushFront(decisionSet);
925  }
926 
927  NodeSet lastSet; //= new gum::NodeSet();
928 
929  for (const auto node: nodeList)
930  if (isChanceNode(node)) lastSet.insert(node);
931 
932  if (!lastSet.empty()) temporalOrder__.pushFront(lastSet);
933  }
934 
935  return temporalOrder__;
936  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
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
std::vector< NodeId > decisionOrder() const
Returns the sequence of decision nodes in the directed path.
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
List< NodeSet > temporalOrder__
The temporal order.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632

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

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

74  {
75  if (this == &other) return true;
76 
77  if (size() != other.size()) return false;
78 
79  if (sizeArcs() != other.sizeArcs()) return false;
80 
81  for (const auto& nid: nodes()) {
82  try {
83  other.idFromName(variable(nid).name());
84  } catch (NotFound) { return false; }
85  }
86 
87  for (const auto& arc: arcs()) {
88  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
89  other.idFromName(variable(arc.head()).name()))))
90  return false;
91  }
92 
93  return true;
94  }
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:96
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::InfluenceDiagram< GUM_SCALAR >::idFromName ( const std::string &  name) const
finalvirtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::GraphicalModel.

Definition at line 485 of file influenceDiagram_tpl.h.

485  {
486  return variableMap__.idFromName(name);
487  }
VariableNodeMap variableMap__
Mapping between id and variable.
NodeId idFromName(const std::string &name) const

◆ 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 122 of file graphicalModel_inl.h.

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

◆ isChanceNode() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode ( NodeId  varId) const

Returns true if node is a chance one.

Definition at line 426 of file influenceDiagram_tpl.h.

426  {
427  return potentialMap__.exists(varId);
428  }
NodeProperty< Potential< GUM_SCALAR > *> potentialMap__
Mapping between potential variable&#39;s id and their CPT.

◆ isChanceNode() [2/2]

template<typename GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode ( const std::string &  name) const
inline

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 169 of file influenceDiagram.h.

169  {
170  return isChanceNode(idFromName(name));
171  };
NodeId idFromName(const std::string &name) const final
Getter by name.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.

◆ isDecisionNode() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode ( NodeId  varId) const

Returns true if node is a decision one.

Definition at line 414 of file influenceDiagram_tpl.h.

414  {
415  bool ret = true;
416 
417  if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
418 
419  return ret;
420  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.

◆ isDecisionNode() [2/2]

template<typename GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode ( const std::string &  name) const
inline

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 161 of file influenceDiagram.h.

161  {
162  return isDecisionNode(idFromName(name));
163  };
NodeId idFromName(const std::string &name) const final
Getter by name.
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.

◆ 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 131 of file DAGmodel_inl.h.

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

131  {
132  return dag().dSeparation(X, Y, Z);
133  }
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:102
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 135 of file DAGmodel_inl.h.

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

137  {
138  return dag().dSeparation(X, Y, Z);
139  }
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:102
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 188 of file DAGmodel.h.

190  {
191  return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
192  };
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:131

◆ 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 194 of file DAGmodel.h.

196  {
197  return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
198  };
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:131

◆ isUtilityNode() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode ( NodeId  varId) const

Returns true if node is a utility one.

Definition at line 406 of file influenceDiagram_tpl.h.

406  {
407  return utilityMap__.exists(varId);
408  }
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ isUtilityNode() [2/2]

template<typename GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode ( const std::string &  name) const
inline

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 154 of file influenceDiagram.h.

154  {
155  return isUtilityNode(idFromName(name));
156  };
NodeId idFromName(const std::string &name) const final
Getter by name.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.

◆ log10DomainSize()

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

Definition at line 75 of file graphicalModel_inl.h.

75  {
76  double dSize = 0.0;
77 
78  for (const auto node: nodes()) {
79  dSize += std::log10(variable(node).domainSize());
80  }
81 
82  return dSize;
83  }
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.

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

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

58  {
59  if (clear
61  == nullptr)) { // we have to call dag().moralGraph()
62  if (mutableMoralGraph__ == nullptr) {
63  mutableMoralGraph__ = new UndiGraph();
64  } else {
65  // clear is True ,__mutableMoralGraph exists
67  }
69  }
70 
71  return *mutableMoralGraph__;
72  }
void clear() override
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:46
UndiGraph moralGraph() const
build a UndiGraph by moralizing the dag
Definition: DAG.cpp:52
UndiGraph * mutableMoralGraph__
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:233
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:

◆ moralGraph_()

template<typename GUM_SCALAR >
void gum::InfluenceDiagram< GUM_SCALAR >::moralGraph_ ( UndiGraph graph) const
protectedvirtual

Returns the moral graph of this InfluenceDiagram.

Definition at line 735 of file influenceDiagram_tpl.h.

735  {
736  for (const auto node: dag_.nodes())
737  if (!isUtilityNode(node)) graph.addNodeWithId(node);
738 
739  for (const auto node: dag_.nodes()) {
740  if (!isDecisionNode(node))
741  for (const auto par: dag_.parents(node)) {
742  if (isChanceNode(node)) graph.addEdge(node, par);
743 
744  for (const auto par2: dag_.parents(node))
745  if (par != par2) graph.addEdge(par, par2);
746  }
747  }
748  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225

◆ 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 127 of file DAGmodel_inl.h.

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

127  {
129  }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:96
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition: DAG.cpp:76
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 121 of file DAGmodel_inl.h.

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

122  {
123  return moralizedAncestralGraph(nodeset(nodenames));
124  }
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:127
+ 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 100 of file graphicalModel_inl.h.

100  {
101  std::vector< std::string > res;
102  const VariableNodeMap& v = variableNodeMap();
103  std::transform(ids.cbegin(),
104  ids.cend(),
105  std::back_inserter(res),
106  [v](NodeId n) { return v[n].name(); });
107  return res;
108  }
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 111 of file graphicalModel_inl.h.

111  {
112  const VariableNodeMap& v = variableNodeMap();
113  std::vector< std::string > res;
114  for (auto n: ids) {
115  res.push_back(v.name(n));
116  }
117  return res;
118  }
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::InfluenceDiagram< GUM_SCALAR >::nodeId ( const DiscreteVariable var) const
finalvirtual

Return id node from discrete var pointer.

Exceptions
NotFoundIf no variable matches var.

Implements gum::GraphicalModel.

Definition at line 478 of file influenceDiagram_tpl.h.

478  {
479  return variableMap__.get(var);
480  }
VariableNodeMap variableMap__
Mapping between id and variable.
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 96 of file DAGmodel_inl.h.

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

96  {
97  return (NodeGraphPart&)dag_;
98  }
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
+ 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 63 of file graphicalModel.cpp.

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

63  {
64  NodeSet res;
65  for (const auto& name: names) {
66  res.insert(idFromName(name));
67  }
68  return res;
69  }
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:632
+ Here is the call graph for this function:

◆ operator=()

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

Copy Operator.

Definition at line 231 of file influenceDiagram_tpl.h.

232  {
233  if (this != &source) {
234  clear();
235  // Copying tables and structure
236  copyStructureAndTables_(source);
237  }
238 
239  return *this;
240  }
void copyStructureAndTables_(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.

◆ 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 54 of file DAGmodel_inl.h.

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

54  {
55  return dag_.parents(id);
56  }
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:225
+ 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 58 of file DAGmodel_inl.h.

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

58  {
59  return parents(idFromName(name));
60  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:54
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 86 of file DAGmodel_inl.h.

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

86  {
87  return dag_.children(ids);
88  }
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:225
+ 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 90 of file DAGmodel_inl.h.

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

90  {
91  return parents(nodeset(names));
92  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:54
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  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
HashTable< std::string, std::string > & properties__() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...

◆ 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 58 of file graphicalModel_inl.h.

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

◆ removeTables_()

template<typename GUM_SCALAR >
void gum::InfluenceDiagram< GUM_SCALAR >::removeTables_ ( )
protected

Removing ancient table.

Definition at line 256 of file influenceDiagram_tpl.h.

256  {
257  for (const auto node: dag_.nodes()) {
258  if (isChanceNode(node))
259  delete &cpt(node);
260  else if (isUtilityNode(node))
261  delete &utility(node);
262  }
263  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.

◆ 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 66 of file graphicalModel_inl.h.

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

◆ 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:225
+ Here is the call graph for this function:

◆ toDot()

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

Definition at line 307 of file influenceDiagram_tpl.h.

307  {
308  std::stringstream output;
309  std::stringstream decisionNode;
310  std::stringstream utilityNode;
311  std::stringstream chanceNode;
312  std::stringstream arcstream;
313  output << "digraph \"";
314 
315  try {
316  output << this->property("name") << "\" {" << std::endl;
317  } catch (NotFound&) { output << "no_name\" {" << std::endl; }
318 
319  output << " node [bgcolor=\"#AAAAAA\", style=filled, height=0];" << std::endl;
320 
321  decisionNode << "node [shape = box];" << std::endl;
322 
323  utilityNode << "node [shape = hexagon, margin=0];" << std::endl;
324  chanceNode << "node [shape = ellipse];" << std::endl;
325  std::string tab = " ";
326 
327  for (const auto node: dag_.nodes()) {
328  if (isChanceNode(node))
329  chanceNode << tab << "\"" << node << "-" << variable(node).name() << "\""
330  << ";";
331  else if (isUtilityNode(node))
332  utilityNode << tab << "\"" << node << "-" << variable(node).name() << "\""
333  << ";";
334  else
335  decisionNode << tab << "\"" << node << "-" << variable(node).name() << "\""
336  << ";";
337 
338  if (dag_.children(node).size() > 0)
339  for (const auto chi: dag_.children(node)) {
340  arcstream << "\"" << node << "-" << variable(node).name() << "\""
341  << " -> "
342  << "\"" << chi << "-" << variable(chi).name() << "\"";
343  if (isDecisionNode(chi)) { arcstream << " [style=\"tapered, bold\"]"; }
344  arcstream << ";" << std::endl;
345  }
346  }
347 
348  output << decisionNode.str() << std::endl
349  << utilityNode.str() << std::endl
350  << chanceNode.str() << std::endl
351  << std::endl
352  << arcstream.str() << std::endl
353  << "}" << std::endl;
354 
355  return output.str();
356  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:225
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:720
const std::string & name() const
returns the name of the variable
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it&#39;s node id.
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 100 of file DAGmodel_inl.h.

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

100  {
101  return dag().topologicalOrder(clear);
102  }
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:90
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 >
std::string gum::InfluenceDiagram< GUM_SCALAR >::toString ( ) const
Returns
Returns a string representation of this Influence Diagram.

Definition at line 359 of file influenceDiagram_tpl.h.

359  {
360  std::stringstream output;
361 
362  output << "Influence Diagram{" << std::endl;
363  output << " chance: " << chanceNodeSize() << "," << std::endl;
364  output << " utility: " << utilityNodeSize() << "," << std::endl;
365  output << " decision: " << decisionNodeSize() << "," << std::endl;
366  output << " arcs: " << dag().sizeArcs() << "," << std::endl;
367 
368  double dSize = log10DomainSize();
369 
370  if (dSize > 6)
371  output << " domainSize: 10^" << dSize;
372  else
373  output << " domainSize: " << std::round(std::pow(10.0, dSize));
374 
375  output << std::endl << "}";
376 
377  return output.str();
378  }
Size decisionNodeSize() const
Returns the number of decision nodes.
Size chanceNodeSize() const
Returns the number of chance nodes.
Size utilityNodeSize() const
Returns the number of utility nodes.
double log10DomainSize() const
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:35

◆ utility() [1/2]

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::InfluenceDiagram< GUM_SCALAR >::utility ( NodeId  varId) const
virtual

Returns the utility table of a utility node.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 398 of file influenceDiagram_tpl.h.

398  {
399  return *(utilityMap__[varId]);
400  }
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ utility() [2/2]

template<typename GUM_SCALAR>
virtual const Potential< GUM_SCALAR >& gum::InfluenceDiagram< GUM_SCALAR >::utility ( std::string  name) const
inlinefinalvirtual

Returns the CPT of a potential variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 140 of file influenceDiagram.h.

140  {
141  return utility(idFromName(name));
142  };
NodeId idFromName(const std::string &name) const final
Getter by name.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.

◆ utilityNodeSize()

template<typename GUM_SCALAR >
INLINE Size gum::InfluenceDiagram< GUM_SCALAR >::utilityNodeSize ( ) const

Returns the number of utility nodes.

Definition at line 434 of file influenceDiagram_tpl.h.

434  {
435  return utilityMap__.size();
436  }
NodeProperty< Potential< GUM_SCALAR > *> utilityMap__
Mapping between utility variable&#39;s id and their utility table.

◆ variable()

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

Returns a constant reference over a variable given it's node id.

Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::GraphicalModel.

Definition at line 469 of file influenceDiagram_tpl.h.

469  {
470  return variableMap__[id];
471  }
VariableNodeMap variableMap__
Mapping between id and variable.

◆ variableFromName()

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::InfluenceDiagram< GUM_SCALAR >::variableFromName ( const std::string &  name) const
finalvirtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::GraphicalModel.

Definition at line 491 of file influenceDiagram_tpl.h.

492  {
493  return variableMap__.variableFromName(name);
494  }
VariableNodeMap variableMap__
Mapping between id and variable.
const DiscreteVariable & variableFromName(const std::string &name) const

◆ variableNodeMap()

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

Returns a constant reference to the VariableNodeMap of this Influence Diagram.

Implements gum::GraphicalModel.

Definition at line 460 of file influenceDiagram_tpl.h.

460  {
461  return variableMap__;
462  }
VariableNodeMap variableMap__
Mapping between id and variable.

Member Data Documentation

◆ dag_

DAG gum::DAGmodel::dag_
protectedinherited

The DAG of this Directed Graphical Model.

Definition at line 225 of file DAGmodel.h.

◆ potentialMap__

template<typename GUM_SCALAR>
NodeProperty< Potential< GUM_SCALAR >* > gum::InfluenceDiagram< GUM_SCALAR >::potentialMap__
private

Mapping between potential variable's id and their CPT.

Definition at line 440 of file influenceDiagram.h.

◆ temporalOrder__

template<typename GUM_SCALAR>
List< NodeSet > gum::InfluenceDiagram< GUM_SCALAR >::temporalOrder__
mutableprivate

The temporal order.

Definition at line 445 of file influenceDiagram.h.

◆ utilityMap__

template<typename GUM_SCALAR>
NodeProperty< Potential< GUM_SCALAR >* > gum::InfluenceDiagram< GUM_SCALAR >::utilityMap__
private

Mapping between utility variable's id and their utility table.

Definition at line 442 of file influenceDiagram.h.

◆ variableMap__

template<typename GUM_SCALAR>
VariableNodeMap gum::InfluenceDiagram< GUM_SCALAR >::variableMap__
private

Mapping between id and variable.

Definition at line 437 of file influenceDiagram.h.


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