49#ifndef GUM_BAYES_NET_H
50#define GUM_BAYES_NET_H
59 template <
typename GUM_SCALAR >
92 template <
typename GUM_SCALAR >
119 static BayesNet< GUM_SCALAR >
fastPrototype(
const std::string& dotlike,
Size domainSize);
120 static BayesNet< GUM_SCALAR >
fastPrototype(
const std::string& dotlike,
121 const std::string& domainSize =
"[2]");
138 explicit BayesNet(std::string name);
148 BayesNet(
const BayesNet< GUM_SCALAR >& source);
162 BayesNet< GUM_SCALAR >&
operator=(
const BayesNet< GUM_SCALAR >& source);
177 const Tensor< GUM_SCALAR >&
cpt(
NodeId varId)
const final;
182 const Tensor< GUM_SCALAR >&
cpt(
const std::string& name)
const {
228 NodeId add(const
std::
string& fast_description,
unsigned int default_nbrmod = 2);
372 const std::string& old_label,
373 const std::string& new_label) {
429 void addArc(
const std::string& tail,
const std::string& head);
451 void eraseArc(
const std::string& tail,
const std::string& head) {
485 void reverseArc(
const std::string& tail,
const std::string& head) {
647 void addWeightedArc(
const std::string& tail,
const std::string& head, GUM_SCALAR causalWeight) {
666 void changeTensor(
const std::string& name, Tensor< GUM_SCALAR >* newPot);
709 template <
typename GUM_SCALAR >
710 std::ostream&
operator<<(std::ostream& output,
const BayesNet< GUM_SCALAR >& bn);
713#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Template implementation of BN/BayesNet.h class.
Class representing the minimal interface for Bayesian network with no numerical data.
The base class for all directed edges.
A factory class to ease BayesNet construction.
NodeId addNoisyORNet(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
NodeId addLogit(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a Logit implementation.
const Tensor< GUM_SCALAR > & cpt(const std::string &name) const
Returns the CPT of a variable.
void changeVariableLabel(const std::string &name, const std::string &old_label, const std::string &new_label)
Changes a variable's name.
NodeId addAMPLITUDE(const DiscreteVariable &var)
Others aggregators.
NodeId addMEDIAN(const DiscreteVariable &var)
Others aggregators.
void endTopologyTransformation()
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
const Tensor< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
void changeVariableLabel(NodeId id, const std::string &old_label, const std::string &new_label)
Changes a variable's label in the gum::BayesNet.
void changeVariableName(NodeId id, const std::string &new_name)
Changes a variable's name in the gum::BayesNet.
NodeId addNoisyOR(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.
NodeId addFORALL(const DiscreteVariable &var, Idx value=1)
Others aggregators.
NodeId addEXISTS(const DiscreteVariable &var, Idx value=1)
Others aggregators.
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
NodeId addOR(const DiscreteVariable &var)
Add a variable, it's associate node and an OR implementation.
const DiscreteVariable & variable(const std::string &name) const
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
const DiscreteVariable & variableFromName(const std::string &name) const final
Returns a variable given its name in the gum::BayesNet.
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
NodeId addAND(const DiscreteVariable &var)
Add a variable, it's associate node and an AND implementation.
void generateCPTs() const
randomly generates CPTs for a given structure
NodeId addCOUNT(const DiscreteVariable &var, Idx value=1)
Others aggregators.
void clear()
clear the whole Bayes net *
void changeVariableName(const std::string &name, const std::string &new_name)
Changes a variable's name.
BayesNet()
Default constructor.
const DiscreteVariable & variable(NodeId id) const final
Returns a gum::DiscreteVariable given its gum::NodeId in the gum::BayesNet.
void changeTensor(NodeId id, Tensor< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
void reverseArc(const std::string &tail, const std::string &head)
Reverses an arc while preserving the same joint distribution.
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.
void reverseArc(NodeId tail, NodeId head)
Reverses an arc while preserving the same joint distribution.
NodeId addMIN(const DiscreteVariable &var)
Others aggregators.
BayesNet< GUM_SCALAR > contextualize(const gum::Instantiation &observations, const gum::Instantiation &interventions) const
create a contextual BN from this and a set of hard observations and hard interventions.
const VariableNodeMap & variableNodeMap() const final
Returns a map between variables and nodes of this gum::BayesNet.
void erase(const std::string &name)
Removes a variable from the gum::BayesNet.
void _copyTensors_(const BayesNet< GUM_SCALAR > &source)
copy of tensors from a BN to another, using names of vars as ref.
void generateCPT(const std::string &name) const
static BayesNet< GUM_SCALAR > fastPrototype(const std::string &dotlike, Size domainSize)
Create a Bayesian network with a dot-like syntax which specifies:
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head's CPT.
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head's CTP.
NodeId addSUM(const DiscreteVariable &var)
Others aggregators.
virtual ~BayesNet()
Destructor.
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.
NodeProperty< Tensor< GUM_SCALAR > * > _probaMap_
Mapping between the variable's id and their CPT.
VariableNodeMap _varMap_
the map between variable and id
NodeId addNoisyAND(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a noisyAND implementation.
NodeId nodeId(const DiscreteVariable &var) const final
Returns a variable's id in the gum::BayesNet.
NodeId addMAX(const DiscreteVariable &var)
Others aggregators.
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
void _clearTensors_()
clear all tensors
void _unsafeChangeTensor_(NodeId id, Tensor< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
NodeId idFromName(const std::string &name) const final
Returns a variable's id given its name in the gum::BayesNet.
BayesNet< GUM_SCALAR > & operator=(const BayesNet< GUM_SCALAR > &source)
Copy operator.
NodeId addNoisyORCompound(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
const DAG & dag() 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.
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
Base class for discrete random variable.
double log10DomainSize() const
IBayesNet()
Default constructor.
Class for assigning/browsing values to tuples of discrete variables.
<agrum/base/multidim/multiDimImplementation.h>
Container used to map discrete variables with nodes.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree