aGrUM  0.16.0
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
 
double log10DomainSize () const
 
bool hasSameStructure (const DAGmodel &other)
 
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 isDecisionNode (NodeId varId) const
 Returns true if node is a decision one. More...
 
bool isChanceNode (NodeId varId) const
 Returns true if node is a chance one. 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 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...
 
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 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)
 RRemoves 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...
 
const List< NodeSet > & getPartialTemporalOrder (bool clear=true) const
 Returns partial temporal ordering. More...
 
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this DAGModel. More...
 
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this DAGModel. More...
 
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this DAGModel. More...
 
Variable manipulation methods.
const DAGdag () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
Size size () const
 Returns the number of variables in this Directed Graphical Model. More...
 
Size sizeArcs () const
 Returns the number of arcs in this Directed Graphical Model. More...
 
bool empty () const
 Retursn true if this Directed Graphical Model is empty. More...
 
const NodeGraphPartnodes () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
virtual Instantiation completeInstantiation () const final
 Get an instantiation over all the variables of the model. More...
 
Arc manipulation methods.
const ArcSetarcs () const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
const NodeSetchildren (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
Graphical methods
const UndiGraphmoralGraph (bool clear=true) const
 The node's id are coherent with the variables and nodes of the topology. More...
 
const Sequence< NodeId > & topologicalOrder (bool clear=true) const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology. More...
 

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(), and gum::InfluenceDiagram< GUM_SCALAR >::operator=().

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 466 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(), and gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode().

467  {
468  // None thread safe code!
469  NodeId proposedId;
470 
471  if (DesiredId == 0)
472  proposedId = _dag.nextNodeId();
473  else
474  proposedId = DesiredId;
475 
476  __variableMap.insert(proposedId, variableType);
477 
478  _dag.addNodeWithId(proposedId);
479 
480  // end critical section
481  return proposedId;
482  }
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:203
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 >::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:203
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 699 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 >::getDecisionGraph().

700  {
701  Sequence< NodeId > childrenSeq;
702 
703  List< NodeId > nodeFIFO;
704  NodeId current;
705 
706  // mark[node] contains false if not visited
707  // mark[node] contains true if visited
708  NodeProperty< bool > mark = _dag.nodesProperty(false);
709 
710  mark[parentDecision] = true;
711 
712  nodeFIFO.pushBack(parentDecision);
713 
714  while (!nodeFIFO.empty()) {
715  current = nodeFIFO.front();
716  nodeFIFO.popFront();
717 
718  for (const auto new_one : _dag.children(current)) {
719  if (mark[new_one]) continue; // if this node is already marked, continue
720 
721  mark[new_one] = true;
722 
723  if (!isDecisionNode(new_one))
724  nodeFIFO.pushBack(new_one);
725  else
726  childrenSeq.insert(new_one);
727  }
728  }
729 
730  return childrenSeq;
731  }
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:203
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 590 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().

590  {
591  for (const auto node : _dag.nodes())
592  if (!isUtilityNode(node)) graph.addNodeWithId(node);
593 
594  for (const auto node : _dag.nodes()) {
595  if (!isDecisionNode(node))
596  for (const auto par : _dag.parents(node)) {
597  if (isChanceNode(node)) graph.addEdge(node, par);
598 
599  for (const auto par2 : _dag.parents(node))
600  if (par != par2) graph.addEdge(par, par2);
601  }
602  }
603  }
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:203
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:

◆ _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 >::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:203
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 358 of file influenceDiagram_tpl.h.

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

359  {
360  return addChanceNode(var, varId);
361  }
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:

◆ addArc()

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 537 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(), and gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID().

537  {
538  if (isUtilityNode(tail)) {
539  GUM_ERROR(InvalidArc, "Tail cannot be a utility node");
540  }
541 
542  _dag.addArc(tail, head);
543 
544  if (isChanceNode(head))
545  // Add parent in the child's CPT
546  (*(__potentialMap[head])) << variable(tail);
547  else if (isUtilityNode(head))
548  // Add parent in the child's UT
549  (*(__utilityMap[head])) << variable(tail);
550  }
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:203
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:

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

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

402  {
403  MultiDimArray< GUM_SCALAR >* newMultiDim = new MultiDimArray< GUM_SCALAR >();
404  NodeId res = 0;
405 
406  try {
407  res = addChanceNode(var, newMultiDim, varId);
408  } catch (Exception&) {
409  delete newMultiDim;
410  throw;
411  }
412 
413  return res;
414  }
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 421 of file influenceDiagram_tpl.h.

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

424  {
425  NodeId proposedId = _addNode(var, DesiredId);
426 
427  Potential< GUM_SCALAR >* varcpt = new Potential< GUM_SCALAR >(aContent);
428  (*varcpt) << variable(proposedId);
429  __potentialMap.insert(proposedId, varcpt);
430 
431  return proposedId;
432  }
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 391 of file influenceDiagram_tpl.h.

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

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID().

392  {
393  return _addNode(var, varId);
394  }
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
InvalidAgrumentIf variable has more than one label
DuplicateElementif id(<>0) is already used

Definition at line 370 of file influenceDiagram_tpl.h.

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID().

371  {
372  MultiDimArray< GUM_SCALAR >* newMultiDim = new MultiDimArray< GUM_SCALAR >();
373  NodeId res = 0;
374 
375  try {
376  res = addUtilityNode(var, newMultiDim, varId);
377  } catch (Exception&) {
378  delete newMultiDim;
379  throw;
380  }
381 
382  return res;
383  }
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
InvalidAgrumentIf variable has more than one label
DuplicateElementif id(<>0) is already used

Definition at line 440 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().

443  {
444  if (var.domainSize() != 1) {
445  GUM_ERROR(InvalidArgument,
446  "Utility var have no state ( which implicates a "
447  "single label for data output reasons ).");
448  }
449 
450  NodeId proposedId = _addNode(var, DesiredId);
451 
452  Potential< GUM_SCALAR >* varut = new Potential< GUM_SCALAR >(aContent);
453 
454  (*varut) << variable(proposedId);
455 
456  __utilityMap.insert(proposedId, varut);
457 
458  return proposedId;
459  }
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 arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 104 of file DAGmodel_inl.h.

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

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

104 { return _dag.arcs(); }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:203
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 299 of file influenceDiagram_tpl.h.

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

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

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

◆ changeVariableName()

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

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

526  {
527  __variableMap.changeName(id, new_name);
528  }
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:

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

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

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

111  {
112  return _dag.children(id);
113  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:203
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]

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

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

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

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 165 of file DAGmodel.h.

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

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

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 86 of file DAGmodel_inl.h.

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

86  {
87  Instantiation I;
88 
89  for (const auto node : dag())
90  I << variable(node);
91 
92  return I;
93  }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:63
+ 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 246 of file influenceDiagram_tpl.h.

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

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

246  {
247  return *(__potentialMap[varId]);
248  }
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 307 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 >::toString().

307  {
308  return (size() - __utilityMap.size() - __potentialMap.size());
309  }
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:96
+ 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 609 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(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().

609  {
610  const Sequence< NodeId >& order = topologicalOrder(true);
611 
612  // Finding first decision node
613  Sequence< NodeId >::const_iterator orderIter = order.begin();
614 
615  while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
616  ++orderIter;
617 
618  if (orderIter == order.end()) return true;
619 
620  NodeId parentDecision = (*orderIter);
621  ++orderIter;
622 
623  // Checking path between decisions nodes
624  while (orderIter != order.end()) {
625  if (isDecisionNode(*orderIter)) {
626  if (!existsPathBetween(parentDecision, *orderIter)) return false;
627 
628  parentDecision = *orderIter;
629  }
630 
631  ++orderIter;
632  }
633 
634  return true;
635  }
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:117
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::DAGmodel::empty ( ) const
inherited

Retursn true if this Directed Graphical Model is empty.

Definition at line 99 of file DAGmodel_inl.h.

References gum::DAGmodel::size().

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

◆ erase() [1/2]

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 490 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().

490  {
491  if (__variableMap.exists(varId)) {
492  // Reduce the variable child's CPT or Utility Table if necessary
493  for (const auto chi : _dag.children(varId))
494  if (isChanceNode(chi))
495  __potentialMap[chi]->erase(variable(varId));
496  else if (isUtilityNode(chi))
497  __utilityMap[chi]->erase(variable(varId));
498 
499  if (isChanceNode(varId)) {
500  delete __potentialMap[varId];
501  __potentialMap.erase(varId);
502  } else if (isUtilityNode(varId)) {
503  delete __utilityMap[varId];
504  __utilityMap.erase(varId);
505  }
506 
507  __variableMap.erase(varId);
508  _dag.eraseNode(varId);
509  }
510  }
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:203
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/2]

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

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

518  {
519  erase(__variableMap.get(var));
520  }
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/2]

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 558 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 >::eraseArc().

