![]() |
aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
|
Class representing a Bayesian network. More...
#include <agrum/BN/BayesNet.h>
Public Member Functions | |
NodeId | addNoisyAND (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id) |
Add a variable, its associate node and a noisyAND implementation. More... | |
NodeId | addNoisyAND (const DiscreteVariable &var, GUM_SCALAR external_weight) |
Add a variable, its associate node and a noisyAND implementation. More... | |
NodeId | addLogit (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id) |
Add a variable, its associate node and a Logit implementation. More... | |
NodeId | addLogit (const DiscreteVariable &var, GUM_SCALAR external_weight) |
Add a variable, its associate node and a Logit implementation. More... | |
NodeId | addOR (const DiscreteVariable &var) |
Add a variable, it's associate node and an OR implementation. More... | |
NodeId | addAND (const DiscreteVariable &var) |
Add a variable, it's associate node and an AND implementation. More... | |
void | addWeightedArc (NodeId tail, NodeId head, GUM_SCALAR causalWeight) |
Add an arc in the BN, and update arc.head's CPT. More... | |
void | addWeightedArc (const std::string &tail, const std::string &head, GUM_SCALAR causalWeight) |
Add an arc in the BN, and update arc.head's CPT. More... | |
void | generateCPTs () const |
randomly generates CPTs for a given structure More... | |
void | generateCPT (NodeId node) const |
randomly generate CPT for a given node in a given structure More... | |
void | generateCPT (const std::string &name) const |
void | changePotential (NodeId id, Potential< GUM_SCALAR > *newPot) |
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId. More... | |
void | changePotential (const std::string &name, Potential< GUM_SCALAR > *newPot) |
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 |
bool | hasSameStructure (const DAGmodel &other) |
double | log10DomainSize () const |
Constructors and Destructor | |
BayesNet () | |
Default constructor. More... | |
BayesNet (std::string name) | |
Default constructor. More... | |
virtual | ~BayesNet () final |
Destructor. More... | |
BayesNet (const BayesNet< GUM_SCALAR > &source) | |
Copy constructor. More... | |
Operators | |
BayesNet< GUM_SCALAR > & | operator= (const BayesNet< GUM_SCALAR > &source) |
Copy operator. More... | |
Variable manipulation methods | |
const Potential< GUM_SCALAR > & | cpt (NodeId varId) const final |
Returns the CPT of a variable. More... | |
const Potential< GUM_SCALAR > & | cpt (const std::string &name) const |
Returns the CPT of a variable. More... | |
const VariableNodeMap & | variableNodeMap () const final |
Returns a map between variables and nodes of this gum::BayesNet. More... | |
NodeId | add (const DiscreteVariable &var) |
Add a variable to the gum::BayesNet. More... | |
NodeId | add (const std::string &name, unsigned int nbrmod) |
Shortcut for add(gum::LabelizedVariable(name,name,nbrmod)) More... | |
NodeId | add (const DiscreteVariable &var, MultiDimImplementation< GUM_SCALAR > *aContent) |
Add a variable to the gum::BayesNet. More... | |
NodeId | add (const DiscreteVariable &var, NodeId id) |
Add a variable to the gum::BayesNet. More... | |
NodeId | add (const DiscreteVariable &var, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id) |
Add a variable to the gum::BayesNet. More... | |
void | clear () |
clear the whole Bayes net * More... | |
void | erase (NodeId varId) |
Remove a variable from the gum::BayesNet. More... | |
void | erase (const std::string &name) |
Removes a variable from the gum::BayesNet. More... | |
void | erase (const DiscreteVariable &var) |
Remove a variable from the gum::BayesNet. More... | |
const DiscreteVariable & | variable (NodeId id) const final |
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet. More... | |
const DiscreteVariable & | variable (const std::string &name) const |
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet. More... | |
void | changeVariableName (NodeId id, const std::string &new_name) |
Changes a variable's name in the gum::BayesNet. More... | |
void | changeVariableName (const std::string &name, const std::string &new_name) |
Changes a variable's name. More... | |
void | changeVariableLabel (NodeId id, const std::string &old_label, const std::string &new_label) |
Changes a variable's label in the gum::BayesNet. More... | |
void | changeVariableLabel (const std::string &name, const std::string &old_label, const std::string &new_label) |
Changes a variable's name. More... | |
NodeId | nodeId (const DiscreteVariable &var) const final |
Returns a variable's id in the gum::BayesNet. More... | |
NodeId | idFromName (const std::string &name) const final |
Returns a variable's id given its name in the gum::BayesNet. More... | |
const DiscreteVariable & | variableFromName (const std::string &name) const final |
Returns a variable given its name in the gum::BayesNet. More... | |
Arc manipulation methods. | |
void | addArc (NodeId tail, NodeId head) |
Add an arc in the BN, and update arc.head's CPT. More... | |
void | addArc (const std::string &tail, const std::string &head) |
Add an arc in the BN, and update arc.head's CPT. More... | |
void | eraseArc (const Arc &arc) |
Removes an arc in the BN, and update head's CTP. More... | |
void | eraseArc (NodeId tail, NodeId head) |
Removes an arc in the BN, and update head's CTP. More... | |
void | eraseArc (const std::string &tail, const std::string &head) |
Removes an arc in the BN, and update head's CTP. More... | |
void | beginTopologyTransformation () |
When inserting/removing arcs, node CPTs change their dimension with a cost in time. More... | |
void | endTopologyTransformation () |
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions. More... | |
void | reverseArc (NodeId tail, NodeId head) |
Reverses an arc while preserving the same joint distribution. More... | |
void | reverseArc (const std::string &tail, const std::string &head) |
Reverses an arc while preserving the same joint distribution. More... | |
void | reverseArc (const Arc &arc) |
Reverses an arc while preserving the same joint distribution. More... | |
Accessors for nodes with CI or logical implementation | |
NodeId | addNoisyOR (const DiscreteVariable &var, GUM_SCALAR external_weight) |
Add a variable, it's associate node and a gum::noisyOR implementation. More... | |
NodeId | addNoisyORNet (const DiscreteVariable &var, GUM_SCALAR external_weight) |
Add a variable, it's associate node and a gum::noisyOR implementation. More... | |
NodeId | addNoisyORCompound (const DiscreteVariable &var, GUM_SCALAR external_weight) |
Add a variable, it's associate node and a gum::noisyOR implementation. More... | |
NodeId | addNoisyOR (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id) |
Add a variable, its associate node and a noisyOR implementation. More... | |
NodeId | addNoisyORNet (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id) |
Add a variable, its associate node and a noisyOR implementation. More... | |
NodeId | addNoisyORCompound (const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id) |
Add a variable, its associate node and a noisyOR implementation. More... | |
NodeId | addAMPLITUDE (const DiscreteVariable &var) |
Others aggregators. More... | |
NodeId | addCOUNT (const DiscreteVariable &var, Idx value=1) |
Others aggregators. More... | |
NodeId | addEXISTS (const DiscreteVariable &var, Idx value=1) |
Others aggregators. More... | |
NodeId | addFORALL (const DiscreteVariable &var, Idx value=1) |
Others aggregators. More... | |
NodeId | addMAX (const DiscreteVariable &var) |
Others aggregators. More... | |
NodeId | addMEDIAN (const DiscreteVariable &var) |
Others aggregators. More... | |
NodeId | addMIN (const DiscreteVariable &var) |
Others aggregators. More... | |
NodeId | addSUM (const DiscreteVariable &var) |
Others aggregators. 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... | |
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... | |
Static Public Member Functions | |
static BayesNet< GUM_SCALAR > | fastPrototype (const std::string &dotlike, Size domainSize=2) |
Create a Bayesian network with a dot-like syntax which specifies: More... | |
Protected Attributes | |
DAG | dag_ |
The DAG of this Directed Graphical Model. More... | |
Friends | |
class | BayesNetFactory< GUM_SCALAR > |
Class representing a Bayesian network.
Bayesian networks are a probabilistic graphical model in which nodes are random variables and the probability distribution is defined by the product:
where \(\pi(X_i)\) is the parent of \(X_i\).
The probability distribution can be represented as a directed acyclic graph (DAG) where:
After a variable is added to the BN, it's domain cannot change. But it arcs are added, the data in its CPT are lost.
You should look a the gum::BayesNetFactory class which can help build Bayesian networks.
You can print a BayesNet using gum::operator<<(std::ostream&, const BayesNet<GUM_SCALAR>&).
Definition at line 77 of file BayesNet.h.
INLINE gum::BayesNet< GUM_SCALAR >::BayesNet | ( | ) |
|
explicit |
Default constructor.
name | The BayesNet's name. |
Definition at line 176 of file BayesNet_tpl.h.
|
finalvirtual |
Destructor.
Definition at line 204 of file BayesNet_tpl.h.
gum::BayesNet< GUM_SCALAR >::BayesNet | ( | const BayesNet< GUM_SCALAR > & | source | ) |
Copy constructor.
Definition at line 182 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add | ( | const DiscreteVariable & | var | ) |
Add a variable to the gum::BayesNet.
Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.
The variable is added by copy to the gum::BayesNet. The variable's gum::Potential implementation will be a gum::MultiDimArray.
var | The variable added by copy. |
DuplicateLabel | Raised if variable.name() is already used in this gum::BayesNet. |
Definition at line 245 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add | ( | const std::string & | name, |
unsigned int | nbrmod | ||
) |
Shortcut for add(gum::LabelizedVariable(name,name,nbrmod))
Add a gum::LabelizedVariable to the gum::BayesNet
This method is just a shortcut for a often used pattern
DuplicateLabel | Raised if variable.name() is already used in this gum::BayesNet. |
NotAllowed | if nbrmod<2 |
Definition at line 261 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add | ( | const DiscreteVariable & | var, |
MultiDimImplementation< GUM_SCALAR > * | aContent | ||
) |
Add a variable to the gum::BayesNet.
Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.
The variable is added by copy to the gum::BayesNet.
var | The variable added by copy. |
aContent | The gum::MultiDimImplementation to use for this variable's gum::Potential implementation. |
DuplicateLabel | Raised if variable.name() is already used in this gum::BayesNet. |
Definition at line 275 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::add | ( | const DiscreteVariable & | var, |
NodeId | id | ||
) |
Add a variable to the gum::BayesNet.
Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.
The variable is added by copy to the gum::BayesNet. The variable's gum::Potential implementation will be a gum::MultiDimArray.
var | The variable added by copy. |
id | The variable's forced gum::NodeId in the gum::BayesNet. |
DuplicateElement | Raised id is already used. |
DuplicateLabel | Raised if variable.name() is already used in this gum::BayesNet. |
Definition at line 286 of file BayesNet_tpl.h.
NodeId gum::BayesNet< GUM_SCALAR >::add | ( | const DiscreteVariable & | var, |
MultiDimImplementation< GUM_SCALAR > * | aContent, | ||
NodeId | id | ||
) |
Add a variable to the gum::BayesNet.
Add a gum::DiscreteVariable, it's associated gum::NodeId and it's gum::Potential.
var | The variable added by copy. |
aContent | The gum::MultiDimImplementation to use for this variable's gum::Potential implementation. |
id | The variable's forced gum::NodeId in the gum::BayesNet. |
DuplicateElement | Raised id is already used. |
DuplicateLabel | Raised if variable.name() is already used in this gum::BayesNet. |
Definition at line 304 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addAMPLITUDE | ( | const DiscreteVariable & | var | ) |
Others aggregators.
Definition at line 485 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addAND | ( | const DiscreteVariable & | var | ) |
Add a variable, it's associate node and an AND implementation.
The id of the new variable is automatically generated.
var | The variable added by copy. |
SizeError | if variable.domainSize()>2 |
Definition at line 490 of file BayesNet_tpl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::addArc | ( | NodeId | tail, |
NodeId | head | ||
) |
Add an arc in the BN, and update arc.head's CPT.
head | and |
tail | as NodeId |
InvalidEdge | If arc.tail and/or arc.head are not in the BN. |
DuplicateElement | if the arc already exists |
Definition at line 372 of file BayesNet_tpl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::addArc | ( | const std::string & | tail, |
const std::string & | head | ||
) |
Add an arc in the BN, and update arc.head's CPT.
gum::DuplicateElement | if the arc already exists |
Definition at line 384 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addCOUNT | ( | const DiscreteVariable & | var, |
Idx | value = 1 |
||
) |
Others aggregators.
Definition at line 497 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addEXISTS | ( | const DiscreteVariable & | var, |
Idx | value = 1 |
||
) |
Others aggregators.
Definition at line 503 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addFORALL | ( | const DiscreteVariable & | var, |
Idx | value = 1 |
||
) |
Others aggregators.
Definition at line 511 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addLogit | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight, | ||
NodeId | id | ||
) |
Add a variable, its associate node and a Logit implementation.
var | The variable added by copy |
external_weight | see gum::MultiDimLogit |
id | proposed gum::nodeId for the variable |
Definition at line 594 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addLogit | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight | ||
) |
Add a variable, its associate node and a Logit implementation.
The id of the new variable is automatically generated.
var | The variable added by copy. |
external_weight | see gum::MultiDimLogit |
Definition at line 574 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addMAX | ( | const DiscreteVariable & | var | ) |
Others aggregators.
Definition at line 519 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addMEDIAN | ( | const DiscreteVariable & | var | ) |
Others aggregators.
Definition at line 524 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addMIN | ( | const DiscreteVariable & | var | ) |
Others aggregators.
Definition at line 529 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyAND | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight, | ||
NodeId | id | ||
) |
Add a variable, its associate node and a noisyAND implementation.
var | The variable added by copy |
external_weight | see gum::MultiDimNoisyAND |
id | proposed gum::nodeId for the variable |
Definition at line 587 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyAND | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight | ||
) |
Add a variable, its associate node and a noisyAND implementation.
The id of the new variable is automatically generated.
var | The variable added by copy. |
external_weight | see gum::MultiDimNoisyAND |
Definition at line 568 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyOR | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight | ||
) |
Add a variable, it's associate node and a gum::noisyOR implementation.
The id of the new variable is automatically generated. Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the gum::BayesNet::addNoisyOR as an alias for gum::BayesNet::addNoisyORCompound
var | The variable added by copy. |
external_weight | see ref gum::MultiDimNoisyORNet,gum::MultiDimNoisyORCompound |
Definition at line 549 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyOR | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight, | ||
NodeId | id | ||
) |
Add a variable, its associate node and a noisyOR implementation.
Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.
var | The variable added by copy. |
external_weight | see gum::MultiDimNoisyORNet, gum::MultiDimNoisyORCompound |
id | The chosen id |
DuplicateElement | if id is already used |
Definition at line 580 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORCompound | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight | ||
) |
Add a variable, it's associate node and a gum::noisyOR implementation.
The id of the new variable is automatically generated. Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the gum::BayesNet::addNoisyOR as an alias for gum::BayesNet::addNoisyORCompound
var | The variable added by copy. |
external_weight | see ref gum::MultiDimNoisyORNet,gum::MultiDimNoisyORCompound |
Definition at line 556 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORCompound | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight, | ||
NodeId | id | ||
) |
Add a variable, its associate node and a noisyOR implementation.
Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.
var | The variable added by copy. |
external_weight | see gum::MultiDimNoisyORNet, gum::MultiDimNoisyORCompound |
id | The chosen id |
DuplicateElement | if id is already used |
Definition at line 602 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORNet | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight | ||
) |
Add a variable, it's associate node and a gum::noisyOR implementation.
The id of the new variable is automatically generated. Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the gum::BayesNet::addNoisyOR as an alias for gum::BayesNet::addNoisyORCompound
var | The variable added by copy. |
external_weight | see ref gum::MultiDimNoisyORNet,gum::MultiDimNoisyORCompound |
Definition at line 562 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addNoisyORNet | ( | const DiscreteVariable & | var, |
GUM_SCALAR | external_weight, | ||
NodeId | id | ||
) |
Add a variable, its associate node and a noisyOR implementation.
Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.
var | The variable added by copy. |
external_weight | see gum::MultiDimNoisyORNet, gum::MultiDimNoisyORCompound |
id | The chosen id |
DuplicateElement | if id is already used |
Definition at line 611 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addOR | ( | const DiscreteVariable & | var | ) |
Add a variable, it's associate node and an OR implementation.
The id of the new variable is automatically generated.
var | The variable added by copy. |
SizeError | if variable.domainSize()>2 |
Definition at line 534 of file BayesNet_tpl.h.
INLINE NodeId gum::BayesNet< GUM_SCALAR >::addSUM | ( | const DiscreteVariable & | var | ) |
Others aggregators.
Definition at line 541 of file BayesNet_tpl.h.
void gum::BayesNet< GUM_SCALAR >::addWeightedArc | ( | NodeId | tail, |
NodeId | head, | ||
GUM_SCALAR | causalWeight | ||
) |
Add an arc in the BN, and update arc.head's CPT.
head | and |
tail | as NodeId |
causalWeight | see gum::MultiDimICIModel |
InvalidArc | If arc.tail and/or arc.head are not in the BN. |
InvalidArc | If variable in arc.head is not a NoisyOR variable. |
Definition at line 618 of file BayesNet_tpl.h.
|
inline |
Add an arc in the BN, and update arc.head's CPT.
head | and |
tail | as std::string |
causalWeight | see gum::MultiDimICIModel |
NotFound | if no node with sun names is found |
InvalidArc | If arc.tail and/or arc.head are not in the BN. |
InvalidArc | If variable in arc.head is not a NoisyOR variable. |
Definition at line 636 of file BayesNet.h.
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 112 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 116 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().
void gum::BayesNet< GUM_SCALAR >::beginTopologyTransformation | ( | ) |
When inserting/removing arcs, node CPTs 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 645 of file BayesNet_tpl.h.
void gum::BayesNet< GUM_SCALAR >::changePotential | ( | NodeId | id, |
Potential< GUM_SCALAR > * | newPot | ||
) |
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
NotAllowed | if newPot has not the same signature as probaMap__[NodeId] |
Definition at line 703 of file BayesNet_tpl.h.
void gum::BayesNet< GUM_SCALAR >::changePotential | ( | const std::string & | name, |
Potential< GUM_SCALAR > * | newPot | ||
) |
Definition at line 732 of file BayesNet_tpl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::changeVariableLabel | ( | NodeId | id, |
const std::string & | old_label, | ||
const std::string & | new_label | ||
) |
Changes a variable's label in the gum::BayesNet.
This will change the gum::LabelizedVariable names in the gum::BayesNet.
DuplicateLabel | Raised if new_label is already used in this gum::LabelizedVariable. |
NotFound | Raised if no variable matches id or if the variable is not a LabelizedVariable |
Definition at line 226 of file BayesNet_tpl.h.
|
inline |
Changes a variable's name.
Definition at line 351 of file BayesNet.h.
INLINE void gum::BayesNet< GUM_SCALAR >::changeVariableName | ( | NodeId | id, |
const std::string & | new_name | ||
) |
Changes a variable's name in the gum::BayesNet.
This will change the gum::DiscreteVariable names in the gum::BayesNet.
DuplicateLabel | Raised if newName is already used in this gum::BayesNet. |
NotFound | Raised if no variable matches id. |
Definition at line 219 of file BayesNet_tpl.h.
|
inline |
Changes a variable's name.
Definition at line 330 of file BayesNet.h.
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 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 73 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
returns the children of a set of nodes
Definition at line 77 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 82 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
void gum::BayesNet< GUM_SCALAR >::clear | ( | ) |
clear the whole Bayes net *
Definition at line 362 of file BayesNet_tpl.h.
|
private |
clear all potentials
Definition at line 659 of file BayesNet_tpl.h.
|
inherited |
Get an instantiation over all the variables of the model.
Definition at line 86 of file graphicalModel_inl.h.
|
private |
copy of potentials from a BN to another, using names of vars as ref.
Definition at line 670 of file BayesNet_tpl.h.
|
finalvirtual |
Returns the CPT of a variable.
varId | A variable's id in the gum::BayesNet. |
NotFound | If no variable's id matches varId. |
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 329 of file BayesNet_tpl.h.
|
inline |
Returns the CPT of a variable.
Definition at line 165 of file BayesNet.h.
|
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 104 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 108 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 79 of file IBayesNet_tpl.h.
|
virtualinherited |
Return true if this graphical model is empty.
Definition at line 96 of file graphicalModel_inl.h.
void gum::BayesNet< GUM_SCALAR >::endTopologyTransformation | ( | ) |
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
end Multiple Change for all CPTs
Definition at line 652 of file BayesNet_tpl.h.
void gum::BayesNet< GUM_SCALAR >::erase | ( | NodeId | varId | ) |
Remove a variable from the gum::BayesNet.
Removes the corresponding variable from the gum::BayesNet and from all of it's children gum::Potential.
If no variable matches the given id, then nothing is done.
varId | The variable's id to remove. |
Definition at line 344 of file BayesNet_tpl.h.
|
inline |
Removes a variable from the gum::BayesNet.
Definition at line 282 of file BayesNet.h.
INLINE void gum::BayesNet< GUM_SCALAR >::erase | ( | const DiscreteVariable & | var | ) |
Remove a variable from the gum::BayesNet.
Removes the corresponding variable from the gum::BayesNet and from all of it's children gum::Potential.
If no variable matches the given variable, then nothing is done.
var | A reference on the variable to remove. |
Definition at line 339 of file BayesNet_tpl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::eraseArc | ( | const Arc & | arc | ) |
Removes an arc in the BN, and update head's CTP.
If (tail, head) doesn't exist, the nothing happens.
arc | The arc removed. |
Definition at line 395 of file BayesNet_tpl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::eraseArc | ( | NodeId | tail, |
NodeId | head | ||
) |
Removes an arc in the BN, and update head's CTP.
If (tail, head) doesn't exist, the nothing happens.
head | and |
tail | as NodeId |
Definition at line 405 of file BayesNet_tpl.h.
|
inline |
Removes an arc in the BN, and update head's CTP.
Definition at line 431 of file BayesNet.h.
Return true if this node exists in this graphical model.
Implements gum::GraphicalModel.
Definition at line 94 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 62 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().
|
static |
Create a Bayesian network with a dot-like syntax which specifies:
Note that if the dot-like string contains such a specification more than once for a variable, the first specification will be used.
dotlike | the string containing the specification |
domainSize | the default domain size for variables |
Definition at line 138 of file BayesNet_tpl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::generateCPT | ( | NodeId | node | ) | const |
randomly generate CPT for a given node in a given structure
Definition at line 696 of file BayesNet_tpl.h.
|
inline |
Definition at line 648 of file BayesNet.h.
INLINE void gum::BayesNet< GUM_SCALAR >::generateCPTs | ( | ) | const |
randomly generates CPTs for a given structure
Definition at line 690 of file BayesNet_tpl.h.
Definition at line 74 of file DAGmodel.cpp.
References gum::Set< Key, Alloc >::emplace().
|
finalvirtual |
Returns a variable's id given its name in the gum::BayesNet.
name | The variable's name from which the gum::NodeId is returned. |
NotFound | Raised if name does not match a variable in the gum::BayesNet. |
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 317 of file BayesNet_tpl.h.
|
inherited |
transform a vector of names into a vector of nodeId
Definition at line 122 of file graphicalModel_inl.h.
|
finalvirtualinherited |
check if node X and node Y are independent given nodes Z
Implements gum::GraphicalModel.
Definition at line 131 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 135 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 188 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 194 of file DAGmodel.h.
|
inherited |
Compute a parameter of the joint probability for the BN (given an instantiation of the vars)
Definition at line 211 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 75 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 230 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 135 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 115 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 95 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 358 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 384 of file IBayesNet_tpl.h.
|
inherited |
Definition at line 125 of file IBayesNet_tpl.h.
|
inherited |
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 58 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 127 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 121 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 100 of file graphicalModel_inl.h.
|
inherited |
transform a NodeSet in a vector of names
Definition at line 111 of file graphicalModel_inl.h.
|
finalvirtual |
Returns a variable's id in the gum::BayesNet.
var | The variable from which the gum::NodeId is returned. |
NotFound | If var is not in the gum::BayesNet. |
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 240 of file BayesNet_tpl.h.
|
finalvirtualinherited |
Returns a constant reference to the dag of this Bayes Net.
Implements gum::GraphicalModel.
Definition at line 96 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
transform a vector of names into a NodeSet
Definition at line 63 of file graphicalModel.cpp.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Definition at line 294 of file IBayesNet_tpl.h.
BayesNet< GUM_SCALAR > & gum::BayesNet< GUM_SCALAR >::operator= | ( | const BayesNet< GUM_SCALAR > & | source | ) |
Copy operator.
source | The copied BayesNet. |
Definition at line 191 of file BayesNet_tpl.h.
|
inherited |
This operator compares 2 BNs !
Definition at line 247 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 54 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 58 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
returns the parents of a set of nodes
Definition at line 86 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 90 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 58 of file graphicalModel_inl.h.
INLINE void gum::BayesNet< GUM_SCALAR >::reverseArc | ( | NodeId | tail, |
NodeId | head | ||
) |
Reverses an arc while preserving the same joint distribution.
This method uses Shachter's 1986 algorithm for reversing an arc in the Bayes net while preserving the same joint distribution. By performing this reversal, we also add new arcs (required to not alter the joint distribution)
InvalidArc | exception if the arc does not exist or if its reversal would induce a directed cycle. |
Definition at line 476 of file BayesNet_tpl.h.
|
inline |
Reverses an arc while preserving the same joint distribution.
This method uses Shachter's 1986 algorithm for reversing an arc in the Bayes net while preserving the same joint distribution. By performing this reversal, we also add new arcs (required to not alter the joint distribution)
InvalidArc | exception if the arc does not exist or if its reversal would induce a directed cycle. |
Definition at line 464 of file BayesNet.h.
void gum::BayesNet< GUM_SCALAR >::reverseArc | ( | const Arc & | arc | ) |
Reverses an arc while preserving the same joint distribution.
This method uses Shachter's 1986 algorithm for reversing an arc in the Bayes net while preserving the same joint distribution. By performing this reversal, we also add new arcs (required to not alter the joint distribution)
InvalidArc | exception if the arc does not exist or if its reversal would induce a directed cycle. |
Definition at line 410 of file BayesNet_tpl.h.
|
inherited |
Add or change a property of this GraphicalModel.
Definition at line 66 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().
|
virtualinherited |
Reimplemented in gum::BayesNetFragment< GUM_SCALAR >, gum::prm::ClassBayesNet< GUM_SCALAR >, and gum::prm::InstanceBayesNet< GUM_SCALAR >.
Definition at line 166 of file IBayesNet_tpl.h.
|
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 100 of file DAGmodel_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Definition at line 145 of file IBayesNet_tpl.h.
|
private |
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
Definition at line 724 of file BayesNet_tpl.h.
|
finalvirtual |
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
id | The variable's id to return. |
NotFound | Raised if id does not match a a variable in the gum::BayesNet. |
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 213 of file BayesNet_tpl.h.
|
inline |
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
Definition at line 312 of file BayesNet.h.
|
finalvirtual |
Returns a variable given its name in the gum::BayesNet.
name | The variable's name in the gum::BayesNet. |
NotFound | Raised if name does not match a variable in the gum::BayesNet. |
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 323 of file BayesNet_tpl.h.
|
finalvirtual |
Returns a map between variables and nodes of this gum::BayesNet.
Implements gum::IBayesNet< GUM_SCALAR >.
Definition at line 334 of file BayesNet_tpl.h.
|
friend |
Definition at line 78 of file BayesNet.h.
|
protectedinherited |
The DAG of this Directed Graphical Model.
Definition at line 225 of file DAGmodel.h.
|
private |
Mapping between the variable's id and their CPT.
Definition at line 670 of file BayesNet.h.
|
private |
the map between variable and id
Definition at line 667 of file BayesNet.h.