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

Class representing an Influence Diagram. More...

#include <agrum/ID/influenceDiagram.h>

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

Public Member Functions

bool operator== (const InfluenceDiagram< GUM_SCALAR > &other) const
std::string toDot () 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 VariableNodeMapvariableNodeMap () const override
 Returns a constant reference to the VariableNodeMap of this model.
const DiscreteVariablevariable (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 DiscreteVariablevariableFromName (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 DAGinternalDag () 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 DiscreteVariablevariable (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< NodeIddecisionOrder () const
 Returns the sequence of decision nodes in the directed path.
bool existsPathBetween (NodeId src, NodeId dest) const
 Returns true if a path exists between two nodes.
bool existsPathBetween (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 NodeGraphPartnodes () 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 ArcSetarcs () const
 return true if the arc tail->head exists in the DAGmodel
bool existsArc (const NodeId tail, const NodeId head) const
 return true if the arc tail->head exists in the DAGmodel
bool existsArc (std::string_view nametail, std::string_view namehead) const
 return true if the arc tail->head exists in the DAGmodel
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node
const NodeSetparents (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 NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node
const NodeSetchildren (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< NodeIdtopologicalOrder () const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology.
NodeProperty< NodeIdconnectedComponents () 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< NodeIdids (const std::vector< std::string > &names) const
 transform a vector of names into a vector of nodeId
NodeSet nodeset (const std::vector< std::string > &names) const
 transform a vector of names into a NodeSet
gum::VariableSet variables (const std::vector< std::string > &l) const
 transform a vector of names into a VariableeSet
gum::VariableSet variables (const NodeSet &ids) const
 transform a vector of NodeId into a VariableeSet
Instantiation completeInstantiation () const
 Get an instantiation over all the variables of the model.

Static Public Member Functions

static InfluenceDiagram< GUM_SCALAR > fastPrototype (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< NodeIdgetChildrenDecision_ (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

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

149 : DAGmodel() {
151 }
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_(), 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 157 of file influenceDiagram_tpl.h.

157 {
160 }
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 189 of file influenceDiagram_tpl.h.

189 {
192 }
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 163 of file influenceDiagram_tpl.h.

164 :
169 }
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 gum::DAGmodel::DAGmodel(), InfluenceDiagram(), _temporalOrder_, _tensorMap_, and _utilityMap_.

Here is the call graph for this function:

Member Function Documentation

◆ _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(), gum::UGmodel::graph(), gum::DAGmodel::moralGraph(), and gum::DAGmodel::moralizedAncestralGraph().

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

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

References addChanceNode().

Here is the call graph for this function:

◆ add() [2/2]

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

857 {
859 switch (*(node.begin())) {
860 case '*' : node.erase(0, 1); return addDecisionNode(node, default_nbrmod);
861 case '$' : node.erase(0, 1); return addUtilityNode(node);
863 }
864 }
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 580 of file influenceDiagram_tpl.h.

580 {
581 if (isUtilityNode(tail)) { GUM_ERROR(InvalidArc, "Tail cannot be a utility node") }
582
583 dag_.addArc(tail, head);
584
585 if (isChanceNode(head))
586 // Add parent in the child's CPT
587 (*(_tensorMap_[head])) << variable(tail);
588 else if (isUtilityNode(head)) {
589 // Add parent in the child's UT
590 (*(_utilityMap_[head])) << variable(tail);
591 }
592 }
DAG dag_
The DAG of this Directed Graphical Model.
Definition DAGmodel.h:284
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.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

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

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

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

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

977 {
979 }
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 471 of file influenceDiagram_tpl.h.

473 {
475
477 (*varcpt) << variable(proposedId);
479
480 return proposedId;
481 }
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 451 of file influenceDiagram_tpl.h.

451 {
453 NodeId res;
454
455 try {
457 } catch (Exception const&) {
458 delete newMultiDim;
459 throw;
460 }
461
462 return res;
463 }

References addChanceNode().

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

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

◆ addChanceNode() [3/3]

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

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

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

Here is the call graph for this function:

◆ addDecisionNode() [1/2]

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

442 {
443 return addNode_(var, varId);
444 }

References addNode_().

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

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

◆ addDecisionNode() [2/2]

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

849 {
851 if (v->domainSize() < 2) GUM_ERROR(OperationNotAllowed, v->name() << " has a domain size <2")
853 }

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

515 {
516 // None thread safe code!
518
519 if (DesiredId == 0) proposedId = dag_.nextNodeId();
520 else proposedId = DesiredId;
521
522 this->varMap_.insert(proposedId, variableType);
523
524 dag_.addNodeWithId(proposedId);
525
526 // end critical section
527 return proposedId;
528 }
VariableNodeMap varMap_
Mapping between NodeIds and discrete variables.

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

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

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

492 {
493 if (var.domainSize() != 1) {
495 "Utility var have no state ( which implicates a "
496 "single label for data output reasons ).")
497 }
498
500
502
503 (*varut) << variable(proposedId);
504
506
507 return proposedId;
508 }

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

422 {
424 NodeId res;
425
426 try {
428 } catch (Exception const&) {
429 if (newMultiDim != nullptr) delete newMultiDim;
430 throw;
431 }
432
433 return res;
434 }

References addUtilityNode().

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

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

◆ addUtilityNode() [3/3]

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

839 {
841 if (v->domainSize() >= 2)
843 v->name() << " has a domain size >= 2 which is impossible for a utility node")
845 }

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

Here is the call graph for this function:

◆ ancestors() [1/2]

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

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

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

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

Definition at line 135 of file DAGmodel_inl.h.

135{ return dag_.ancestors(id); }

References dag_.

Referenced by ancestors().

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

137 {
138 return ancestors(idFromName(name));
139 }
NodeSet ancestors(const NodeId id) const
returns the set of nodes with directed path ingoing to a given node
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.

References ancestors(), 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(); }

References dag_.

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

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

868 {
869 for (const auto node: nodes())
870 if (isChanceNode(node)) _tensorMap_[node]->beginMultipleChanges();
871 else if (this->isUtilityNode(node)) _utilityMap_[node]->beginMultipleChanges();
872 }
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().

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

395 {
396 return _tensorMap_.size();
397 }

References _tensorMap_.

Referenced by 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 569 of file influenceDiagram_tpl.h.

569 {
570 this->varMap_.changeName(id, new_name);
571 }

References gum::DiscreteGraphicalModel::varMap_.

Referenced by changeVariableName().

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

972 {
974 }
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

Definition at line 95 of file DAGmodel_inl.h.

95{ return dag_.children(id); }

References dag_.

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

Here is the caller graph for this function:

◆ children() [2/4]

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

returns the children of a set of nodes

Definition at line 101 of file DAGmodel_inl.h.

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

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

Here is the call graph for this function:

◆ children() [3/4]

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

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

References children(), 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 97 of file DAGmodel_inl.h.

97 {
98 return dag_.children(idFromName(name));
99 }

◆ clear()

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

References InfluenceDiagram(), clear(), gum::DiscreteGraphicalModel::idFromName(), gum::DiscreteGraphicalModel::nodeId(), gum::DiscreteGraphicalModel::variable(), variable(), gum::DiscreteGraphicalModel::variableFromName(), and gum::DiscreteGraphicalModel::variableNodeMap().

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

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

◆ completeInstantiation()

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

Get an instantiation over all the variables of the model.

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

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

125 {
126 return dag_.connectedComponents();
127 }

References dag_.

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

235 {
236 for (auto node: IDsource.nodes()) {
239 else // decision node
241 }
242 // we add arc in the same order of the tensors
243 for (auto node: IDsource.nodes()) {
244 const auto& s = IDsource.variable(node).name();
246 for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
247 addArc(IDsource.cpt(node).variable(par).name(), s);
248 } else if (IDsource.isUtilityNode(node)) {
249 for (Idx par = 1; par <= IDsource.parents(node).size(); par++)
250 addArc(IDsource.utility(node).variable(par).name(), s);
251 } else { // decision node
252 // here the order does not depend on a Tensor
254 addArc(par, node);
255 }
256 }
257
258 // Copying tensors
259 for (auto node: IDsource.nodes()) {
260 const auto& s = IDsource.variable(node).name();
262 cpt(node).fillWith(IDsource.cpt(s));
263 } else if (IDsource.isUtilityNode(node)) {
264 utility(node).fillWith(IDsource.utility(s));
265 }
266 }
267 }
Size size() const final
Returns the number of variables in this Directed Graphical Model.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual const Tensor< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a tensor variable.
virtual const Tensor< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
const std::string & name() const
returns the name of the variable

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

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

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

◆ cpt() [1/2]

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

343 {
344 return *(_tensorMap_[varId]);
345 }

References _tensorMap_.

Referenced by 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 936 of file influenceDiagram_tpl.h.

936 {
937 return cpt(idFromName(name));
938 }

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

403 {
404 return (size() - _utilityMap_.size() - _tensorMap_.size());
405 }

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

Referenced by toString().

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

◆ decisionOrder()

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

777 {
778 if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists") }
779
781
782 for (const auto elt: topologicalOrder())
783 if (isDecisionNode(elt)) decisionSequence.push_back(elt);
784
785 return decisionSequence;
786 }
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 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 652 of file influenceDiagram_tpl.h.

652 {
654
655 // Finding first decision node
657
658 while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
659 ++orderIter;
660
661 if (orderIter == order.end()) return true;
662
663 NodeId parentDecision = (*orderIter);
664 ++orderIter;
665
666 // Checking path between decisions nodes
667 while (orderIter != order.end()) {
669 if (!existsPathBetween(parentDecision, *orderIter)) return false;
670
672 }
673
674 ++orderIter;
675 }
676
677 return true;
678 }
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.

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

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

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

◆ descendants() [1/2]

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

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

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

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

Definition at line 129 of file DAGmodel_inl.h.

129{ return dag_.descendants(id); }

References dag_.

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

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

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

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

876 {
877 for (const auto node: nodes())
878 if (isChanceNode(node)) _tensorMap_[node]->endMultipleChanges();
879 else if (isUtilityNode(node)) _utilityMap_[node]->endMultipleChanges();
880 }

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

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

562 {
563 erase(this->varMap_.get(var));
564 }

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

536 {
537 if (this->varMap_.exists(varId)) {
538 // Reduce the variable child's CPT or Utility Table if necessary
539 for (const auto chi: dag_.children(varId))
541 else if (isUtilityNode(chi)) _utilityMap_[chi]->erase(variable(varId));
542
543 if (isChanceNode(varId)) {
544 delete _tensorMap_[varId];
545 _tensorMap_.erase(varId);
546 } else if (isUtilityNode(varId)) {
547 delete _utilityMap_[varId];
548 _utilityMap_.erase(varId);
549 }
550
551 this->varMap_.erase(varId);
552 dag_.eraseNode(varId);
553 }
554 }

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

Referenced by 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 966 of file influenceDiagram_tpl.h.

966 {
968 }

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

600 {
601 if (dag_.existsArc(arc)) {
602 NodeId head = arc.head();
603 NodeId tail = arc.tail();
604 dag_.eraseArc(arc);
605
606 if (isChanceNode(head))
607 // Removes parent in the child's CPT
608 (*(_tensorMap_[head])) >> variable(tail);
609 else if (isUtilityNode(head))
610 // Removes parent in the child's UT
611 (*(_utilityMap_[head])) >> variable(tail);
612 }
613 }

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

Referenced by eraseArc(), and eraseArc().

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

◆ eraseArc() [2/3]

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

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

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

982 {
984 }

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

113{ return dag_.exists(node); }

References dag_.

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

115 {
116 return variableNodeMap().exists(name);
117 }
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.

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

References dag_.

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

Here is the caller graph for this function:

◆ existsArc() [2/2]

INLINE bool gum::DAGmodel::existsArc ( 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 684 of file influenceDiagram_tpl.h.

684 {
686 // mark[node] contains 0 if not visited
687 // mark[node] = predecessor if visited
688 NodeProperty< int > mark = dag_.nodesPropertyFromVal(-1);
690
691 mark[src] = (int)src;
692 nodeFIFO.pushBack(src);
693
694 while (!nodeFIFO.empty()) {
695 current = nodeFIFO.front();
696 nodeFIFO.popFront();
697
698 for (const auto new_one: dag_.children(current)) {
699 if (mark[new_one] != -1) continue; // if this node is already marked, continue
700
702
703 if (new_one == dest) break; // if we reach *orderIter, stop.
704
705 nodeFIFO.pushBack(new_one);
706 }
707 }
708
709 if (mark[dest] == -1) return false;
710
711 return true;
712 }
virtual bool empty() const
Return true if this graphical model is empty.

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

Referenced by decisionOrderExists(), and existsPathBetween().

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

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

988 {
990 }

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 }

References _propertiesMap_.

◆ family() [1/2]

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

returns the parents of a node and the node

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

Implements gum::GraphicalModel.

Definition at line 89 of file DAGmodel_inl.h.

89{ return dag_.family(id); }

References dag_.

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

91 {
92 return dag_.family(idFromName(name));
93 }

References dag_, 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 99 of file influenceDiagram_tpl.h.

99 {
100 return fastPrototype(dotlike, "[" + std::to_string(domainSize) + "]");
101 }
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 105 of file influenceDiagram_tpl.h.

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

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

Here is the call graph for this function:

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

741 {
743
746
747 // mark[node] contains false if not visited
748 // mark[node] contains true if visited
749 NodeProperty< bool > mark = dag_.nodesPropertyFromVal(false);
750
751 mark[parentDecision] = true;
752
753 nodeFIFO.pushBack(parentDecision);
754
755 while (!nodeFIFO.empty()) {
756 current = nodeFIFO.front();
757 nodeFIFO.popFront();
758
759 for (const auto new_one: dag_.children(current)) {
760 if (mark[new_one]) continue; // if this node is already marked, continue
761
762 mark[new_one] = true;
763
764 if (!isDecisionNode(new_one)) nodeFIFO.pushBack(new_one);
765 else childrenSeq.insert(new_one);
766 }
767 }
768
769 return childrenSeq;
770 }

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

Referenced by getDecisionGraph().

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

◆ getDecisionGraph()

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

Returns the temporal Graph.

Definition at line 718 of file influenceDiagram_tpl.h.

718 {
720
721 for (const auto node: dag_.nodes()) {
722 if (isDecisionNode(node)) {
723 if (!temporalGraph.existsNode(node)) temporalGraph.addNodeWithId(node);
724
725 for (const auto chi: getChildrenDecision_(node)) {
726 if (!temporalGraph.existsNode(chi)) temporalGraph.addNodeWithId(chi);
727
729 }
730 }
731 }
732
733 return temporalGraph;
734 }
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().

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

793 {
794 if (clear) {
795 _temporalOrder_.clear();
796
798 NodeSet nodeList = dag_.asNodeSet();
799
800 for (auto i: order) {
802
803 for (const auto par: dag_.parents(i)) {
804 if (nodeList.contains(par) && isChanceNode(par)) {
805 partialOrderedSet.insert(par);
807 }
808 }
809
811
813
814 decisionSet.insert(i);
815
816 _temporalOrder_.pushFront(decisionSet);
817 }
818
819 NodeSet lastSet; //= new gum::NodeSet();
820
821 for (const auto node: nodeList)
822 if (isChanceNode(node)) lastSet.insert(node);
823
824 if (!lastSet.empty()) _temporalOrder_.pushFront(lastSet);
825 }
826
827 return _temporalOrder_;
828 }
std::vector< NodeId > decisionOrder() const
Returns the sequence of decision nodes in the directed path.

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

Here is the call graph for this function:

◆ hasSameStructure()

bool gum::DAGmodel::hasSameStructure ( const DAGmodel & other) 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(), 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 379 of file influenceDiagram_tpl.h.

379 {
380 return _tensorMap_.exists(varId);
381 }

References _tensorMap_.

Referenced by addArc(), beginTopologyTransformation(), 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 956 of file influenceDiagram_tpl.h.

956 {
958 }

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

367 {
368 bool ret = true;
369
370 if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
371
372 return ret;
373 }

References isChanceNode(), and isUtilityNode().

Referenced by gum::InfluenceDiagramGenerator< GUM_SCALAR >::_checkTemporalOrder_(), 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 951 of file influenceDiagram_tpl.h.

951 {
953 }

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

156 {
157 return dag_.dSeparation(X, Y, Z);
158 }

References dag_.

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

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

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

152 {
153 return dag_.dSeparation(X, Y, Z);
154 }

Referenced by gum::BayesNet< double >::ancestors(), and isIndependent().

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

180 {
181 return isIndependent(idFromName(Xname), idFromName(Yname), nodeset(Znames));
182 }

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

Here is the call graph for this function:

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

359 {
360 return _utilityMap_.exists(varId);
361 }

References _utilityMap_.

Referenced by addArc(), beginTopologyTransformation(), 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 946 of file influenceDiagram_tpl.h.

946 {
948 }

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

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

◆ minimalCondSet() [1/4]

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

Definition at line 164 of file DAGmodel_inl.h.

164 {
165 return dag_.minimalCondSet(targets, soids);
166 }

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

174 {
175 return dag_.minimalCondSet(nodeset(targets), nodeset(soids));
176 }

◆ minimalCondSet() [3/4]

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

Definition at line 160 of file DAGmodel_inl.h.

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

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

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

169 {
170 return dag_.minimalCondSet(idFromName(target), nodeset(soids));
171 }

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

Here is the call graph for this function:

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

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

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

633 {
634 for (const auto node: dag_.nodes())
635 if (!isUtilityNode(node)) graph.addNodeWithId(node);
636
637 for (const auto node: dag_.nodes()) {
638 if (!isDecisionNode(node))
639 for (const auto par: dag_.parents(node)) {
640 if (isChanceNode(node)) graph.addEdge(node, par);
641
642 for (const auto par2: dag_.parents(node))
643 if (par != par2) graph.addEdge(par, par2);
644 }
645 }
646 }

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

Here is the call graph for this function:

◆ moralizedAncestralGraph() [1/2]

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

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

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

Definition at line 146 of file DAGmodel_inl.h.

146 {
147 auto g = dag_.moralizedAncestralGraph(nodes);
148 _nameNodes_(g);
149 return g;
150 }

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

Referenced by moralizedAncestralGraph().

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

◆ moralizedAncestralGraph() [2/2]

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

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

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

Definition at line 142 of file DAGmodel_inl.h.

142 {
143 return moralizedAncestralGraph(nodeset(nodenames));
144 }
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 119 of file DAGmodel_inl.h.

119 {
120 return static_cast< const NodeGraphPart& >(dag_);
121 }

References dag_.

Referenced by gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_verticesSampling_(), gum::BayesNet< GUM_SCALAR >::beginTopologyTransformation(), gum::InfluenceDiagram< GUM_SCALAR >::beginTopologyTransformation(), gum::IBayesNet< GUM_SCALAR >::check(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::BayesNet< GUM_SCALAR >::clear(), gum::InfluenceDiagram< GUM_SCALAR >::copyStructureAndTables_(), gum::IBayesNet< GUM_SCALAR >::dim(), gum::BayesNet< GUM_SCALAR >::endTopologyTransformation(), gum::InfluenceDiagram< GUM_SCALAR >::endTopologyTransformation(), gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype(), gum::BayesNet< GUM_SCALAR >::generateCPTs(), gum::getMaxModality(), hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::log2JointProbability(), gum::IBayesNet< GUM_SCALAR >::maxParam(), gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize(), gum::IBayesNet< GUM_SCALAR >::minParam(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), moralizedAncestralGraph(), 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.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

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

Referenced by gum::BayesNet< double >::ancestors(), gum::DAGmodel::children(), gum::DAGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::DAGmodel::minimalCondSet(), and gum::DAGmodel::moralizedAncestralGraph().

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

199 {
200 if (this != &source) {
201 clear();
202 // Copying tables and structure
204 }
205
206 return *this;
207 }

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

173 {
174 if (this != &source) {
181 }
182 return *this;
183 }
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 883 of file influenceDiagram_tpl.h.

883 {
884 if (size() != from.size()) { return false; }
885
886 if (sizeArcs() != from.sizeArcs()) { return false; }
887
888 // alignment of variables between the 2 BNs
890
891 for (auto node: nodes()) {
892 const auto& v1 = variable(node);
893 if (!from.exists(v1.name())) return false;
894 const auto& v2 = from.variableFromName(v1.name());
895 if (v1 != v2) { return false; }
896
897 if (isChanceNode(v1.name()) && !from.isChanceNode(v2.name())) { return false; }
898 if (isUtilityNode(v1.name()) && !from.isUtilityNode(v2.name())) { return false; }
899 if (isDecisionNode(v1.name()) && !from.isDecisionNode(v2.name())) { return false; }
900
901 alignment.insert(&variable(node), &from.variableFromName(v1.name()));
902 }
903
904 auto check_pot
905 = [&](const gum::Tensor< GUM_SCALAR >& p1, const gum::Tensor< GUM_SCALAR >& p2) -> bool {
906 if (p1.nbrDim() != p2.nbrDim()) { return false; }
907
908 if (p1.domainSize() != p2.domainSize()) { return false; }
909
912
913 for (i.setFirst(); !i.end(); i.inc()) {
914 for (Idx indice = 0; indice < p1.nbrDim(); ++indice) {
915 const DiscreteVariable* p = &(i.variable(indice));
916 j.chgVal(*(alignment.second(p)), i.val(*p));
917 }
918
919 if (std::pow(p1.get(i) - p2.get(j), (GUM_SCALAR)2) > (GUM_SCALAR)1e-6) { return false; }
920 }
921 return true;
922 };
923 for (auto node: nodes()) {
925 if (isChanceNode(node)) {
926 if (!check_pot(cpt(node), from.cpt(fromnode))) { return false; }
927 } else if (isUtilityNode(node)) {
928 if (!check_pot(utility(node), from.utility(fromnode))) { return false; }
929 }
930 }
931
932 return true;
933 }
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(), cpt(), gum::MultiDimDecorator< GUM_ELEMENT >::domainSize(), gum::Instantiation::end(), 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

Definition at line 83 of file DAGmodel_inl.h.

83{ return dag_.parents(id); }

References dag_.

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_(), parents(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot().

Here is the caller graph for this function:

◆ parents() [2/4]

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

returns the parents of a set of nodes

Definition at line 107 of file DAGmodel_inl.h.

107{ return dag_.parents(ids); }

References dag_, and 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 109 of file DAGmodel_inl.h.

109 {
110 return parents(nodeset(names));
111 }

References gum::GraphicalModel::names().

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

85 {
86 return parents(idFromName(name));
87 }

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

Here is the call graph for this function:

◆ properties()

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

List of all the 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_.

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

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

223 {
224 for (const auto& [node, tensor]: _tensorMap_)
225 delete tensor;
226 for (const auto& [node, tensor]: _utilityMap_)
227 delete tensor;
228 }

References _tensorMap_, and _utilityMap_.

Referenced by ~InfluenceDiagram(), 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 }

References _propertiesMap_.

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

Here is the caller graph for this function:

◆ size()

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

Returns the number of variables in this Directed Graphical Model.

Implements gum::GraphicalModel.

Definition at line 68 of file DAGmodel_inl.h.

68{ return dag_.size(); }

References dag_.

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 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(); }

References dag_.

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

◆ toDot()

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

270 {
276
277 output << std::format("digraph \"{}\" {{\n", this->propertyWithDefault("name", "no_name"));
278
279 output << " node [bgcolor=\"#AAAAAA\", style=filled, height=0];" << std::endl;
280
281 decisionNode << "node [shape = box];" << std::endl;
282
283 utilityNode << "node [shape = hexagon, margin=0];" << std::endl;
284 chanceNode << "node [shape = ellipse];" << std::endl;
285 std::string tab = " ";
286
287 for (const auto node: dag_.nodes()) {
288 if (isChanceNode(node))
289 chanceNode << std::format(" \"{}-{}\";", node, variable(node).name());
290 else if (isUtilityNode(node))
291 utilityNode << std::format(" \"{}-{}\";", node, variable(node).name());
292 else decisionNode << std::format(" \"{}-{}\";", node, variable(node).name());
293
294 if (dag_.children(node).size() > 0)
295 for (const auto chi: dag_.children(node)) {
296 arcstream << std::format("\"{}-{}\" -> \"{}-{}\"",
297 node,
298 variable(node).name(),
299 chi,
300 variable(chi).name());
301 if (isDecisionNode(chi)) { arcstream << " [style=\"tapered, bold\"]"; }
302 arcstream << ";\n";
303 }
304 }
305
306 output << decisionNode.str() << std::endl
307 << utilityNode.str() << std::endl
308 << chanceNode.str() << std::endl
309 << std::endl
310 << arcstream.str() << std::endl
311 << "}" << std::endl;
312
313 return output.str();
314 }
const std::string & propertyWithDefault(std::string_view name, const std::string &byDefault) const
Return the value of the property name of this GraphicalModel.

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

Here is the call graph for this function:

◆ topologicalOrder()

INLINE Sequence< NodeId > gum::DAGmodel::topologicalOrder ( ) const
inherited

The topological order stays the same as long as no variable or arcs are added or erased src the topology.

Parameters
clearIf false returns the previously created topology.

Definition at line 123 of file DAGmodel_inl.h.

123{ return dag_.topologicalOrder(); }

References dag_.

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

Here is the caller graph for this function:

◆ toString()

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

Definition at line 317 of file influenceDiagram_tpl.h.

317 {
319
320 output << "Influence Diagram{" << std::endl;
321 output << std::format(" chance: {},\n", chanceNodeSize());
322 output << std::format(" utility: {},\n", utilityNodeSize());
323 output << std::format(" decision: {},\n", decisionNodeSize());
324 output << std::format(" arcs: {},\n", dag().sizeArcs());
325
326 if (double dSize = log10DomainSize(); dSize > 6)
327 output << std::format(" domainSize: 10^{}", dSize);
328 else output << std::format(" domainSize: {}", std::round(std::pow(10.0, dSize)));
329
330 output << std::endl << "}";
331
332 return output.str();
333 }
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_.

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

351 {
352 return *(_utilityMap_[varId]);
353 }

References _utilityMap_.

Referenced by 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 941 of file influenceDiagram_tpl.h.

941 {
942 return utility(idFromName(name));
943 }

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

387 {
388 return _utilityMap_.size();
389 }

References _utilityMap_.

Referenced by 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 961 of file influenceDiagram_tpl.h.

961 {
962 return variable(idFromName(name));
963 }

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

Here is the call graph for this function:

Member Data Documentation

◆ _propertiesMap_

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

The properties of this Directed Graphical Model.

Definition at line 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 527 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

◆ varMap_


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