29 #ifndef GUM_BAYESNET_FACTORY_H 30 #define GUM_BAYESNET_FACTORY_H 35 #include <agrum/BN/BayesNet.h> 36 #include <agrum/BN/IBayesNetFactory.h> 60 template <
typename GUM_SCALAR >
61 class BayesNetFactory:
public IBayesNetFactory {
168 void addMin(
const long& min);
171 void addMax(
const long& max);
174 void addTick(
const GUM_SCALAR& tick);
260 const std::vector<
float >& rawTable)
final;
362 void setVariable(
const DiscreteVariable& var)
final;
387 MultiDimAdressable* table,
388 bool redefineParents)
final;
428 BayesNetFactory< GUM_SCALAR >&
operator=(
const BayesNetFactory< GUM_SCALAR >& source) =
delete;
453 const std::vector<
float >& rawTable);
458 bool _increment_(std::vector< gum::Idx >& modCounter, List<
const DiscreteVariable* >& varList);
462 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 463 extern template class BayesNetFactory<
double >;
468 #include <agrum/BN/BayesNetFactory_tpl.h> void endRawProbabilityDeclaration() final
Tells the factory that we finished declaring a conditional probability table.
void variableName(const std::string &name) final
Tells the factory the current variable's name.
BayesNet< GUM_SCALAR > * _bn_
The constructed BayesNet.
void rawConditionalTable(const std::vector< float > &rawTable) final
Fills the variable's table with the values in rawTable.
void endFactorizedEntry() final
Tells the factory that we end an entry of a factorized conditional probability table.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Potential.
void startFactorizedEntry() final
Tells the factory that we start an entry of a factorized conditional probability table.
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
void addParent(const std::string &var) final
Tells the factory for which variable we're declaring parents.
INLINE void emplace(Args &&... args)
void setVariable(const DiscreteVariable &var) final
Define a variable.
BayesNet< GUM_SCALAR > * bayesNet()
Returns the BayesNet created by this factory.
factory_state state() const final
Returns the current state of the factory.
void addNetworkProperty(const std::string &propName, const std::string &propValue) final
Tells the factory to add a property to the current network.
void startParentsDeclaration(const std::string &var) final
Tells the factory that we're declaring parents for some variable.
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.
HashTable< std::string, NodeId > _varNameMap_
Mapping between a declared variable's name and it's node id.
void _checkModalityInBag_(const std::string &mod)
Check if in stringBag there is no other modality with the same name.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
void _resetParts_()
Reset the different parts used to constructed the BayesNet.
void variableType(const VarType &type)
Tells the factory the current variable's type.
MultiDimImplementation< GUM_SCALAR > * _impl_
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls...
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.
std::vector< factory_state > _states_
State stack.
void startFactorizedProbabilityDeclaration(const std::string &var) final
Tells the factory that we're starting a factorized declaration.
NodeId variableId(const std::string &name) const final
Returns the NodeId of a variable given it's name.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
bool _bar_flag_
Depending on the context this flag is used for some VERY important reasons.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void _setCPTAndParents_(const DiscreteVariable &var, Potential< GUM_SCALAR > *table)
Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.
void addMax(const long &max)
Adds the max value of the current range variable.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
Size cptDomainSize(NodeId n) const final
Returns the domainSize of the cpt for the node n.
void startRawProbabilityDeclaration(const std::string &var) final
Tells the factory that we're declaring a conditional probability table for some variable.
const DiscreteVariable & varInBN(NodeId id) final
short-cut accessor for a DiscreveVariable in the BN
void setVariableValuesUnchecked(const std::vector< float > &values) final
Gives the values of the variable with respect to precedent parents modality.
void _checkVariableName_(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
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.
BayesNetFactory< GUM_SCALAR > & operator=(const BayesNetFactory< GUM_SCALAR > &source)=delete
Copy operator is illegal, use only copy constructor.
void _fillProbaWithValuesTable_(const std::vector< float > &rawTable)
Fill a potential from a raw CPT.(using the canonical order of vars)
void addMin(const long &min)
Adds the min value of the current range variable.
void variableDescription(const std::string &desc) final
Tells the factory the current variable's description.
BayesNetFactory(const BayesNetFactory< GUM_SCALAR > &source)
Copy constructor.
bool _foo_flag_
Depending on the context this flag is used for some VERY important reasons.
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 _fillProbaWithValuesTable_(const std::vector< std::string > &variables, const std::vector< float > &rawTable)
Fill a potential from a raw CPT.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
const DiscreteVariable & variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
void addModality(const std::string &name) final
Adds a modality to the current labelized variable.
Instantiation * _parents_
Used when a factorized CPT is built.
void _illegalStateError_(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
bool _increment_(std::vector< gum::Idx > &modCounter, List< const DiscreteVariable * > &varList)
Increment a modality counter for the fillProbaWithValuesTable method.
void setVariableValues(const std::vector< float > &values) final
same than below with gum::OperationNotAllowed exception if value's size not OK.
virtual ~BayesNetFactory()
Destructor.
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.