558  {
559  if (_dag.existsArc(arc)) {
560  NodeId head = arc.head(), tail = arc.tail();
561  _dag.eraseArc(arc);
562 
563  if (isChanceNode(head))
564  // Removes parent in the child's CPT
565  (*(__potentialMap[head])) >> variable(tail);
566  else if (isUtilityNode(head))
567  // Removes parent in the child's UT
568  (*(__utilityMap[head])) >> variable(tail);
569  }
570  }
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:203
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/2]

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

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

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

578  {
579  eraseArc(Arc(tail, head));
580  }
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()

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 641 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().

642  {
643  List< NodeId > nodeFIFO;
644  // mark[node] contains 0 if not visited
645  // mark[node] = predecessor if visited
646  NodeProperty< int > mark = _dag.nodesProperty((int)-1);
647  NodeId current;
648 
649  mark[src] = (int)src;
650  nodeFIFO.pushBack(src);
651 
652  while (!nodeFIFO.empty()) {
653  current = nodeFIFO.front();
654  nodeFIFO.popFront();
655 
656  for (const auto new_one : _dag.children(current)) {
657  if (mark[new_one] != -1)
658  continue; // if this node is already marked, continue
659 
660  mark[new_one] = (int)current;
661 
662  if (new_one == dest) break; // if we reach *orderIter, stop.
663 
664  nodeFIFO.pushBack(new_one);
665  }
666  }
667 
668  if (mark[dest] == -1) return false;
669 
670  return true;
671  }
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:203
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:

