aGrUM 3.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 >:
[legend]
Collaboration diagram for gum::InfluenceDiagram< GUM_SCALAR >:
[legend]

Public Member Functions

bool operator== (const InfluenceDiagram< GUM_SCALAR > &other) const
std::string toDot () const
std::string toDot (const dot::DotOptions &options) const
std::string toString () const
void clear ()
NodeId idFromName (std::string_view name) const override
 Returns the NodeId of a variable given its name.
const VariableNodeMap & variableNodeMap () const override
 Returns a constant reference to the VariableNodeMap of this model.
const DiscreteVariable & variable (NodeId id) const override
 Returns a constant reference over a variable given its node id.
NodeId nodeId (const DiscreteVariable &var) const override
 Returns the NodeId of a variable.
const DiscreteVariable & variableFromName (std::string_view name) const override
 Returns a constant reference over a variable given its name.
bool hasSameStructure (const DAGmodel &other) const
NodeSet minimalCondSet (NodeId target, const NodeSet &soids) const
NodeSet minimalCondSet (const NodeSet &targets, const NodeSet &soids) const
NodeSet minimalCondSet (std::string_view target, const std::vector< std::string > &soids) const
NodeSet minimalCondSet (const std::vector< std::string > &targets, const std::vector< std::string > &soids) const
const DAG & internalDag () const
 Returns a const reference to the internal (unnamed) DAG. O(1), no copy. Use for stable references or pointers (e.g. graph listeners). For named node access, use dag() instead.
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.
 InfluenceDiagram (InfluenceDiagram< GUM_SCALAR > &&) noexcept
 Default constructor.
InfluenceDiagram< GUM_SCALAR > & operator= (InfluenceDiagram< GUM_SCALAR > &&) noexcept
 Default constructor.
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_view 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_view name) const final
 Returns the CPT of a tensor variable.
bool isUtilityNode (NodeId varId) const
 Returns true if node is a utility one.
bool isUtilityNode (std::string_view name) const
 Returns the CPT of a tensor variable.
bool isDecisionNode (NodeId varId) const
 Returns true if node is a decision one.
bool isDecisionNode (std::string_view name) const
 Returns the CPT of a tensor variable.
bool isChanceNode (NodeId varId) const
 Returns true if node is a chance one.
