aGrUM  0.14.2
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 52 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 41 of file influenceDiagram_tpl.h.

41  : DAGmodel() {
42  GUM_CONSTRUCTOR(InfluenceDiagram);
43  }
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:28
InfluenceDiagram()
Default constructor.

◆ ~InfluenceDiagram()

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

Destructor.

Definition at line 49 of file influenceDiagram_tpl.h.

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

49  {
50  GUM_DESTRUCTOR(InfluenceDiagram);
51  _removeTables();
52  }
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 58 of file influenceDiagram_tpl.h.

References gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), and gum::InfluenceDiagram< GUM_SCALAR >::operator=().

59  :
60  DAGmodel(source),
61  __variableMap(source.__variableMap) {
62  GUM_CONS_CPY(InfluenceDiagram);
63  _copyTables(source);
64  }
VariableNodeMap __variableMap
Mapping between id and variable.
DAGmodel()
Default constructor.
Definition: DAGmodel.cpp:28
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 463 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().

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

106  {
107  // Copying potentials
108  for (const auto& pot : IDsource.__potentialMap) {
109  // Instanciation of the node's CPT
110  auto potentialCpy = new Potential< GUM_SCALAR >;
111  (*potentialCpy) << variable(pot.first);
112 
113  // Addition of the parents
114  for (const auto par : _dag.parents(pot.first))
115  (*potentialCpy) << variable(par);
116 
117  // Filling up of the table
118  Instantiation srcInst(*pot.second);
119  Instantiation cpyInst(*potentialCpy);
120 
121  for (cpyInst.setFirst(); !cpyInst.end(); cpyInst.inc()) {
122  for (Idx i = 0; i < cpyInst.nbrDim(); i++) {
123  NodeId id = nodeId(cpyInst.variable(i));
124  srcInst.chgVal(IDsource.variable(id), cpyInst.val(i));
125  }
126 
127  potentialCpy->set(cpyInst, (*pot.second)[srcInst]);
128  }
129 
130  // Adding cpt to cpt map
131  __potentialMap.set(pot.first, potentialCpy);
132  }
133 
134  // Copying Utilities
135  for (const auto& uti : IDsource.__utilityMap) {
136  // Instanciation of the node's CPT
137  auto utilityCpy = new Potential< GUM_SCALAR >;
138  (*utilityCpy) << variable(uti.first);
139 
140  // Addition of the parents
141  for (const auto par : _dag.parents(uti.first))
142  (*utilityCpy) << variable(par);
143 
144  // Filling up of the table
145  Instantiation srcInst(*uti.second);
146 
147  Instantiation cpyInst(*utilityCpy);
148 
149  for (cpyInst.setFirst(); !cpyInst.end(); cpyInst.inc()) {
150  for (Idx i = 0; i < cpyInst.nbrDim(); i++) {
151  NodeId id = nodeId(cpyInst.variable(i));
152  srcInst.chgVal(IDsource.variable(id), cpyInst.val(i));
153  }
154 
155  utilityCpy->set(cpyInst, (*uti.second)[srcInst]);
156  }
157 
158  // Adding cpt to cpt map
159  __utilityMap.set(uti.first, utilityCpy);
160  }
161  }
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:200
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:97
+ 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 696 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().

697  {
698  Sequence< NodeId > childrenSeq;
699 
700  List< NodeId > nodeFIFO;
701  NodeId current;
702 
703  // mark[node] contains false if not visited
704  // mark[node] contains true if visited
705  NodeProperty< bool > mark = _dag.nodesProperty(false);
706 
707  mark[parentDecision] = true;
708 
709  nodeFIFO.pushBack(parentDecision);
710 
711  while (!nodeFIFO.empty()) {
712  current = nodeFIFO.front();
713  nodeFIFO.popFront();
714 
715  for (const auto new_one : _dag.children(current)) {
716  if (mark[new_one]) continue; // if this node is already marked, continue
717 
718  mark[new_one] = true;
719 
720  if (!isDecisionNode(new_one))
721  nodeFIFO.pushBack(new_one);
722  else
723  childrenSeq.insert(new_one);
724  }
725  }
726 
727  return childrenSeq;
728  }
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:200
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:97
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:405
+ 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 587 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().

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

92  {
93  for (const auto node : _dag.nodes()) {
94  if (isChanceNode(node))
95  delete &cpt(node);
96  else if (isUtilityNode(node))
97  delete &utility(node);
98  }
99  }
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:200
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 355 of file influenceDiagram_tpl.h.

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

356  {
357  return addChanceNode(var, varId);
358  }
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 534 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().

534  {
535  if (isUtilityNode(tail)) {
536  GUM_ERROR(InvalidArc, "Tail cannot be a utility node");
537  }
538 
539  _dag.addArc(tail, head);
540 
541  if (isChanceNode(head))
542  // Add parent in the child's CPT
543  (*(__potentialMap[head])) << variable(tail);
544  else if (isUtilityNode(head))
545  // Add parent in the child's UT
546  (*(__utilityMap[head])) << variable(tail);
547  }
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:200
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:40
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 398 of file influenceDiagram_tpl.h.

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

399  {
400  MultiDimArray< GUM_SCALAR >* newMultiDim = new MultiDimArray< GUM_SCALAR >();
401  NodeId res = 0;
402 
403  try {
404  res = addChanceNode(var, newMultiDim, varId);
405  } catch (Exception&) {
406  delete newMultiDim;
407  throw;
408  }
409 
410  return res;
411  }
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 418 of file influenceDiagram_tpl.h.

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

421  {
422  NodeId proposedId = _addNode(var, DesiredId);
423 
424  Potential< GUM_SCALAR >* varcpt = new Potential< GUM_SCALAR >(aContent);
425  (*varcpt) << variable(proposedId);
426  __potentialMap.insert(proposedId, varcpt);
427 
428  return proposedId;
429  }
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:97
+ 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 388 of file influenceDiagram_tpl.h.

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

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

389  {
390  return _addNode(var, varId);
391  }
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 367 of file influenceDiagram_tpl.h.

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

368  {
369  MultiDimArray< GUM_SCALAR >* newMultiDim = new MultiDimArray< GUM_SCALAR >();
370  NodeId res = 0;
371 
372  try {
373  res = addUtilityNode(var, newMultiDim, varId);
374  } catch (Exception&) {
375  delete newMultiDim;
376  throw;
377  }
378 
379  return res;
380  }
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it&#39;s associate node and it&#39;s UT.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 437 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().

440  {
441  if (var.domainSize() != 1) {
442  GUM_ERROR(InvalidArgument,
443  "Utility var have no state ( which implicates a "
444  "single label for data output reasons ).");
445  }
446 
447  NodeId proposedId = _addNode(var, DesiredId);
448 
449  Potential< GUM_SCALAR >* varut = new Potential< GUM_SCALAR >(aContent);
450 
451  (*varut) << variable(proposedId);
452 
453  __utilityMap.insert(proposedId, varut);
454 
455  return proposedId;
456  }
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:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 101 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().

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

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

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

296  {
297  return __potentialMap.size();
298  }
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 522 of file influenceDiagram_tpl.h.

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

523  {
524  __variableMap.changeName(id, new_name);
525  }
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 108 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().

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

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

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

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

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

83  {
84  Instantiation I;
85 
86  for (const auto node : dag())
87  I << variable(node);
88 
89  return I;
90  }
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:60
+ 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 243 of file influenceDiagram_tpl.h.

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

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

243  {
244  return *(__potentialMap[varId]);
245  }
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 304 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().

304  {
305  return (size() - __utilityMap.size() - __potentialMap.size());
306  }
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:93
+ 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 606 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().

606  {
607  const Sequence< NodeId >& order = topologicalOrder(true);
608 
609  // Finding first decision node
610  Sequence< NodeId >::const_iterator orderIter = order.begin();
611 
612  while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
613  ++orderIter;
614 
615  if (orderIter == order.end()) return true;
616 
617  NodeId parentDecision = (*orderIter);
618  ++orderIter;
619 
620  // Checking path between decisions nodes
621  while (orderIter != order.end()) {
622  if (isDecisionNode(*orderIter)) {
623  if (!existsPathBetween(parentDecision, *orderIter)) return false;
624 
625  parentDecision = *orderIter;
626  }
627 
628  ++orderIter;
629  }
630 
631  return true;
632  }
SequenceIterator< NodeId > const_iterator
Definition: sequence.h:1033
iterator begin() const
Returns an unsafe begin iterator.
Definition: sequence_tpl.h:654
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:115
const iterator & end() const noexcept
Returns the unsafe end iterator.
Definition: sequence_tpl.h:661
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 96 of file DAGmodel_inl.h.

References gum::DAGmodel::size().

96 { return size() == 0; }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
+ 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 487 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().

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

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

515  {
516  erase(__variableMap.get(var));
517  }
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 555 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().

555  {
556  if (_dag.existsArc(arc)) {
557  NodeId head = arc.head(), tail = arc.tail();
558  _dag.eraseArc(arc);
559 
560  if (isChanceNode(head))
561  // Removes parent in the child's CPT
562  (*(__potentialMap[head])) >> variable(tail);
563  else if (isUtilityNode(head))
564  // Removes parent in the child's UT
565  (*(__utilityMap[head])) >> variable(tail);
566  }
567  }
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:200
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:97
+ 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 575 of file influenceDiagram_tpl.h.

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

575  {
576  eraseArc(Arc(tail, head));
577  }
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 638 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().

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

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

735  {
736  if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists"); }
737 
738  std::vector< NodeId >* decisionSequence = new std::vector< NodeId >();
739 
740  for (const auto elt : topologicalOrder(false))
741  if (isDecisionNode(elt)) decisionSequence->push_back(elt);
742 
743  return decisionSequence;
744  }
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:115
bool decisionOrderExists() const
True if a directed path exist with all decison nodes.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 752 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().

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