◆ getDecisionGraph()

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

Returns the temporal Graph.

Definition at line 677 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().

677  {
678  gum::DAG* temporalGraph = new gum::DAG();
679 
680  for (const auto node : _dag.nodes()) {
681  if (isDecisionNode(node)) {
682  if (!temporalGraph->existsNode(node)) temporalGraph->addNodeWithId(node);
683 
684  for (const auto chi : _getChildrenDecision(node)) {
685  if (!temporalGraph->existsNode(chi)) temporalGraph->addNodeWithId(chi);
686 
687  temporalGraph->addArc(node, chi);
688  }
689  }
690  }
691 
692  return temporalGraph;
693  }
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:203
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:

◆ 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 738 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 >::getPartialTemporalOrder().

738  {
739  if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists"); }
740 
741  std::vector< NodeId >* decisionSequence = new std::vector< NodeId >();
742 
743  for (const auto elt : topologicalOrder(false))
744  if (isDecisionNode(elt)) decisionSequence->push_back(elt);
745 
746  return decisionSequence;
747  }
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:117
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 755 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().

755  {
756  if (clear) {
757  __temporalOrder.clear();
758 
759  std::vector< NodeId >* decisionOrder = getDecisionOrder();
760  NodeSet nodeList = _dag.asNodeSet();
761 
762  for (Idx i = 0; i < decisionOrder->size(); i++) {
763  NodeSet partialOrderedSet;
764 
765  for (const auto par : _dag.parents(decisionOrder->at(i))) {
766  if (nodeList.contains(par) && isChanceNode(par)) {
767  partialOrderedSet.insert(par);
768  nodeList.erase(par);
769  }
770  }
771 
772  if (!partialOrderedSet.empty())
773  __temporalOrder.pushFront(partialOrderedSet);
774 
775  NodeSet decisionSet;
776 
777  decisionSet.insert(decisionOrder->at(i));
778 
779  __temporalOrder.pushFront(decisionSet);
780  }
781 
782  NodeSet lastSet; //= new gum::NodeSet();
783 
784  for (const auto node : nodeList)
785  if (isChanceNode(node)) lastSet.insert(node);
786 
787  if (!lastSet.empty()) __temporalOrder.pushFront(lastSet);
788  }
789 
790  return __temporalOrder;
791  }
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:203
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:613
+ Here is the call 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 121 of file DAGmodel.cpp.

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

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

121  {
122  if (this == &other) return true;
123 
124  if (size() != other.size()) return false;
125 
126  if (sizeArcs() != other.sizeArcs()) return false;
127 
128  for (const auto& nid : nodes()) {
129  try {
130  other.idFromName(variable(nid).name());
131  } catch (NotFound) { return false; }
132  }
133 
134  for (const auto& arc : arcs()) {
135  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
136  other.idFromName(variable(arc.head()).name()))))
137  return false;
138  }
139 
140  return true;
141  }
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:102
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:96
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:115
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
+ Here is the call graph for this function:
+ Here is the caller 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 342 of file influenceDiagram_tpl.h.

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

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

◆ isChanceNode()

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

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

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 >::getPartialTemporalOrder(), gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode(), and gum::InfluenceDiagram< GUM_SCALAR >::toDot().

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

◆ isDecisionNode()

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 271 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(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().

271  {
272  bool ret = true;
273 
274  if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
275 
276  return ret;
277  }
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:

◆ isUtilityNode()

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 263 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(), and gum::InfluenceDiagram< GUM_SCALAR >::toDot().

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

◆ log10DomainSize()

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

Definition at line 75 of file DAGmodel_inl.h.

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

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

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  }
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:115
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
+ Here is the call graph for this function:
+ 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 101 of file DAGmodel.cpp.

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

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

