aGrUM  0.17.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
 
bool hasSameStructure (const DAGmodel &other)
 
double log10DomainSize () const
 
Constructors / Destructors
 InfluenceDiagram ()
 Default constructor. More...
 
virtual ~InfluenceDiagram ()
 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 > & utility (NodeId varId) const
 Returns the utility table of a utility node. More...
 
virtual const VariableNodeMapvariableNodeMap () const
 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...
 
virtual const DiscreteVariablevariable (NodeId id) const
 Returns a constant reference over a variabe given it's node id. More...
 
virtual NodeId nodeId (const DiscreteVariable &var) const
 Return id node from discrete var pointer. More...
 
virtual NodeId idFromName (const std::string &name) const
 Getter by name. More...
 
virtual const DiscreteVariablevariableFromName (const std::string &name) const
 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 childs. 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 childs. 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 decison nodes. More...
 
gum::DAGgetDecisionGraph () const
 Returns the temporal Graph. More...
 
std::vector< NodeId > * getDecisionOrder () 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 decison 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
 Returns a constant reference to the dag of this Bayes Net. More...
 
Arc manipulation methods.
const ArcSetarcs () const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
const NodeSetchildren (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
Graphical methods
const UndiGraphmoralGraph (bool clear=true) const
 The node's id are coherent with the variables and nodes of the topology. More...
 
const Sequence< NodeId > & topologicalOrder (bool clear=true) const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology. More...
 
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...
 
Variable manipulation methods.
virtual bool empty () const
 Retursn true if this Directed Graphical Model is empty. More...
 
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model. 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 _copyTables (const InfluenceDiagram< GUM_SCALAR > &IDsource)
 Copying tables from another influence diagram. More...
 
NodeId _addNode (const DiscreteVariable &variableType, NodeId DesiredId)
 Add a node. More...
 
Sequence< NodeId_getChildrenDecision (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 54 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 44 of file influenceDiagram_tpl.h.

44  : DAGmodel() {
45  GUM_CONSTRUCTOR(InfluenceDiagram);
46  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:30
InfluenceDiagram()
Default constructor.

◆ ~InfluenceDiagram()

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

Destructor.

Definition at line 52 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::_removeTables().

52  {
53  GUM_DESTRUCTOR(InfluenceDiagram);
54  _removeTables();
55  }
InfluenceDiagram()
Default constructor.
void _removeTables()
Removing ancient table.
+ Here is the call graph for this function:

◆ InfluenceDiagram() [2/2]

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

Copy Constructor.

Definition at line 61 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::_copyTables().

62  :
63  DAGmodel(source),
64  __variableMap(source.__variableMap) {
65  GUM_CONS_CPY(InfluenceDiagram);
66  _copyTables(source);
67  }
VariableNodeMap __variableMap
Mapping between id and variable.
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:30
void _copyTables(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
InfluenceDiagram()
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ _addNode()

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

Add a node.

Definition at line 465 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, gum::DAGmodel::_dag, gum::NodeGraphPart::addNodeWithId(), gum::VariableNodeMap::insert(), and gum::NodeGraphPart::nextNodeId().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::addDecisionNode(), gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode(), and gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween().

466  {
467  // None thread safe code!
468  NodeId proposedId;
469 
470  if (DesiredId == 0)
471  proposedId = _dag.nextNodeId();
472  else
473  proposedId = DesiredId;
474 
475  __variableMap.insert(proposedId, variableType);
476 
477  _dag.addNodeWithId(proposedId);
478 
479  // end critical section
480  return proposedId;
481  }
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:162
NodeId nextNodeId() const
returns a new node id, not yet used by any node
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _copyTables()

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

Copying tables from another influence diagram.

Definition at line 108 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, gum::DAGmodel::_dag, gum::Instantiation::chgVal(), gum::Instantiation::end(), gum::Instantiation::inc(), gum::Instantiation::nbrDim(), gum::InfluenceDiagram< GUM_SCALAR >::nodeId(), gum::ArcGraphPart::parents(), gum::Instantiation::setFirst(), gum::Instantiation::val(), gum::InfluenceDiagram< GUM_SCALAR >::variable(), and gum::Instantiation::variable().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::InfluenceDiagram(), and gum::InfluenceDiagram< GUM_SCALAR >::operator=().

109  {
110  // Copying potentials
111  for (const auto& pot: IDsource.__potentialMap) {
112  // Instanciation of the node's CPT
113  auto potentialCpy = new Potential< GUM_SCALAR >;
114  (*potentialCpy) << variable(pot.first);
115 
116  // Addition of the parents
117  for (const auto par: _dag.parents(pot.first))
118  (*potentialCpy) << variable(par);
119 
120  // Filling up of the table
121  Instantiation srcInst(*pot.second);
122  Instantiation cpyInst(*potentialCpy);
123 
124  for (cpyInst.setFirst(); !cpyInst.end(); cpyInst.inc()) {
125  for (Idx i = 0; i < cpyInst.nbrDim(); i++) {
126  NodeId id = nodeId(cpyInst.variable(i));
127  srcInst.chgVal(IDsource.variable(id), cpyInst.val(i));
128  }
129 
130  potentialCpy->set(cpyInst, (*pot.second)[srcInst]);
131  }
132 
133  // Adding cpt to cpt map
134  __potentialMap.set(pot.first, potentialCpy);
135  }
136 
137  // Copying Utilities
138  for (const auto& uti: IDsource.__utilityMap) {
139  // Instanciation of the node's CPT
140  auto utilityCpy = new Potential< GUM_SCALAR >;
141  (*utilityCpy) << variable(uti.first);
142 
143  // Addition of the parents
144  for (const auto par: _dag.parents(uti.first))
145  (*utilityCpy) << variable(par);
146 
147  // Filling up of the table
148  Instantiation srcInst(*uti.second);
149 
150  Instantiation cpyInst(*utilityCpy);
151 
152  for (cpyInst.setFirst(); !cpyInst.end(); cpyInst.inc()) {
153  for (Idx i = 0; i < cpyInst.nbrDim(); i++) {
154  NodeId id = nodeId(cpyInst.variable(i));
155  srcInst.chgVal(IDsource.variable(id), cpyInst.val(i));
156  }
157 
158  utilityCpy->set(cpyInst, (*uti.second)[srcInst]);
159  }
160 
161  // Adding cpt to cpt map
162  __utilityMap.set(uti.first, utilityCpy);
163  }
164  }
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual NodeId nodeId(const DiscreteVariable &var) const
Return id node from discrete var pointer.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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 698 of file influenceDiagram_tpl.h.

References gum::DAGmodel::_dag, gum::ArcGraphPart::children(), gum::List< Val, Alloc >::empty(), gum::List< Val, Alloc >::front(), gum::SequenceImplementation< Key, Alloc, Gen >::insert(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), gum::NodeGraphPart::nodesProperty(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph().

699  {
700  Sequence< NodeId > childrenSeq;
701 
702  List< NodeId > nodeFIFO;
703  NodeId current;
704 
705  // mark[node] contains false if not visited
706  // mark[node] contains true if visited
707  NodeProperty< bool > mark = _dag.nodesProperty(false);
708 
709  mark[parentDecision] = true;
710 
711  nodeFIFO.pushBack(parentDecision);
712 
713  while (!nodeFIFO.empty()) {
714  current = nodeFIFO.front();
715  nodeFIFO.popFront();
716 
717  for (const auto new_one: _dag.children(current)) {
718  if (mark[new_one]) continue; // if this node is already marked, continue
719 
720  mark[new_one] = true;
721 
722  if (!isDecisionNode(new_one))
723  nodeFIFO.pushBack(new_one);
724  else
725  childrenSeq.insert(new_one);
726  }
727  }
728 
729  return childrenSeq;
730  }
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:162
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408
+ Here is the call graph for this function:
+ Here is the caller 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 589 of file influenceDiagram_tpl.h.

References gum::DAGmodel::_dag, gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), gum::NodeGraphPart::nodes(), and gum::ArcGraphPart::parents().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween().

589  {
590  for (const auto node: _dag.nodes())
591  if (!isUtilityNode(node)) graph.addNodeWithId(node);
592 
593  for (const auto node: _dag.nodes()) {
594  if (!isDecisionNode(node))
595  for (const auto par: _dag.parents(node)) {
596  if (isChanceNode(node)) graph.addEdge(node, par);
597 
598  for (const auto par2: _dag.parents(node))
599  if (par != par2) graph.addEdge(par, par2);
600  }
601  }
602  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
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 NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _removeTables()

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

Removing ancient table.

Definition at line 95 of file influenceDiagram_tpl.h.

References gum::DAGmodel::_dag, gum::InfluenceDiagram< GUM_SCALAR >::cpt(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), gum::NodeGraphPart::nodes(), and gum::InfluenceDiagram< GUM_SCALAR >::utility().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::operator=(), and gum::InfluenceDiagram< GUM_SCALAR >::~InfluenceDiagram().

95  {
96  for (const auto node: _dag.nodes()) {
97  if (isChanceNode(node))
98  delete &cpt(node);
99  else if (isUtilityNode(node))
100  delete &utility(node);
101  }
102  }
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.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 357 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

358  {
359  return addChanceNode(var, varId);
360  }
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 536 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, gum::DAGmodel::_dag, gum::DAG::addArc(), GUM_ERROR, gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), and gum::InfluenceDiagram< GUM_SCALAR >::variable().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName(), and gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID().

536  {
537  if (isUtilityNode(tail)) {
538  GUM_ERROR(InvalidArc, "Tail cannot be a utility node");
539  }
540 
541  _dag.addArc(tail, head);
542 
543  if (isChanceNode(head))
544  // Add parent in the child's CPT
545  (*(__potentialMap[head])) << variable(tail);
546  else if (isUtilityNode(head))
547  // Add parent in the child's UT
548  (*(__utilityMap[head])) << variable(tail);
549  }
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 const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:43
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 312 of file influenceDiagram.h.

References gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), and gum::InfluenceDiagram< GUM_SCALAR >::idFromName().

312  {
313  addArc(idFromName(tail), idFromName(head));
314  }
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
virtual NodeId idFromName(const std::string &name) const
Getter by name.
+ Here is the call graph for this function:

◆ 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 400 of file influenceDiagram_tpl.h.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::add(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), and gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

401  {
402  MultiDimArray< GUM_SCALAR >* newMultiDim = new MultiDimArray< GUM_SCALAR >();
403  NodeId res = 0;
404 
405  try {
406  res = addChanceNode(var, newMultiDim, varId);
407  } catch (Exception&) {
408  delete newMultiDim;
409  throw;
410  }
411 
412  return res;
413  }
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:98
+ Here is the caller graph for this function:

◆ 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 420 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), and gum::InfluenceDiagram< GUM_SCALAR >::variable().

423  {
424  NodeId proposedId = _addNode(var, DesiredId);
425 
426  Potential< GUM_SCALAR >* varcpt = new Potential< GUM_SCALAR >(aContent);
427  (*varcpt) << variable(proposedId);
428  __potentialMap.insert(proposedId, varcpt);
429 
430  return proposedId;
431  }
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
NodeId _addNode(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:

◆ 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 390 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::_addNode().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), and gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

391  {
392  return _addNode(var, varId);
393  }
NodeId _addNode(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 369 of file influenceDiagram_tpl.h.

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), and gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

370  {
371  MultiDimArray< GUM_SCALAR >* newMultiDim = new MultiDimArray< GUM_SCALAR >();
372  NodeId res = 0;
373 
374  try {
375  res = addUtilityNode(var, newMultiDim, varId);
376  } catch (Exception&) {
377  delete newMultiDim;
378  throw;
379  }
380 
381  return res;
382  }
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:98
+ Here is the caller graph for this function:

◆ 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 439 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), gum::DiscreteVariable::domainSize(), GUM_ERROR, and gum::InfluenceDiagram< GUM_SCALAR >::variable().

442  {
443  if (var.domainSize() != 1) {
444  GUM_ERROR(InvalidArgument,
445  "Utility var have no state ( which implicates a "
446  "single label for data output reasons ).");
447  }
448 
449  NodeId proposedId = _addNode(var, DesiredId);
450 
451  Potential< GUM_SCALAR >* varut = new Potential< GUM_SCALAR >(aContent);
452 
453  (*varut) << variable(proposedId);
454 
455  __utilityMap.insert(proposedId, varut);
456 
457  return proposedId;
458  }
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
NodeId _addNode(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ arcs()

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

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

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

Parameters
idthe node toward which the nodes returned share an arc

Definition at line 44 of file DAGmodel_inl.h.

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

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::DAGmodel::__moralGraph(), gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), and gum::BayesNetFragment< GUM_SCALAR >::toBN().

44 { return _dag.arcs(); }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:
+ Here is the caller 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 298 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

298  {
299  return __potentialMap.size();
300  }
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
+ Here is the caller graph for this function:

◆ 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 524 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, and gum::VariableNodeMap::changeName().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName(), and gum::InfluenceDiagram< GUM_SCALAR >::erase().

525  {
526  __variableMap.changeName(id, new_name);
527  }
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 292 of file influenceDiagram.h.

References gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName(), and gum::InfluenceDiagram< GUM_SCALAR >::idFromName().

292  {
293  changeVariableName(idFromName(name), new_name);
294  }
void changeVariableName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
virtual NodeId idFromName(const std::string &name) const
Getter by name.
+ Here is the call graph for this function:

◆ children() [1/2]

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

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

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

Parameters
idthe node which is the tail of the arcs returned

Definition at line 53 of file DAGmodel_inl.h.

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

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::MarkovBlanket::MarkovBlanket(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

53  {
54  return _dag.children(id);
55  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ children() [2/2]

INLINE const NodeSet & gum::DAGmodel::children ( const std::string &  name) 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 toward which the nodes returned share an arc

Definition at line 56 of file DAGmodel_inl.h.

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

56  {
57  return _dag.children(idFromName(name));
58  }
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
+ Here is the call graph for this function:

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 85 of file graphicalModel_inl.h.

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

85  {
86  Instantiation I;
87 
88  for (const auto node: nodes())
89  I << variable(node);
90 
91  return I;
92  }
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.
+ Here is the call graph for this function:

◆ cpt()

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 245 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), and gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID().

245  {
246  return *(__potentialMap[varId]);
247  }
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
+ Here is the caller graph for this function:

◆ dag()

◆ decisionNodeSize()

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

Returns the number of decision nodes.

Definition at line 306 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, and gum::DAGmodel::size().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

306  {
307  return (size() - __utilityMap.size() - __potentialMap.size());
308  }
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:39
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decisionOrderExists()

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

True if a directed path exist with all decison nodes.

Definition at line 608 of file influenceDiagram_tpl.h.

References gum::SequenceImplementation< Key, Alloc, Gen >::begin(), gum::SequenceImplementation< Key, Alloc, Gen >::end(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::DAGmodel::topologicalOrder().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().

608  {
609  const Sequence< NodeId >& order = topologicalOrder(true);
610 
611  // Finding first decision node
612  Sequence< NodeId >::const_iterator orderIter = order.begin();
613 
614  while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
615  ++orderIter;
616 
617  if (orderIter == order.end()) return true;
618 
619  NodeId parentDecision = (*orderIter);
620  ++orderIter;
621 
622  // Checking path between decisions nodes
623  while (orderIter != order.end()) {
624  if (isDecisionNode(*orderIter)) {
625  if (!existsPathBetween(parentDecision, *orderIter)) return false;
626 
627  parentDecision = *orderIter;
628  }
629 
630  ++orderIter;
631  }
632 
633  return true;
634  }
SequenceIterator< NodeId > const_iterator
Definition: sequence.h:1036
iterator begin() const
Returns an unsafe begin iterator.
Definition: sequence_tpl.h:657
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.cpp:99
const iterator & end() const noexcept
Returns the unsafe end iterator.
Definition: sequence_tpl.h:664
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

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

Retursn true if this Directed Graphical Model is empty.

Definition at line 95 of file graphicalModel_inl.h.

References gum::GraphicalModel::size().

95 { return size() == 0; }
virtual Size size() const =0
Returns the number of variables in this Directed Graphical Model.
+ Here is the call graph for this function:

◆ 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 childs.

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

Parameters
idThe id of the variable to erase.

Definition at line 489 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, gum::DAGmodel::_dag, gum::ArcGraphPart::children(), gum::VariableNodeMap::erase(), gum::DiGraph::eraseNode(), gum::VariableNodeMap::exists(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), and gum::InfluenceDiagram< GUM_SCALAR >::variable().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::erase(), and gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

489  {
490  if (__variableMap.exists(varId)) {
491  // Reduce the variable child's CPT or Utility Table if necessary
492  for (const auto chi: _dag.children(varId))
493  if (isChanceNode(chi))
494  __potentialMap[chi]->erase(variable(varId));
495  else if (isUtilityNode(chi))
496  __utilityMap[chi]->erase(variable(varId));
497 
498  if (isChanceNode(varId)) {
499  delete __potentialMap[varId];
500  __potentialMap.erase(varId);
501  } else if (isUtilityNode(varId)) {
502  delete __utilityMap[varId];
503  __utilityMap.erase(varId);
504  }
505 
506  __variableMap.erase(varId);
507  _dag.eraseNode(varId);
508  }
509  }
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 childs.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
bool exists(NodeId id) const
Return true if id matches a node.
VariableNodeMap __variableMap
Mapping between id and variable.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
void erase(NodeId id)
Removes a var and it&#39;s id of this mapping. The pointer is deleted.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), and gum::InfluenceDiagram< GUM_SCALAR >::variableFromName().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::erase().

276 { erase(variableFromName(name)); };
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his childs.
virtual const DiscreteVariable & variableFromName(const std::string &name) const
Getter by name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 childs.

If no variable matches, then nothing is done.

Parameters
varThe reference on the variable to remove.

Definition at line 517 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, gum::InfluenceDiagram< GUM_SCALAR >::erase(), and gum::VariableNodeMap::get().

517  {
518  erase(__variableMap.get(var));
519  }
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his childs.
VariableNodeMap __variableMap
Mapping between id and variable.
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.
+ Here is the call graph for this function:

◆ 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 557 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, gum::DAGmodel::_dag, gum::ArcGraphPart::eraseArc(), gum::ArcGraphPart::existsArc(), gum::Arc::head(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), gum::Arc::tail(), and gum::InfluenceDiagram< GUM_SCALAR >::variable().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::addArc(), and gum::InfluenceDiagram< GUM_SCALAR >::eraseArc().

557  {
558  if (_dag.existsArc(arc)) {
559  NodeId head = arc.head(), tail = arc.tail();
560  _dag.eraseArc(arc);
561 
562  if (isChanceNode(head))
563  // Removes parent in the child's CPT
564  (*(__potentialMap[head])) >> variable(tail);
565  else if (isUtilityNode(head))
566  // Removes parent in the child's UT
567  (*(__utilityMap[head])) >> variable(tail);
568  }
569  }
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 const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 577 of file influenceDiagram_tpl.h.

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

577  {
578  eraseArc(Arc(tail, head));
579  }
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
+ Here is the call graph for this function:

◆ 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 334 of file influenceDiagram.h.

References gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder(), and gum::InfluenceDiagram< GUM_SCALAR >::idFromName().

334  {
335  eraseArc(idFromName(tail), idFromName(head));
336  }
virtual NodeId idFromName(const std::string &name) const
Getter by name.
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
+ 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 640 of file influenceDiagram_tpl.h.

References gum::DAGmodel::_dag, gum::ArcGraphPart::children(), gum::List< Val, Alloc >::empty(), gum::List< Val, Alloc >::front(), gum::NodeGraphPart::nodesProperty(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), and gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween().

641  {
642  List< NodeId > nodeFIFO;
643  // mark[node] contains 0 if not visited
644  // mark[node] = predecessor if visited
645  NodeProperty< int > mark = _dag.nodesProperty((int)-1);
646  NodeId current;
647 
648  mark[src] = (int)src;
649  nodeFIFO.pushBack(src);
650 
651  while (!nodeFIFO.empty()) {
652  current = nodeFIFO.front();
653  nodeFIFO.popFront();
654 
655  for (const auto new_one: _dag.children(current)) {
656  if (mark[new_one] != -1)
657  continue; // if this node is already marked, continue
658 
659  mark[new_one] = (int)current;
660 
661  if (new_one == dest) break; // if we reach *orderIter, stop.
662 
663  nodeFIFO.pushBack(new_one);
664  }
665  }
666 
667  if (mark[dest] == -1) return false;
668 
669  return true;
670  }
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:162
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 decison nodes.

Definition at line 365 of file influenceDiagram.h.

References gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), and gum::InfluenceDiagram< GUM_SCALAR >::idFromName().

365  {
366  return existsPathBetween(idFromName(src), idFromName(dest));
367  }
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.
virtual NodeId idFromName(const std::string &name) const
Getter by name.
+ Here is the call graph for this function:

◆ getDecisionGraph()

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

Returns the temporal Graph.

Definition at line 676 of file influenceDiagram_tpl.h.

References gum::DAGmodel::_dag, gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), gum::NodeGraphPart::existsNode(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::NodeGraphPart::nodes().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::eraseArc().

676  {
677  gum::DAG* temporalGraph = new gum::DAG();
678 
679  for (const auto node: _dag.nodes()) {
680  if (isDecisionNode(node)) {
681  if (!temporalGraph->existsNode(node)) temporalGraph->addNodeWithId(node);
682 
683  for (const auto chi: _getChildrenDecision(node)) {
684  if (!temporalGraph->existsNode(chi)) temporalGraph->addNodeWithId(chi);
685 
686  temporalGraph->addArc(node, chi);
687  }
688  }
689  }
690 
691  return temporalGraph;
692  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:43
Sequence< NodeId > _getChildrenDecision(NodeId parentDecision) const
Returns the list of children decision for a given nodeId.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
Base class for dag.
Definition: DAG.h:102
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDecisionOrder()

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

Returns the sequence of decision nodes in the directed path.

Exceptions
NotFoundif such a path does not exist

Definition at line 737 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), GUM_ERROR, gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::DAGmodel::topologicalOrder().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), and gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder().

737  {
738  if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists"); }
739 
740  std::vector< NodeId >* decisionSequence = new std::vector< NodeId >();
741 
742  for (const auto elt: topologicalOrder(false))
743  if (isDecisionNode(elt)) decisionSequence->push_back(elt);
744 
745  return decisionSequence;
746  }
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.cpp:99
bool decisionOrderExists() const
True if a directed path exist with all decison nodes.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 754 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__temporalOrder, gum::DAGmodel::_dag, gum::NodeGraphPart::asNodeSet(), gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::erase(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder(), gum::Set< Key, Alloc >::insert(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::ArcGraphPart::parents().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween().

754  {
755  if (clear) {
756  __temporalOrder.clear();
757 
758  std::vector< NodeId >* decisionOrder = getDecisionOrder();
759  NodeSet nodeList = _dag.asNodeSet();
760 
761  for (Idx i = 0; i < decisionOrder->size(); i++) {
762  NodeSet partialOrderedSet;
763 
764  for (const auto par: _dag.parents(decisionOrder->at(i))) {
765  if (nodeList.contains(par) && isChanceNode(par)) {
766  partialOrderedSet.insert(par);
767  nodeList.erase(par);
768  }
769  }
770 
771  if (!partialOrderedSet.empty())
772  __temporalOrder.pushFront(partialOrderedSet);
773 
774  NodeSet decisionSet;
775 
776  decisionSet.insert(decisionOrder->at(i));
777 
778  __temporalOrder.pushFront(decisionSet);
779  }
780 
781  NodeSet lastSet; //= new gum::NodeSet();
782 
783  for (const auto node: nodeList)
784  if (isChanceNode(node)) lastSet.insert(node);
785 
786  if (!lastSet.empty()) __temporalOrder.pushFront(lastSet);
787  }
788 
789  return __temporalOrder;
790  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
std::vector< NodeId > * getDecisionOrder() const
Returns the sequence of decision nodes in the directed path.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
List< NodeSet > __temporalOrder
The temporal order.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

103  {
104  if (this == &other) return true;
105 
106  if (size() != other.size()) return false;
107 
108  if (sizeArcs() != other.sizeArcs()) return false;
109 
110  for (const auto& nid: nodes()) {
111  try {
112  other.idFromName(variable(nid).name());
113  } catch (NotFound) { return false; }
114  }
115 
116  for (const auto& arc: arcs()) {
117  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
118  other.idFromName(variable(arc.head()).name()))))
119  return false;
120  }
121 
122  return true;
123  }
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:44
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:42
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:39
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
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
virtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::DAGmodel.

Definition at line 341 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, and gum::VariableNodeMap::idFromName().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode().

341  {
342  return __variableMap.idFromName(name);
343  }
VariableNodeMap __variableMap
Mapping between id and variable.
NodeId idFromName(const std::string &name) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isChanceNode() [1/2]

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

◆ isChanceNode() [2/2]

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

◆ 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 270 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode().

270  {
271  bool ret = true;
272 
273  if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
274 
275  return ret;
276  }
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 126 of file influenceDiagram.h.

References gum::InfluenceDiagram< GUM_SCALAR >::idFromName(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode().

126  {
127  return isDecisionNode(idFromName(name));
128  };
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
virtual NodeId idFromName(const std::string &name) const
Getter by name.
+ Here is the call graph for this function:

◆ 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 262 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), and gum::InfluenceDiagram< GUM_SCALAR >::toDot().

262  {
263  return __utilityMap.exists(varId);
264  }
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
+ Here is the caller graph for this function:

◆ 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 119 of file influenceDiagram.h.

References gum::InfluenceDiagram< GUM_SCALAR >::idFromName(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode().

119  {
120  return isUtilityNode(idFromName(name));
121  };
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
virtual NodeId idFromName(const std::string &name) const
Getter by name.
+ Here is the call graph for this function:

◆ log10DomainSize()

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

Definition at line 74 of file graphicalModel_inl.h.

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

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toString(), and gum::IMarkovNet< GUM_SCALAR >::toString().

74  {
75  double dSize = 0.0;
76 
77  for (const auto node: nodes()) {
78  dSize += std::log10(variable(node).domainSize());
79  }
80 
81  return dSize;
82  }
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

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

83  {
84  if (clear
85  || (__mutableMoralGraph == nullptr)) { // we have to call _moralGraph
86  if (__mutableMoralGraph == nullptr) {
87  __mutableMoralGraph = new UndiGraph();
88  } else {
89  // clear is True ,__mutableMoralGraph exists
91  }
92 
93  __moralGraph();
94  }
95 
96  return *__mutableMoralGraph;
97  }
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:43
UndiGraph * __mutableMoralGraph
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:170
void __moralGraph() const
Returns the moral graph of this DAGModel.
Definition: DAGmodel.cpp:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nodeId()

template<typename GUM_SCALAR >
INLINE NodeId gum::InfluenceDiagram< GUM_SCALAR >::nodeId ( const DiscreteVariable var) const
virtual

Return id node from discrete var pointer.

Exceptions
NotFoundIf no variable matches var.

Implements gum::DAGmodel.

Definition at line 334 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, and gum::VariableNodeMap::get().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), and gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

334  {
335  return __variableMap.get(var);
336  }
VariableNodeMap __variableMap
Mapping between id and variable.
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nodes()

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

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

Implements gum::GraphicalModel.

Definition at line 60 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::credal::CredalNet< GUM_SCALAR >::__sort_varType(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::getMaxModality(), gum::DAGmodel::hasSameStructure(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::BayesNetFragment< GUM_SCALAR >::toBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

60  {
61  return (NodeGraphPart&)_dag;
62  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
+ Here is the caller 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 73 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__potentialMap, gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap, gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), and gum::DAGmodel::operator=().

74  {
75  if (this != &source) {
76  DAGmodel::operator=(source);
77  // Removing previous potentials
78  _removeTables();
79  __potentialMap.clear();
80  __utilityMap.clear();
81 
82  __variableMap = source.__variableMap;
83 
84  // Copying tables
85  _copyTables(source);
86  }
87 
88  return *this;
89  }
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
Definition: DAGmodel.cpp:69
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
VariableNodeMap __variableMap
Mapping between id and variable.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
void _copyTables(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
void _removeTables()
Removing ancient table.
+ Here is the call graph for this function:

◆ parents() [1/2]

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 toward which the nodes returned share an arc

Definition at line 46 of file DAGmodel_inl.h.

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

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

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

◆ parents() [2/2]

INLINE const NodeSet & gum::DAGmodel::parents ( const std::string &  name) 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 toward which the nodes returned share an arc

Definition at line 49 of file DAGmodel_inl.h.

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

49  {
50  return parents(idFromName(name));
51  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:46
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ 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 37 of file graphicalModel_inl.h.

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

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

37  {
38  try {
39  return __properties()[name];
40  } catch (NotFound&) {
41  std::string msg = "The following property does not exists: ";
42  GUM_ERROR(NotFound, msg + name);
43  }
44  }
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:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

References gum::GraphicalModel::__properties().

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

◆ 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.

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

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

66  {
67  try {
68  __properties()[name] = value;
69  } catch (NotFound&) { __properties().insert(name, value); }
70  }
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 39 of file DAGmodel_inl.h.

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

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

39 { 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:36
+ Here is the call graph for this function:
+ Here is the caller 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 42 of file DAGmodel_inl.h.

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

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

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

◆ 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 167 of file influenceDiagram_tpl.h.

References gum::DAGmodel::_dag, gum::ArcGraphPart::children(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode(), gum::Variable::name(), gum::NodeGraphPart::nodes(), gum::GraphicalModel::property(), gum::Set< Key, Alloc >::size(), and gum::InfluenceDiagram< GUM_SCALAR >::variable().

167  {
168  std::stringstream output;
169  std::stringstream decisionNode;
170  std::stringstream utilityNode;
171  std::stringstream chanceNode;
172  std::stringstream arcstream;
173  output << "digraph \"";
174 
175  try {
176  output << this->property("name") << "\" {" << std::endl;
177  } catch (NotFound&) { output << "no_name\" {" << std::endl; }
178 
179  output << " node [bgcolor=\"#AAAAAA\", style=filled];" << std::endl;
180 
181  decisionNode << "node [shape = box];" << std::endl;
182 
183  utilityNode << "node [shape = diamond];" << std::endl;
184  chanceNode << "node [shape = ellipse];" << std::endl;
185  std::string tab = " ";
186 
187  for (const auto node: _dag.nodes()) {
188  if (isChanceNode(node))
189  chanceNode << tab << "\"" << variable(node).name() << "\""
190  << ";";
191  else if (isUtilityNode(node))
192  utilityNode << tab << "\"" << variable(node).name() << "\""
193  << ";";
194  else
195  decisionNode << tab << "\"" << variable(node).name() << "\""
196  << ";";
197 
198  if (_dag.children(node).size() > 0)
199  for (const auto chi: _dag.children(node))
200  arcstream << tab << "\"" << variable(node).name() << "\""
201  << " -> "
202  << "\"" << variable(chi).name() << "\";" << std::endl;
203  }
204 
205  output << decisionNode.str() << std::endl
206  << utilityNode.str() << std::endl
207  << chanceNode.str() << std::endl
208  << arcstream.str() << std::endl
209  << "}" << std::endl;
210 
211  return output.str();
212  }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:162
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703
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.
+ Here is the call graph for this function:

◆ topologicalOrder()

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

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

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

99  {
100  return this->dag().topologicalOrder(clear);
101  }
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:91
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:36
+ Here is the call graph for this function:
+ Here is the caller 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 215 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::chanceNodeSize(), gum::DAGmodel::dag(), gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize(), gum::GraphicalModel::log10DomainSize(), gum::ArcGraphPart::sizeArcs(), and gum::InfluenceDiagram< GUM_SCALAR >::utilityNodeSize().

215  {
216  std::stringstream output;
217 
218  output << "Influence Diagram{" << std::endl;
219  output << " chance: " << chanceNodeSize() << "," << std::endl;
220  output << " utility: " << utilityNodeSize() << "," << std::endl;
221  output << " decision: " << decisionNodeSize() << "," << std::endl;
222  output << " arcs: " << dag().sizeArcs() << "," << std::endl;
223 
224  double dSize = log10DomainSize();
225 
226  if (dSize > 6)
227  output << " domainSize: 10^" << dSize;
228  else
229  output << " domainSize: " << std::round(std::pow(10.0, dSize));
230 
231  output << std::endl << "}";
232 
233  return output.str();
234  }
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:36
+ Here is the call graph for this function:

◆ utility()

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 254 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), and gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID().

254  {
255  return *(__utilityMap[varId]);
256  }
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
+ Here is the caller graph for this function:

◆ utilityNodeSize()

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

Returns the number of utility nodes.

Definition at line 290 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__utilityMap.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

290  {
291  return __utilityMap.size();
292  }
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
+ Here is the caller graph for this function:

◆ variable()

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

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

Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::DAGmodel.

Definition at line 325 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode(), gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode(), and gum::InfluenceDiagram< GUM_SCALAR >::toDot().

325  {
326  return __variableMap[id];
327  }
VariableNodeMap __variableMap
Mapping between id and variable.
+ Here is the caller graph for this function:

◆ variableFromName()

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

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::DAGmodel.

Definition at line 347 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap, and gum::VariableNodeMap::variableFromName().

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::erase(), and gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode().

348  {
349  return __variableMap.variableFromName(name);
350  }
VariableNodeMap __variableMap
Mapping between id and variable.
const DiscreteVariable & variableFromName(const std::string &name) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variableNodeMap()

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

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

Implements gum::GraphicalModel.

Definition at line 316 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::__variableMap.

316  {
317  return __variableMap;
318  }
VariableNodeMap __variableMap
Mapping between id and variable.

Member Data Documentation

◆ __potentialMap

◆ __temporalOrder

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

The temporal order.

Definition at line 411 of file influenceDiagram.h.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder().

◆ __utilityMap

◆ __variableMap

◆ _dag


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