bool isChanceNode (std::string_view 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 DiscreteVariable & variable (std::string_view name) const
 Returns the CPT of a tensor variable.
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 (std::string_view fast_description, unsigned int default_nbrmod=2)
 Add a chance, a decision or an utility variable from a description in "fast" syntax.
NodeId addChanceNode (std::string_view fast_description, unsigned int default_nbrmod=2)
 Add a chance variable from a description in "fast" syntax.
NodeId addUtilityNode (std::string_view fast_description)
 Add a utility variable from a description in "fast" syntax with only one value.
NodeId addDecisionNode (std::string_view 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 (std::string_view 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, std::string_view new_name)
 we allow the user to change the name of a variable
void changeVariableName (std::string_view name, std::string_view 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 (std::string_view tail, std::string_view 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 (std::string_view tail, std::string_view 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::DAG getDecisionGraph () const
 Returns the temporal Graph.
std::vector< NodeId > decisionOrder () 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 (std::string_view src, std::string_view 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.
DAG dag () const
 Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding variable.
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 NodeGraphPart & nodes () const final
 Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding variable.
bool exists (NodeId node) const final
 Return true if this node exists in this graphical model.
bool exists (std::string_view name) const final
 Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding variable.
Arc manipulation methods.
const ArcSet & arcs () 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 (std::string_view nametail, std::string_view namehead) const
 return true if the arc tail->head exists in the DAGmodel
const NodeSet & parents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node
const NodeSet & parents (std::string_view 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 (std::string_view name) const final
 return true if the arc tail->head exists in the DAGmodel
const NodeSet & children (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node
const NodeSet & children (std::string_view 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 (std::string_view 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 (std::string_view 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 (std::string_view Xname, std::string_view 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< NodeId > topologicalOrder () const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology.
NodeProperty< NodeId > connectedComponents () const
 Returns the weakly connected components of the underlying DAG. Each node maps to the id of its component root.
Getter and setters
const std::string & property (std::string_view name) const
 Return the value of the property name of this GraphicalModel.
const std::string & propertyWithDefault (std::string_view name, const std::string &byDefault) const
 Return the value of the property name of this GraphicalModel.
void setProperty (std::string_view name, std::string_view value)
 Add or change a property of this GraphicalModel.
std::vector< std::string > properties () const
 List of all the names of property in the Graphical model.
bool existsProperty (std::string_view name) const
 check wether a property exists in this GraphicalModel
void updateMetaData ()
 update the meta data of this Graphical Model (version, creation date, last modification date) This method is called by the writers ONLY before writing the model to a file.
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< NodeId > ids (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 (std::string_view dotlike, Size domainSize)
 Create an Influence Diagram with a dot-like syntax which specifies:
static InfluenceDiagram< GUM_SCALAR > fastPrototype (std::string_view dotlike, std::string_view domain="[2]")
static std::string spaceCplxToString (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< NodeId > getChildrenDecision_ (NodeId parentDecision) const
 Returns the list of children decision for a given nodeId.
void _nameNodes_ (NodeGraphPart &g) const
 Names every node of g using variable(id).name() for each node id in g.

Protected Attributes

DAG dag_
 The DAG of this Directed Graphical Model.
VariableNodeMap varMap_
 Mapping between NodeIds and discrete variables.

Private Member Functions

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

Private Attributes

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<GUM_Numeric GUM_SCALAR>
class gum::InfluenceDiagram< GUM_SCALAR >

Class representing an Influence Diagram.

Definition at line 76 of file influenceDiagram.h.

Constructor & Destructor Documentation

◆ InfluenceDiagram() [1/3]

template<GUM_Numeric GUM_SCALAR>
gum::InfluenceDiagram< GUM_SCALAR >::InfluenceDiagram ( )

Default constructor.

Definition at line 144 of file influenceDiagram_tpl.h.

144 : DAGmodel() {
146 }
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(), ~InfluenceDiagram(), clear(), copyStructureAndTables_(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID(), operator=(), operator=(), and operator==().

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

◆ ~InfluenceDiagram()

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

Destructor.

Definition at line 152 of file influenceDiagram_tpl.h.

152 {
155 }
void removeTables_()
Removing ancient table.

References InfluenceDiagram(), and removeTables_().

Here is the call graph for this function:

◆ InfluenceDiagram() [2/3]

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

Copy Constructor.

Definition at line 184 of file influenceDiagram_tpl.h.

184 {
187 }
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:

◆ InfluenceDiagram() [3/3]

template<GUM_Numeric GUM_SCALAR>
gum::InfluenceDiagram< GUM_SCALAR >::InfluenceDiagram ( InfluenceDiagram< GUM_SCALAR > && source)
noexcept

Default constructor.

Definition at line 158 of file influenceDiagram_tpl.h.

159 :
164 }
List< NodeSet > _temporalOrder_
The temporal order.
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.

References InfluenceDiagram(), _temporalOrder_, _tensorMap_, and _utilityMap_.

Here is the call graph for this function:

Member Function Documentation

◆ _checkNodeExists_()

INLINE void gum::DAGmodel::_checkNodeExists_ ( NodeId id) const
privateinherited
Exceptions
NotFoundif id is not a node of the model

Definition at line 83 of file DAGmodel_inl.h.

83 {
84 if (!dag_.exists(id)) GUM_ERROR(NotFound, "No node with id " << id << " in the model")
85 }
DAG dag_
The DAG of this Directed Graphical Model.
Definition DAGmodel.h:291
bool exists(const NodeId id) const
alias for existsNode
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References dag_, gum::NodeGraphPart::exists(), and GUM_ERROR.

Referenced by ancestors(), children(), descendants(), family(), and parents().

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

◆ _nameNodes_()

INLINE void gum::GraphicalModel::_nameNodes_ ( NodeGraphPart & g) const
protectedinherited

Names every node of g using variable(id).name() for each node id in g.

Call this before returning any newly constructed graph from a model method.

Definition at line 175 of file graphicalModel_inl.h.

175 {
176 for (auto id: g)
177 g.setName(id, variable(id).name());
178 }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.

References gum::NodeGraphPart::setName(), and variable().

Referenced by gum::DAGmodel::dag(), family(), gum::UGmodel::graph(), and gum::DAGmodel::moralGraph().

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

◆ _properties_()

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

Return the properties of this Directed Graphical Model.

Definition at line 67 of file graphicalModel_inl.h.

67 {
68 return _propertiesMap_;
69 }
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<GUM_Numeric 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 422 of file influenceDiagram_tpl.h.

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

References addChanceNode().

Referenced by clear().

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

◆ add() [2/2]

template<GUM_Numeric GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::add ( std::string_view 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 866 of file influenceDiagram_tpl.h.

867 {
869 switch (*(node.begin())) {
870 case '*' : node.erase(0, 1); return addDecisionNode(node, default_nbrmod);
871 case '$' : node.erase(0, 1); return addUtilityNode(node);
873 }
874 }
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<GUM_Numeric GUM_SCALAR>
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 590 of file influenceDiagram_tpl.h.

590 {
591 if (isUtilityNode(tail)) { GUM_ERROR(InvalidArc, "Tail cannot be a utility node") }
592
593 dag_.addArc(tail, head);
594
595 if (isChanceNode(head))
596 // Add parent in the child's CPT
597 (*(_tensorMap_[head])) << variable(tail);
598 else if (isUtilityNode(head)) {
599 // Add parent in the child's UT
600 (*(_utilityMap_[head])) << variable(tail);
601 }
602 }
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const DiscreteVariable & variable(std::string_view name) const
Returns the CPT of a tensor variable.

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

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

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

◆ addArc() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::addArc ( std::string_view tail,
std::string_view 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 990 of file influenceDiagram_tpl.h.

990 {
992 }
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram's tensor nodes cpt if necessary.

References addArc(), and idFromName().

Here is the call graph for this function:

◆ addChanceNode() [1/3]

template<GUM_Numeric 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 481 of file influenceDiagram_tpl.h.

483 {
485
487 (*varcpt) << variable(proposedId);
489
490 return proposedId;
491 }
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<GUM_Numeric 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 461 of file influenceDiagram_tpl.h.

461 {
463 NodeId res;
464
465 try {
467 } catch (Exception const&) {
468 delete newMultiDim;
469 throw;
470 }
471
472 return res;
473 }
MultiDimArray()
Default constructor.

References gum::MultiDimArray< GUM_ELEMENT >::MultiDimArray(), and addChanceNode().

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

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

◆ addChanceNode() [3/3]

template<GUM_Numeric GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addChanceNode ( std::string_view 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 841 of file influenceDiagram_tpl.h.

842 {
844 if (v->domainSize() < 2) GUM_ERROR(OperationNotAllowed, v->name() << " has a domain size <2")
846 }

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

Here is the call graph for this function:

◆ addDecisionNode() [1/2]

template<GUM_Numeric 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 451 of file influenceDiagram_tpl.h.

452 {
453 return addNode_(var, varId);
454 }

References addNode_().

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

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

◆ addDecisionNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addDecisionNode ( std::string_view 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 858 of file influenceDiagram_tpl.h.

859 {
861 if (v->domainSize() < 2) GUM_ERROR(OperationNotAllowed, v->name() << " has a domain size <2")
863 }

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

Here is the call graph for this function:

◆ addNode_()

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

Add a node.

Definition at line 524 of file influenceDiagram_tpl.h.

525 {
526 // None thread safe code!
528
529 if (DesiredId == 0) proposedId = dag_.nextNodeId();
530 else proposedId = DesiredId;
531
532 this->varMap_.insert(proposedId, variableType);
533
534 dag_.addNodeWithId(proposedId);
535
536 // end critical section
537 return proposedId;
538 }
VariableNodeMap varMap_
Mapping between NodeIds and discrete variables.

References gum::DAGmodel::dag_, and gum::DiscreteGraphicalModel::varMap_.

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

Here is the caller graph for this function:

◆ addUtilityNode() [1/3]

template<GUM_Numeric 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 500 of file influenceDiagram_tpl.h.

502 {
503 if (var.domainSize() != 1) {
505 "Utility var have no state ( which implicates a "
506 "single label for data output reasons ).")
507 }
508
510
512
513 (*varut) << variable(proposedId);
514
516
517 return proposedId;
518 }

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

Here is the call graph for this function:

◆ addUtilityNode() [2/3]

template<GUM_Numeric 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 432 of file influenceDiagram_tpl.h.

432 {
434 NodeId res;
435
436 try {
438 } catch (Exception const&) {
439 if (newMultiDim != nullptr) delete newMultiDim;
440 throw;
441 }
442
443 return res;
444 }

References gum::MultiDimArray< GUM_ELEMENT >::MultiDimArray(), and addUtilityNode().

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

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

◆ addUtilityNode() [3/3]

template<GUM_Numeric GUM_SCALAR>
NodeId gum::InfluenceDiagram< GUM_SCALAR >::addUtilityNode ( std::string_view 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 849 of file influenceDiagram_tpl.h.

849 {
851 if (v->domainSize() >= 2)
853 v->name() << " has a domain size >= 2 which is impossible for a utility node")
855 }

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
Exceptions
NotFoundif the node does not exist in the model

Definition at line 167 of file DAGmodel_inl.h.

167 {
168 auto res = dag_.ancestors(id);
169 if (res.empty()) _checkNodeExists_(id);
170 return res;
171 }
void _checkNodeExists_(NodeId id) const
NodeSet ancestors(NodeId id) const
returns the set of all ancestors of id (nodes from which id is reachable)

References _checkNodeExists_(), gum::DiGraph::ancestors(), dag_, and gum::Set< Key >::empty().

Here is the call graph for this function:

◆ ancestors() [2/2]

INLINE NodeSet gum::DAGmodel::ancestors ( std::string_view 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 173 of file DAGmodel_inl.h.

173 {
174 return dag_.ancestors(idFromName(name));
175 }
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.

References gum::DiGraph::ancestors(), dag_, and gum::DiscreteGraphicalModel::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 73 of file DAGmodel_inl.h.

73{ return dag_.arcs(); }
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart

References gum::ArcGraphPart::arcs(), and dag_.

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

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

◆ beginTopologyTransformation()

template<GUM_Numeric 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 878 of file influenceDiagram_tpl.h.

878 {
879 for (const auto node: nodes())
880 if (isChanceNode(node)) _tensorMap_[node]->beginMultipleChanges();
881 else if (this->isUtilityNode(node)) _utilityMap_[node]->beginMultipleChanges();
882 }
const NodeGraphPart & nodes() const final
Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding vari...

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

Referenced by clear().

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

◆ chanceNodeSize()

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

Returns the number of chance nodes.

Definition at line 405 of file influenceDiagram_tpl.h.

405 {
406 return _tensorMap_.size();
407 }

References _tensorMap_.

Referenced by clear(), and toString().

Here is the caller graph for this function:

◆ changeVariableName() [1/2]

template<GUM_Numeric GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName ( NodeId id,
std::string_view 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 579 of file influenceDiagram_tpl.h.

579 {
580 this->varMap_.changeName(id, new_name);
581 }

References gum::DiscreteGraphicalModel::varMap_.

Referenced by changeVariableName(), and clear().

Here is the caller graph for this function:

◆ changeVariableName() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::changeVariableName ( std::string_view name,
std::string_view new_name )

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 984 of file influenceDiagram_tpl.h.

985 {
987 }
void changeVariableName(NodeId id, std::string_view 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:

◆ 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
Exceptions
NotFoundif the node does not exist in the model

Definition at line 109 of file DAGmodel_inl.h.

109 {
110 const NodeSet& res = dag_.children(id);
111 if (res.empty()) _checkNodeExists_(id);
112 return res;
113 }
NodeSet children(const NodeSet &ids) const
returns the set of nodes which consists in the node and its parents returns the set of children of a ...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

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

Exceptions
NotFoundif one of the nodes does not exist in the model

Definition at line 119 of file DAGmodel_inl.h.

119 {
120 for (const auto id: ids)
122 return dag_.children(ids);
123 }
std::vector< NodeId > ids(const std::vector< std::string > &names) const
transform a vector of names into a vector of nodeId

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

Here is the call graph for this function:

◆ children() [3/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 126 of file DAGmodel_inl.h.

126 {
127 return dag_.children(nodeset(names));
128 }
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::ArcGraphPart::children(), dag_, gum::GraphicalModel::names(), and gum::GraphicalModel::nodeset().

Here is the call graph for this function:

◆ children() [4/4]

INLINE const NodeSet & gum::DAGmodel::children ( std::string_view 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 115 of file DAGmodel_inl.h.

115 {
116 return dag_.children(idFromName(name));
117 }

◆ clear()

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

Definition at line 104 of file graphicalModel_inl.h.

104 {
105 Instantiation I;
106
107 for (const auto node: nodes())
108 I << variable(node);
109
110 return I;
111 }
virtual const NodeGraphPart & nodes() const =0
Returns the number of variables in this Directed Graphical Model.

References nodes(), and variable().

Referenced by nodes().

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

◆ connectedComponents()

INLINE NodeProperty< NodeId > gum::DAGmodel::connectedComponents ( ) const
inherited

Returns the weakly connected components of the underlying DAG. Each node maps to the id of its component root.

Definition at line 153 of file DAGmodel_inl.h.

153 {
154 return dag_.connectedComponents();
155 }
NodeProperty< NodeId > connectedComponents() const
returns a property {node:id of weakly connected component}

References gum::DiGraph::connectedComponents(), and dag_.

Here is the call graph for this function:

◆ copyStructureAndTables_()

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

Copying tables from another influence diagram.

Definition at line 229 of file influenceDiagram_tpl.h.

230 {
231 for (auto node: IDsource.nodes()) {
234 else // decision node
236 }
237 // we add arc in the same order of the tensors
238 for (auto node: IDsource.nodes()) {
239 const auto& s = IDsource.variable(node).name();
241 for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
242 addArc(IDsource.cpt(node).variable(par).name(), s);
243 } else if (IDsource.isUtilityNode(node)) {
244 for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
245 addArc(IDsource.utility(node).variable(par).name(), s);
246 } else { // decision node
247 // here the order does not depend on a Tensor
249 addArc(par, node);
250 }
251 }
252
253 // Copying tensors
254 for (auto node: IDsource.nodes()) {
255 const auto& s = IDsource.variable(node).name();
257 cpt(node).fillWith(IDsource.cpt(s));
258 } else if (IDsource.isUtilityNode(node)) {
259 utility(node).fillWith(IDsource.utility(s));
260 }
261 }
262 }
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(), clear(), and operator=().

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

◆ cpt() [1/2]

template<GUM_Numeric GUM_SCALAR>
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 353 of file influenceDiagram_tpl.h.

353 {
354 return *(_tensorMap_[varId]);
355 }

References _tensorMap_.

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

Here is the caller graph for this function:

◆ cpt() [2/2]

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::InfluenceDiagram< GUM_SCALAR >::cpt ( std::string_view name) const
finalvirtual

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 949 of file influenceDiagram_tpl.h.

949 {
950 return cpt(idFromName(name));
951 }

References cpt(), and idFromName().

Here is the call graph for this function:

◆ dag()

INLINE DAG gum::DAGmodel::dag ( ) const
nodiscardinherited

Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding variable.

O(n) — allocates a new DAG. For a stable reference (listeners, long-lived pointers), use internalDag().

Definition at line 61 of file DAGmodel_inl.h.

61 {
62 DAG g = dag_;
63 _nameNodes_(g);
64 return g;
65 }
void _nameNodes_(NodeGraphPart &g) const
Names every node of g using variable(id).name() for each node id in g.

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

Referenced by gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment(), gum::MarginalTargetedInference< GUM_SCALAR >::MarginalTargetedInference(), gum::BayesNet< GUM_SCALAR >::add(), gum::BayesNet< GUM_SCALAR >::reverseArc(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

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

◆ decisionNodeSize()

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

Returns the number of decision nodes.

Definition at line 413 of file influenceDiagram_tpl.h.

413 {
414 return (size() - _utilityMap_.size() - _tensorMap_.size());
415 }

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

Referenced by clear(), and toString().

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

◆ decisionOrder()

template<GUM_Numeric 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 787 of file influenceDiagram_tpl.h.

787 {
788 if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists") }
789
791
792 for (const auto elt: topologicalOrder())
793 if (isDecisionNode(elt)) decisionSequence.push_back(elt);
794
795 return decisionSequence;
796 }
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 decisionOrderExists() const
True if a directed path exist with all decision nodes.
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.

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

Referenced by clear(), and getPartialTemporalOrder().

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

◆ decisionOrderExists()

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

True if a directed path exist with all decision nodes.

Definition at line 662 of file influenceDiagram_tpl.h.

662 {
664
665 // Finding first decision node
667
668 while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
669 ++orderIter;
670
671 if (orderIter == order.end()) return true;
672
673 NodeId parentDecision = (*orderIter);
674 ++orderIter;
675
676 // Checking path between decisions nodes
677 while (orderIter != order.end()) {
679 if (!existsPathBetween(parentDecision, *orderIter)) return false;
680
682 }
683
684 ++orderIter;
685 }
686
687 return true;
688 }
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_(), clear(), 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
Exceptions
NotFoundif the node does not exist in the model

Definition at line 157 of file DAGmodel_inl.h.

157 {
158 auto res = dag_.descendants(id);
159 if (res.empty()) _checkNodeExists_(id);
160 return res;
161 }
NodeSet descendants(NodeId id) const
returns the set of all descendants of id (nodes reachable from id)

References _checkNodeExists_(), dag_, gum::DiGraph::descendants(), and gum::Set< Key >::empty().

Here is the call graph for this function:

◆ descendants() [2/2]

INLINE NodeSet gum::DAGmodel::descendants ( std::string_view 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 163 of file DAGmodel_inl.h.

163 {
164 return dag_.descendants(idFromName(name));
165 }

References dag_, gum::DiGraph::descendants(), and gum::DiscreteGraphicalModel::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 114 of file graphicalModel_inl.h.

114{ 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(), gum::BayesNet< GUM_SCALAR >::clear(), and size().

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

◆ endTopologyTransformation()

template<GUM_Numeric 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 886 of file influenceDiagram_tpl.h.

886 {
887 for (const auto node: nodes())
888 if (isChanceNode(node)) _tensorMap_[node]->endMultipleChanges();
889 else if (isUtilityNode(node)) _utilityMap_[node]->endMultipleChanges();
890 }

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

Referenced by clear().

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

◆ erase() [1/3]

template<GUM_Numeric GUM_SCALAR>
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 572 of file influenceDiagram_tpl.h.

572 {
573 erase(this->varMap_.get(var));
574 }

References erase(), and gum::DiscreteGraphicalModel::varMap_.

Here is the call graph for this function:

◆ erase() [2/3]

template<GUM_Numeric 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 546 of file influenceDiagram_tpl.h.

546 {
547 if (this->varMap_.exists(varId)) {
548 // Reduce the variable child's CPT or Utility Table if necessary
549 for (const auto chi: dag_.children(varId))
551 else if (isUtilityNode(chi)) _utilityMap_[chi]->erase(variable(varId));
552
553 if (isChanceNode(varId)) {
554 delete _tensorMap_[varId];
555 _tensorMap_.erase(varId);
556 } else if (isUtilityNode(varId)) {
557 delete _utilityMap_[varId];
558 _utilityMap_.erase(varId);
559 }
560
561 this->varMap_.erase(varId);
562 dag_.eraseNode(varId);
563 }
564 }
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node

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

Referenced by clear(), erase(), and erase().

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

◆ erase() [3/3]

template<GUM_Numeric GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::erase ( std::string_view name)

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 979 of file influenceDiagram_tpl.h.

979 {
981 }

References erase(), and idFromName().

Here is the call graph for this function:

◆ eraseArc() [1/3]

template<GUM_Numeric GUM_SCALAR>
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 610 of file influenceDiagram_tpl.h.

610 {
611 if (dag_.existsArc(arc)) {
612 NodeId head = arc.head();
613 NodeId tail = arc.tail();
615
616 if (isChanceNode(head))
617 // Removes parent in the child's CPT
618 (*(_tensorMap_[head])) >> variable(tail);
619 else if (isUtilityNode(head))
620 // Removes parent in the child's UT
621 (*(_utilityMap_[head])) >> variable(tail);
622 }
623 }
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram's tensor nodes cpt if necessary.

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

Referenced by clear(), eraseArc(), and eraseArc().

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

◆ eraseArc() [2/3]

template<GUM_Numeric GUM_SCALAR>
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 631 of file influenceDiagram_tpl.h.

631 {
633 }
Arc(NodeId tail, NodeId head)
basic constructor. Creates tail -> head.

References gum::Arc::Arc(), and eraseArc().

Here is the call graph for this function:

◆ eraseArc() [3/3]

template<GUM_Numeric GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::eraseArc ( std::string_view tail,
std::string_view 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 995 of file influenceDiagram_tpl.h.

995 {
997 }

References eraseArc(), and idFromName().

Here is the call graph for this function:

◆ exists() [1/2]

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

Return true if this node exists in this graphical model.

Implements gum::GraphicalModel.

Definition at line 141 of file DAGmodel_inl.h.

141{ return dag_.exists(node); }

References dag_, and gum::NodeGraphPart::exists().

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

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

◆ exists() [2/2]

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

Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding variable.

O(n) — allocates a new DAG. For a stable reference (listeners, long-lived pointers), use internalDag().

Implements gum::GraphicalModel.

Definition at line 143 of file DAGmodel_inl.h.

143 {
144 return variableNodeMap().exists(name);
145 }
const VariableNodeMap & variableNodeMap() const override
Returns a constant reference to the VariableNodeMap of this model.
bool exists(NodeId id) const
Return true if id matches a node.

References gum::VariableNodeMap::exists(), and gum::DiscreteGraphicalModel::variableNodeMap().

Here is the call graph for this function:

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

75 {
76 return dag_.existsArc(tail, head);
77 }
bool existsArc(const Arc &arc) const
indicates whether a given arc exists

References dag_, and gum::ArcGraphPart::existsArc().

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

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

◆ existsArc() [2/2]

INLINE bool gum::DAGmodel::existsArc ( std::string_view nametail,
std::string_view 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 79 of file DAGmodel_inl.h.

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

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

Here is the call graph for this function:

◆ existsPathBetween() [1/2]

template<GUM_Numeric 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 694 of file influenceDiagram_tpl.h.

694 {
696 // mark[node] contains 0 if not visited
697 // mark[node] = predecessor if visited
698 NodeProperty< int > mark = dag_.nodesPropertyFromVal(-1);
700
701 mark[src] = (int)src;
702 nodeFIFO.pushBack(src);
703
704 while (!nodeFIFO.empty()) {
705 current = nodeFIFO.front();
706 nodeFIFO.popFront();
707
708 for (const auto new_one: dag_.children(current)) {
709 if (mark[new_one] != -1) continue; // if this node is already marked, continue
710
712
713 if (new_one == dest) break; // if we reach *orderIter, stop.
714
715 nodeFIFO.pushBack(new_one);
716 }
717 }
718
719 if (mark[dest] == -1) return false;
720
721 return true;
722 }
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 clear(), decisionOrderExists(), and existsPathBetween().

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

◆ existsPathBetween() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween ( std::string_view src,
std::string_view dest ) const

True if a directed path exist with all decision nodes.

Definition at line 1000 of file influenceDiagram_tpl.h.

1001 {
1003 }

References existsPathBetween(), and idFromName().

Here is the call graph for this function:

◆ existsProperty()

INLINE bool gum::GraphicalModel::existsProperty ( std::string_view name) const
inherited

check wether a property exists in this GraphicalModel

Definition at line 170 of file graphicalModel_inl.h.

170 {
171 return _propertiesMap_.exists(name);
172 }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

References _propertiesMap_, and gum::HashTable< Key, Val >::exists().

Here is the call 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
Exceptions
NotFoundif the node does not exist in the model

Implements gum::GraphicalModel.

Definition at line 100 of file DAGmodel_inl.h.

100 {
102 return dag_.family(id);
103 }
NodeSet family(NodeId id) const
returns { id } ∪ parents(id)

References _checkNodeExists_(), dag_, and gum::DiGraph::family().

Here is the call graph for this function:

◆ family() [2/2]

INLINE NodeSet gum::DAGmodel::family ( std::string_view 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 105 of file DAGmodel_inl.h.

105 {
106 return dag_.family(idFromName(name));
107 }

References dag_, gum::DiGraph::family(), and gum::DiscreteGraphicalModel::idFromName().

Here is the call graph for this function:

◆ fastPrototype() [1/2]

template<GUM_Numeric GUM_SCALAR>
InfluenceDiagram< GUM_SCALAR > gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype ( std::string_view 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 103 of file influenceDiagram_tpl.h.

103 {
104 return fastPrototype(dotlike, "[" + std::to_string(domainSize) + "]");
105 }
static InfluenceDiagram< GUM_SCALAR > fastPrototype(std::string_view 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:

◆ fastPrototype() [2/2]

template<GUM_Numeric GUM_SCALAR>
InfluenceDiagram< GUM_SCALAR > gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype ( std::string_view dotlike,
std::string_view domain = "[2]" )
static

Definition at line 109 of file influenceDiagram_tpl.h.

110 {
112
113 auto resolve
114 = [&](const std::string& node) { return build_node_for_ID(infdiag, node, domain); };
115 auto addArc = [&](NodeId tail, NodeId head, const std::string&) { infdiag.addArc(tail, head); };
116 auto addEdge = [&](NodeId, NodeId, const std::string& token) {
118 "fastPrototype: '" << token << "' is preceded by '-' but an InfluenceDiagram "
119 << "does not support edges")
120 };
121
122 for (const auto& chaine: split(remove_newline(dotlike), ";")) {
123 using namespace detail;
125 }
126
127 for (const auto n: infdiag.nodes()) {
128 if (infdiag.isChanceNode(n)) infdiag.cpt(n).randomCPT();
129 else if (infdiag.isUtilityNode(n)) { infdiag.utility(n).random().scale(50).translate(-10); }
130 }
131
132 infdiag.setProperty("name", "anonymousID");
133 return infdiag;
134 }
void setProperty(std::string_view name, std::string_view value)
Add or change a property of this GraphicalModel.

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

Here is the call graph for this function:

◆ getChildrenDecision_()

template<GUM_Numeric 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 751 of file influenceDiagram_tpl.h.

751 {
753
756
757 // mark[node] contains false if not visited
758 // mark[node] contains true if visited
759 NodeProperty< bool > mark = dag_.nodesPropertyFromVal(false);
760
761 mark[parentDecision] = true;
762
763 nodeFIFO.pushBack(parentDecision);
764
765 while (!nodeFIFO.empty()) {
766 current = nodeFIFO.front();
767 nodeFIFO.popFront();
768
769 for (const auto new_one: dag_.children(current)) {
770 if (mark[new_one]) continue; // if this node is already marked, continue
771
772 mark[new_one] = true;
773
774 if (!isDecisionNode(new_one)) nodeFIFO.pushBack(new_one);
775 else childrenSeq.insert(new_one);
776 }
777 }
778
779 return childrenSeq;
780 }

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 clear(), and getDecisionGraph().

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

◆ getDecisionGraph()

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

Returns the temporal Graph.

Definition at line 728 of file influenceDiagram_tpl.h.

728 {
730
731 for (const auto node: dag_.nodes()) {
732 if (isDecisionNode(node)) {
733 if (!temporalGraph.existsNode(node)) temporalGraph.addNodeWithId(node);
734
735 for (const auto chi: getChildrenDecision_(node)) {
736 if (!temporalGraph.existsNode(chi)) temporalGraph.addNodeWithId(chi);
737
739 }
740 }
741 }
742
743 return temporalGraph;
744 }
Sequence< NodeId > getChildrenDecision_(NodeId parentDecision) const
Returns the list of children decision for a given nodeId.

References gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), gum::DAGmodel::dag_, gum::NodeGraphPart::existsNode(), getChildrenDecision_(), and isDecisionNode().

Referenced by clear().

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

◆ getPartialTemporalOrder()

template<GUM_Numeric 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 803 of file influenceDiagram_tpl.h.

803 {
804 if (clear) {
805 _temporalOrder_.clear();
806
808 NodeSet nodeList = dag_.asNodeSet();
809
810 for (auto i: order) {
812
813 for (const auto par: dag_.parents(i)) {
814 if (nodeList.contains(par) && isChanceNode(par)) {
815 partialOrderedSet.insert(par);
817 }
818 }
819
821
823
824 decisionSet.insert(i);
825
826 _temporalOrder_.pushFront(decisionSet);
827 }
828
829 NodeSet lastSet; //= new gum::NodeSet();
830
831 for (const auto node: nodeList)
832 if (isChanceNode(node)) lastSet.insert(node);
833
834 if (!lastSet.empty()) _temporalOrder_.pushFront(lastSet);
835 }
836
837 return _temporalOrder_;
838 }
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().

Referenced by clear().

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

◆ hasSameStructure()

bool gum::DAGmodel::hasSameStructure ( const DAGmodel & other) const
inherited
Returns
true if all the named node are the same and all the named arcs are the same

Definition at line 87 of file DAGmodel.cpp.

87 {
88 if (this == &other) return true;
89
90 if (size() != other.size()) return false;
91
92 if (sizeArcs() != other.sizeArcs()) return false;
93
94 for (const auto& nid: nodes()) {
95 if (!other.exists(variable(nid).name())) return false;
96 }
97
98 for (const auto& arc: arcs()) {
99 if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
100 other.idFromName(variable(arc.head()).name()))))
101 return false;
102 }
103
104 return true;
105 }
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.
const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variable given its node id.

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

Here is the call graph for this function:

◆ idFromName()

template<GUM_Numeric GUM_SCALAR>
INLINE NodeId gum::DiscreteGraphicalModel::idFromName ( std::string_view name) const
overridevirtual

Returns the NodeId of a variable given its name.

Exceptions
NotFoundif no such name exists in the model.

Reimplemented from gum::DiscreteGraphicalModel.

Definition at line 104 of file discreteGraphicalModel_inl.h.

61 {
62 return varMap_.idFromName(name);
63 }

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(), and variableNodeMap().

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

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

◆ internalDag()

INLINE const DAG & gum::DAGmodel::internalDag ( ) const
inherited

Returns a const reference to the internal (unnamed) DAG. O(1), no copy. Use for stable references or pointers (e.g. graph listeners). For named node access, use dag() instead.

Definition at line 58 of file DAGmodel_inl.h.

58{ return dag_; }

References dag_.

Referenced by gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment(), gum::MarkovBlanket::MarkovBlanket(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::BayesNetFragment< GUM_SCALAR >::toBN(), gum::BayesNetFragment< GUM_SCALAR >::toDot(), and gum::BayesNetFragment< GUM_SCALAR >::whenArcDeleted().

Here is the caller graph for this function:

◆ isChanceNode() [1/2]

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

Returns true if node is a chance one.

Definition at line 389 of file influenceDiagram_tpl.h.

389 {
390 return _tensorMap_.exists(varId);
391 }

References _tensorMap_.

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

Here is the caller graph for this function:

◆ isChanceNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::isChanceNode ( std::string_view name) const

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 969 of file influenceDiagram_tpl.h.

969 {
971 }

References idFromName(), and isChanceNode().

Here is the call graph for this function:

◆ isDecisionNode() [1/2]

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

Returns true if node is a decision one.

Definition at line 377 of file influenceDiagram_tpl.h.

377 {
378 bool ret = true;
379
380 if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
381
382 return ret;
383 }

References isChanceNode(), and isUtilityNode().

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

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

◆ isDecisionNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::isDecisionNode ( std::string_view name) const

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 964 of file influenceDiagram_tpl.h.

964 {
966 }

References idFromName(), and isDecisionNode().

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

192 {
193 return dag_.dSeparation(X, Y, Z);
194 }
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:80

◆ isIndependent() [2/4]

INLINE bool gum::DAGmodel::isIndependent ( const std::vector< std::string > & Xnames,
const std::vector< std::string > & Ynames,
const std::vector< std::string > & Znames ) 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 220 of file DAGmodel_inl.h.

222 {
223 return isIndependent(nodeset(Xnames), nodeset(Ynames), nodeset(Znames));
224 }
bool isIndependent(NodeId X, NodeId Y, const NodeSet &Z) const final
check if node X and node Y are independent given nodes Z

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

Here is the call graph for this function:

◆ isIndependent() [3/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 188 of file DAGmodel_inl.h.

188 {
189 return dag_.dSeparation(X, Y, Z);
190 }

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

Referenced by isIndependent().

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

◆ isIndependent() [4/4]

INLINE bool gum::DAGmodel::isIndependent ( std::string_view Xname,
std::string_view Yname,
const std::vector< std::string > & Znames ) 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 214 of file DAGmodel_inl.h.

216 {
217 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
218 }

◆ isUtilityNode() [1/2]

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

Returns true if node is a utility one.

Definition at line 369 of file influenceDiagram_tpl.h.

369 {
370 return _utilityMap_.exists(varId);
371 }

References _utilityMap_.

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

Here is the caller graph for this function:

◆ isUtilityNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::InfluenceDiagram< GUM_SCALAR >::isUtilityNode ( std::string_view name) const

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 959 of file influenceDiagram_tpl.h.

959 {
961 }

References idFromName(), and isUtilityNode().

Here is the call graph for this function:

◆ log10DomainSize()

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

Definition at line 93 of file graphicalModel_inl.h.

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

References nodes().

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

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

200 {
201 return dag_.minimalCondSet(targets, soids);
202 }
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
Definition DAG.cpp:88

References dag_, and gum::DAG::minimalCondSet().

Here is the call graph for this function:

◆ minimalCondSet() [2/4]

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

Definition at line 209 of file DAGmodel_inl.h.

210 {
211 return dag_.minimalCondSet(nodeset(targets), nodeset(soids));
212 }

◆ minimalCondSet() [3/4]

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

Definition at line 196 of file DAGmodel_inl.h.

196 {
197 return dag_.minimalCondSet(target, soids);
198 }

References dag_, and gum::DAG::minimalCondSet().

Referenced by gum::ASTposteriorProba< GUM_SCALAR >::_compute_knw_from_bn().

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

◆ minimalCondSet() [4/4]

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

Definition at line 204 of file DAGmodel_inl.h.

205 {
206 return dag_.minimalCondSet(idFromName(target), nodeset(soids));
207 }

◆ moralGraph()

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

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

Definition at line 81 of file DAGmodel.cpp.

81 {
82 auto g = dag_.moralGraph();
83 _nameNodes_(g);
84 return g;
85 }
UndiGraph moralGraph() const
build a UndiGraph by moralizing the dag
Definition DAG.cpp:74

References gum::GraphicalModel::_nameNodes_(), 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<GUM_Numeric GUM_SCALAR>
void gum::InfluenceDiagram< GUM_SCALAR >::moralGraph_ ( UndiGraph & graph) const
protectedvirtual

Returns the moral graph of this InfluenceDiagram.

Definition at line 643 of file influenceDiagram_tpl.h.

643 {
644 for (const auto node: dag_.nodes())
645 if (!isUtilityNode(node)) graph.addNodeWithId(node);
646
647 for (const auto node: dag_.nodes()) {
648 if (!isDecisionNode(node))
649 for (const auto par: dag_.parents(node)) {
650 if (isChanceNode(node)) graph.addEdge(node, par);
651
652 for (const auto par2: dag_.parents(node))
653 if (par != par2) graph.addEdge(par, par2);
654 }
655 }
656 }

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

Referenced by clear().

Here is the call graph for this function:
Here is the caller 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 182 of file DAGmodel_inl.h.

182 {
184 _nameNodes_(g);
185 return g;
186 }
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
Definition DAG.cpp:76

Referenced by moralizedAncestralGraph().

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

178 {
179 return moralizedAncestralGraph(nodeset(nodenames));
180 }
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 }

References ids(), gum::VariableNodeMap::name(), and variableNodeMap().

Here is the call graph for this function:

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

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

References ids().

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<GUM_Numeric GUM_SCALAR>
INLINE NodeId gum::DiscreteGraphicalModel::nodeId ( const DiscreteVariable & var) const
overridevirtual

Returns the NodeId of a variable.

Exceptions
NotFoundif no variable matches var.

Reimplemented from gum::DiscreteGraphicalModel.

Definition at line 98 of file discreteGraphicalModel_inl.h.

56 {
57 return varMap_.get(var);
58 }

◆ nodes()

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

Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding variable.

O(n) — allocates a new DAG. For a stable reference (listeners, long-lived pointers), use internalDag().

Implements gum::GraphicalModel.

Definition at line 147 of file DAGmodel_inl.h.

147 {
148 return static_cast< const NodeGraphPart& >(dag_);
149 }

References dag_.

Referenced by gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment(), gum::EssentialGraph::_buildEssentialGraph_(), 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 >::maxNonOneParam(), gum::IBayesNet< GUM_SCALAR >::maxParam(), gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize(), gum::IBayesNet< GUM_SCALAR >::memoryFootprint(), gum::IBayesNet< GUM_SCALAR >::minParam(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::IBayesNet< GUM_SCALAR >::operator==(), 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 102 of file graphicalModel.cpp.

102 {
103 NodeSet res;
104 for (const auto& name: names) {
105 res.insert(idFromName(name));
106 }
107 return res;
108 }
virtual NodeId idFromName(std::string_view name) const =0
Getter by name.

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

Referenced by gum::DAGmodel::children(), exists(), 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=() [1/2]

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

Copy Operator.

Definition at line 194 of file influenceDiagram_tpl.h.

194 {
195 if (this != &source) {
196 clear();
197 // Copying tables and structure
199 }
200
201 return *this;
202 }

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

Here is the call graph for this function:

◆ operator=() [2/2]

template<GUM_Numeric GUM_SCALAR>
InfluenceDiagram< GUM_SCALAR > & gum::InfluenceDiagram< GUM_SCALAR >::operator= ( InfluenceDiagram< GUM_SCALAR > && source)
noexcept

Default constructor.

Definition at line 168 of file influenceDiagram_tpl.h.

168 {
169 if (this != &source) {
176 }
177 return *this;
178 }
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
Definition DAGmodel.cpp:62

References InfluenceDiagram(), _temporalOrder_, _tensorMap_, _utilityMap_, gum::DAGmodel::operator=(), and removeTables_().

Here is the call graph for this function:

◆ operator==()

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

Definition at line 893 of file influenceDiagram_tpl.h.

893 {
894 if (size() != from.size()) { return false; }
895
896 if (sizeArcs() != from.sizeArcs()) { return false; }
897
898 // alignment of variables between the 2 BNs
900
901 for (auto node: nodes()) {
902 const auto& v1 = variable(node);
903 if (!from.exists(v1.name())) return false;
904 const auto& v2 = from.variableFromName(v1.name());
905 if (v1 != v2) { return false; }
906
907 if (isChanceNode(v1.name()) && !from.isChanceNode(v2.name())) { return false; }
908 if (isUtilityNode(v1.name()) && !from.isUtilityNode(v2.name())) { return false; }
909 if (isDecisionNode(v1.name()) && !from.isDecisionNode(v2.name())) { return false; }
910
911 alignment.insert(&variable(node), &from.variableFromName(v1.name()));
912 }
913
914 auto check_pot
915 = [&](const gum::Tensor< GUM_SCALAR >& p1, const gum::Tensor< GUM_SCALAR >& p2) -> bool {
916 if (p1.nbrDim() != p2.nbrDim()) { return false; }
917
918 if (p1.domainSize() != p2.domainSize()) { return false; }
919
922 // the tolerance applies to the squared difference: two values are equal when
923 // |a - b| <= sqrt(epsilonStandard), i.e. 1e-3 by default
924 const GUM_SCALAR tolerance = static_cast< GUM_SCALAR >(config().epsilonStandard());
925
926 for (i.setFirst(); !i.end(); i.inc()) {
927 for (Idx indice = 0; indice < p1.nbrDim(); ++indice) {
928 const DiscreteVariable* p = &(i.variable(indice));
929 j.chgVal(*(alignment.second(p)), i.val(*p));
930 }
931
932 if (std::pow(p1.get(i) - p2.get(j), (GUM_SCALAR)2) > tolerance) { return false; }
933 }
934 return true;
935 };
936 for (auto node: nodes()) {
938 if (isChanceNode(node)) {
939 if (!check_pot(cpt(node), from.cpt(fromnode))) { return false; }
940 } else if (isUtilityNode(node)) {
941 if (!check_pot(utility(node), from.utility(fromnode))) { return false; }
942 }
943 }
944
945 return true;
946 }
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
const DiscreteVariable & variableFromName(std::string_view name) const override
Returns a constant reference over a variable given its name.

References InfluenceDiagram(), gum::Instantiation::chgVal(), gum::config(), cpt(), gum::MultiDimDecorator< GUM_ELEMENT >::domainSize(), gum::Instantiation::end(), gum::Configuration::epsilonStandard(), gum::DAGmodel::exists(), gum::MultiDimDecorator< GUM_ELEMENT >::get(), idFromName(), gum::Instantiation::inc(), gum::BijectionImplementation< T1, T2, Gen >::insert(), isChanceNode(), isDecisionNode(), isUtilityNode(), gum::MultiDimDecorator< GUM_ELEMENT >::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().

Here is the call 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
Exceptions
NotFoundif the node does not exist in the model

Definition at line 89 of file DAGmodel_inl.h.

89 {
90 const NodeSet& res = dag_.parents(id);
91 if (res.empty()) _checkNodeExists_(id);
92 return res;
93 }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node

References _checkNodeExists_(), dag_, gum::Set< Key >::empty(), and gum::ArcGraphPart::parents().

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

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

Exceptions
NotFoundif one of the nodes does not exist in the model

Definition at line 130 of file DAGmodel_inl.h.

130 {
131 for (const auto id: ids)
133 return dag_.parents(ids);
134 }

References gum::GraphicalModel::ids().

Here is the call graph for this function:

◆ parents() [3/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 137 of file DAGmodel_inl.h.

137 {
138 return dag_.parents(nodeset(names));
139 }

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

Here is the call graph for this function:

◆ parents() [4/4]

INLINE const NodeSet & gum::DAGmodel::parents ( std::string_view 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 96 of file DAGmodel_inl.h.

96 {
97 return dag_.parents(idFromName(name));
98 }

References dag_, gum::DiscreteGraphicalModel::idFromName(), and gum::ArcGraphPart::parents().

Here is the call graph for this function:

◆ properties()

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

List of all the names of property in the Graphical model.

Definition at line 79 of file graphicalModel_inl.h.

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

References _propertiesMap_.

◆ property()

INLINE const std::string & gum::GraphicalModel::property ( std::string_view 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 auto p = _properties_().tryGet(name);
62 if (!p) { GUM_ERROR(NotFound, "The following property does not exists: " << name) }
63 return *p;
64 }
const HashTable< std::string, std::string > & _properties_() const
Return the properties of this Directed Graphical Model.
optional_ref< Val > tryGet(const Key &key)
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.

References _properties_(), GUM_ERROR, and gum::HashTable< Key, Val >::tryGet().

Here is the call graph for this function:

◆ propertyWithDefault()

INLINE const std::string & gum::GraphicalModel::propertyWithDefault ( std::string_view 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 72 of file graphicalModel_inl.h.

73 {
74 auto p = _propertiesMap_.tryGet(name);
75 return p ? *p : byDefault;
76 }

References _propertiesMap_, and gum::HashTable< Key, Val >::tryGet().

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:

◆ removeTables_()

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

Removing ancient table.

Definition at line 218 of file influenceDiagram_tpl.h.

218 {
219 for (const auto& [node, tensor]: _tensorMap_)
220 delete tensor;
221 for (const auto& [node, tensor]: _utilityMap_)
222 delete tensor;
223 }

References _tensorMap_, and _utilityMap_.

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

Here is the caller graph for this function:

◆ setProperty()

INLINE void gum::GraphicalModel::setProperty ( std::string_view name,
std::string_view value )
inherited

Add or change a property of this GraphicalModel.

Definition at line 87 of file graphicalModel_inl.h.

87 {
88 if (auto p = _propertiesMap_.tryGet(name)) *p = value;
89 else _propertiesMap_.insert(std::string(name), std::string(value));
90 }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

References _propertiesMap_, gum::HashTable< Key, Val >::insert(), and gum::HashTable< Key, Val >::tryGet().

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

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

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 68 of file DAGmodel_inl.h.

68{ 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(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot().

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

71{ return dag_.sizeArcs(); }
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart

References dag_, and gum::ArcGraphPart::sizeArcs().

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

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

◆ spaceCplxToString()

std::string gum::GraphicalModel::spaceCplxToString ( 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 110 of file graphicalModel.cpp.

110 {
111 std::string result;
112 if (dSize > 6) result = std::format("domainSize: 10^{:.6g}", dSize);
113 else result = std::format("domainSize: {}", (long long)std::round(std::pow(10.0, dSize)));
114
115 result += std::format(", dim: {}, mem: ", dim);
116
117 if (const Size go = usedMem / (1024 * 1024 * 1024); go > 0) result += std::format("{}Go ", go);
118 if (const Size mo = (usedMem / (1024 * 1024)) % 1024; mo > 0)
119 result += std::format("{}Mo ", mo);
120 if (const Size ko = (usedMem / 1024) % 1024; ko > 0) result += std::format("{}Ko ", ko);
121 result += std::format("{}o", usedMem % 1024);
122 return result;
123 }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

Referenced by isIndependent().

Here is the caller graph for this function:

◆ toDot() [1/2]

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

Definition at line 265 of file influenceDiagram_tpl.h.

265 {
266 return toDot(dot::DotOptions());
267 }
std::string toDot() const

References toDot().

Referenced by toDot().

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

◆ toDot() [2/2]

template<GUM_Numeric GUM_SCALAR>
std::string gum::InfluenceDiagram< GUM_SCALAR >::toDot ( const dot::DotOptions & options) const
Returns
Returns a dot representation of this Influence Diagram, with the options given by the caller.

The nodes are named after the variables, with the tooltip "(id) name" ; the chance, decision and utility nodes have the colors and shapes of the section influenceDiagram of the configuration. The arcs towards a decision node or a utility node have the styles decisionArcStyle and utilityArcStyle.

Definition at line 270 of file influenceDiagram_tpl.h.

270 {
272 dot::DotWriter writer(true, this->propertyWithDefault("name", ""));
274
275 // the nodes of a kind, whose default look is the one of the kind
276 const auto writeNodes = [&](const std::function< bool(NodeId) >& isOfThisKind,
277 const std::string& bgColor,
278 const std::string& fgColor,
279 const std::string& shape) {
280 writer.nodeDefaults({{"fillcolor", bgColor},
281 {"fontcolor", fgColor},
282 {"style", "filled"},
283 {"shape", shape},
284 {"height", "0"},
285 {"margin", "0.1"}});
286
287 // a font color which is adaptive is resolved against the background of the kind
288 auto kindStyle = static_cast< dot::DotStyle >(style);
289 kindStyle.nodeBgColor = bgColor;
290 for (const auto node: dag_.nodes()) {
291 if (!isOfThisKind(node)) continue;
292 const auto& name = variable(node).name();
293 writer.node(name,
295 options.node(node),
296 "",
297 "(" + std::to_string(node) + ") " + name));
298 }
299 };
300
301 writeNodes([this](NodeId n) { return isChanceNode(n); },
302 style.chanceBgColor,
303 style.chanceFgColor,
304 style.chanceShape);
305 writeNodes([this](NodeId n) { return isDecisionNode(n); },
306 style.decisionBgColor,
307 style.decisionFgColor,
308 style.decisionShape);
309 writeNodes([this](NodeId n) { return isUtilityNode(n); },
310 style.utilityBgColor,
311 style.utilityFgColor,
312 style.utilityShape);
313
314 for (const auto& arc: dag_.arcs()) {
315 auto attributes = dot::arcAttributes(options.arc(arc.tail(), arc.head()));
316 if (isDecisionNode(arc.head()))
317 dot::addDefaultAttribute(attributes, "style", style.decisionArcStyle);
318 else if (isUtilityNode(arc.head()))
319 dot::addDefaultAttribute(attributes, "style", style.utilityArcStyle);
320 writer.edge(variable(arc.tail()).name(), variable(arc.head()).name(), attributes);
321 }
322
323 return writer.str();
324 }
const std::string & propertyWithDefault(std::string_view name, const std::string &byDefault) const
Return the value of the property name of this GraphicalModel.
void writePreamble(DotWriter &writer, const DotStyle &style, const DotOptions &options, std::string_view defaultLabel)
Writes the beginning of a graph, as pyAgrum displays it.
void addDefaultAttribute(DotAttributes &attributes, std::string_view key, std::string_view value)
Adds an attribute at the beginning of the list, unless the list already gives a value for this key : ...
DotAttributes arcAttributes(const DotArcOptions *options)
The attributes of an arc or an edge given by the options : color, penwidth, label,...
static InfluenceDiagramDotStyle read()
Definition dotStyle.cpp:133

References gum::dot::addDefaultAttribute(), gum::dot::DotOptions::arc(), gum::dot::arcAttributes(), gum::DAGmodel::dag_, gum::dot::DotWriter::edge(), isChanceNode(), isDecisionNode(), isUtilityNode(), gum::dot::DotOptions::node(), gum::dot::DotWriter::node(), gum::dot::nodeAttributes(), gum::dot::DotStyle::nodeBgColor, gum::dot::DotWriter::nodeDefaults(), gum::GraphicalModel::propertyWithDefault(), gum::dot::InfluenceDiagramDotStyle::read(), gum::dot::DotWriter::str(), variable(), and gum::dot::writePreamble().

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

151{ return dag_.topologicalOrder(); }
Sequence< NodeId > topologicalOrder() const
Build and return a topological order.

References dag_, and gum::DiGraph::topologicalOrder().

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

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

◆ toString()

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

Definition at line 327 of file influenceDiagram_tpl.h.

327 {
329
330 output << "Influence Diagram{" << std::endl;
331 output << std::format(" chance: {},\n", chanceNodeSize());
332 output << std::format(" utility: {},\n", utilityNodeSize());
333 output << std::format(" decision: {},\n", decisionNodeSize());
334 output << std::format(" arcs: {},\n", dag().sizeArcs());
335
336 if (double dSize = log10DomainSize(); dSize > 6)
337 output << std::format(" domainSize: 10^{}", dSize);
338 else output << std::format(" domainSize: {}", std::round(std::pow(10.0, dSize)));
339
340 output << std::endl << "}";
341
342 return output.str();
343 }
DAG dag() const
Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding vari...
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(), gum::DAGmodel::sizeArcs(), and utilityNodeSize().

Here is the call graph for this function:

◆ updateMetaData()

void gum::GraphicalModel::updateMetaData ( )
inherited

update the meta data of this Graphical Model (version, creation date, last modification date) This method is called by the writers ONLY before writing the model to a file.

Definition at line 81 of file graphicalModel.cpp.

81 {
82 auto const time = std::chrono::time_point_cast< std::chrono::milliseconds >(
83 std::chrono::system_clock::now());
84 auto const currentdate = std::format("{:%Y-%m-%d %T}", time);
85
86 const std::string currentSoftware = "aGrUM " GUM_VERSION;
87 if (auto software = _propertiesMap_.tryGet("software")) {
88 *software = currentSoftware;
89 } else {
90 _propertiesMap_.insert("software", currentSoftware);
91 }
92
93 if (!_propertiesMap_.tryGet("creation")) { _propertiesMap_.insert("creation", currentdate); }
94
95 if (auto lastModification = _propertiesMap_.tryGet("lastModification")) {
96 *lastModification = currentdate;
97 } else {
98 _propertiesMap_.insert("lastModification", currentdate);
99 }
100 }

References _propertiesMap_, gum::HashTable< Key, Val >::insert(), and gum::HashTable< Key, Val >::tryGet().

Here is the call graph for this function:

◆ utility() [1/2]

template<GUM_Numeric GUM_SCALAR>
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 361 of file influenceDiagram_tpl.h.

361 {
362 return *(_utilityMap_[varId]);
363 }

References _utilityMap_.

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

Here is the caller graph for this function:

◆ utility() [2/2]

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::InfluenceDiagram< GUM_SCALAR >::utility ( std::string_view name) const
finalvirtual

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 954 of file influenceDiagram_tpl.h.

954 {
955 return utility(idFromName(name));
956 }

References idFromName(), and utility().

Here is the call graph for this function:

◆ utilityNodeSize()

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

Returns the number of utility nodes.

Definition at line 397 of file influenceDiagram_tpl.h.

397 {
398 return _utilityMap_.size();
399 }

References _utilityMap_.

Referenced by clear(), and toString().

Here is the caller graph for this function:

◆ variable() [1/2]

template<GUM_Numeric GUM_SCALAR>
INLINE const DiscreteVariable & gum::DiscreteGraphicalModel::variable ( NodeId id) const
overridevirtual

Returns a constant reference over a variable given its node id.

Exceptions
NotFoundif no variable's id matches id.

Reimplemented from gum::DiscreteGraphicalModel.

Definition at line 92 of file discreteGraphicalModel_inl.h.

51 {
52 return varMap_.get(id);
53 }

◆ variable() [2/2]

template<GUM_Numeric GUM_SCALAR>
const DiscreteVariable & gum::InfluenceDiagram< GUM_SCALAR >::variable ( std::string_view name) const

Returns the CPT of a tensor variable.

Exceptions
NotFoundIf no variable's id matches varId.

Definition at line 974 of file influenceDiagram_tpl.h.

974 {
975 return variable(idFromName(name));
976 }

References idFromName(), and variable().

Referenced by addArc(), addChanceNode(), addUtilityNode(), clear(), copyStructureAndTables_(), erase(), eraseArc(), operator==(), toDot(), and variable().

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

◆ variableFromName()

template<GUM_Numeric GUM_SCALAR>
INLINE const DiscreteVariable & gum::DiscreteGraphicalModel::variableFromName ( std::string_view name) const
overridevirtual

Returns a constant reference over a variable given its name.

Exceptions
NotFoundif no such name exists in the model.

Reimplemented from gum::DiscreteGraphicalModel.

Definition at line 110 of file discreteGraphicalModel_inl.h.

66 {
67 return varMap_.variableFromName(name);
68 }

Referenced by operator==().

Here is the caller graph for this function:

◆ variableNodeMap()

template<GUM_Numeric GUM_SCALAR>
INLINE const VariableNodeMap & gum::DiscreteGraphicalModel::variableNodeMap ( ) const
overridevirtual

Returns a constant reference to the VariableNodeMap of this model.

Reimplemented from gum::DiscreteGraphicalModel.

Definition at line 86 of file discreteGraphicalModel_inl.h.

48{ return varMap_; }

◆ 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

◆ 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 gum::Set< Key >::insert(), gum::VariableNodeMap::variableFromName(), and variableNodeMap().

Referenced by exists().

Here is the call graph for this function:
Here is the caller 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 262 of file graphicalModel.h.

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

◆ _temporalOrder_

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

The temporal order.

Definition at line 542 of file influenceDiagram.h.

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

◆ _tensorMap_

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

◆ _utilityMap_

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

◆ dag_

DAG gum::DAGmodel::dag_
protectedinherited

The DAG of this Directed Graphical Model.

Definition at line 291 of file DAGmodel.h.

Referenced by DAGmodel(), DAGmodel(), _checkNodeExists_(), gum::prm::ClassBayesNet< GUM_SCALAR >::_get_(), gum::prm::ClassBayesNet< GUM_SCALAR >::_init_(), gum::prm::InstanceBayesNet< GUM_SCALAR >::_init_(), gum::BayesNet< GUM_SCALAR >::add(), gum::BayesNet< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::InfluenceDiagram< GUM_SCALAR >::addNode_(), ancestors(), ancestors(), arcs(), children(), connectedComponents(), dag(), descendants(), descendants(), gum::BayesNet< GUM_SCALAR >::erase(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), gum::BayesNet< GUM_SCALAR >::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), exists(), existsArc(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), family(), family(), gum::InfluenceDiagram< GUM_SCALAR >::getChildrenDecision_(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::BayesNetFragment< GUM_SCALAR >::installArc_(), gum::BayesNetFragment< GUM_SCALAR >::installNode(), internalDag(), isIndependent(), minimalCondSet(), minimalCondSet(), moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::moralGraph_(), nodes(), operator=(), operator=(), parents(), parents(), parents(), size(), sizeArcs(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), topologicalOrder(), gum::BayesNetFragment< GUM_SCALAR >::uninstallArc_(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallNode().

◆ varMap_


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