![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Virtual base class for PGMs using a DAG. More...
#include <agrum/tools/graphicalModels/DAGmodel.h>
Public Member Functions | |
bool | hasSameStructure (const DAGmodel &other) |
double | log10DomainSize () const |
Constructors / Destructors | |
DAGmodel () | |
Default constructor. More... | |
virtual | ~DAGmodel () |
Destructor. More... | |
DAGmodel (const DAGmodel &source) | |
Copy constructor. More... | |
Variable manipulation methods. | |
const DAG & | dag () const |
Returns a constant reference to the dag of this Bayes Net. More... | |
virtual Size | size () const final |
Returns the number of variables in this Directed Graphical Model. More... | |
Size | sizeArcs () const |
Returns the number of arcs in this Directed Graphical Model. More... | |
const NodeGraphPart & | nodes () const final |
Returns a constant reference to the dag of this Bayes Net. More... | |
bool | exists (NodeId node) const final |
Return true if this node exists in this graphical model. More... | |
Arc manipulation methods. | |
const ArcSet & | arcs () const |
return true if the arc tail->head exists in the DAGmodel More... | |
bool | existsArc (const NodeId tail, const NodeId head) const |
return true if the arc tail->head exists in the DAGmodel More... | |
bool | existsArc (const std::string &nametail, const std::string &namehead) const |
return true if the arc tail->head exists in the DAGmodel More... | |
const NodeSet & | parents (const NodeId id) const |
returns the set of nodes with arc ingoing to a given node More... | |
const NodeSet & | parents (const std::string &name) const |
return true if the arc tail->head exists in the DAGmodel More... | |
NodeSet | parents (const NodeSet &ids) const |
returns the parents of a set of nodes More... | |
NodeSet | parents (const std::vector< std::string > &names) const |
return true if the arc tail->head exists in the DAGmodel More... | |
NodeSet | family (const NodeId id) const |
returns the parents of a node and the node More... | |
NodeSet | family (const std::string &name) const |
return true if the arc tail->head exists in the DAGmodel More... | |
const NodeSet & | children (const NodeId id) const |
returns the set of nodes with arc outgoing from a given node More... | |
const NodeSet & | children (const std::string &name) const |
return true if the arc tail->head exists in the DAGmodel More... | |
NodeSet | children (const NodeSet &ids) const |
returns the children of a set of nodes More... | |
NodeSet | children (const std::vector< std::string > &names) const |
return true if the arc tail->head exists in the DAGmodel More... | |
NodeSet | descendants (const NodeId id) const |
returns the set of nodes with directed path outgoing from a given node More... | |
NodeSet | descendants (const std::string &name) const |
return true if the arc tail->head exists in the DAGmodel More... | |
NodeSet | ancestors (const NodeId id) const |
returns the set of nodes with directed path ingoing to a given node More... | |
NodeSet | ancestors (const std::string &name) const |
return true if the arc tail->head exists in the DAGmodel More... | |
Graphical methods | |
UndiGraph | moralizedAncestralGraph (const NodeSet &nodes) const |
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More... | |
UndiGraph | moralizedAncestralGraph (const std::vector< std::string > &nodenames) const |
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More... | |
bool | isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const final |
check if node X and node Y are independent given nodes Z More... | |
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 More... | |
bool | isIndependent (const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const |
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes More... | |
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 More... | |
const UndiGraph & | moralGraph (bool clear=true) const |
The node's id are coherent with the variables and nodes of the topology. More... | |
const Sequence< NodeId > & | topologicalOrder (bool clear=true) const |
The topological order stays the same as long as no variable or arcs are added or erased src the topology. More... | |
Getter and setters | |
const std::string & | property (const std::string &name) const |
Return the value of the property name of this GraphicalModel. More... | |
const std::string & | propertyWithDefault (const std::string &name, const std::string &byDefault) const |
Return the value of the property name of this GraphicalModel. More... | |
void | setProperty (const std::string &name, const std::string &value) |
Add or change a property of this GraphicalModel. More... | |
Variable manipulation methods. | |
virtual const VariableNodeMap & | variableNodeMap () const =0 |
Returns a constant reference to the VariableNodeMap of this Graphical Model. More... | |
virtual bool | empty () const |
Return true if this graphical model is empty. More... | |
bool | exists (const std::string &name) const |
Return true if this graphical model is empty. More... | |
std::vector< std::string > | names (const std::vector< NodeId > &ids) const |
transform a vector of NodeId in a vector of names More... | |
std::vector< std::string > | names (const NodeSet &ids) const |
transform a NodeSet in a vector of names More... | |
std::vector< NodeId > | ids (const std::vector< std::string > &names) const |
transform a vector of names into a vector of nodeId More... | |
NodeSet | nodeset (const std::vector< std::string > &names) const |
transform a vector of names into a NodeSet More... | |
Instantiation | completeInstantiation () const |
Get an instantiation over all the variables of the model. More... | |
virtual const DiscreteVariable & | variable (NodeId id) const =0 |
Returns a constant reference over a variable given it's node id. More... | |
virtual NodeId | nodeId (const DiscreteVariable &var) const =0 |
Return id node src discrete var pointer. More... | |
virtual NodeId | idFromName (const std::string &name) const =0 |
Getter by name. More... | |
virtual const DiscreteVariable & | variableFromName (const std::string &name) const =0 |
Getter by name. More... | |
Protected Attributes | |
DAG | dag_ |
The DAG of this Directed Graphical Model. More... | |
Protected Member Functions | |
DAGmodel & | operator= (const DAGmodel &source) |
Private copy operator. More... | |
Virtual base class for PGMs using a DAG.
Definition at line 47 of file DAGmodel.h.
gum::DAGmodel::DAGmodel | ( | ) |
Default constructor.
Definition at line 29 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
|
virtual |
Destructor.
Definition at line 35 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::DAGmodel::DAGmodel | ( | const DAGmodel & | source | ) |
Copy constructor.
Do nothing.
Definition at line 31 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
|
private |
Returns the moral graph of this DAGModel.
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.
id | the node which is the head of a directed path with the returned nodes |
name | the name of the node which is the head of a directed path with the returned nodes |
Definition at line 96 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE NodeSet gum::DAGmodel::ancestors | ( | const std::string & | name | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 98 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE const ArcSet & gum::DAGmodel::arcs | ( | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 43 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
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.
id | the node which is the tail of an arc with the returned nodes |
name | the name of the node which is the tail of an arc with the returned nodes |
Definition at line 65 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE const NodeSet & gum::DAGmodel::children | ( | const std::string & | name | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 66 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
returns the children of a set of nodes
Definition at line 70 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE NodeSet gum::DAGmodel::children | ( | const std::vector< std::string > & | names | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 72 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Get an instantiation over all the variables of the model.
Definition at line 84 of file graphicalModel_inl.h.
INLINE const DAG & gum::DAGmodel::dag | ( | ) | const |
Returns a constant reference to the dag of this Bayes Net.
Definition at line 35 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
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.
id | the node which is the tail of a directed path with the returned nodes |
name | the name of the node which is the tail of a directed path with the returned nodes |
Definition at line 90 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE NodeSet gum::DAGmodel::descendants | ( | const std::string & | name | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 92 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
Return true if this graphical model is empty.
Definition at line 94 of file graphicalModel_inl.h.
Return true if this node exists in this graphical model.
Implements gum::GraphicalModel.
Definition at line 82 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inlineinherited |
Return true if this graphical model is empty.
Definition at line 112 of file graphicalModel.h.
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 45 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE bool gum::DAGmodel::existsArc | ( | const std::string & | nametail, |
const std::string & | namehead | ||
) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 49 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
returns the parents of a node and the node
Note that the set of nodes returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.
id | the node which is the head of an arc with the returned nodes |
name | the name of the node the node which is the head of an arc with the returned nodes |
Definition at line 59 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE NodeSet gum::DAGmodel::family | ( | const std::string & | name | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 61 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
Definition at line 69 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
|
pure virtualinherited |
Getter by name.
NotFound | if no such name exists in the graph. |
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IMarkovNet< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
|
inherited |
transform a vector of names into a vector of nodeId
Definition at line 117 of file graphicalModel_inl.h.
|
finalvirtual |
check if node X and node Y are independent given nodes Z
Implements gum::GraphicalModel.
Definition at line 113 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
finalvirtual |
check if nodes X and nodes Y are independent given nodes Z
Implements gum::GraphicalModel.
Definition at line 117 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inline |
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
nodes | the set of nodeId |
nodenames | the vector of names of nodes |
Definition at line 185 of file DAGmodel.h.
|
inline |
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
nodes | the set of nodeId |
nodenames | the vector of names of nodes |
Definition at line 191 of file DAGmodel.h.
|
inherited |
Definition at line 73 of file graphicalModel_inl.h.
The node's id are coherent with the variables and nodes of the topology.
clear | If false returns the previously created moral graph. |
Definition at line 55 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
nodes | the set of nodeId |
nodenames | the vector of names of nodes |
Definition at line 109 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE UndiGraph gum::DAGmodel::moralizedAncestralGraph | ( | const std::vector< std::string > & | nodenames | ) | const |
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
nodes | the set of nodeId |
nodenames | the vector of names of nodes |
Definition at line 104 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
transform a vector of NodeId in a vector of names
Definition at line 97 of file graphicalModel_inl.h.
|
inherited |
transform a NodeSet in a vector of names
Definition at line 107 of file graphicalModel_inl.h.
|
pure virtualinherited |
Return id node src discrete var pointer.
NotFound | If no variable matches var. |
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IMarkovNet< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
|
finalvirtual |
Returns a constant reference to the dag of this Bayes Net.
Implements gum::GraphicalModel.
Definition at line 84 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
transform a vector of names into a NodeSet
Definition at line 58 of file graphicalModel.cpp.
References gum::Set< Key, Alloc >::emplace().
Private copy operator.
Definition at line 41 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
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.
id | the node which is the head of an arc with the returned nodes |
name | the name of the node the node which is the head of an arc with the returned nodes |
Definition at line 53 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE const NodeSet & gum::DAGmodel::parents | ( | const std::string & | name | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 55 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
returns the parents of a set of nodes
Definition at line 76 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE NodeSet gum::DAGmodel::parents | ( | const std::vector< std::string > & | names | ) | const |
return true if the arc tail->head exists in the DAGmodel
tail | the nodeId (or the name) of the tail in tail->head |
head | the nodeId (or the name) of the head in tail->head |
Definition at line 78 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Return the value of the property name of this GraphicalModel.
NotFound | Raised if no name property is found. |
Definition at line 38 of file graphicalModel_inl.h.
|
inherited |
Return the value of the property name of this GraphicalModel.
return byDefault if the property name is not found
Definition at line 57 of file graphicalModel_inl.h.
|
inherited |
Add or change a property of this GraphicalModel.
Definition at line 65 of file graphicalModel_inl.h.
|
finalvirtual |
Returns the number of variables in this Directed Graphical Model.
Implements gum::GraphicalModel.
Definition at line 38 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Size gum::DAGmodel::sizeArcs | ( | ) | const |
Returns the number of arcs in this Directed Graphical Model.
Definition at line 41 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
The topological order stays the same as long as no variable or arcs are added or erased src the topology.
clear | If false returns the previously created topology. |
Definition at line 86 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
pure virtualinherited |
Returns a constant reference over a variable given it's node id.
NotFound | If no variable's id matches varId. |
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IMarkovNet< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
|
pure virtualinherited |
Getter by name.
NotFound | if no such name exists in the graph. |
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IMarkovNet< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
|
pure virtualinherited |
Returns a constant reference to the VariableNodeMap of this Graphical Model.
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::InfluenceDiagram< GUM_SCALAR >, gum::BayesNetFragment< GUM_SCALAR >, gum::IMarkovNet< GUM_SCALAR >, gum::IBayesNet< GUM_SCALAR >, gum::IBayesNet< double >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
|
mutableprivate |
The moral graph of this Directed Graphical Model.
Definition at line 230 of file DAGmodel.h.
|
protected |
The DAG of this Directed Graphical Model.
Definition at line 222 of file DAGmodel.h.