49#ifndef GUM_BAYES_NET_H
50#define GUM_BAYES_NET_H
59 template < GUM_Numeric GUM_SCALAR >
62 template < GUM_Numeric GUM_SCALAR >
65 template < GUM_Numeric GUM_SCALAR >
98 template < GUM_Numeric GUM_SCALAR >
127 static BayesNet< GUM_SCALAR >
fastPrototype(std::string_view dotlike,
Size domainSize);
128 static BayesNet< GUM_SCALAR >
fastPrototype(std::string_view dotlike,
129 std::string_view domainSize =
"[2]");
146 explicit BayesNet(std::string_view name);
156 BayesNet(
const BayesNet< GUM_SCALAR >& source);
161 BayesNet(BayesNet< GUM_SCALAR >&& source);
175 BayesNet< GUM_SCALAR >&
operator=(
const BayesNet< GUM_SCALAR >& source);
183 BayesNet< GUM_SCALAR >&
operator=(BayesNet< GUM_SCALAR >&& source);
198 const Tensor< GUM_SCALAR >&
cpt(
NodeId varId)
const final;
203 const Tensor< GUM_SCALAR >&
cpt(std::string_view name)
const;
240 NodeId add(std::string_view fast_description,
unsigned int default_nbrmod = 2);
316 void erase(std::string_view name);
367 std::string_view old_label,
368 std::string_view new_label);
392 void addArc(std::string_view tail, std::string_view head);
414 void eraseArc(std::string_view tail, std::string_view head);
446 void reverseArc(std::string_view tail, std::string_view head);
607 void addWeightedArc(std::string_view tail, std::string_view head, GUM_SCALAR causalWeight);
624 void changeTensor(std::string_view name, Tensor< GUM_SCALAR >* newPot);
681 template < GUM_Numeric GUM_SCALAR >
682 std::ostream&
operator<<(std::ostream& output,
const BayesNet< GUM_SCALAR >& bn);
685#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.
<agrum/BN/inference/tools/aggregatorDecomposition.h>
The base class for all directed edges.
A factory class to ease BayesNet construction.
NodeId addLogit(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a Logit implementation.
void eraseArc(const Arc &arc)
Removes an arc in the BN, and update head's CTP.
void endTopologyTransformation()
terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
NodeId addCOUNT(const DiscreteVariable &var, Idx value=1)
Others aggregators.
NodeId addAMPLITUDE(const DiscreteVariable &var)
Others aggregators.
static BayesNet< GUM_SCALAR > fastPrototype(std::string_view dotlike, Size domainSize)
Create a Bayesian network with a dot-like syntax which specifies:
NodeId addAND(const DiscreteVariable &var)
Add a variable, it's associate node and an AND implementation.
void beginTopologyTransformation()
When inserting/removing arcs, node CPTs change their dimension with a cost in time.
const Tensor< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
void erase(NodeId varId)
Remove a variable from the gum::BayesNet.
NodeId addMAX(const DiscreteVariable &var)
Others aggregators.
void clear()
clear the whole Bayes net *
void changeVariableLabel(NodeId id, std::string_view old_label, std::string_view new_label)
Changes a variable's label in the gum::BayesNet.
const DiscreteVariable & variable(std::string_view name) const
Returns a gum::DiscreteVariable given its name 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.
NodeId addEXISTS(const DiscreteVariable &var, Idx value=1)
Others aggregators.
void addWeightedArc(NodeId tail, NodeId head, GUM_SCALAR causalWeight)
Add an arc in the BN, and update arc.head's CPT.
NodeId addSUM(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.
NodeId _addAggregator_(std::string_view aggregatorType, const DiscreteVariable &var, Idx value=1)
Generic factory for aggregator nodes, dispatching on the aggregator's name.
NodeId addNoisyORNet(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
void _copyTensors_(const BayesNet< GUM_SCALAR > &source)
copy of tensors from a BN to another, using names of vars as ref.
NodeId addNoisyAND(const DiscreteVariable &var, GUM_SCALAR external_weight, NodeId id)
Add a variable, its associate node and a noisyAND implementation.
void addArc(NodeId tail, NodeId head)
Add an arc in the BN, and update arc.head's CPT.
NodeId addFORALL(const DiscreteVariable &var, Idx value=1)
Others aggregators.
NodeId add(const DiscreteVariable &var)
Add a variable to the gum::BayesNet.
void reverseArc(NodeId tail, NodeId head)
Reverses an arc while preserving the same joint distribution.
NodeId addMIN(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 addNoisyOR(const DiscreteVariable &var, GUM_SCALAR external_weight)
Add a variable, it's associate node and a gum::noisyOR implementation.
void generateCPT(NodeId node) const
randomly generate CPT for a given node in a given structure
NodeProperty< Tensor< GUM_SCALAR > * > _probaMap_
Mapping between the variable's id and their CPT.
NodeId addMEDIAN(const DiscreteVariable &var)
Others aggregators.
void changeVariableName(NodeId id, std::string_view new_name)
Changes a variable's name in the gum::BayesNet.
void _clearTensors_()
clear all tensors
NodeId addOR(const DiscreteVariable &var)
Add a variable, it's associate node and an OR implementation.
void _unsafeChangeTensor_(NodeId id, Tensor< GUM_SCALAR > *newPot)
change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
~BayesNet() override
Destructor.
void generateCPTs() const
randomly generates CPTs for a given structure
BayesNet()
Default constructor.
NodeId _addICIModel_(std::string_view iciType, const DiscreteVariable &var, GUM_SCALAR externalWeight)
Generic factory for ICI model nodes, dispatching on the implementation's name.
BayesNet< GUM_SCALAR > & operator=(const BayesNet< GUM_SCALAR > &source)
Copy operator.
Size size() const final
Returns the number of variables in this Directed Graphical Model.
DAG dag() const
Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding vari...
const NodeGraphPart & nodes() const final
Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding vari...
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.
const VariableNodeMap & variableNodeMap() const override
Returns a constant reference to the VariableNodeMap of this model.
const DiscreteVariable & variableFromName(std::string_view name) const override
Returns a constant reference over a variable given its name.
NodeId nodeId(const DiscreteVariable &var) const override
Returns the NodeId of a variable.
const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variable given its node id.
Base class for discrete random variable.
double log10DomainSize() const
IBayesNet()
Default constructor.
Class for assigning/browsing values to tuples of discrete variables.
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