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

Class representing an Influence Diagram. More...

#include <agrum/ID/influenceDiagram.h>

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

Public Member Functions

bool operator== (const InfluenceDiagram< GUM_SCALAR > &other) const
bool operator!= (const InfluenceDiagram< GUM_SCALAR > &other) const
std::string toDot () const
std::string toString () const
void clear ()
bool hasSameStructure (const DAGmodel &other)
NodeSet minimalCondSet (NodeId target, const NodeSet &soids) const
NodeSet minimalCondSet (const NodeSet &targets, const NodeSet &soids) const
NodeSet minimalCondSet (const std::string &target, const std::vector< std::string > &soids) const
NodeSet minimalCondSet (const std::vector< std::string > &targets, const std::vector< std::string > &soids) const
double log10DomainSize () const
Constructors / Destructors
 InfluenceDiagram ()
 Default constructor.
 ~InfluenceDiagram () override
 Destructor.
 InfluenceDiagram (const InfluenceDiagram< GUM_SCALAR > &source)
 Copy Constructor.
InfluenceDiagram< GUM_SCALAR > & operator= (const InfluenceDiagram< GUM_SCALAR > &source)
 Copy Operator.
Variable manipulation methods.
virtual const Tensor< GUM_SCALAR > & cpt (NodeId varId) const
 Returns the CPT of a tensor variable.
virtual const Tensor< GUM_SCALAR > & cpt (std::string name) const final
 Returns the CPT of a tensor variable.
virtual const Tensor< GUM_SCALAR > & utility (NodeId varId) const
 Returns the utility table of a utility node.
virtual const Tensor< GUM_SCALAR > & utility (std::string name) const final
 Returns the CPT of a tensor variable.
const VariableNodeMapvariableNodeMap () const final
 Returns a constant reference to the VariableNodeMap of this Influence Diagram.
bool isUtilityNode (NodeId varId) const
 Returns true if node is a utility one.
bool isUtilityNode (const std::string &name) const
 Returns the CPT of a tensor variable.
bool isDecisionNode (NodeId varId) const
 Returns true if node is a decision one.
bool isDecisionNode (const std::string &name) const
 Returns the CPT of a tensor variable.
bool isChanceNode (NodeId varId) const
 Returns true if node is a chance one.
bool isChanceNode (const std::string &name) const
 Returns the CPT of a tensor variable.
Size utilityNodeSize () const
 Returns the number of utility nodes.
Size chanceNodeSize () const
 Returns the number of chance nodes.
Size decisionNodeSize () const
 Returns the number of decision nodes.
const DiscreteVariablevariable (NodeId id) const final
 Returns a constant reference over a variable given it's node id.
const DiscreteVariablevariable (const std::string &name) const
 Returns the CPT of a tensor variable.
NodeId nodeId (const DiscreteVariable &var) const final
 Return id node from discrete var pointer.
NodeId idFromName (const std::string &name) const final
 Getter by name.
const DiscreteVariablevariableFromName (const std::string &name) const final
 Getter by name.
NodeId add (const DiscreteVariable &variable, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT.
NodeId addChanceNode (const DiscreteVariable &variable, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT.
NodeId addUtilityNode (const DiscreteVariable &variable, NodeId id=0)
 Add a utility variable, it's associate node and it's UT.
NodeId addDecisionNode (const DiscreteVariable &variable, NodeId id=0)
 Add a decision variable.
NodeId addChanceNode (const DiscreteVariable &variable, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT.
NodeId addUtilityNode (const DiscreteVariable &variable, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id=0)
 Add a chance variable, it's associate node and it's CPT.
NodeId add (const std::string &fast_description, unsigned int default_nbrmod=2)
 Add a chance, a decision or an utility variable from a description in "fast" syntax.
NodeId addChanceNode (const std::string &fast_description, unsigned int default_nbrmod=2)
 Add a chance variable from a description in "fast" syntax.
NodeId addUtilityNode (const std::string &fast_description)
 Add a utility variable from a description in "fast" syntax with only one value.
NodeId addDecisionNode (const std::string &fast_description, unsigned int default_nbrmod=2)
 Add a decision variable from a description in "fast" syntax.
void erase (NodeId id)
 Erase a Variable from the network and remove the variable from all his children.
void erase (const std::string &name)
 Returns the CPT of a tensor variable.
void erase (const DiscreteVariable &var)
 Erase a Variable from the network and remove the variable from all his children.
void changeVariableName (NodeId id, const std::string &new_name)
 we allow the user to change the name of a variable
void changeVariableName (const std::string &name, const std::string &new_name)
 Returns the CPT of a tensor variable.
Arc manipulation methods.
void addArc (NodeId tail, NodeId head)
 Add an arc in the ID, and update diagram's tensor nodes cpt if necessary.
void addArc (const std::string &tail, const std::string &head)
 Add an arc in the ID, and update diagram's tensor nodes cpt if necessary.
void eraseArc (const Arc &arc)
 Removes an arc in the ID, and update diagram's tensor nodes cpt if necessary.
void eraseArc (NodeId tail, NodeId head)
 Removes an arc in the ID, and update diagram's tensor nodes cpt if necessary.
void eraseArc (const std::string &tail, const std::string &head)
 Add an arc in the ID, and update diagram's tensor nodes cpt if necessary.
Decisions methods
bool decisionOrderExists () const
 True if a directed path exist with all decision nodes.
gum::DAGgetDecisionGraph () const
 Returns the temporal Graph.
std::vector< NodeIddecisionOrder () const
 Returns the sequence of decision nodes in the directed path.
bool existsPathBetween (NodeId src, NodeId dest) const
 Returns true if a path exists between two nodes.
bool existsPathBetween (const std::string &src, const std::string &dest) const
 True if a directed path exist with all decision nodes.
const List< NodeSet > & getPartialTemporalOrder (bool clear=true) const
 Returns partial temporal ordering.
void beginTopologyTransformation ()
 When inserting/removing arcs, node CPTs/utilities change their dimension with a cost in time.
void endTopologyTransformation ()
 terminates a sequence of insertions/deletions of arcs by adjusting all CPTs/utilities dimensions.
Variable manipulation methods.
const DAGdag () const
 Returns a constant reference to the dag of this Bayes Net.
virtual Size size () const final
 Returns the number of variables in this Directed Graphical Model.
Size sizeArcs () const
 Returns the number of arcs in this Directed Graphical Model.
const NodeGraphPartnodes () const final
 Returns a constant reference to the dag of this Bayes Net.
bool exists (NodeId node) const final
 Return true if this node exists in this graphical model.
bool exists (const std::string &name) const final
 Returns a constant reference to the dag of this Bayes Net.
Arc manipulation methods.
const ArcSetarcs () const
 return true if the arc tail->head exists in the DAGmodel
bool existsArc (const NodeId tail, const NodeId head) const
 return true if the arc tail->head exists in the DAGmodel
bool existsArc (const std::string &nametail, const std::string &namehead) const
 return true if the arc tail->head exists in the DAGmodel
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node
const NodeSetparents (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel
NodeSet parents (const NodeSet &ids) const
 returns the parents of a set of nodes
NodeSet parents (const std::vector< std::string > &names) const
 return true if the arc tail->head exists in the DAGmodel
NodeSet family (const NodeId id) const final
 returns the parents of a node and the node
NodeSet family (const std::string &name) const final
 return true if the arc tail->head exists in the DAGmodel
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node
const NodeSetchildren (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel
NodeSet children (const NodeSet &ids) const
 returns the children of a set of nodes
NodeSet children (const std::vector< std::string > &names) const
 return true if the arc tail->head exists in the DAGmodel
NodeSet descendants (const NodeId id) const
 returns the set of nodes with directed path outgoing from a given node
NodeSet descendants (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel
NodeSet ancestors (const NodeId id) const
 returns the set of nodes with directed path ingoing to a given node
NodeSet ancestors (const std::string &name) const
 return true if the arc tail->head exists in the DAGmodel
Graphical methods
UndiGraph moralizedAncestralGraph (const NodeSet &nodes) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
UndiGraph moralizedAncestralGraph (const std::vector< std::string > &nodenames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
bool isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const final
 check if node X and node Y are independent given nodes Z
bool isIndependent (const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const final
 check if nodes X and nodes Y are independent given nodes Z
bool isIndependent (const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
bool isIndependent (const std::vector< std::string > &Xnames, const std::vector< std::string > &Ynames, const std::vector< std::string > &Znames) const
 build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
UndiGraph moralGraph () const
 The node's id are coherent with the variables and nodes of the topology.
Sequence< NodeIdtopologicalOrder () const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology.
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this GraphicalModel.
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this GraphicalModel.
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this GraphicalModel.
std::vector< std::string > properties () const
 List of all the properties.
Variable manipulation methods.
virtual bool empty () const
 Return true if this graphical model is empty.
std::vector< std::string > names (const std::vector< NodeId > &ids) const
 transform a vector of NodeId in a vector of names
std::vector< std::string > names (const NodeSet &ids) const
 transform a NodeSet in a vector of names
std::vector< NodeIdids (const std::vector< std::string > &names) const
 transform a vector of names into a vector of nodeId
NodeSet nodeset (const std::vector< std::string > &names) const
 transform a vector of names into a NodeSet
gum::VariableSet variables (const std::vector< std::string > &l) const
 transform a vector of names into a VariableeSet
gum::VariableSet variables (const NodeSet &ids) const
 transform a vector of NodeId into a VariableeSet
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model.

Static Public Member Functions

static InfluenceDiagram< GUM_SCALAR > fastPrototype (const std::string &dotlike, Size domainSize)
 Create an Influence Diagram with a dot-like syntax which specifies:
static InfluenceDiagram< GUM_SCALAR > fastPrototype (const std::string &dotlike, const std::string &domain="[2]")
static void spaceCplxToStream (std::stringstream &s, double dSize, int dim, Size usedMem)
 send to the stream the space complexity with 3 parametrs

Protected Member Functions

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

Protected Attributes

DAG dag_
 The DAG of this Directed Graphical Model.

Private Member Functions

const HashTable< std::string, std::string > & _properties_ () const
 Return the properties of this Directed Graphical Model.

Private Attributes

VariableNodeMap _variableMap_
 Mapping between id and variable.
NodeProperty< Tensor< GUM_SCALAR > * > _tensorMap_
 Mapping between tensor variable's id and their CPT.
NodeProperty< Tensor< GUM_SCALAR > * > _utilityMap_
 Mapping between utility variable's id and their utility table.
List< NodeSet_temporalOrder_
 The temporal order.
HashTable< std::string, std::string > _propertiesMap_
 The properties of this Directed Graphical Model.

Detailed Description

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

Class representing an Influence Diagram.

Definition at line 72 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 148 of file influenceDiagram_tpl.h.

148 : DAGmodel() {
150 }
DAGmodel()
Default constructor.
Definition DAGmodel.cpp:49
Class representing an Influence Diagram.
InfluenceDiagram()
Default constructor.

References gum::DAGmodel::DAGmodel(), and InfluenceDiagram().

Referenced by InfluenceDiagram(), InfluenceDiagram(), ~InfluenceDiagram(), copyStructureAndTables_(), operator!=(), operator=(), and operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~InfluenceDiagram()

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

Destructor.

Definition at line 156 of file influenceDiagram_tpl.h.

156 {
159 }
void removeTables_()
Removing ancient table.

References InfluenceDiagram(), and removeTables_().

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

165 {
168 }
void copyStructureAndTables_(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.

References InfluenceDiagram(), and copyStructureAndTables_().

Here is the call graph for this function:

Member Function Documentation

◆ _properties_()

INLINE const HashTable< std::string, std::string > & gum::GraphicalModel::_properties_ ( ) const
privateinherited

Return the properties of this Directed Graphical Model.

Definition at line 70 of file graphicalModel_inl.h.

70 {
71 return _propertiesMap_;
72 }
HashTable< std::string, std::string > _propertiesMap_
The properties of this Directed Graphical Model.

References _propertiesMap_.

Referenced by property().

Here is the caller graph for this function:

◆ add() [1/2]

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

431 {
432 return addChanceNode(var, varId);
433 }
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it's associate node and it's CPT.

References addChanceNode().

Here is the call graph for this function:

◆ add() [2/2]

template<typename GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::add ( const std::string & fast_description,
unsigned int default_nbrmod = 2 )

Add a chance, a decision or an utility variable from a description in "fast" syntax.

  • see addChancdeNode for the syntax of the type of variable
  • if the description starts with "*", its a decision node
  • if the description starts with "$", irs an utility node
  • otherwise, it is a chance node.
Parameters
fast_description(str) following "fast" syntax description
default_nbrmod(int) nbr of modality if fast_description do not indicate it. default_nbrmod=1 is the way to create a variable with only one value (for instance for reward in influence diagram).
Exceptions
DuplicateLabelRaised if variable.name() is already used in this gum::InfluenceDiagram.
NotAllowedif nbrmod<2

Definition at line 876 of file influenceDiagram_tpl.h.

877 {
879 switch (*(node.begin())) {
880 case '*' : node.erase(0, 1); return addDecisionNode(node, default_nbrmod);
881 case '$' : node.erase(0, 1); return addUtilityNode(node);
883 }
884 }
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it's associate node and it's UT.
NodeId addDecisionNode(const DiscreteVariable &variable, NodeId id=0)
Add a decision variable.
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his children.

References addChanceNode(), addDecisionNode(), and addUtilityNode().

Here is the call graph for this function:

◆ addArc() [1/2]

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

Add an arc in the ID, and update diagram's tensor 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 449 of file influenceDiagram.h.

449 {
451 }
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram's tensor nodes cpt if necessary.
NodeId idFromName(const std::string &name) const final
Getter by name.

References addArc(), and idFromName().

Here is the call graph for this function:

◆ addArc() [2/2]

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

Add an arc in the ID, and update diagram's tensor 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 600 of file influenceDiagram_tpl.h.

600 {
601 if (isUtilityNode(tail)) { GUM_ERROR(InvalidArc, "Tail cannot be a utility node") }
602
603 dag_.addArc(tail, head);
604
605 if (isChanceNode(head))
606 // Add parent in the child's CPT
607 (*(_tensorMap_[head])) << variable(tail);
608 else if (isUtilityNode(head)) {
609 // Add parent in the child's UT
610 (*(_utilityMap_[head])) << variable(tail);
611 }
612 }
DAG dag_
The DAG of this Directed Graphical Model.
Definition DAGmodel.h:272
NodeProperty< Tensor< GUM_SCALAR > * > _tensorMap_
Mapping between tensor variable's id and their CPT.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
const DiscreteVariable & variable(NodeId id) const final
Returns a constant reference over a variable given it's node id.
NodeProperty< Tensor< GUM_SCALAR > * > _utilityMap_
Mapping between utility variable's id and their utility table.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References _tensorMap_, _utilityMap_, gum::DAGmodel::dag_, GUM_ERROR, isChanceNode(), isUtilityNode(), and variable().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), addArc(), copyStructureAndTables_(), and fastPrototype().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addChanceNode() [1/3]

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

492 {
494
496 (*varcpt) << variable(proposedId);
498
499 return proposedId;
500 }
NodeId addNode_(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.

References _tensorMap_, addNode_(), and variable().

Here is the call graph for this function:

◆ addChanceNode() [2/3]

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

470 {
472 NodeId res;
473
474 try {
476 } catch (Exception const&) {
477 delete newMultiDim;
478 throw;
479 }
480
481 return res;
482 }

References addChanceNode().

Referenced by add(), add(), addChanceNode(), addChanceNode(), gum::build_node_for_ID(), and copyStructureAndTables_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addChanceNode() [3/3]

template<typename GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode ( const std::string & fast_description,
unsigned int default_nbrmod = 2 )

Add a chance variable from a description in "fast" syntax.

  • a : range variable from 0 to default_nbrmod-1
  • a[5] : range variable from 0 to 5
  • a[-3,5] : range variable from -3 to 5
  • a[1,3.14,5,3] : discretized variable
  • a{x|y|z} : labelized variable
  • a{-3|0|3|100} : integer variable
Parameters
fast_description(str) following "fast" syntax description
default_nbrmod(int) nbr of modality if fast_description do not indicate it. default_nbrmod=1 is the way to create a variable with only one value (for instance for reward in influence diagram).
Exceptions
DuplicateLabelRaised if variable.name() is already used in this gum::InfluenceDiagram.
NotAllowedif nbrmod<2

Definition at line 851 of file influenceDiagram_tpl.h.

852 {
854 if (v->domainSize() < 2) GUM_ERROR(OperationNotAllowed, v->name() << " has a domain size <2")
856 }
std::unique_ptr< DiscreteVariable > fastVariable(std::string var_description, Size default_domain_size)
Create a pointer on a Discrete Variable from a "fast" syntax.

References addChanceNode(), gum::fastVariable(), and GUM_ERROR.

Here is the call graph for this function:

◆ addDecisionNode() [1/2]

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

461 {
462 return addNode_(var, varId);
463 }

References addNode_().

Referenced by add(), addDecisionNode(), gum::build_node_for_ID(), and copyStructureAndTables_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addDecisionNode() [2/2]

template<typename GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addDecisionNode ( const std::string & fast_description,
unsigned int default_nbrmod = 2 )

Add a decision variable from a description in "fast" syntax.

  • a : range variable from 0 to default_nbrmod-1
  • a[5] : range variable from 0 to 5
  • a[-3,5] : range variable from -3 to 5
  • a[1,3.14,5,3] : discretized variable
  • a{x|y|z} : labelized variable
  • a{-3|0|3|100} : integer variable
Parameters
fast_description(str) following "fast" syntax description
default_nbrmod(int) nbr of modality if fast_description do not indicate it.
Exceptions
DuplicateLabelRaised if variable.name() is already used in this gum::InfluenceDiagram.
NotAllowedif nbrmod<2

Definition at line 868 of file influenceDiagram_tpl.h.

869 {
871 if (v->domainSize() < 2) GUM_ERROR(OperationNotAllowed, v->name() << " has a domain size <2")
873 }

References addDecisionNode(), gum::fastVariable(), and GUM_ERROR.

Here is the call graph for this function:

◆ addNode_()

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

Add a node.

Definition at line 533 of file influenceDiagram_tpl.h.

534 {
535 // None thread safe code!
537
538 if (DesiredId == 0) proposedId = dag_.nextNodeId();
539 else proposedId = DesiredId;
540
542
543 dag_.addNodeWithId(proposedId);
544
545 // end critical section
546 return proposedId;
547 }
VariableNodeMap _variableMap_
Mapping between id and variable.

References _variableMap_, and gum::DAGmodel::dag_.

Referenced by addChanceNode(), addDecisionNode(), and addUtilityNode().

Here is the caller graph for this function:

◆ addUtilityNode() [1/3]

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

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

The id of the new variable is automatically generated.

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

Definition at line 509 of file influenceDiagram_tpl.h.

511 {
512 if (var.domainSize() != 1) {
514 "Utility var have no state ( which implicates a "
515 "single label for data output reasons ).")
516 }
517
519
521
522 (*varut) << variable(proposedId);
523
525
526 return proposedId;
527 }

References _utilityMap_, addNode_(), gum::DiscreteVariable::domainSize(), GUM_ERROR, and variable().

Here is the call graph for this function:

◆ addUtilityNode() [2/3]

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

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

The id of the new variable is automatically generated.

The implementation of the Utility is by default a MultiDimArray.

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

Definition at line 441 of file influenceDiagram_tpl.h.

441 {
443 NodeId res;
444
445 try {
447 } catch (Exception const&) {
448 if (newMultiDim != nullptr) delete newMultiDim;
449 throw;
450 }
451
452 return res;
453 }

References addUtilityNode().

Referenced by add(), addUtilityNode(), addUtilityNode(), gum::build_node_for_ID(), and copyStructureAndTables_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addUtilityNode() [3/3]

template<typename GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode ( const std::string & fast_description)

Add a utility variable from a description in "fast" syntax with only one value.

  • a : range variable from 0 to default_nbrmod-1
  • a[x,x] : range variable from x to x
  • a{value} : labelized variable with only one label "value"
Parameters
fast_description(str) following "fast" syntax description

Definition at line 859 of file influenceDiagram_tpl.h.

859 {
861 if (v->domainSize() >= 2)
863 v->name() << " has a domain size >= 2 which is impossible for a utility node")
865 }

References addUtilityNode(), gum::fastVariable(), and GUM_ERROR.

Here is the call graph for this function:

◆ ancestors() [1/2]

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

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

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

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

Definition at line 123 of file DAGmodel_inl.h.

123{ return dag().ancestors(id); }
NodeSet ancestors(NodeId id) const
returns the set of nodes with directed path ingoing to a given node
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.

References gum::ArcGraphPart::ancestors(), and dag().

Referenced by ancestors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ancestors() [2/2]

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

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

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

Definition at line 125 of file DAGmodel_inl.h.

125 {
126 return ancestors(idFromName(name));
127 }
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.

References ancestors(), and gum::GraphicalModel::idFromName().

Here is the call graph for this function:

◆ arcs()

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

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

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

Definition at line 65 of file DAGmodel_inl.h.

65{ return dag_.arcs(); }

References dag_.

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

Here is the caller graph for this function:

◆ beginTopologyTransformation()

template<typename GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::beginTopologyTransformation ( )

When inserting/removing arcs, node CPTs/utilities change their dimension with a cost in time.

begin Multiple Change for all CPTs

These functions delay the CPTs change to be done just once at the end of a* sequence of topology modification. begins a sequence of insertions/deletions of arcs without changing the dimensions of the CPTs.

Definition at line 888 of file influenceDiagram_tpl.h.

888 {
889 for (const auto node: nodes())
890 if (isChanceNode(node)) _tensorMap_[node]->beginMultipleChanges();
891 else if (this->isUtilityNode(node)) _utilityMap_[node]->beginMultipleChanges();
892 }
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.

References _tensorMap_, _utilityMap_, isChanceNode(), isUtilityNode(), and gum::DAGmodel::nodes().

Here is the call graph for this function:

◆ chanceNodeSize()

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

Returns the number of chance nodes.

Definition at line 376 of file influenceDiagram_tpl.h.

376 {
377 return _tensorMap_.size();
378 }

References _tensorMap_.

Referenced by toString().

Here is the caller graph for this function:

◆ changeVariableName() [1/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 428 of file influenceDiagram.h.

428 {
430 }
void changeVariableName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable

References changeVariableName(), and idFromName().

Here is the call graph for this function:

◆ changeVariableName() [2/2]

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

we allow the user to change the name of a variable

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

Definition at line 588 of file influenceDiagram_tpl.h.

589 {
590 _variableMap_.changeName(id, new_name);
591 }

References _variableMap_.

Referenced by changeVariableName().

Here is the caller graph for this function:

◆ children() [1/4]

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

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

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

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

Definition at line 87 of file DAGmodel_inl.h.

87{ return dag_.children(id); }

References dag_.

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

Here is the caller graph for this function:

◆ children() [2/4]

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

returns the children of a set of nodes

Definition at line 93 of file DAGmodel_inl.h.

93{ return dag_.children(ids); }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId

References dag_, and gum::GraphicalModel::ids().

Here is the call graph for this function:

◆ children() [3/4]

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

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

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

Definition at line 89 of file DAGmodel_inl.h.

89 {
90 return dag_.children(idFromName(name));
91 }

References dag_, and gum::GraphicalModel::idFromName().

Here is the call graph for this function:

◆ children() [4/4]

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

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

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

Definition at line 95 of file DAGmodel_inl.h.

95 {
96 return children(nodeset(names));
97 }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
std::vector< std::string > names(const std::vector< NodeId > &ids) const
transform a vector of NodeId in a vector of names
NodeSet nodeset(const std::vector< std::string > &names) const
transform a vector of names into a NodeSet

References gum::GraphicalModel::names().

Here is the call graph for this function:

◆ clear()

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

Referenced by getPartialTemporalOrder(), and operator=().

Here is the caller graph for this function:

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 106 of file graphicalModel_inl.h.

106 {
107 Instantiation I;
108
109 for (const auto node: nodes())
110 I << variable(node);
111
112 return I;
113 }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
virtual const NodeGraphPart & nodes() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

References nodes().

Here is the call graph for this function:

◆ copyStructureAndTables_()

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

Copying tables from another influence diagram.

Definition at line 210 of file influenceDiagram_tpl.h.

211 {
212 for (auto node: IDsource.nodes()) {
215 else // decision node
217 }
218 // we add arc in the same order of the tensors
219 for (auto node: IDsource.nodes()) {
220 const auto& s = IDsource.variable(node).name();
222 for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
223 addArc(IDsource.cpt(node).variable(par).name(), s);
224 } else if (IDsource.isUtilityNode(node)) {
225 for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
226 addArc(IDsource.utility(node).variable(par).name(), s);
227 } else { // decision node
228 // here the order does not depend on a Tensor
230 addArc(par, node);
231 }
232 }
233
234 // Copying tensors
235 for (auto node: IDsource.nodes()) {
236 const auto& s = IDsource.variable(node).name();
238 cpt(node).fillWith(IDsource.cpt(s));
239 } else if (IDsource.isUtilityNode(node)) {
240 utility(node).fillWith(IDsource.utility(s));
241 }
242 }
243 }
virtual Size size() const final
Returns the number of variables in this Directed Graphical Model.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual const Tensor< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a tensor variable.
virtual const Tensor< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
const std::string & name() const
returns the name of the variable

References InfluenceDiagram(), addArc(), addChanceNode(), addDecisionNode(), addUtilityNode(), cpt(), isChanceNode(), isUtilityNode(), gum::Variable::name(), gum::DAGmodel::nodes(), gum::DAGmodel::parents(), gum::DAGmodel::size(), utility(), and variable().

Referenced by InfluenceDiagram(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpt() [1/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 324 of file influenceDiagram_tpl.h.

324 {
325 return *(_tensorMap_[varId]);
326 }

References _tensorMap_.

Referenced by copyStructureAndTables_(), cpt(), fastPrototype(), operator==(), and removeTables_().

Here is the caller graph for this function:

◆ cpt() [2/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 158 of file influenceDiagram.h.

158 {
159 return cpt(idFromName(name));
160 };

References cpt(), and idFromName().

Here is the call 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 384 of file influenceDiagram_tpl.h.

384 {
385 return (size() - _utilityMap_.size() - _tensorMap_.size());
386 }

References _tensorMap_, _utilityMap_, and gum::DAGmodel::size().

Referenced by toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decisionOrder()

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

Returns the sequence of decision nodes in the directed path.

Exceptions
NotFoundif such a path does not exist

Definition at line 797 of file influenceDiagram_tpl.h.

797 {
798 if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists") }
799
801
802 for (const auto elt: topologicalOrder())
803 if (isDecisionNode(elt)) decisionSequence.push_back(elt);
804
805 return decisionSequence;
806 }
Sequence< NodeId > topologicalOrder() const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool decisionOrderExists() const
True if a directed path exist with all decision nodes.

References decisionOrderExists(), GUM_ERROR, isDecisionNode(), and gum::DAGmodel::topologicalOrder().

Referenced by getPartialTemporalOrder().

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 decision nodes.

Definition at line 672 of file influenceDiagram_tpl.h.

672 {
674
675 // Finding first decision node
677
678 while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
679 ++orderIter;
680
681 if (orderIter == order.end()) return true;
682
683 NodeId parentDecision = (*orderIter);
684 ++orderIter;
685
686 // Checking path between decisions nodes
687 while (orderIter != order.end()) {
689 if (!existsPathBetween(parentDecision, *orderIter)) return false;
690
692 }
693
694 ++orderIter;
695 }
696
697 return true;
698 }
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.

References gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::begin(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::end(), existsPathBetween(), isDecisionNode(), and gum::DAGmodel::topologicalOrder().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), and decisionOrder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ descendants() [1/2]

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

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

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

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

Definition at line 117 of file DAGmodel_inl.h.

117{ return dag().descendants(id); }
NodeSet descendants(NodeId id) const
returns the set of nodes with directed path outgoing from a given node

References dag(), and gum::ArcGraphPart::descendants().

Referenced by descendants().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ descendants() [2/2]

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

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

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

Definition at line 119 of file DAGmodel_inl.h.

119 {
120 return descendants(idFromName(name));
121 }
NodeSet descendants(const NodeId id) const
returns the set of nodes with directed path outgoing from a given node

References descendants(), and gum::GraphicalModel::idFromName().

Here is the call graph for this function:

◆ empty()

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

Return true if this graphical model is empty.

Definition at line 116 of file graphicalModel_inl.h.

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

References size().

Referenced by gum::IBayesNet< GUM_SCALAR >::check(), and gum::BayesNet< GUM_SCALAR >::clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endTopologyTransformation()

template<typename GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::endTopologyTransformation ( )

terminates a sequence of insertions/deletions of arcs by adjusting all CPTs/utilities dimensions.

end Multiple Change for all CPTs

Definition at line 896 of file influenceDiagram_tpl.h.

896 {
897 for (const auto node: nodes())
898 if (isChanceNode(node)) _tensorMap_[node]->endMultipleChanges();
899 else if (isUtilityNode(node)) _utilityMap_[node]->endMultipleChanges();
900 }

References _tensorMap_, _utilityMap_, isChanceNode(), isUtilityNode(), and gum::DAGmodel::nodes().

Here is the call graph for this function:

◆ erase() [1/3]

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

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

If no variable matches, then nothing is done.

Parameters
varThe reference on the variable to remove.

Definition at line 581 of file influenceDiagram_tpl.h.

581 {
582 erase(_variableMap_.get(var));
583 }

References _variableMap_, and erase().

Here is the call graph for this function:

◆ erase() [2/3]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 411 of file influenceDiagram.h.

411{ erase(idFromName(name)); };

References erase(), and idFromName().

Referenced by erase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [3/3]

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

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

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

Parameters
idThe id of the variable to erase.

Definition at line 555 of file influenceDiagram_tpl.h.

555 {
556 if (_variableMap_.exists(varId)) {
557 // Reduce the variable child's CPT or Utility Table if necessary
558 for (const auto chi: dag_.children(varId))
560 else if (isUtilityNode(chi)) _utilityMap_[chi]->erase(variable(varId));
561
562 if (isChanceNode(varId)) {
563 delete _tensorMap_[varId];
564 _tensorMap_.erase(varId);
565 } else if (isUtilityNode(varId)) {
566 delete _utilityMap_[varId];
567 _utilityMap_.erase(varId);
568 }
569
570 _variableMap_.erase(varId);
571 dag_.eraseNode(varId);
572 }
573 }

References _tensorMap_, _utilityMap_, _variableMap_, gum::DAGmodel::dag_, isChanceNode(), isUtilityNode(), and variable().

Referenced by erase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseArc() [1/3]

template<typename GUM_SCALAR>
INLINE void gum::InfluenceDiagram< GUM_SCALAR >::eraseArc ( const Arc & arc)

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

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

Parameters
arcThe arc removed.

Definition at line 620 of file influenceDiagram_tpl.h.

620 {
621 if (dag_.existsArc(arc)) {
622 NodeId head = arc.head();
623 NodeId tail = arc.tail();
624 dag_.eraseArc(arc);
625
626 if (isChanceNode(head))
627 // Removes parent in the child's CPT
628 (*(_tensorMap_[head])) >> variable(tail);
629 else if (isUtilityNode(head))
630 // Removes parent in the child's UT
631 (*(_utilityMap_[head])) >> variable(tail);
632 }
633 }

References _tensorMap_, _utilityMap_, gum::DAGmodel::dag_, gum::Arc::head(), isChanceNode(), isUtilityNode(), gum::Arc::tail(), and variable().

Referenced by eraseArc(), and eraseArc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseArc() [2/3]

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

Add an arc in the ID, and update diagram's tensor 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 472 of file influenceDiagram.h.

472 {
474 }
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram's tensor nodes cpt if necessary.

References eraseArc(), and idFromName().

Here is the call graph for this function:

◆ eraseArc() [3/3]

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

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

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

Parameters
headand
tailas NodeId

Definition at line 641 of file influenceDiagram_tpl.h.

641 {
643 }

References eraseArc().

Here is the call graph for this function:

◆ exists() [1/2]

INLINE bool gum::DAGmodel::exists ( const std::string & name) const
finalvirtualinherited

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

Implements gum::GraphicalModel.

Definition at line 107 of file DAGmodel_inl.h.

107 {
108 try {
109 return exists(idFromName(name));
110 } catch ([[maybe_unused]] gum::NotFound& e) { return false; }
111 }
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.

◆ exists() [2/2]

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

Return true if this node exists in this graphical model.

Implements gum::GraphicalModel.

Definition at line 105 of file DAGmodel_inl.h.

105{ return dag_.exists(node); }

References dag_.

◆ existsArc() [1/2]

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

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

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

Definition at line 67 of file DAGmodel_inl.h.

67 {
68 return dag_.existsArc(tail, head);
69 }

References dag_.

Referenced by existsArc(), gum::BayesNet< GUM_SCALAR >::reverseArc(), gum::BayesNetFragment< GUM_SCALAR >::toDot(), and gum::BayesNetFragment< GUM_SCALAR >::whenArcDeleted().

Here is the caller graph for this function:

◆ existsArc() [2/2]

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

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

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

Definition at line 71 of file DAGmodel_inl.h.

71 {
72 return existsArc(idFromName(nametail), idFromName(namehead));
73 }
bool existsArc(const NodeId tail, const NodeId head) const
return true if the arc tail->head exists in the DAGmodel

References existsArc(), and gum::GraphicalModel::idFromName().

Here is the call graph for this function:

◆ existsPathBetween() [1/2]

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

True if a directed path exist with all decision nodes.

Definition at line 504 of file influenceDiagram.h.

504 {
506 }

References existsPathBetween(), and idFromName().

Here is the call graph for this function:

◆ existsPathBetween() [2/2]

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

Returns true if a path exists between two nodes.

Definition at line 704 of file influenceDiagram_tpl.h.

704 {
706 // mark[node] contains 0 if not visited
707 // mark[node] = predecessor if visited
708 NodeProperty< int > mark = dag_.nodesPropertyFromVal(-1);
710
711 mark[src] = (int)src;
712 nodeFIFO.pushBack(src);
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] != -1) continue; // if this node is already marked, continue
720
722
723 if (new_one == dest) break; // if we reach *orderIter, stop.
724
725 nodeFIFO.pushBack(new_one);
726 }
727 }
728
729 if (mark[dest] == -1) return false;
730
731 return true;
732 }
virtual bool empty() const
Return true if this graphical model is empty.

References gum::DAGmodel::dag_, gum::List< Val >::empty(), gum::List< Val >::front(), gum::List< Val >::popFront(), and gum::List< Val >::pushBack().

Referenced by decisionOrderExists(), and existsPathBetween().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ family() [1/2]

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

returns the parents of a node and the node

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

Implements gum::GraphicalModel.

Definition at line 81 of file DAGmodel_inl.h.

81{ return dag_.family(id); }

References dag_.

◆ family() [2/2]

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

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

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

Implements gum::GraphicalModel.

Definition at line 83 of file DAGmodel_inl.h.

83 {
84 return dag_.family(idFromName(name));
85 }

References dag_, and gum::GraphicalModel::idFromName().

Here is the call graph for this function:

◆ fastPrototype() [1/2]

template<typename GUM_SCALAR>
InfluenceDiagram< GUM_SCALAR > gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype ( const std::string & dotlike,
const std::string & domain = "[2]" )
static

Definition at line 104 of file influenceDiagram_tpl.h.

105 {
107
108 for (const auto& chaine: split(remove_newline(dotlike), ";")) {
109 NodeId lastId = 0;
110 bool notfirst = false;
111 for (const auto& souschaine: split(chaine, "->")) {
112 bool forward = true;
113 for (auto& node: split(souschaine, "<-")) {
115 if (notfirst) {
116 if (forward) {
118 forward = false;
119 } else {
121 }
122 } else {
123 notfirst = true;
124 forward = false;
125 }
126 lastId = idVar;
127 }
128 }
129 }
130
131 for (const auto n: infdiag.nodes()) {
132 if (infdiag.isChanceNode(n)) infdiag.cpt(n).randomCPT();
133 else if (infdiag.isUtilityNode(n)) { infdiag.utility(n).random().scale(50).translate(-10); }
134 }
135
136 infdiag.setProperty("name", "fastPrototype");
137 return infdiag;
138 }
void setProperty(const std::string &name, const std::string &value)
Add or change a property of this GraphicalModel.
std::string remove_newline(const std::string &s)
remove all newlines in a string
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
NodeId build_node_for_ID(gum::InfluenceDiagram< GUM_SCALAR > &infdiag, std::string node, const std::string &domain)

References addArc(), gum::build_node_for_ID(), cpt(), isChanceNode(), isUtilityNode(), gum::DAGmodel::nodes(), gum::remove_newline(), gum::GraphicalModel::setProperty(), gum::split(), and utility().

Here is the call graph for this function:

◆ fastPrototype() [2/2]

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

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

  • the structure "a->*b->$c;b->d<-*e;".
  • the prefix of a variable can be :
    • nothing : chance node (a,d)
    • * : decision node (*b)
    • $ : utility node ($c) *
  • the type of the chance or decision variables with different syntax:

Note that if the dot-like string contains such a specification more than once for a variable, the first specification will be used.

Parameters
dotlikethe string containing the specification
domainSizethe default domain size for chance and decision variables
Returns
the resulting influence diagram

Definition at line 98 of file influenceDiagram_tpl.h.

98 {
99 return fastPrototype(dotlike, "[" + std::to_string(domainSize) + "]");
100 }
static InfluenceDiagram< GUM_SCALAR > fastPrototype(const std::string &dotlike, Size domainSize)
Create an Influence Diagram with a dot-like syntax which specifies:

References fastPrototype().

Referenced by fastPrototype().

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

761 {
763
766
767 // mark[node] contains false if not visited
768 // mark[node] contains true if visited
769 NodeProperty< bool > mark = dag_.nodesPropertyFromVal(false);
770
771 mark[parentDecision] = true;
772
773 nodeFIFO.pushBack(parentDecision);
774
775 while (!nodeFIFO.empty()) {
776 current = nodeFIFO.front();
777 nodeFIFO.popFront();
778
779 for (const auto new_one: dag_.children(current)) {
780 if (mark[new_one]) continue; // if this node is already marked, continue
781
782 mark[new_one] = true;
783
784 if (!isDecisionNode(new_one)) nodeFIFO.pushBack(new_one);
785 else childrenSeq.insert(new_one);
786 }
787 }
788
789 return childrenSeq;
790 }

References gum::DAGmodel::dag_, gum::List< Val >::empty(), gum::List< Val >::front(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::insert(), isDecisionNode(), gum::List< Val >::popFront(), and gum::List< Val >::pushBack().

Referenced by getDecisionGraph().

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

738 {
739 auto temporalGraph = new gum::DAG();
740
741 for (const auto node: dag_.nodes()) {
742 if (isDecisionNode(node)) {
743 if (!temporalGraph->existsNode(node)) temporalGraph->addNodeWithId(node);
744
745 for (const auto chi: getChildrenDecision_(node)) {
746 if (!temporalGraph->existsNode(chi)) temporalGraph->addNodeWithId(chi);
747
749 }
750 }
751 }
752
753 return temporalGraph;
754 }
Sequence< NodeId > getChildrenDecision_(NodeId parentDecision) const
Returns the list of children decision for a given nodeId.

References gum::DAGmodel::dag_, getChildrenDecision_(), and isDecisionNode().

Here is the call 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 813 of file influenceDiagram_tpl.h.

813 {
814 if (clear) {
815 _temporalOrder_.clear();
816
818 NodeSet nodeList = dag_.asNodeSet();
819
820 for (auto i: order) {
822
823 for (const auto par: dag_.parents(i)) {
824 if (nodeList.contains(par) && isChanceNode(par)) {
825 partialOrderedSet.insert(par);
827 }
828 }
829
831
833
834 decisionSet.insert(i);
835
836 _temporalOrder_.pushFront(decisionSet);
837 }
838
839 NodeSet lastSet; //= new gum::NodeSet();
840
841 for (const auto node: nodeList)
842 if (isChanceNode(node)) lastSet.insert(node);
843
844 if (!lastSet.empty()) _temporalOrder_.pushFront(lastSet);
845 }
846
847 return _temporalOrder_;
848 }
List< NodeSet > _temporalOrder_
The temporal order.
std::vector< NodeId > decisionOrder() const
Returns the sequence of decision nodes in the directed path.

References _temporalOrder_, clear(), gum::Set< Key >::contains(), gum::DAGmodel::dag_, decisionOrder(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and isChanceNode().

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

66 {
67 if (this == &other) return true;
68
69 if (size() != other.size()) return false;
70
71 if (sizeArcs() != other.sizeArcs()) return false;
72
73 for (const auto& nid: nodes()) {
74 try {
75 other.idFromName(variable(nid).name());
76 } catch (NotFound const&) { return false; }
77 }
78
79 for (const auto& arc: arcs()) {
80 if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
81 other.idFromName(variable(arc.head()).name()))))
82 return false;
83 }
84
85 return true;
86 }
const ArcSet & arcs() const
return true if the arc tail->head exists in the DAGmodel
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.

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

Here is the call graph for this function:

◆ idFromName()

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

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::GraphicalModel.

Definition at line 415 of file influenceDiagram_tpl.h.

415 {
416 return _variableMap_.idFromName(name);
417 }

References _variableMap_.

Referenced by addArc(), gum::build_node_for_ID(), changeVariableName(), cpt(), erase(), eraseArc(), existsPathBetween(), isChanceNode(), isDecisionNode(), isUtilityNode(), operator==(), utility(), and variable().

Here is the caller graph for this function:

◆ ids()

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

transform a vector of names into a vector of nodeId

Returns
the vector of names

Definition at line 139 of file graphicalModel_inl.h.

139 {
140 std::vector< NodeId > res;
141 const VariableNodeMap& v = variableNodeMap();
142 std::transform(names.cbegin(),
143 names.cend(),
144 std::back_inserter(res),
145 [v](const std::string& n) { return v.idFromName(n); });
146 return res;
147 }
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of this Graphical Model.

References names().

Referenced by gum::DAGmodel::children(), exists(), names(), and gum::DAGmodel::parents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isChanceNode() [1/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 197 of file influenceDiagram.h.

197{ return isChanceNode(idFromName(name)); };

References idFromName(), and isChanceNode().

Referenced by isChanceNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isChanceNode() [2/2]

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

Returns true if node is a chance one.

Definition at line 360 of file influenceDiagram_tpl.h.

360 {
361 return _tensorMap_.exists(varId);
362 }

References _tensorMap_.

Referenced by addArc(), beginTopologyTransformation(), copyStructureAndTables_(), endTopologyTransformation(), erase(), eraseArc(), fastPrototype(), getPartialTemporalOrder(), isDecisionNode(), moralGraph_(), operator==(), removeTables_(), and toDot().

Here is the caller graph for this function:

◆ isDecisionNode() [1/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 190 of file influenceDiagram.h.

190{ return isDecisionNode(idFromName(name)); };

References idFromName(), and isDecisionNode().

Referenced by isDecisionNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDecisionNode() [2/2]

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

Returns true if node is a decision one.

Definition at line 348 of file influenceDiagram_tpl.h.

348 {
349 bool ret = true;
350
351 if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
352
353 return ret;
354 }

References isChanceNode(), and isUtilityNode().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), decisionOrder(), decisionOrderExists(), getChildrenDecision_(), getDecisionGraph(), moralGraph_(), operator==(), and toDot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isIndependent() [1/4]

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

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

Implements gum::GraphicalModel.

Definition at line 142 of file DAGmodel_inl.h.

142 {
143 return dag().dSeparation(X, Y, Z);
144 }
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation)
Definition DAG.cpp:117

References dag(), and gum::DAG::dSeparation().

Here is the call graph for this function:

◆ isIndependent() [2/4]

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

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

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

Definition at line 202 of file DAGmodel.h.

204 {
205 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
206 };
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z

References gum::GraphicalModel::idFromName(), isIndependent(), and gum::GraphicalModel::nodeset().

Here is the call graph for this function:

◆ isIndependent() [3/4]

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

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

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

Definition at line 208 of file DAGmodel.h.

210 {
211 return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
212 };

References isIndependent(), and gum::GraphicalModel::nodeset().

Here is the call graph for this function:

◆ isIndependent() [4/4]

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

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

Implements gum::GraphicalModel.

Definition at line 138 of file DAGmodel_inl.h.

138 {
139 return dag().dSeparation(X, Y, Z);
140 }

References dag(), and gum::DAG::dSeparation().

Referenced by isIndependent(), and isIndependent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isUtilityNode() [1/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 183 of file influenceDiagram.h.

183{ return isUtilityNode(idFromName(name)); };

References idFromName(), isUtilityNode(), and isUtilityNode().

Referenced by isUtilityNode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isUtilityNode() [2/2]

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

Returns true if node is a utility one.

Definition at line 340 of file influenceDiagram_tpl.h.

340 {
341 return _utilityMap_.exists(varId);
342 }

References _utilityMap_.

Referenced by addArc(), beginTopologyTransformation(), copyStructureAndTables_(), endTopologyTransformation(), erase(), eraseArc(), fastPrototype(), isDecisionNode(), isUtilityNode(), moralGraph_(), operator==(), removeTables_(), and toDot().

Here is the caller graph for this function:

◆ log10DomainSize()

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

Definition at line 95 of file graphicalModel_inl.h.

95 {
96 double dSize = 0.0;
97
98 for (const auto node: nodes()) {
99 dSize += std::log10(variable(node).domainSize());
100 }
101
102 return dSize;
103 }

References nodes().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ minimalCondSet() [1/4]

INLINE NodeSet gum::DAGmodel::minimalCondSet ( const NodeSet & targets,
const NodeSet & soids ) const
inherited

Definition at line 150 of file DAGmodel_inl.h.

150 {
151 return dag_.minimalCondSet(targets, soids);
152 }

References dag_.

◆ minimalCondSet() [2/4]

INLINE NodeSet gum::DAGmodel::minimalCondSet ( const std::string & target,
const std::vector< std::string > & soids ) const
inherited

Definition at line 154 of file DAGmodel_inl.h.

155 {
156 return dag_.minimalCondSet(idFromName(target), nodeset(soids));
157 }

◆ minimalCondSet() [3/4]

INLINE NodeSet gum::DAGmodel::minimalCondSet ( const std::vector< std::string > & targets,
const std::vector< std::string > & soids ) const
inherited

Definition at line 159 of file DAGmodel_inl.h.

160 {
161 return dag_.minimalCondSet(nodeset(targets), nodeset(soids));
162 }

◆ minimalCondSet() [4/4]

INLINE NodeSet gum::DAGmodel::minimalCondSet ( NodeId target,
const NodeSet & soids ) const
inherited

Definition at line 146 of file DAGmodel_inl.h.

146 {
147 return dag_.minimalCondSet(target, soids);
148 }

◆ moralGraph()

UndiGraph gum::DAGmodel::moralGraph ( ) const
inherited

The node's id are coherent with the variables and nodes of the topology.

Definition at line 64 of file DAGmodel.cpp.

64{ return dag().moralGraph(); }
UndiGraph moralGraph() const
build a UndiGraph by moralizing the dag
Definition DAG.cpp:68

References dag(), and gum::DAG::moralGraph().

Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVE< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), and gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_().

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

653 {
654 for (const auto node: dag_.nodes())
655 if (!isUtilityNode(node)) graph.addNodeWithId(node);
656
657 for (const auto node: dag_.nodes()) {
658 if (!isDecisionNode(node))
659 for (const auto par: dag_.parents(node)) {
660 if (isChanceNode(node)) graph.addEdge(node, par);
661
662 for (const auto par2: dag_.parents(node))
663 if (par != par2) graph.addEdge(par, par2);
664 }
665 }
666 }

References gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), gum::DAGmodel::dag_, isChanceNode(), isDecisionNode(), and isUtilityNode().

Here is the call graph for this function:

◆ moralizedAncestralGraph() [1/2]

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

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

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

Definition at line 134 of file DAGmodel_inl.h.

134 {
136 }
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition DAG.cpp:91

References dag(), gum::DAG::moralizedAncestralGraph(), and nodes().

Referenced by moralizedAncestralGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moralizedAncestralGraph() [2/2]

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

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

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

Definition at line 130 of file DAGmodel_inl.h.

130 {
131 return moralizedAncestralGraph(nodeset(nodenames));
132 }
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes

References moralizedAncestralGraph(), and gum::GraphicalModel::nodeset().

Here is the call graph for this function:

◆ names() [1/2]

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

transform a NodeSet in a vector of names

Returns
the vector of names

Definition at line 129 of file graphicalModel_inl.h.

129 {
130 const VariableNodeMap& v = variableNodeMap();
131 std::vector< std::string > res;
132 for (auto n: ids) {
133 res.push_back(v.name(n));
134 }
135 return res;
136 }

◆ names() [2/2]

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

transform a vector of NodeId in a vector of names

Returns
the vector of names

Definition at line 119 of file graphicalModel_inl.h.

119 {
120 std::vector< std::string > res;
121 const VariableNodeMap& v = variableNodeMap();
122 std::transform(ids.cbegin(), ids.cend(), std::back_inserter(res), [v](NodeId n) {
123 return v[n].name();
124 });
125 return res;
126 }
Size NodeId
Type for node ids.

References ids(), and variableNodeMap().

Referenced by gum::DAGmodel::children(), exists(), ids(), nodeset(), and gum::DAGmodel::parents().

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
finalvirtual

Return id node from discrete var pointer.

Exceptions
NotFoundIf no variable matches var.

Implements gum::GraphicalModel.

Definition at line 409 of file influenceDiagram_tpl.h.

409 {
410 return _variableMap_.get(var);
411 }

References _variableMap_.

◆ nodes()

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

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

Implements gum::GraphicalModel.

Definition at line 113 of file DAGmodel_inl.h.

113{ return (NodeGraphPart&)dag_; }

References dag_.

Referenced by gum::Estimator< GUM_SCALAR >::Estimator(), gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_verticesSampling_(), gum::BayesNet< GUM_SCALAR >::beginTopologyTransformation(), gum::InfluenceDiagram< GUM_SCALAR >::beginTopologyTransformation(), gum::IBayesNet< GUM_SCALAR >::check(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::BayesNet< GUM_SCALAR >::clear(), gum::InfluenceDiagram< GUM_SCALAR >::copyStructureAndTables_(), gum::IBayesNet< GUM_SCALAR >::dim(), gum::BayesNet< GUM_SCALAR >::endTopologyTransformation(), gum::InfluenceDiagram< GUM_SCALAR >::endTopologyTransformation(), gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype(), gum::BayesNet< GUM_SCALAR >::generateCPTs(), gum::getMaxModality(), hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::jointProbability(), gum::IBayesNet< GUM_SCALAR >::maxNonOneParam(), gum::IBayesNet< GUM_SCALAR >::maxParam(), gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize(), gum::IBayesNet< GUM_SCALAR >::memoryFootprint(), gum::IBayesNet< GUM_SCALAR >::minNonZeroParam(), gum::IBayesNet< GUM_SCALAR >::minParam(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), moralizedAncestralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::BayesNetFragment< GUM_SCALAR >::toBN(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::ImportanceSampling< GUM_SCALAR >::unsharpenBN_().

◆ nodeset()

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

transform a vector of names into a NodeSet

Returns
NodeSet

Definition at line 60 of file graphicalModel.cpp.

60 {
61 NodeSet res;
62 for (const auto& name: names) {
63 res.insert(idFromName(name));
64 }
65 return res;
66 }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

References idFromName(), gum::Set< Key >::insert(), and names().

Referenced by gum::IBayesNet< double >::children(), gum::IBayesNet< double >::children(), gum::DAGmodel::isIndependent(), gum::DAGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::DAGmodel::moralizedAncestralGraph(), and gum::DAGmodel::parents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

template<typename GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::operator!= ( const InfluenceDiagram< GUM_SCALAR > & other) const
inline

Definition at line 135 of file influenceDiagram.h.

135 {
136 return !operator==(other);
137 }
bool operator==(const InfluenceDiagram< GUM_SCALAR > &other) const

References InfluenceDiagram(), and operator==().

Here is the call graph for this function:

◆ operator=()

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

Copy Operator.

Definition at line 175 of file influenceDiagram_tpl.h.

175 {
176 if (this != &source) {
177 clear();
178 // Copying tables and structure
180 }
181
182 return *this;
183 }

References InfluenceDiagram(), clear(), and copyStructureAndTables_().

Here is the call graph for this function:

◆ operator==()

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

Definition at line 903 of file influenceDiagram_tpl.h.

903 {
904 if (size() != from.size()) { return false; }
905
906 if (sizeArcs() != from.sizeArcs()) { return false; }
907
908 // alignment of variables between the 2 BNs
910
911 for (auto node: nodes()) {
912 try {
913 const auto& v1 = variable(node);
914 const auto& v2 = from.variableFromName(variable(node).name());
915 if (v1 != v2) { return false; }
916
917 if (isChanceNode(v1.name()) && !from.isChanceNode(v2.name())) { return false; }
918 if (isUtilityNode(v1.name()) && !from.isUtilityNode(v2.name())) { return false; }
919 if (isDecisionNode(v1.name()) && !from.isDecisionNode(v2.name())) { return false; }
920
922 } catch (NotFound const&) {
923 // a name is not found in from
924 return false;
925 }
926 }
927
928 auto check_pot
929 = [&](const gum::Tensor< GUM_SCALAR >& p1, const gum::Tensor< GUM_SCALAR >& p2) -> bool {
930 if (p1.nbrDim() != p2.nbrDim()) { return false; }
931
932 if (p1.domainSize() != p2.domainSize()) { return false; }
933
936
937 for (i.setFirst(); !i.end(); i.inc()) {
938 for (Idx indice = 0; indice < p1.nbrDim(); ++indice) {
939 const DiscreteVariable* p = &(i.variable(indice));
940 j.chgVal(*(alignment.second(p)), i.val(*p));
941 }
942
943 if (std::pow(p1.get(i) - p2.get(j), (GUM_SCALAR)2) > (GUM_SCALAR)1e-6) { return false; }
944 }
945 return true;
946 };
947 for (auto node: nodes()) {
949 if (isChanceNode(node)) {
950 if (!check_pot(cpt(node), from.cpt(fromnode))) { return false; }
951 } else if (isUtilityNode(node)) {
952 if (!check_pot(utility(node), from.utility(fromnode))) { return false; }
953 }
954 }
955
956 return true;
957 }
const DiscreteVariable & variableFromName(const std::string &name) const final
Getter by name.

References InfluenceDiagram(), gum::Instantiation::chgVal(), cpt(), gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), gum::Instantiation::end(), gum::MultiDimDecorator< GUM_SCALAR >::get(), idFromName(), gum::Instantiation::inc(), gum::BijectionImplementation< T1, T2, Gen >::insert(), isChanceNode(), isDecisionNode(), isUtilityNode(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::DAGmodel::nodes(), gum::BijectionImplementation< T1, T2, Gen >::second(), gum::Instantiation::setFirst(), gum::DAGmodel::size(), gum::DAGmodel::sizeArcs(), utility(), gum::Instantiation::val(), variable(), gum::Instantiation::variable(), and variableFromName().

Referenced by operator!=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parents() [1/4]

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

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

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

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

Definition at line 75 of file DAGmodel_inl.h.

75{ return dag_.parents(id); }

References dag_.

Referenced by gum::IBayesNet< GUM_SCALAR >::check(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::InfluenceDiagram< GUM_SCALAR >::copyStructureAndTables_(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::BayesNetFragment< GUM_SCALAR >::installCPT_(), parents(), parents(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot().

Here is the caller graph for this function:

◆ parents() [2/4]

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

returns the parents of a set of nodes

Definition at line 99 of file DAGmodel_inl.h.

99{ return dag_.children(ids); }

References dag_, and gum::GraphicalModel::ids().

Here is the call graph for this function:

◆ parents() [3/4]

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

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

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

Definition at line 77 of file DAGmodel_inl.h.

77 {
78 return parents(idFromName(name));
79 }

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

Here is the call graph for this function:

◆ parents() [4/4]

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

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

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

Definition at line 101 of file DAGmodel_inl.h.

101 {
102 return parents(nodeset(names));
103 }

References gum::GraphicalModel::names(), gum::GraphicalModel::nodeset(), and parents().

Here is the call graph for this function:

◆ properties()

INLINE std::vector< std::string > gum::GraphicalModel::properties ( ) const
inherited

List of all the properties.

Definition at line 81 of file graphicalModel_inl.h.

81 {
82 std::vector< std::string > prop;
83 for (const auto& [p, v]: _propertiesMap_)
84 prop.push_back(p);
85 return prop;
86 }

References _propertiesMap_.

◆ property()

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

Return the value of the property name of this GraphicalModel.

Exceptions
NotFoundRaised if no name property is found.

Definition at line 60 of file graphicalModel_inl.h.

60 {
61 try {
62 return _properties_()[name];
63 } catch (NotFound const&) {
64 std::string msg = "The following property does not exists: ";
65 GUM_ERROR(NotFound, msg + name)
66 }
67 }
const HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model.

References _properties_(), and GUM_ERROR.

Referenced by gum::IMarkovRandomField< GUM_SCALAR >::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ propertyWithDefault()

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

Return the value of the property name of this GraphicalModel.

return byDefault if the property name is not found

Definition at line 75 of file graphicalModel_inl.h.

76 {
77 return (_propertiesMap_.exists(name)) ? _propertiesMap_[name] : byDefault;
78 }

References _propertiesMap_.

◆ removeTables_()

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

Removing ancient table.

Definition at line 199 of file influenceDiagram_tpl.h.

199 {
200 for (const auto node: dag_.nodes()) {
201 if (isChanceNode(node)) delete &cpt(node);
202 else if (isUtilityNode(node)) delete &utility(node);
203 }
204 }

References cpt(), gum::DAGmodel::dag_, isChanceNode(), isUtilityNode(), and utility().

Referenced by ~InfluenceDiagram().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setProperty()

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

Add or change a property of this GraphicalModel.

Definition at line 89 of file graphicalModel_inl.h.

89 {
90 if (_propertiesMap_.exists(name)) _propertiesMap_[name] = value;
91 else _propertiesMap_.insert(name, value);
92 }

References _propertiesMap_.

Referenced by gum::IBayesNet< GUM_SCALAR >::IBayesNet(), gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField(), and gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype().

Here is the caller graph for this function:

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 60 of file DAGmodel_inl.h.

60{ return dag().size(); }
Size size() const
alias for sizeNodes

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

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::copyStructureAndTables_(), gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize(), hasSameStructure(), gum::MarkovBlanket::hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toString().

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

63{ return dag_.sizeArcs(); }

References dag_.

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

Here is the caller graph for this function:

◆ spaceCplxToStream()

void gum::GraphicalModel::spaceCplxToStream ( std::stringstream & s,
double dSize,
int dim,
Size usedMem )
staticinherited

send to the stream the space complexity with 3 parametrs

Parameters
sthe stream
dSizethe log10domainSize
dimthe dimension
usedMemthe memory needed for the params

Definition at line 69 of file graphicalModel.cpp.

69 {
70 if (dSize > 6) s << "domainSize: 10^" << dSize;
71 else s << "domainSize: " << std::round(std::pow(10.0, dSize));
72
73 s << ", dim: " << dim << ", mem: ";
74
75 if (const Size go = usedMem / (1024 * 1024 * 1024); go > 0) s << go << "Go ";
76 if (const Size mo = (usedMem / (1024 * 1024)) % 1024; mo > 0) s << mo << "Mo ";
77 if (const Size ko = (usedMem / 1024) % 1024; ko > 0) s << ko << "Ko ";
78 s << usedMem % 1024 << "o";
79 }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

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

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

246 {
252 output << "digraph \"";
253
254 try {
255 output << this->property("name") << "\" {" << std::endl;
256 } catch (NotFound const&) { output << "no_name\" {" << std::endl; }
257
258 output << " node [bgcolor=\"#AAAAAA\", style=filled, height=0];" << std::endl;
259
260 decisionNode << "node [shape = box];" << std::endl;
261
262 utilityNode << "node [shape = hexagon, margin=0];" << std::endl;
263 chanceNode << "node [shape = ellipse];" << std::endl;
264 std::string tab = " ";
265
266 for (const auto node: dag_.nodes()) {
267 if (isChanceNode(node))
268 chanceNode << tab << "\"" << node << "-" << variable(node).name() << "\""
269 << ";";
270 else if (isUtilityNode(node))
271 utilityNode << tab << "\"" << node << "-" << variable(node).name() << "\""
272 << ";";
273 else
274 decisionNode << tab << "\"" << node << "-" << variable(node).name() << "\""
275 << ";";
276
277 if (dag_.children(node).size() > 0)
278 for (const auto chi: dag_.children(node)) {
279 arcstream << "\"" << node << "-" << variable(node).name() << "\""
280 << " -> "
281 << "\"" << chi << "-" << variable(chi).name() << "\"";
282 if (isDecisionNode(chi)) { arcstream << " [style=\"tapered, bold\"]"; }
283 arcstream << ";" << std::endl;
284 }
285 }
286
287 output << decisionNode.str() << std::endl
288 << utilityNode.str() << std::endl
289 << chanceNode.str() << std::endl
290 << std::endl
291 << arcstream.str() << std::endl
292 << "}" << std::endl;
293
294 return output.str();
295 }
const std::string & property(const std::string &name) const
Return the value of the property name of this GraphicalModel.

References gum::DAGmodel::dag_, isChanceNode(), isDecisionNode(), isUtilityNode(), gum::GraphicalModel::property(), and variable().

Here is the call graph for this function:

◆ topologicalOrder()

INLINE Sequence< NodeId > gum::DAGmodel::topologicalOrder ( ) 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_inl.h.

115{ return dag().topologicalOrder(); }
Sequence< NodeId > topologicalOrder() const
Build and return a topological order.
Definition diGraph.cpp:111

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrder(), and gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists().

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

298 {
300
301 output << "Influence Diagram{" << std::endl;
302 output << " chance: " << chanceNodeSize() << "," << std::endl;
303 output << " utility: " << utilityNodeSize() << "," << std::endl;
304 output << " decision: " << decisionNodeSize() << "," << std::endl;
305 output << " arcs: " << dag().sizeArcs() << "," << std::endl;
306
307
308 if (double dSize = log10DomainSize(); dSize > 6) output << " domainSize: 10^" << dSize;
309 else output << " domainSize: " << std::round(std::pow(10.0, dSize));
310
311 output << std::endl << "}";
312
313 return output.str();
314 }
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
double log10DomainSize() const
Size chanceNodeSize() const
Returns the number of chance nodes.
Size utilityNodeSize() const
Returns the number of utility nodes.
Size decisionNodeSize() const
Returns the number of decision nodes.

References chanceNodeSize(), gum::DAGmodel::dag(), decisionNodeSize(), gum::GraphicalModel::log10DomainSize(), and utilityNodeSize().

Here is the call graph for this function:

◆ utility() [1/2]

template<typename GUM_SCALAR>
INLINE const Tensor< 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 332 of file influenceDiagram_tpl.h.

332 {
333 return *(_utilityMap_[varId]);
334 }

References _utilityMap_.

Referenced by copyStructureAndTables_(), fastPrototype(), operator==(), removeTables_(), and utility().

Here is the caller graph for this function:

◆ utility() [2/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 168 of file influenceDiagram.h.

168 {
169 return utility(idFromName(name));
170 };

References idFromName(), and utility().

Here is the call 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 368 of file influenceDiagram_tpl.h.

368 {
369 return _utilityMap_.size();
370 }

References _utilityMap_.

Referenced by toString().

Here is the caller graph for this function:

◆ variable() [1/2]

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

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 220 of file influenceDiagram.h.

220 {
221 return variable(idFromName(name));
222 };

References idFromName(), and variable().

Here is the call graph for this function:

◆ variable() [2/2]

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

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

Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::GraphicalModel.

Definition at line 401 of file influenceDiagram_tpl.h.

401 {
402 return _variableMap_[id];
403 }

References _variableMap_.

Referenced by addArc(), addChanceNode(), addUtilityNode(), copyStructureAndTables_(), erase(), eraseArc(), operator==(), toDot(), 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
finalvirtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::GraphicalModel.

Definition at line 422 of file influenceDiagram_tpl.h.

422 {
423 return _variableMap_.variableFromName(name);
424 }

References _variableMap_.

Referenced by operator==().

Here is the caller graph for this function:

◆ variableNodeMap()

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

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

Implements gum::GraphicalModel.

Definition at line 393 of file influenceDiagram_tpl.h.

393 {
394 return _variableMap_;
395 }

References _variableMap_.

◆ variables() [1/2]

INLINE VariableSet gum::GraphicalModel::variables ( const NodeSet & ids) const
inherited

transform a vector of NodeId into a VariableeSet

Returns
NodeSet

Definition at line 160 of file graphicalModel_inl.h.

160 {
161 VariableSet s;
162 const VariableNodeMap& v = variableNodeMap();
163 for (const auto& node: l) {
164 s.insert(&v.get(node));
165 }
166 return s;
167 }
Set< const DiscreteVariable * > VariableSet

References gum::VariableNodeMap::get(), gum::Set< Key >::insert(), and variableNodeMap().

Here is the call graph for this function:

◆ variables() [2/2]

INLINE VariableSet gum::GraphicalModel::variables ( const std::vector< std::string > & l) const
inherited

transform a vector of names into a VariableeSet

Returns
NodeSet

Definition at line 150 of file graphicalModel_inl.h.

150 {
151 VariableSet s;
152 const VariableNodeMap& v = variableNodeMap();
153 for (const auto& name: l) {
154 s.insert(&v.variableFromName(name));
155 }
156 return s;
157 }

References variableNodeMap().

Here is the call graph for this function:

Member Data Documentation

◆ _propertiesMap_

HashTable< std::string, std::string > gum::GraphicalModel::_propertiesMap_
privateinherited

The properties of this Directed Graphical Model.

Definition at line 236 of file graphicalModel.h.

Referenced by _properties_(), operator=(), properties(), propertyWithDefault(), and setProperty().

◆ _temporalOrder_

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

The temporal order.

Definition at line 565 of file influenceDiagram.h.

Referenced by getPartialTemporalOrder().

◆ _tensorMap_

template<typename GUM_SCALAR>
NodeProperty< Tensor< GUM_SCALAR >* > gum::InfluenceDiagram< GUM_SCALAR >::_tensorMap_
private

Mapping between tensor variable's id and their CPT.

Definition at line 560 of file influenceDiagram.h.

Referenced by addArc(), addChanceNode(), beginTopologyTransformation(), chanceNodeSize(), cpt(), decisionNodeSize(), endTopologyTransformation(), erase(), eraseArc(), and isChanceNode().

◆ _utilityMap_

template<typename GUM_SCALAR>
NodeProperty< Tensor< GUM_SCALAR >* > gum::InfluenceDiagram< GUM_SCALAR >::_utilityMap_
private

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

Definition at line 562 of file influenceDiagram.h.

Referenced by addArc(), addUtilityNode(), beginTopologyTransformation(), decisionNodeSize(), endTopologyTransformation(), erase(), eraseArc(), isUtilityNode(), utility(), and utilityNodeSize().

◆ _variableMap_

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

Mapping between id and variable.

Definition at line 557 of file influenceDiagram.h.

Referenced by addNode_(), changeVariableName(), erase(), erase(), idFromName(), nodeId(), variable(), variableFromName(), and variableNodeMap().

◆ dag_


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