49#ifndef GUM_BAYESNET_FACTORY_H
50#define GUM_BAYESNET_FACTORY_H
82 template < GUM_Numeric GUM_SCALAR >
190 void addMin(
const long& min)
override;
193 void addMax(
const long& max)
override;
196 void addTick(
const GUM_SCALAR& tick);
238 void addParent(std::string_view var)
final;
282 const std::vector< float >& rawTable)
final;
317 void setParentModality(std::string_view parent, std::string_view modality)
final;
410 bool redefineParents)
final;
475 const std::vector< float >& rawTable);
480 bool _increment_(std::vector< gum::Idx >& modCounter,
485#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Implementation of the BayesNetFactory class.
Class representing Bayesian networks.
Header of the IBayesNetFactory class.
const DiscreteVariable & varInBN(NodeId id) final
short-cut accessor for a DiscreveVariable in the BN
std::vector< factory_state > _states_
State stack.
void startFactorizedProbabilityDeclaration(std::string_view var) final
Tells the factory that we're starting a factorized declaration.
void _checkVariableName_(std::string_view name) const
Check if a variable with the given name exists, if not raise an NotFound exception.
bool _bar_flag_
Depending on the context this flag is used for some VERY important reasons.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
BayesNet< GUM_SCALAR > * bayesNet()
Returns the BayesNet created by this factory.
Size cptDomainSize(NodeId n) const final
Returns the domainSize of the cpt for the node n.
bool _increment_(std::vector< gum::Idx > &modCounter, List< const DiscreteVariable * > &varList) const
Increment a modality counter for the fillProbaWithValuesTable method.
void _fillProbaWithValuesTable_(const std::vector< std::string > &variables, const std::vector< float > &rawTable)
Fill a tensor from a raw CPT.
HashTable< std::string, NodeId > _varNameMap_
Mapping between a declared variable's name and it's node id.
void setVariableCPT(std::string_view varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
void setVariableValuesUnchecked(const std::vector< float > &values) final
Gives the values of the variable with respect to precedent parents modality.
void addModality(std::string_view name) final
Adds a modality to the current labelized variable.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
void rawConditionalTable(const std::vector< std::string > &variables, const std::vector< float > &rawTable) final
Fills the variable's table with the values in rawTable.
BayesNet< GUM_SCALAR > * _bn_
The constructed BayesNet.
void _setCPTAndParents_(const DiscreteVariable &var, Tensor< GUM_SCALAR > *table)
Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.
const DiscreteVariable & variable(std::string_view name) const
Returns a constant reference on a variable given it's name.
void addParent(std::string_view var) final
Tells the factory for which variable we're declaring parents.
void endFactorizedProbabilityDeclaration() final
Tells the factory that we finished declaring a conditional probability table.
void setVariable(const DiscreteVariable &var) final
Define a variable.
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.
BayesNetFactory< GUM_SCALAR > & operator=(const BayesNetFactory< GUM_SCALAR > &source)=delete
Copy operator is illegal, use only copy constructor.
NodeId variableId(std::string_view name) const final
Returns the NodeId of a variable given it's name.
void startFactorizedEntry() final
Tells the factory that we start an entry of a factorized conditional probability table.
void startRawProbabilityDeclaration(std::string_view var) final
Tells the factory that we're declaring a conditional probability table for some variable.
void endFactorizedEntry() final
Tells the factory that we end an entry of a factorized conditional probability table.
bool _foo_flag_
Depending on the context this flag is used for some VERY important reasons.
void _resetParts_()
Reset the different parts used to constructed the BayesNet.
factory_state state() const final
Returns the current state of the factory.
void _checkModalityInBag_(std::string_view mod)
Check if in stringBag there is no other modality with the same name.
void addMax(const long &max) override
Adds the max value of the current range variable.
Idx _checkVariableModality_(std::string_view name, std::string_view mod)
Check if var exists and if mod is one of it's modality, if not raise an NotFound exception.
Instantiation * _parents_
Used when a factorized CPT is built.
void endRawProbabilityDeclaration() final
Tells the factory that we finished declaring a conditional probability table.
void variableType(const VarType &type) override
Tells the factory the current variable's type.
void setVariableValues(const std::vector< float > &values) final
same than below with gum::OperationNotAllowed exception if value's size not OK.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
void startParentsDeclaration(std::string_view var) final
Tells the factory that we're declaring parents for some variable.
void variableDescription(std::string_view desc) final
Tells the factory the current variable's description.
void addNetworkProperty(std::string_view propName, std::string_view propValue) final
Tells the factory to add a property to the current network.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Tensor.
MultiDimImplementation< GUM_SCALAR > * _impl_
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void addMin(const long &min) override
Adds the min value of the current range variable.
void _illegalStateError_(std::string_view s)
Raise an OperationNotAllowed with the message "Illegal state.".
void setParentModality(std::string_view parent, std::string_view modality) final
Tells the factory on which modality we want to instantiate one of variable's parent.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void variableName(std::string_view name) final
Tells the factory the current variable's name.
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
Base class for discrete random variable.
factory_state
The enumeration of states in which the factory can be in.
Class for assigning/browsing values to tuples of discrete variables.
Generic doubly linked lists.
Abstract base class for all multi dimensionnal addressable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
template class GUM_PUBLIC_BN BayesNetFactory< double >