119  {
120  if (this == &other) return true;
121 
122  if (size() != other.size()) return false;
123 
124  if (sizeArcs() != other.sizeArcs()) return false;
125 
126  for (const auto& nid : nodes()) {
127  try {
128  other.idFromName(variable(nid).name());
129  } catch (NotFound) { return false; }
130  }
131 
132  for (const auto& arc : arcs()) {
133  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
134  other.idFromName(variable(arc.head()).name()))))
135  return false;
136  }
137 
138  return true;
139  }
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:101
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:99
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
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 339 of file influenceDiagram_tpl.h.

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

339  {
340  return __variableMap.idFromName(name);
341  }
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 280 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().

280  {
281  return __potentialMap.exists(varId);
282  }
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 268 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().

268  {
269  bool ret = true;
270 
271  if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
272 
273  return ret;
274  }
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 260 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().

260  {
261  return __utilityMap.exists(varId);
262  }
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 72 of file DAGmodel_inl.h.

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

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

72  {
73  double dSize = 0.0;
74 
75  for (const auto node : nodes()) {
76  dSize += std::log10(variable(node).domainSize());
77  }
78 
79  return dSize;
80  }
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
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 99 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().

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

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

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

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

332  {
333  return __variableMap.get(var);
334  }
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 112 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::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().

112  {
113  return (NodeGraphPart&)_dag;
114  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
+ 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 71 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().

71  {
72  if (this != &source) {
73  DAGmodel::operator=(source);
74  // Removing previous potentials
75  _removeTables();
76  __potentialMap.clear();
77  __utilityMap.clear();
78 
79  __variableMap = source.__variableMap;
80 
81  // Copying tables
82  _copyTables(source);
83  }
84 
85  return *this;
86  }
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
Definition: DAGmodel.cpp:76
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 103 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().

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

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

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

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

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

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

34  {
35  try {
36  return __properties()[name];
37  } catch (NotFound&) {
38  std::string msg = "The following property does not exists: ";
39  GUM_ERROR(NotFound, msg + name);
40  }
41  }
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:63
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 45 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties().

46  {
47  try {
48  return __properties()[name];
49  } catch (NotFound&) { return byDefault; }
50  }
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:63
+ 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 53 of file DAGmodel_inl.h.

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

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

53  {
54  try {
55  __properties()[name] = value;
56  } catch (NotFound&) { __properties().insert(name, value); }
57  }
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:63
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 93 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().

93 { 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:60
+ 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 99 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==().

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

◆ 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 164 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().

164  {
165  std::stringstream output;
166  std::stringstream decisionNode;
167  std::stringstream utilityNode;
168  std::stringstream chanceNode;
169  std::stringstream arcstream;
170  output << "digraph \"";
171 
172  try {
173  output << this->property("name") << "\" {" << std::endl;
174  } catch (NotFound&) { output << "no_name\" {" << std::endl; }
175 
176  output << " node [bgcolor=\"#AAAAAA\", style=filled];" << std::endl;
177 
178  decisionNode << "node [shape = box];" << std::endl;
179 
180  utilityNode << "node [shape = diamond];" << std::endl;
181  chanceNode << "node [shape = ellipse];" << std::endl;
182  std::string tab = " ";
183 
184  for (const auto node : _dag.nodes()) {
185  if (isChanceNode(node))
186  chanceNode << tab << "\"" << variable(node).name() << "\""
187  << ";";
188  else if (isUtilityNode(node))
189  utilityNode << tab << "\"" << variable(node).name() << "\""
190  << ";";
191  else
192  decisionNode << tab << "\"" << variable(node).name() << "\""
193  << ";";
194 
195  if (_dag.children(node).size() > 0)
196  for (const auto chi : _dag.children(node))
197  arcstream << tab << "\"" << variable(node).name() << "\""
198  << " -> "
199  << "\"" << variable(chi).name() << "\""
200  << ";" << std::endl;
201  }
202 
203  output << decisionNode.str() << std::endl
204  << utilityNode.str() << std::endl
205  << chanceNode.str() << std::endl
206  << arcstream.str() << std::endl
207  << "}" << std::endl;
208 
209  return output.str();
210  }
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:200
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:34
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:698
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 115 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().

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

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

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

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

252  {
253  return *(__utilityMap[varId]);
254  }
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 288 of file influenceDiagram_tpl.h.

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

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

288  {
289  return __utilityMap.size();
290  }
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 323 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().

323  {
324  return __variableMap[id];
325  }
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 345 of file influenceDiagram_tpl.h.

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

346  {
347  return __variableMap.variableFromName(name);
348  }
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 314 of file influenceDiagram_tpl.h.

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

314  {
315  return __variableMap;
316  }
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 390 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: