![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
Class representing the minimal interface for Markov random field. More...
#include <agrum/BN/IMarkovRandomField.h>
Public Member Functions | |
| bool | operator== (const IMarkovRandomField< GUM_SCALAR > &from) const |
| This operator compares 2 BNs ! | |
| bool | operator!= (const IMarkovRandomField< GUM_SCALAR > &from) const |
| Size | dim () const |
| Returns the dimension (the number of free parameters) in this bayes net. | |
| Size | maxVarDomainSize () const |
| GUM_SCALAR | minParam () const |
| GUM_SCALAR | maxParam () const |
| GUM_SCALAR | minNonZeroParam () const |
| GUM_SCALAR | maxNonOneParam () const |
| virtual std::string | toDot () const |
| virtual std::string | toDotAsFactorGraph () 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 UGmodel &other) |
| check if nodes X and nodes Y are independent given nodes Z | |
| NodeSet | family (const NodeId id) const final |
| returns the the node as a NodeSet (in mixed graph : family is the node and its parents | |
| NodeSet | family (const std::string &name) const final |
| double | log10DomainSize () const |
Constructors / Destructors | |
| IMarkovRandomField () | |
| Default constructor. | |
| IMarkovRandomField (std::string name) | |
| Default constructor. | |
| virtual | ~IMarkovRandomField () |
| Destructor. | |
| IMarkovRandomField (const IMarkovRandomField< GUM_SCALAR > &source) | |
| Copy constructor. | |
| IMarkovRandomField< GUM_SCALAR > & | operator= (const IMarkovRandomField< GUM_SCALAR > &source) |
| Copy operator. | |
Pure Virtual methods | |
| virtual const Tensor< GUM_SCALAR > & | factor (const NodeSet &varIds) const =0 |
| Returns the factor of a set of variable. | |
| virtual const NodeSet & | smallestFactorFromNode (NodeId node) const =0 |
| Returns the smallest factor that contains this variable. | |
| virtual const NodeSet & | smallestFactorFromNode (const std::string &name) const |
| Returns the smallest factor that contains this variable. | |
| virtual const FactorTable< GUM_SCALAR > & | factors () const =0 |
| Returns the set of factors as a IMarkovRandomField::FactorTable. | |
| virtual const VariableNodeMap & | variableNodeMap () const =0 |
| Returns a constant reference to the VariableNodeMap of thisBN. | |
| virtual const DiscreteVariable & | variable (NodeId id) const =0 |
| Returns a constant reference over a variable given it's node id. | |
| virtual NodeId | nodeId (const DiscreteVariable &var) const =0 |
| Return id node from discrete var pointer. | |
| virtual NodeId | idFromName (const std::string &name) const =0 |
| Getter by name. | |
| virtual const DiscreteVariable & | variableFromName (const std::string &name) const =0 |
| Getter by name. | |
Variable manipulation methods. | |
| const UndiGraph & | graph () const |
| Returns a constant reference to the dag of this Bayes Net. | |
| virtual Size | size () const final |
| Returns the number of variables in this Directed Graphical Model. | |
| Size | sizeEdges () const |
| Returns the number of arcs in this Directed Graphical Model. | |
| const NodeGraphPart & | nodes () const final |
| Returns a constant reference to the dag of this Bayes Net. | |
| bool | exists (NodeId node) const final |
| Return true if this node exists in this graphical model. | |
| bool | exists (const std::string &name) const final |
| Returns a constant reference to the dag of this Bayes Net. | |
Edge manipulation methods. | |
| const EdgeSet & | edges () const |
| return true if the edge node1-node2 exists in the UGModel | |
| bool | existsEdge (const NodeId node1, const NodeId node2) const |
| return true if the edge node1-node2 exists in the UGModel | |
| bool | existsEdge (const std::string &name1, const std::string &name2) const |
| return true if the edge node1-node2 exists in the UGModel | |
| const NodeSet & | neighbours (const NodeId id) const |
| returns the neighbours of a node as set of nodes | |
| const NodeSet & | neighbours (const std::string &name) const |
| return true if the edge node1-node2 exists in the UGModel | |
| bool | isIndependent (NodeId X, NodeId Y, const NodeSet &Z) const final |
| check if X and Y are independent given Z | |
| bool | isIndependent (const NodeSet &X, const NodeSet &Y, const NodeSet &Z) const final |
| check if nodes X and nodes Y are independent given nodes Z | |
| bool | isIndependent (const std::string &Xname, const std::string &Yname, const std::vector< std::string > &Znames) const |
| return true if the edge node1-node2 exists in the UGModel | |
| bool | isIndependent (const std::vector< std::string > &Xnames, const std::vector< std::string > &Ynames, const std::vector< std::string > &Znames) const |
| return true if the edge node1-node2 exists in the UGModel | |
Getter and setters | |
| const std::string & | property (const std::string &name) const |
| Return the value of the property name of this GraphicalModel. | |
| const std::string & | propertyWithDefault (const std::string &name, const std::string &byDefault) const |
| Return the value of the property name of this GraphicalModel. | |
| void | setProperty (const std::string &name, const std::string &value) |
| Add or change a property of this GraphicalModel. | |
| std::vector< std::string > | properties () const |
| List of all the properties. | |
Variable manipulation methods. | |
| virtual bool | empty () const |
| Return true if this graphical model is empty. | |
| std::vector< std::string > | names (const std::vector< NodeId > &ids) const |
| transform a vector of NodeId in a vector of names | |
| std::vector< std::string > | names (const NodeSet &ids) const |
| transform a NodeSet in a vector of names | |
| std::vector< NodeId > | ids (const std::vector< std::string > &names) const |
| transform a vector of names into a vector of nodeId | |
| NodeSet | nodeset (const std::vector< std::string > &names) const |
| transform a vector of names into a NodeSet | |
| gum::VariableSet | variables (const std::vector< std::string > &l) const |
| transform a vector of names into a VariableeSet | |
| gum::VariableSet | variables (const NodeSet &ids) const |
| transform a vector of NodeId into a VariableeSet | |
| Instantiation | completeInstantiation () const |
| Get an instantiation over all the variables of the model. | |
Static Public Member Functions | |
| static void | spaceCplxToStream (std::stringstream &s, double dSize, int dim, Size usedMem) |
| send to the stream the space complexity with 3 parametrs | |
Protected Attributes | |
| UndiGraph | graph_ |
| The DAG of this Directed Graphical Model. | |
Private Member Functions | |
| void | _minimalCondSetVisit_ (NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisited) const |
| const HashTable< std::string, std::string > & | _properties_ () const |
| Return the properties of this Directed Graphical Model. | |
Private Attributes | |
| HashTable< std::string, std::string > | _propertiesMap_ |
| The properties of this Directed Graphical Model. | |
Class representing the minimal interface for Markov random field.
This class is used as a base class for different versions of Markov random fields. No data (except the graph herited from UGModel are included in this class. Many algorithms (inference for instance) may use this class when a simple MRF is needed.
Definition at line 75 of file IMarkovRandomField.h.
| INLINE gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField | ( | ) |
Default constructor.
Definition at line 62 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField(), and gum::UGmodel::UGmodel().
Referenced by IMarkovRandomField(), IMarkovRandomField(), IMarkovRandomField(), ~IMarkovRandomField(), operator!=(), operator=(), operator==(), and variableFromName().
|
explicit |
Default constructor.
Definition at line 67 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField(), gum::UGmodel::UGmodel(), and gum::GraphicalModel::setProperty().
|
virtual |
Destructor.
Definition at line 87 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField().
| gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField | ( | const IMarkovRandomField< GUM_SCALAR > & | source | ) |
Copy constructor.
Definition at line 73 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField(), and gum::UGmodel::UGmodel().
|
private |
Definition at line 336 of file IMarkovRandomField_tpl.h.
References _minimalCondSetVisit_(), gum::Set< Key >::contains(), and gum::UGmodel::graph_.
Referenced by _minimalCondSetVisit_(), and minimalCondSet().
|
privateinherited |
Return the properties of this Directed Graphical Model.
Definition at line 70 of file graphicalModel_inl.h.
References _propertiesMap_.
Referenced by property().
|
inherited |
Get an instantiation over all the variables of the model.
Definition at line 106 of file graphicalModel_inl.h.
References nodes().
| INLINE Size gum::IMarkovRandomField< GUM_SCALAR >::dim | ( | ) | const |
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 92 of file IMarkovRandomField_tpl.h.
References factors().
|
inherited |
return true if the edge node1-node2 exists in the UGModel
| node1 | the nodeId (or the name) of the node1 |
| node2 | the nodeId (or the name) of the node2 |
Definition at line 65 of file UGmodel_inl.h.
References graph_.
Referenced by hasSameStructure().
|
virtualinherited |
Return true if this graphical model is empty.
Definition at line 116 of file graphicalModel_inl.h.
References size().
Referenced by gum::IBayesNet< GUM_SCALAR >::check(), and gum::BayesNet< GUM_SCALAR >::clear().
|
finalvirtualinherited |
Returns a constant reference to the dag of this Bayes Net.
Implements gum::GraphicalModel.
Definition at line 83 of file UGmodel_inl.h.
References exists(), and gum::GraphicalModel::idFromName().
Return true if this node exists in this graphical model.
Implements gum::GraphicalModel.
Definition at line 81 of file UGmodel_inl.h.
References graph_.
Referenced by exists().
return true if the edge node1-node2 exists in the UGModel
| node1 | the nodeId (or the name) of the node1 |
| node2 | the nodeId (or the name) of the node2 |
Definition at line 67 of file UGmodel_inl.h.
References graph_.
Referenced by existsEdge().
|
inherited |
return true if the edge node1-node2 exists in the UGModel
| node1 | the nodeId (or the name) of the node1 |
| node2 | the nodeId (or the name) of the node2 |
Definition at line 71 of file UGmodel_inl.h.
References existsEdge(), and gum::GraphicalModel::idFromName().
|
pure virtual |
Returns the factor of a set of variable.
| NotFound | If no variable's id matches varId. |
Referenced by operator==(), and toString().
|
pure virtual |
Returns the set of factors as a IMarkovRandomField::FactorTable.
Referenced by dim(), maxNonOneParam(), maxParam(), minNonZeroParam(), minParam(), operator==(), toDotAsFactorGraph(), and toString().
returns the the node as a NodeSet (in mixed graph : family is the node and its parents
| 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 |
Implements gum::GraphicalModel.
Definition at line 99 of file UGmodel_inl.h.
Referenced by family().
|
finalvirtualinherited |
Implements gum::GraphicalModel.
Definition at line 105 of file UGmodel_inl.h.
References family(), and gum::GraphicalModel::idFromName().
|
inherited |
Returns a constant reference to the dag of this Bayes Net.
Definition at line 57 of file UGmodel_inl.h.
References graph_.
Referenced by gum::MarginalTargetedMRFInference< GUM_SCALAR >::MarginalTargetedMRFInference(), isIndependent(), isIndependent(), size(), and gum::IMarkovRandomField< GUM_SCALAR >::toString().
check if nodes X and nodes Y are independent given nodes Z
Definition at line 70 of file UGmodel.cpp.
References UGmodel(), edges(), gum::Set< Key >::exists(), gum::GraphicalModel::idFromName(), nodes(), size(), sizeEdges(), and gum::GraphicalModel::variable().
|
pure virtual |
Getter by name.
| NotFound | if no such name exists in the graph. |
Implements gum::GraphicalModel.
Referenced by operator==(), and smallestFactorFromNode().
|
inherited |
transform a vector of names into a vector of nodeId
Definition at line 139 of file graphicalModel_inl.h.
References names().
Referenced by gum::DAGmodel::children(), exists(), names(), and gum::DAGmodel::parents().
|
finalvirtualinherited |
check if nodes X and nodes Y are independent given nodes Z
Implements gum::GraphicalModel.
Definition at line 95 of file UGmodel_inl.h.
References graph(), and gum::EdgeGraphPart::hasUndirectedPath().
|
inlineinherited |
return true if the edge node1-node2 exists in the UGModel
| node1 | the nodeId (or the name) of the node1 |
| node2 | the nodeId (or the name) of the node2 |
Definition at line 144 of file UGmodel.h.
References gum::GraphicalModel::idFromName(), isIndependent(), and gum::GraphicalModel::nodeset().
|
inlineinherited |
return true if the edge node1-node2 exists in the UGModel
| node1 | the nodeId (or the name) of the node1 |
| node2 | the nodeId (or the name) of the node2 |
Definition at line 150 of file UGmodel.h.
References isIndependent(), and gum::GraphicalModel::nodeset().
|
finalvirtualinherited |
check if X and Y are independent given Z
Implements gum::GraphicalModel.
Definition at line 91 of file UGmodel_inl.h.
References graph(), and gum::EdgeGraphPart::hasUndirectedPath().
Referenced by isIndependent(), and isIndependent().
|
inherited |
Definition at line 95 of file graphicalModel_inl.h.
References nodes().
Referenced by gum::IBayesNet< GUM_SCALAR >::toString(), gum::IMarkovRandomField< GUM_SCALAR >::toString(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().
| INLINE GUM_SCALAR gum::IMarkovRandomField< GUM_SCALAR >::maxNonOneParam | ( | ) | const |
Definition at line 141 of file IMarkovRandomField_tpl.h.
References factors().
| INLINE GUM_SCALAR gum::IMarkovRandomField< GUM_SCALAR >::maxParam | ( | ) | const |
Definition at line 121 of file IMarkovRandomField_tpl.h.
References factors().
| INLINE Size gum::IMarkovRandomField< GUM_SCALAR >::maxVarDomainSize | ( | ) | const |
Definition at line 101 of file IMarkovRandomField_tpl.h.
References gum::UGmodel::nodes(), and variable().
| NodeSet gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet | ( | const NodeSet & | targets, |
| const NodeSet & | soids ) const |
Definition at line 366 of file IMarkovRandomField_tpl.h.
References minimalCondSet().
| NodeSet gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet | ( | NodeId | target, |
| const NodeSet & | soids ) const |
Definition at line 352 of file IMarkovRandomField_tpl.h.
References _minimalCondSetVisit_(), gum::Set< Key >::contains(), and gum::UGmodel::graph_.
Referenced by minimalCondSet().
| INLINE GUM_SCALAR gum::IMarkovRandomField< GUM_SCALAR >::minNonZeroParam | ( | ) | const |
Definition at line 131 of file IMarkovRandomField_tpl.h.
References factors().
| INLINE GUM_SCALAR gum::IMarkovRandomField< GUM_SCALAR >::minParam | ( | ) | const |
Definition at line 111 of file IMarkovRandomField_tpl.h.
References factors().
|
inherited |
transform a NodeSet in a vector of names
Definition at line 129 of file graphicalModel_inl.h.
|
inherited |
transform a vector of NodeId in a vector of names
Definition at line 119 of file graphicalModel_inl.h.
References ids(), and variableNodeMap().
Referenced by gum::DAGmodel::children(), exists(), ids(), nodeset(), and gum::DAGmodel::parents().
returns the neighbours of a node as set of nodes
Note that the set of nodes returned may be empty if no edge within the EdgeGraphPart contains the given node.
| id | the node toward which the edge returned are pointing |
Definition at line 75 of file UGmodel_inl.h.
References graph_.
Referenced by neighbours(), and gum::IMarkovRandomField< GUM_SCALAR >::toDot().
|
inherited |
return true if the edge node1-node2 exists in the UGModel
| node1 | the nodeId (or the name) of the node1 |
| node2 | the nodeId (or the name) of the node2 |
Definition at line 77 of file UGmodel_inl.h.
References gum::GraphicalModel::idFromName(), and neighbours().
|
pure virtual |
Return id node from discrete var pointer.
| NotFound | If no variable matches var. |
Implements gum::GraphicalModel.
|
finalvirtualinherited |
Returns a constant reference to the dag of this Bayes Net.
Implements gum::GraphicalModel.
Definition at line 89 of file UGmodel_inl.h.
References graph_.
Referenced by hasSameStructure(), gum::IMarkovRandomField< GUM_SCALAR >::maxVarDomainSize(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph().
|
inherited |
transform a vector of names into a NodeSet
Definition at line 60 of file graphicalModel.cpp.
References idFromName(), gum::Set< Key >::insert(), and names().
Referenced by gum::IBayesNet< double >::children(), gum::IBayesNet< double >::children(), gum::DAGmodel::isIndependent(), gum::DAGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::UGmodel::isIndependent(), gum::DAGmodel::moralizedAncestralGraph(), and gum::DAGmodel::parents().
| INLINE bool gum::IMarkovRandomField< GUM_SCALAR >::operator!= | ( | const IMarkovRandomField< GUM_SCALAR > & | from | ) | const |
Definition at line 313 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField(), and gum::operator==().
| IMarkovRandomField< GUM_SCALAR > & gum::IMarkovRandomField< GUM_SCALAR >::operator= | ( | const IMarkovRandomField< GUM_SCALAR > & | source | ) |
Copy operator.
Definition at line 80 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField(), and gum::UGmodel::operator=().
| bool gum::IMarkovRandomField< GUM_SCALAR >::operator== | ( | const IMarkovRandomField< GUM_SCALAR > & | from | ) | const |
This operator compares 2 BNs !
Definition at line 263 of file IMarkovRandomField_tpl.h.
References IMarkovRandomField(), gum::Instantiation::chgVal(), gum::Instantiation::end(), factor(), factors(), idFromName(), gum::Instantiation::inc(), gum::BijectionImplementation< T1, T2, Gen >::insert(), gum::Set< Key >::insert(), gum::UGmodel::nodes(), gum::BijectionImplementation< T1, T2, Gen >::second(), gum::Instantiation::setFirst(), gum::UGmodel::size(), gum::UGmodel::sizeEdges(), gum::Instantiation::val(), variable(), gum::Instantiation::variable(), and variableFromName().
|
inherited |
List of all the properties.
Definition at line 81 of file graphicalModel_inl.h.
References _propertiesMap_.
|
inherited |
Return the value of the property name of this GraphicalModel.
| NotFound | Raised if no name property is found. |
Definition at line 60 of file graphicalModel_inl.h.
References _properties_(), and GUM_ERROR.
Referenced by gum::IMarkovRandomField< GUM_SCALAR >::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toDotAsFactorGraph().
|
inherited |
Return the value of the property name of this GraphicalModel.
return byDefault if the property name is not found
Definition at line 75 of file graphicalModel_inl.h.
References _propertiesMap_.
|
inherited |
Add or change a property of this GraphicalModel.
Definition at line 89 of file graphicalModel_inl.h.
References _propertiesMap_.
Referenced by gum::IBayesNet< GUM_SCALAR >::IBayesNet(), gum::IMarkovRandomField< GUM_SCALAR >::IMarkovRandomField(), and gum::InfluenceDiagram< GUM_SCALAR >::fastPrototype().
|
finalvirtualinherited |
Returns the number of variables in this Directed Graphical Model.
Implements gum::GraphicalModel.
Definition at line 60 of file UGmodel_inl.h.
References graph(), and gum::NodeGraphPart::size().
Referenced by hasSameStructure(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::toDot(), and gum::IMarkovRandomField< GUM_SCALAR >::toString().
|
inherited |
Returns the number of arcs in this Directed Graphical Model.
Definition at line 63 of file UGmodel_inl.h.
References graph_.
Referenced by hasSameStructure(), and gum::IMarkovRandomField< GUM_SCALAR >::operator==().
|
virtual |
Returns the smallest factor that contains this variable.
| NotFound | If no variable's id matches varId. |
Definition at line 326 of file IMarkovRandomField_tpl.h.
References GUM_ERROR, idFromName(), and smallestFactorFromNode().
|
pure virtual |
Returns the smallest factor that contains this variable.
| NotFound | If no variable's id matches varId. |
Referenced by smallestFactorFromNode().
|
staticinherited |
send to the stream the space complexity with 3 parametrs
| s | the stream |
| dSize | the log10domainSize |
| dim | the dimension |
| usedMem | the memory needed for the params |
Definition at line 69 of file graphicalModel.cpp.
Referenced by gum::IBayesNet< GUM_SCALAR >::toString().
|
virtual |
Definition at line 170 of file IMarkovRandomField_tpl.h.
References gum::UGmodel::neighbours(), gum::UGmodel::nodes(), gum::GraphicalModel::property(), gum::UGmodel::size(), and variable().
|
virtual |
Definition at line 211 of file IMarkovRandomField_tpl.h.
References factors(), gum::UGmodel::nodes(), gum::GraphicalModel::property(), and variable().
| INLINE std::string gum::IMarkovRandomField< GUM_SCALAR >::toString | ( | ) | const |
Definition at line 151 of file IMarkovRandomField_tpl.h.
References factor(), factors(), gum::UGmodel::graph(), gum::GraphicalModel::log10DomainSize(), and gum::UGmodel::size().
Referenced by gum::operator<<().
|
pure virtual |
Returns a constant reference over a variable given it's node id.
| NotFound | If no variable's id matches varId. |
Implements gum::GraphicalModel.
Referenced by maxVarDomainSize(), operator==(), toDot(), and toDotAsFactorGraph().
|
pure virtual |
Getter by name.
| NotFound | if no such name exists in the graph. |
Implements gum::GraphicalModel.
References IMarkovRandomField().
Referenced by operator==().
|
pure virtual |
Returns a constant reference to the VariableNodeMap of thisBN.
Implements gum::GraphicalModel.
|
inherited |
transform a vector of NodeId into a VariableeSet
Definition at line 160 of file graphicalModel_inl.h.
References gum::VariableNodeMap::get(), gum::Set< Key >::insert(), and variableNodeMap().
|
inherited |
transform a vector of names into a VariableeSet
Definition at line 150 of file graphicalModel_inl.h.
References variableNodeMap().
|
privateinherited |
The properties of this Directed Graphical Model.
Definition at line 236 of file graphicalModel.h.
Referenced by _properties_(), operator=(), properties(), propertyWithDefault(), and setProperty().
|
protectedinherited |
The DAG of this Directed Graphical Model.
Definition at line 182 of file UGmodel.h.
Referenced by UGmodel(), gum::IMarkovRandomField< GUM_SCALAR >::_minimalCondSetVisit_(), edges(), exists(), existsEdge(), graph(), gum::IMarkovRandomField< GUM_SCALAR >::minimalCondSet(), neighbours(), nodes(), operator=(), and sizeEdges().