![]() |
aGrUM
0.16.0
|
Class representing the minimal interface for Bayesian Network. More...
#include <agrum/BN/IBayesNet.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 |
virtual std::string | toDot () const |
std::string | toString () const |
NodeSet | minimalCondSet (NodeId target, const NodeSet &soids) const |
NodeSet | minimalCondSet (const NodeSet &targets, const NodeSet &soids) const |
double | log10DomainSize () const |
bool | hasSameStructure (const DAGmodel &other) |
Constructors / Destructors | |
IBayesNet () | |
Default constructor. More... | |
IBayesNet (std::string name) | |
Default constructor. More... | |
virtual | ~IBayesNet () |
Destructor. More... | |
IBayesNet (const IBayesNet< GUM_SCALAR > &source) | |
Copy constructor. More... | |
IBayesNet< GUM_SCALAR > & | operator= (const IBayesNet< GUM_SCALAR > &source) |
Copy operator. More... | |
Pure Virtual methods | |
virtual const Potential< GUM_SCALAR > & | cpt (NodeId varId) const =0 |
Returns the CPT of a variable. More... | |
virtual const VariableNodeMap & | variableNodeMap () const =0 |
Returns a constant reference to the VariableNodeMap of thisBN. 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 from 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... | |
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... | |
Getter and setters | |
const std::string & | property (const std::string &name) const |
Return the value of the property name of this DAGModel. More... | |
const std::string & | propertyWithDefault (const std::string &name, const std::string &byDefault) const |
Return the value of the property name of this DAGModel. More... | |
void | setProperty (const std::string &name, const std::string &value) |
Add or change a property of this DAGModel. More... | |
Variable manipulation methods. | |
const DAG & | dag () const |
Returns a constant reference to the dag of this Bayes Net. More... | |
Size | size () const |
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... | |
bool | empty () const |
Retursn true if this Directed Graphical Model is empty. More... | |
const NodeGraphPart & | nodes () const |
Returns a constant reference to the dag of this Bayes Net. More... | |
virtual Instantiation | completeInstantiation () const final |
Get an instantiation over all the variables of the model. More... | |
Arc manipulation methods. | |
const ArcSet & | arcs () const |
returns the set of nodes with arc ingoing to a given node 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 |
returns the set of nodes with arc ingoing to a given node 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 |
returns the set of nodes with arc ingoing to a given node More... | |
Graphical methods | |
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... | |
Protected Attributes | |
DAG | _dag |
The DAG of this Directed Graphical Model. More... | |
Class representing the minimal interface for Bayesian Network.
This class is used as a base class for different versions of Bayesian Networks. No data (except the dag herited from DAGmodel are included in this class. Many algorithms (inference for instance) may use this class when a simple BN is needed.
Definition at line 62 of file IBayesNet.h.
INLINE gum::IBayesNet< GUM_SCALAR >::IBayesNet | ( | ) |
|
explicit |
Default constructor.
Definition at line 54 of file IBayesNet_tpl.h.
|
virtual |
gum::IBayesNet< GUM_SCALAR >::IBayesNet | ( | const IBayesNet< GUM_SCALAR > & | source | ) |
|
private |
Definition at line 332 of file IBayesNet_tpl.h.
|
private |
Definition at line 309 of file IBayesNet_tpl.h.
|
inherited |
returns the set of nodes with arc ingoing to a given node
Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.
id | the node toward which the arcs returned are pointing |
Definition at line 104 of file DAGmodel_inl.h.
References gum::DAGmodel::_dag, and gum::ArcGraphPart::arcs().
Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::DAGmodel::__moralGraph(), gum::MarkovBlanket::hasSameStructure(), and gum::DAGmodel::hasSameStructure().
returns the set of nodes with arc outgoing from a given node
Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is outgoing from the given node.
id | the node which is the tail of the arcs returned |
Definition at line 111 of file DAGmodel_inl.h.
References gum::DAGmodel::_dag, and gum::ArcGraphPart::children().
Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::parents(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().
|
inlineinherited |
returns the set of nodes with arc ingoing to a given node
Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.
id | the node toward which the arcs returned are pointing |
Definition at line 165 of file DAGmodel.h.
References gum::DAGmodel::hasSameStructure(), gum::DAGmodel::idFromName(), gum::DAGmodel::log10DomainSize(), gum::DAGmodel::moralGraph(), gum::DAGmodel::operator=(), gum::DAGmodel::parents(), and gum::DAGmodel::topologicalOrder().
|
finalvirtualinherited |
Get an instantiation over all the variables of the model.
Definition at line 86 of file DAGmodel_inl.h.
References gum::DAGmodel::dag(), and gum::DAGmodel::variable().
|
pure virtual |
Returns the CPT of a variable.
NotFound | If no variable's id matches varId. |
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::BarrenNodesFinder::barrenPotentials(), and gum::IBayesNet< double >::operator==().
|
inherited |
Returns a constant reference to the dag of this Bayes Net.
Definition at line 63 of file DAGmodel_inl.h.
References gum::DAGmodel::_dag.
Referenced by gum::DAGmodel::__moralGraph(), gum::DAGmodel::completeInstantiation(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::learning::genericBNLearner::Database::Database(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), gum::MarginalTargetedInference< GUM_SCALAR >::MarginalTargetedInference(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::DAGmodel::size(), gum::BayesNetFragment< GUM_SCALAR >::toDot(), gum::DAGmodel::topologicalOrder(), gum::InfluenceDiagram< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::whenArcDeleted().
Size gum::IBayesNet< 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 79 of file IBayesNet_tpl.h.
|
inherited |
Retursn true if this Directed Graphical Model is empty.
Definition at line 99 of file DAGmodel_inl.h.
References gum::DAGmodel::size().
Definition at line 121 of file DAGmodel.cpp.
References gum::DAGmodel::arcs(), gum::Set< Key, Alloc >::exists(), gum::DAGmodel::idFromName(), gum::DAGmodel::nodes(), gum::DAGmodel::size(), gum::DAGmodel::sizeArcs(), and gum::DAGmodel::variable().
Referenced by gum::DAGmodel::children().
|
pure virtual |
Getter by name.
NotFound | if no such name exists in the graph. |
Implements gum::DAGmodel.
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Referenced by gum::IBayesNet< double >::operator==().
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::jointProbability | ( | const Instantiation & | i | ) | const |
Compute a parameter of the joint probability for the BN (given an instantiation of the vars)
Definition at line 220 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 75 of file DAGmodel_inl.h.
References gum::DAGmodel::nodes(), and gum::DAGmodel::variable().
Referenced by gum::DAGmodel::children(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::log2JointProbability | ( | const Instantiation & | i | ) | const |
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 239 of file IBayesNet_tpl.h.
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::maxNonOneParam | ( | ) | const |
Definition at line 135 of file IBayesNet_tpl.h.
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::maxParam | ( | ) | const |
Definition at line 115 of file IBayesNet_tpl.h.
Size gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize | ( | ) | const |
Definition at line 95 of file IBayesNet_tpl.h.
Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize().
NodeSet gum::IBayesNet< GUM_SCALAR >::minimalCondSet | ( | NodeId | target, |
const NodeSet & | soids | ||
) | const |
Definition at line 355 of file IBayesNet_tpl.h.
NodeSet gum::IBayesNet< GUM_SCALAR >::minimalCondSet | ( | const NodeSet & | targets, |
const NodeSet & | soids | ||
) | const |
Definition at line 375 of file IBayesNet_tpl.h.
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::minNonZeroParam | ( | ) | const |
Definition at line 125 of file IBayesNet_tpl.h.
Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize().
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::minParam | ( | ) | const |
Definition at line 105 of file IBayesNet_tpl.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 101 of file DAGmodel.cpp.
References gum::DAGmodel::__moralGraph(), gum::DAGmodel::__mutableMoralGraph, and gum::UndiGraph::clear().
Referenced by gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), and gum::DAGmodel::children().
|
pure virtual |
Return id node from discrete var pointer.
NotFound | If no variable matches var. |
Implements gum::DAGmodel.
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Referenced by gum::BayesBall::relevantPotentials(), and gum::dSeparation::relevantPotentials().
|
inherited |
Returns a constant reference to the dag of this Bayes Net.
Definition at line 115 of file DAGmodel_inl.h.
References gum::DAGmodel::_dag.
Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::credal::CredalNet< GUM_SCALAR >::__sort_varType(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::getMaxModality(), gum::DAGmodel::hasSameStructure(), gum::DAGmodel::log10DomainSize(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().
bool gum::IBayesNet< GUM_SCALAR >::operator!= | ( | const IBayesNet< GUM_SCALAR > & | from | ) | const |
Definition at line 303 of file IBayesNet_tpl.h.
IBayesNet< GUM_SCALAR > & gum::IBayesNet< GUM_SCALAR >::operator= | ( | const IBayesNet< GUM_SCALAR > & | source | ) |
Copy operator.
Definition at line 67 of file IBayesNet_tpl.h.
Referenced by gum::prm::InstanceBayesNet< GUM_SCALAR >::operator=(), and gum::prm::ClassBayesNet< GUM_SCALAR >::operator=().
bool gum::IBayesNet< GUM_SCALAR >::operator== | ( | const IBayesNet< GUM_SCALAR > & | from | ) | const |
This operator compares 2 BNs !
Definition at line 256 of file IBayesNet_tpl.h.
returns the set of nodes with arc ingoing to a given node
Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.
id | the node toward which the arcs returned are pointing |
Definition at line 106 of file DAGmodel_inl.h.
References gum::DAGmodel::_dag, and gum::ArcGraphPart::parents().
Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::DAGmodel::children(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::DAGmodel::parents(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().
|
inlineinherited |
returns the set of nodes with arc ingoing to a given node
Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.
id | the node toward which the arcs returned are pointing |
Definition at line 156 of file DAGmodel.h.
References gum::DAGmodel::children(), gum::DAGmodel::idFromName(), and gum::DAGmodel::parents().
|
inherited |
Return the value of the property name of this DAGModel.
NotFound | Raised if no name property is found. |
Definition at line 37 of file DAGmodel_inl.h.
References gum::DAGmodel::__properties(), and GUM_ERROR.
Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toDot().
|
inherited |
Return the value of the property name of this DAGModel.
return byDefault if the property name is not found
Definition at line 48 of file DAGmodel_inl.h.
References gum::DAGmodel::__properties().
|
inherited |
Add or change a property of this DAGModel.
Definition at line 56 of file DAGmodel_inl.h.
References gum::DAGmodel::__properties(), and gum::HashTable< Key, Val, Alloc >::insert().
Referenced by gum::BayesNet< double >::fastPrototype().
|
inherited |
Returns the number of variables in this Directed Graphical Model.
Definition at line 96 of file DAGmodel_inl.h.
References gum::DAGmodel::dag(), and gum::NodeGraphPart::size().
Referenced by gum::credal::CredalNet< GUM_SCALAR >::__initCNNets(), gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize(), gum::DAGmodel::empty(), gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), gum::IBayesNet< double >::operator==(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().
|
inherited |
Returns the number of arcs in this Directed Graphical Model.
Definition at line 102 of file DAGmodel_inl.h.
References gum::DAGmodel::_dag, and gum::ArcGraphPart::sizeArcs().
Referenced by gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), and gum::IBayesNet< double >::operator==().
|
virtual |
Reimplemented in gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Definition at line 175 of file IBayesNet_tpl.h.
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 117 of file DAGmodel.cpp.
References gum::DAGmodel::dag(), and gum::DiGraph::topologicalOrder().
Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), gum::DAGmodel::children(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().
INLINE std::string gum::IBayesNet< GUM_SCALAR >::toString | ( | ) | const |
Definition at line 145 of file IBayesNet_tpl.h.
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::DAGmodel.
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__insertEvidence(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::Estimator< GUM_SCALAR >::Estimator(), and gum::Estimator< GUM_SCALAR >::setFromBN().
|
pure virtual |
Getter by name.
NotFound | if no such name exists in the graph. |
Implements gum::DAGmodel.
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Referenced by gum::IBayesNet< double >::operator==().
|
pure virtual |
Returns a constant reference to the VariableNodeMap of thisBN.
Implements gum::DAGmodel.
Implemented in gum::BayesNet< GUM_SCALAR >, gum::BayesNet< double >, gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
|
protectedinherited |
The DAG of this Directed Graphical Model.
Definition at line 203 of file DAGmodel.h.
Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::__get(), gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::BayesNetFragment< GUM_SCALAR >::_installArc(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), gum::BayesNetFragment< GUM_SCALAR >::_uninstallArc(), gum::InfluenceDiagram< GUM_SCALAR >::addArc(), gum::DAGmodel::arcs(), gum::DAGmodel::children(), gum::DAGmodel::dag(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::BayesNetFragment< GUM_SCALAR >::installNode(), gum::DAGmodel::nodes(), gum::DAGmodel::operator=(), gum::DAGmodel::parents(), gum::DAGmodel::sizeArcs(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallNode().