29 #ifndef GUM_BAYES_NET_H 30 #define GUM_BAYES_NET_H 34 #include <agrum/agrum.h> 36 #include <agrum/tools/core/hashTable.h> 38 #include <agrum/BN/IBayesNet.h> 39 #include <agrum/tools/multidim/potential.h> 43 template <
typename GUM_SCALAR >
44 class BayesNetFactory;
76 template <
typename GUM_SCALAR >
78 friend class BayesNetFactory< GUM_SCALAR >;
120 explicit BayesNet(std::string name);
165 return cpt(idFromName(name));
274 void erase(NodeId varId);
279 void erase(
const std::string& name) { erase(idFromName(name)); };
291 void erase(
const DiscreteVariable& var);
310 return variable(idFromName(name));
328 changeVariableName(idFromName(name), new_name);
341 void changeVariableLabel(NodeId id,
const std::string& old_label,
const std::string& new_label);
347 const std::string& old_label,
348 const std::string& new_label) {
349 changeVariableLabel(idFromName(name), old_label, new_label);
397 void addArc(NodeId tail, NodeId head);
404 void addArc(
const std::string& tail,
const std::string& head);
421 void eraseArc(NodeId tail, NodeId head);
426 void eraseArc(
const std::string& tail,
const std::string& head) {
427 eraseArc(idFromName(tail), idFromName(head));
459 void reverseArc(
const std::string& tail,
const std::string& head) {
460 reverseArc(idFromName(tail), idFromName(head));
608 void addWeightedArc(NodeId tail, NodeId head, GUM_SCALAR causalWeight);
620 void addWeightedArc(
const std::string& tail,
const std::string& head, GUM_SCALAR causalWeight) {
621 addWeightedArc(idFromName(tail), idFromName(head), causalWeight);
630 void generateCPT(
const std::string& name)
const { generateCPT(idFromName(name)); };
637 void changePotential(
const std::string& name, Potential< GUM_SCALAR >* newPot);
667 template <
typename GUM_SCALAR >
671 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 672 extern template class BayesNet<
double >;
677 #include <agrum/BN/BayesNet_tpl.h> void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head's CPT.
void changeVariableName(const std::string &name, const std::string &new_name)
Changes a variable's name.
BayesNet< GUM_SCALAR > & operator=(const BayesNet< GUM_SCALAR > &source)
Copy operator.
NodeId addCOUNT(const DiscreteVariable &var, Idx value=1)
Others aggregators.
NodeId addNoisyOR(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
void _clearPotentials_()
clear all potentials
void changeVariableName(NodeId id, const std::string &new_name)
Changes a variable's name in the gum::BayesNet.
NodeId addLogit(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, its associate node and a Logit implementation.
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
void addArc(const std::string &tail, const std::string &head)
Add an arc in the BN, and update arc.head's CPT.
INLINE void emplace(Args &&... args)
void reverseArc(const std::string &tail, const std::string &head)
Reverses an arc while preserving the same joint distribution.
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
NodeId addAMPLITUDE(const DiscreteVariable &var)
Others aggregators.
BayesNet()
Default constructor.
NodeId add(const DiscreteVariable &var, MultiDimImplementation< GUM_SCALAR > *aContent)
Add a variable to the gum::BayesNet.
NodeId addLogit(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a Logit implementation.
NodeId addAND(const DiscreteVariable &var)
Add a variable, it's associate node and an AND implementation.
void clear()
clear the whole Bayes net *
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
NodeId addNoisyORCompound(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a noisyOR implementation.
void _copyPotentials_(const BayesNet< GUM_SCALAR > &source)
copy of potentials from a BN to another, using names of vars as ref.
NodeId addFORALL(const DiscreteVariable &var, Idx value=1)
Others aggregators.
NodeId addNoisyOR(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a noisyOR implementation.
BayesNet(const BayesNet< GUM_SCALAR > &source)
Copy constructor.
static BayesNet< GUM_SCALAR > fastPrototype(const std::string &dotlike, Size domainSize=2)
Create a Bayesian network with a dot-like syntax which specifies:
void eraseArc(const std::string &tail, const std::string &head)
Removes an arc in the BN, and update head's CTP.
void addWeightedArc(NodeId tail, NodeId head, GUM_SCALAR causalWeight)
Add an arc in the BN, and update arc.head's CPT.
NodeId addNoisyORNet(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
void beginTopologyTransformation()
When inserting/removing arcs, node CPTs change their dimension with a cost in time.
const DiscreteVariable & variableFromName(const std::string &name) const final
Returns a variable given its name in the gum::BayesNet.
NodeProperty< Potential< GUM_SCALAR > *> _probaMap_
Mapping between the variable's id and their CPT.
void eraseArc(NodeId tail, NodeId head)
Removes an arc in the BN, and update head's CTP.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
const VariableNodeMap & variableNodeMap() const final
Returns a map between variables and nodes of this gum::BayesNet.
NodeId addNoisyAND(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a noisyAND implementation.
NodeId addNoisyAND(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, its associate node and a noisyAND implementation.
BayesNet(std::string name)
Default constructor.
NodeId addOR(const DiscreteVariable &var)
Add a variable, it's associate node and an OR implementation.
void generateCPT(const std::string &name) const
void generateCPTs() const
randomly generates CPTs for a given structure
NodeId addEXISTS(const DiscreteVariable &var, Idx value=1)
Others aggregators.
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
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.
void erase(const DiscreteVariable &var)
Remove a variable from the gum::BayesNet.
void changeVariableLabel(NodeId id, const std::string &old_label, const std::string &new_label)
Changes a variable's label in the gum::BayesNet.
NodeId add(const std::string &name, unsigned int nbrmod)
Shortcut for add(gum::LabelizedVariable(name,name,nbrmod))
NodeId addMAX(const DiscreteVariable &var)
Others aggregators.
NodeId nodeId(const DiscreteVariable &var) const final
Returns a variable's id in the gum::BayesNet.
virtual ~BayesNet() final
Destructor.
void endTopologyTransformation()
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
VariableNodeMap _varMap_
the map between variable and id
NodeId addNoisyORNet(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a noisyOR implementation.
const Potential< GUM_SCALAR > & cpt(const std::string &name) const
Returns the CPT of a variable.
NodeId add(const DiscreteVariable &var, NodeId id)
Add a variable to the gum::BayesNet.
NodeId add(const DiscreteVariable &var, MultiDimImplementation< GUM_SCALAR > *aContent, NodeId id)
Add a variable to the gum::BayesNet.
void changePotential(NodeId id, Potential< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
void changeVariableLabel(const std::string &name, const std::string &old_label, const std::string &new_label)
Changes a variable's name.
NodeId addMEDIAN(const DiscreteVariable &var)
Others aggregators.
NodeId addNoisyORCompound(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
NodeId idFromName(const std::string &name) const final
Returns a variable's id given its name in the gum::BayesNet.
const DiscreteVariable & variable(const std::string &name) const
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
NodeId addSUM(const DiscreteVariable &var)
Others aggregators.
void _unsafeChangePotential_(NodeId id, Potential< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
void changePotential(const std::string &name, Potential< GUM_SCALAR > *newPot)
NodeId addMIN(const DiscreteVariable &var)
Others aggregators.
void reverseArc(const Arc &arc)
Reverses an arc while preserving the same joint distribution.
void reverseArc(NodeId tail, NodeId head)
Reverses an arc while preserving the same joint distribution.
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head's CTP.