49#ifndef GUM_BAYESNET_FACTORY_H
50#define GUM_BAYESNET_FACTORY_H
80 template <
typename GUM_SCALAR >
162 void addNetworkProperty(
const std::string& propName,
const std::string& propValue)
final;
188 void addMin(
const long& min);
191 void addMax(
const long& max);
194 void addTick(
const GUM_SCALAR& tick);
236 void addParent(
const std::string& var)
final;
280 const std::vector< float >& rawTable)
final;
315 void setParentModality(
const std::string& parent,
const std::string& modality)
final;
408 bool redefineParents)
final;
473 const std::vector< float >& rawTable);
478 bool _increment_(std::vector< gum::Idx >& modCounter,
483#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Implementation of the BayesNetFactory class.
Class representing Bayesian networks.
Header of the IBayesNetFactory class.
A factory class to ease BayesNet construction.
factory_state state() const final
Returns the current state of the factory.
void variableDescription(const std::string &desc) final
Tells the factory the current variable's description.
void endRawProbabilityDeclaration() final
Tells the factory that we finished declaring a conditional probability table.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
void startFactorizedProbabilityDeclaration(const std::string &var) final
Tells the factory that we're starting a factorized declaration.
std::vector< factory_state > _states_
State stack.
BayesNet< GUM_SCALAR > * bayesNet()
Returns the BayesNet created by this factory.
const DiscreteVariable & variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
bool _bar_flag_
Depending on the context this flag is used for some VERY important reasons.
void _setCPTAndParents_(const DiscreteVariable &var, Tensor< GUM_SCALAR > *table)
Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.
void rawConditionalTable(const std::vector< std::string > &variables, const std::vector< float > &rawTable) final
Fills the variable's table with the values in rawTable.
void startParentsDeclaration(const std::string &var) final
Tells the factory that we're declaring parents for some variable.
void _illegalStateError_(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
Size cptDomainSize(NodeId n) const final
Returns the domainSize of the cpt for the node n.
HashTable< std::string, NodeId > _varNameMap_
Mapping between a declared variable's name and it's node id.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
void variableType(const VarType &type)
Tells the factory the current variable's type.
void endFactorizedEntry() final
Tells the factory that we end an entry of a factorized conditional probability table.
void addModality(const std::string &name) final
Adds a modality to the current labelized variable.
void startFactorizedEntry() final
Tells the factory that we start an entry of a factorized conditional probability table.
BayesNet< GUM_SCALAR > * _bn_
The constructed BayesNet.
void setVariableCPT(const std::string &varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
void endFactorizedProbabilityDeclaration() final
Tells the factory that we finished declaring a conditional probability table.
Idx _checkVariableModality_(const std::string &name, const std::string &mod)
Check if var exists and if mod is one of it's modality, if not raise an NotFound exception.
void startRawProbabilityDeclaration(const std::string &var) final
Tells the factory that we're declaring a conditional probability table for some variable.
void _checkVariableName_(const std::string &name) const
Check if a variable with the given name exists, if not raise an NotFound exception.
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.
void addMin(const long &min)
Adds the min value of the current range variable.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Tensor.
BayesNetFactory< GUM_SCALAR > & operator=(const BayesNetFactory< GUM_SCALAR > &source)=delete
Copy operator is illegal, use only copy constructor.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
bool _foo_flag_
Depending on the context this flag is used for some VERY important reasons.
const DiscreteVariable & varInBN(NodeId id) final
short-cut accessor for a DiscreveVariable in the BN
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void setVariable(const DiscreteVariable &var) final
Define a variable.
virtual ~BayesNetFactory()
Destructor.
Instantiation * _parents_
Used when a factorized CPT is built.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void _checkModalityInBag_(const std::string &mod)
Check if in stringBag there is no other modality with the same name.
NodeId variableId(const std::string &name) const final
Returns the NodeId of a variable given it's name.
void addNetworkProperty(const std::string &propName, const std::string &propValue) final
Tells the factory to add a property to the current network.
void setParentModality(const std::string &parent, const std::string &modality) final
Tells the factory on which modality we want to instantiate one of variable's parent.
void variableName(const std::string &name) final
Tells the factory the current variable's name.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
bool _increment_(std::vector< gum::Idx > &modCounter, List< const DiscreteVariable * > &varList) const
Increment a modality counter for the fillProbaWithValuesTable method.
MultiDimImplementation< GUM_SCALAR > * _impl_
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls.
void addParent(const std::string &var) final
Tells the factory for which variable we're declaring parents.
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
void setVariableValuesUnchecked(const std::vector< float > &values) final
Gives the values of the variable with respect to precedent parents modality.
void setVariableValues(const std::vector< float > &values) final
same than below with gum::OperationNotAllowed exception if value's size not OK.
void _resetParts_()
Reset the different parts used to constructed the BayesNet.
void _fillProbaWithValuesTable_(const std::vector< std::string > &variables, const std::vector< float > &rawTable)
Fill a tensor from a raw CPT.
void addMax(const long &max)
Adds the max value of the current range variable.
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.
<agrum/base/multidim/multiDimImplementation.h>
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