![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
This class decorates an PRMInstance<GUM_SCALAR> as an IBaseBayesNet. More...
#include <agrum/PRM/instanceBayesNet.h>
Public Member Functions | |
bool | operator== (const IBayesNet< GUM_SCALAR > &from) const |
This operator compares 2 BNs ! More... | |
bool | operator!= (const IBayesNet< GUM_SCALAR > &from) const |
Size | dim () const |
Returns the dimension (the number of free parameters) in this bayes net. More... | |
Size | maxVarDomainSize () const |
GUM_SCALAR | minParam () const |
GUM_SCALAR | maxParam () const |
GUM_SCALAR | minNonZeroParam () const |
GUM_SCALAR | maxNonOneParam () const |
std::string | toString () const |
NodeSet | minimalCondSet (NodeId target, const NodeSet &soids) const |
NodeSet | minimalCondSet (const NodeSet &targets, const NodeSet &soids) const |
bool | hasSameStructure (const DAGmodel &other) |
double | log10DomainSize () const |
Constructors & destructor. | |
InstanceBayesNet (const PRMInstance< GUM_SCALAR > &i) | |
Default constructor. More... | |
InstanceBayesNet (const InstanceBayesNet &from) | |
Copy constructor. More... | |
InstanceBayesNet & | operator= (const InstanceBayesNet &from) |
Copy operator. More... | |
virtual | ~InstanceBayesNet () |
Destructor. More... | |
Variable manipulation methods. | |
virtual const Potential< GUM_SCALAR > & | cpt (NodeId varId) const |
See gum::IBaseBayesNet::cpt(). More... | |
virtual const VariableNodeMap & | variableNodeMap () const |
See gum::IBaseBayesNet::variableNodeMap(). More... | |
virtual const DiscreteVariable & | variable (NodeId id) const |
See gum::IBaseBayesNet::variable(). More... | |
virtual NodeId | nodeId (const DiscreteVariable &var) const |
See gum::IBaseBayesNet::nodeId(). More... | |
virtual NodeId | idFromName (const std::string &name) const |
See gum::IBaseBayesNet::idFromName(). More... | |
virtual const DiscreteVariable & | variableFromName (const std::string &name) const |
See gum::IBaseBayesNet::variableFromName(). More... | |
const NodeProperty< Size > & | modalities () const |
See gum::IBaseBayesNet::cpt(). More... | |
Graphical methods | |
virtual std::string | toDot () const |
Joint Probability manipulation methods | |
GUM_SCALAR | jointProbability (const Instantiation &i) const |
Compute a parameter of the joint probability for the BN (given an instantiation of the vars) More... | |
GUM_SCALAR | log2JointProbability (const Instantiation &i) const |
Compute a parameter of the log joint probability for the BN (given an instantiation of the vars) 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... | |
Variable manipulation methods. | |
bool | exists (const std::string &name) const |
Return true if this graphical model is empty. More... | |
virtual bool | empty () 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... | |
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... | |
Protected Attributes | |
DAG | dag_ |
The DAG of this Directed Graphical Model. More... | |
This class decorates an PRMInstance<GUM_SCALAR> as an IBaseBayesNet.
Remember that an InstanceBayesNet does not contain input nodes parents and output nodes children. Thus you should be careful when using one of the BayesNetInference over a InstanceBayesNet since some variables are missing in the DAG but not in the nodes CPT.
Definition at line 56 of file instanceBayesNet.h.
INLINE gum::prm::InstanceBayesNet< GUM_SCALAR >::InstanceBayesNet | ( | const PRMInstance< GUM_SCALAR > & | i | ) |
Default constructor.
i | The PRMInstance<GUM_SCALAR> decorated by this InstanceBayesNet. |
Definition at line 57 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
INLINE gum::prm::InstanceBayesNet< GUM_SCALAR >::InstanceBayesNet | ( | const InstanceBayesNet< GUM_SCALAR > & | from | ) |
Copy constructor.
Definition at line 64 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
virtual |
Destructor.
Definition at line 70 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
private |
Private getter with type checking in case the id is not a formal PRMAttribute<GUM_SCALAR>.
NotFound | Raised if id is not a formal attribute. |
Definition at line 119 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
private |
Definition at line 125 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
private |
Definition at line 35 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
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().
|
inherited |
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().
|
inherited |
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().
|
inherited |
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().
|
inherited |
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.
|
virtual |
See gum::IBaseBayesNet::cpt().
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 87 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
inherited |
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().
|
inherited |
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().
|
inherited |
Returns the dimension (the number of free parameters) in this bayes net.
\( dim(G)=\sum_{i \in nodes} ((r_i-1)\cdot q_i) \) where \( r_i \) is the number of instantiations of node \( i \) and \( q_i \) is the number of instantiations of its parents.
Definition at line 78 of file IBayesNet_tpl.h.
|
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().
|
inherited |
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().
|
inherited |
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().
|
virtual |
See gum::IBaseBayesNet::idFromName().
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 107 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
inherited |
transform a vector of names into a vector of nodeId
Definition at line 117 of file graphicalModel_inl.h.
|
finalvirtualinherited |
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().
|
finalvirtualinherited |
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().
|
inlineinherited |
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.
|
inlineinherited |
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 |
Compute a parameter of the joint probability for the BN (given an instantiation of the vars)
Definition at line 207 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 73 of file graphicalModel_inl.h.
|
inherited |
Compute a parameter of the log joint probability for the BN (given an instantiation of the vars)
Compute a parameter of the joint probability for the BN (given an instantiation of the vars)
Definition at line 225 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 134 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 114 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 94 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 332 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 349 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 124 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 104 of file IBayesNet_tpl.h.
INLINE const NodeProperty< Size > & gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities | ( | ) | const |
See gum::IBaseBayesNet::cpt().
Definition at line 132 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
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().
|
inherited |
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.
|
virtual |
See gum::IBaseBayesNet::nodeId().
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 102 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
finalvirtualinherited |
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().
|
inherited |
Definition at line 286 of file IBayesNet_tpl.h.
INLINE InstanceBayesNet< GUM_SCALAR > & gum::prm::InstanceBayesNet< GUM_SCALAR >::operator= | ( | const InstanceBayesNet< GUM_SCALAR > & | from | ) |
Copy operator.
Definition at line 76 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
inherited |
This operator compares 2 BNs !
Definition at line 242 of file IBayesNet_tpl.h.
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().
|
inherited |
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().
|
inherited |
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.
|
finalvirtualinherited |
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().
|
inherited |
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().
|
virtual |
Reimplemented from gum::IBayesNet< GUM_SCALAR >.
Definition at line 143 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
inherited |
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().
|
inherited |
Definition at line 144 of file IBayesNet_tpl.h.
|
virtual |
See gum::IBaseBayesNet::variable().
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 97 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
virtual |
See gum::IBaseBayesNet::variableFromName().
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 113 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
virtual |
See gum::IBaseBayesNet::variableNodeMap().
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 92 of file instanceBayesNet_tpl.h.
References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().
|
private |
The PRMClassElementContainer decorated by this.
Definition at line 124 of file instanceBayesNet.h.
|
mutableprivate |
Definition at line 126 of file instanceBayesNet.h.
|
private |
Mapping between DiscreteVariable and their NodeId.
Definition at line 114 of file instanceBayesNet.h.
|
protectedinherited |
The DAG of this Directed Graphical Model.
Definition at line 222 of file DAGmodel.h.