101  {
102  if (clear
103  || (__mutableMoralGraph == nullptr)) { // we have to call _moralGraph
104  if (__mutableMoralGraph == nullptr) {
105  __mutableMoralGraph = new UndiGraph();
106  } else {
107  // clear is True ,__mutableMoralGraph exists
109  }
110 
111  __moralGraph();
112  }
113 
114  return *__mutableMoralGraph;
115  }
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:211
void __moralGraph() const
Returns the moral graph of this DAGModel.
Definition: DAGmodel.cpp:53
+ 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 335 of file influenceDiagram_tpl.h.

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

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

335  {
336  return __variableMap.get(var);
337  }
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
inherited

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

Definition at line 115 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::DAGmodel::log10DomainSize(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

115  {
116  return (NodeGraphPart&)_dag;
117  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:203
+ 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 74 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=().

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

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:78
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:
+ Here is the caller 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 arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 106 of file DAGmodel_inl.h.

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

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

106  {
107  return _dag.parents(id);
108  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:203
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]

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

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

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

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 156 of file DAGmodel.h.

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

156  {
157  return parents(idFromName(name));
158  };
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:106
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::DAGmodel::property ( const std::string &  name) const
inherited

Return the value of the property name of this DAGModel.

Exceptions
NotFoundRaised if no name property is found.

Definition at line 37 of file DAGmodel_inl.h.

References gum::DAGmodel::__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...
Definition: DAGmodel_inl.h:66
#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::DAGmodel::propertyWithDefault ( const std::string &  name,
const std::string &  byDefault 
) const
inherited

Return the value of the property name of this DAGModel.

return byDefault if the property name is not found

Definition at line 48 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties().

49  {
50  try {
51  return __properties()[name];
52  } catch (NotFound&) { return byDefault; }
53  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:66
+ Here is the call graph for this function:

◆ setProperty()

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

Add or change a property of this DAGModel.

Definition at line 56 of file DAGmodel_inl.h.

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

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

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

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Definition at line 96 of file DAGmodel_inl.h.

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

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

96 { 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:63
+ 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 102 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==().

102 { return _dag.sizeArcs(); }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:203
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::DAGmodel::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() << "\""
203  << ";" << std::endl;
204  }
205 
206  output << decisionNode.str() << std::endl
207  << utilityNode.str() << std::endl
208  << chanceNode.str() << std::endl
209  << arcstream.str() << std::endl
210  << "}" << std::endl;
211 
212  return output.str();
213  }
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:203
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const std::string & property(const std::string &name) const
Return the value of the property name of this DAGModel.
Definition: DAGmodel_inl.h:37
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:701
const std::string & name() const
returns the name of the variable
+ 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 117 of file DAGmodel.cpp.

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

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

117  {
118  return this->dag().topologicalOrder(clear);
119  }
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:63
+ 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 216 of file influenceDiagram_tpl.h.

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

216  {
217  std::stringstream output;
218 
219  output << "Influence Diagram{" << std::endl;
220  output << " chance: " << chanceNodeSize() << "," << std::endl;
221  output << " utility: " << utilityNodeSize() << "," << std::endl;
222  output << " decision: " << decisionNodeSize() << "," << std::endl;
223  output << " arcs: " << dag().sizeArcs() << "," << std::endl;
224 
225  double dSize = log10DomainSize();
226 
227  if (dSize > 6)
228  output << " domainSize: 10^" << dSize;
229  else
230  output << " domainSize: " << std::round(std::pow(10.0, dSize));
231 
232  output << std::endl << "}";
233 
234  return output.str();
235  }
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.
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
double log10DomainSize() const
Definition: DAGmodel_inl.h:75
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:63
+ 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 255 of file influenceDiagram_tpl.h.

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

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

255  {
256  return *(__utilityMap[varId]);
257  }
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 291 of file influenceDiagram_tpl.h.

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

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

291  {
292  return __utilityMap.size();
293  }
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 326 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(), and gum::InfluenceDiagram< GUM_SCALAR >::toDot().

326  {
327  return __variableMap[id];
328  }
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 348 of file influenceDiagram_tpl.h.

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

349  {
350  return __variableMap.variableFromName(name);
351  }
VariableNodeMap __variableMap
Mapping between id and variable.
const DiscreteVariable & variableFromName(const std::string &name) const
+ Here is the call 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::DAGmodel.

Definition at line 317 of file influenceDiagram_tpl.h.

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

317  {
318  return __variableMap;
319  }
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 392 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: