![]() |
aGrUM
0.16.0
|
A factory class to ease BayesNet construction. More...
#include <agrum/BN/BayesNetFactory.h>
Public Member Functions | |
Constructor & destructor. | |
BayesNetFactory (BayesNet< GUM_SCALAR > *bn) | |
Use this constructor if you want to use an already created BayesNet. More... | |
BayesNetFactory (const BayesNetFactory< GUM_SCALAR > &source) | |
Copy constructor. More... | |
virtual | ~BayesNetFactory () |
Destructor. More... | |
Getter and setters. | |
BayesNet< GUM_SCALAR > * | bayesNet () |
Returns the BayesNet created by this factory. More... | |
const DiscreteVariable & | varInBN (NodeId id) final |
short-cut accessor for a DiscreveVariable in the BN More... | |
factory_state | state () const final |
Returns the current state of the factory. More... | |
NodeId | variableId (const std::string &name) const final |
Returns the NodeId of a variable given it's name. More... | |
const DiscreteVariable & | variable (const std::string &name) const |
Returns a constant reference on a variable given it's name. More... | |
Size | cptDomainSize (NodeId n) const final |
Returns the domainSize of the cpt for the node n. More... | |
Network declaration methods (NONE -> NETWORK) | |
void | startNetworkDeclaration () final |
Tells the factory that we're in a network declaration. More... | |
void | addNetworkProperty (const std::string &propName, const std::string &propValue) final |
Tells the factory to add a property to the current network. More... | |
void | endNetworkDeclaration () final |
Tells the factory that we're out of a network declaration. More... | |
Variable declaration methods (NONE -> VARIABLE) | |
void | startVariableDeclaration () final |
Tells the factory that we're in a variable declaration. More... | |
void | variableName (const std::string &name) final |
Tells the factory the current variable's name. More... | |
void | variableDescription (const std::string &desc) final |
Tells the factory the current variable's description. More... | |
void | addModality (const std::string &name) final |
Adds a modality to the current variable. More... | |
void | setVariableCPTImplementation (MultiDimAdressable *adressable) final |
Defines the implementation to use for var's Potential. More... | |
NodeId | endVariableDeclaration () final |
Tells the factory that we're out of a variable declaration. More... | |
Parents declaration methods (NONE -> PARENTS) | |
void | startParentsDeclaration (const std::string &var) final |
Tells the factory that we're declaring parents for some variable. More... | |
void | addParent (const std::string &var) final |
Tells the factory for which variable we're declaring parents. More... | |
void | endParentsDeclaration () final |
Tells the factory that we've finished declaring parents for some variable. More... | |
Raw Probability table declaration methods (NONE -> RAW_CPT) | |
void | startRawProbabilityDeclaration (const std::string &var) final |
Tells the factory that we're declaring a conditional probability table for some variable. More... | |
void | rawConditionalTable (const std::vector< std::string > &variables, const std::vector< float > &rawTable) final |
Fills the variable's table with the values in rawTable. More... | |
void | rawConditionalTable (const std::vector< float > &rawTable) final |
Fills the variable's table with the values in rawTable. More... | |
void | endRawProbabilityDeclaration () final |
Tells the factory that we finished declaring a conditional probability table. More... | |
Factorized probability table declaration methods | |
void | startFactorizedProbabilityDeclaration (const std::string &var) final |
Tells the factory that we're starting a factorized declaration. More... | |
void | startFactorizedEntry () final |
Tells the factory that we start an entry of a factorized conditional probability table. More... | |
void | endFactorizedEntry () final |
Tells the factory that we end an entry of a factorized conditional probability table. More... | |
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. More... | |
void | setVariableValuesUnchecked (const std::vector< float > &values) final |
Gives the values of the variable with respect to precedent parents modality. More... | |
void | setVariableValues (const std::vector< float > &values) final |
same than below with gum::OperationNotAllowed exception if value's size not OK. More... | |
void | endFactorizedProbabilityDeclaration () final |
Tells the factory that we finished declaring a conditional probability table. More... | |
Delegated CPT definitions methods | |
(NONE, NETWORK) | |
void | setVariable (const DiscreteVariable &var) final |
Define a variable. More... | |
void | setVariableCPT (const std::string &varName, MultiDimAdressable *table, bool redefineParents) final |
Define a variable's CPT. More... | |
verbosity control | |
void | setVerbose () |
void | resetVerbose () |
bool | isVerbose () |
Public Types | |
enum | factory_state : char { factory_state::NONE, factory_state::NETWORK, factory_state::VARIABLE, factory_state::PARENTS, factory_state::RAW_CPT, factory_state::FACT_CPT, factory_state::FACT_ENTRY } |
The enumeration of states in which the factory can be in. More... | |
A factory class to ease BayesNet construction.
A BayesNetFactory will never create a BayesNet and works on only one BayesNet.
The only exception of this behaviour is when you create a copy of the factory, it will create a copy of it's BayesNet. This is useful if you want to create two BayesNet sharing a common base.
However be very careful because the copy will not delete it's BayesNet.
Each method will raise an OperationNotAllowed if you call it when the factory is not in a valid state for that call. The error message is "Illegal state.".
Definition at line 45 of file BayesNet.h.
|
stronginherited |
The enumeration of states in which the factory can be in.
Every documentation section's name indicates from which state you can call it's methods, and in which state it places the factory.
There is an exception for the delegated CPT definition methods which do not change the state of the factory.
Enumerator | |
---|---|
NONE | |
NETWORK | |
VARIABLE | |
PARENTS | |
RAW_CPT | |
FACT_CPT | |
FACT_ENTRY |
Definition at line 60 of file IBayesNetFactory.h.
|
explicit |
Use this constructor if you want to use an already created BayesNet.
bn | A pointer over the BayesNet filled by this factory. |
DuplicateElement | Raised if two variables in bn share the same name. |
Definition at line 45 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::HashTable< Key, Val, Alloc >::exists(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::DAGmodel::nodes(), gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::resetVerbose(), and gum::BayesNet< GUM_SCALAR >::variable().
INLINE gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory | ( | const BayesNetFactory< GUM_SCALAR > & | source | ) |
Copy constructor.
The copy will have an exact copy of the constructed BayesNet in source.
OperationNotAllowed | Raised if the state of source is not NONE or NETWORK. |
Definition at line 65 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__states, GUM_ERROR, gum::IBayesNetFactory::NONE, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
virtual |
Destructor.
To prevent strange behaviour you should always destroy a BayesNetFactory when it's state equals NONE.
FatalError | Raised if the state of the factory prevents it to die peacefully. |
Definition at line 81 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__impl, and gum::BayesNetFactory< GUM_SCALAR >::__parents.
|
private |
Check if in __stringBag there is no other modality with the same name.
Definition at line 867 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__stringBag, and GUM_ERROR.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::addModality().
|
private |
Check if var exists and if mod is one of it's modality, if not raise an NotFound exception.
Definition at line 852 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::DiscreteVariable::domainSize(), GUM_ERROR, and gum::DiscreteVariable::label().
Referenced by gum::BayesNetFactory< GUM_SCALAR >::setParentModality().
|
private |
Check if a variable with the given name exists, if not raise an NotFound exception.
Definition at line 845 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::HashTable< Key, Val, Alloc >::exists(), and GUM_ERROR.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__checkVariableModality(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::BayesNetFactory< GUM_SCALAR >::addParent(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startParentsDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::startRawProbabilityDeclaration().
|
private |
Fill a potential from a raw CPT.
Definition at line 422 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__increment(), gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::Instantiation::chgVal(), gum::List< Val, Alloc >::pushBack(), gum::MultiDimDecorator< GUM_SCALAR >::set(), and gum::List< Val, Alloc >::size().
Referenced by gum::BayesNetFactory< GUM_SCALAR >::rawConditionalTable().
|
private |
Fill a potential from a raw CPT.(using the canonical order of vars)
Definition at line 473 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::Instantiation::end(), gum::Instantiation::incNotVar(), gum::Instantiation::incVar(), gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirstNotVar(), gum::Instantiation::setFirstVar(), gum::Instantiation::unsetEnd(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
|
private |
Raise an OperationNotAllowed with the message "Illegal state.".
Definition at line 792 of file BayesNetFactory_tpl.h.
References gum::IBayesNetFactory::FACT_CPT, gum::IBayesNetFactory::FACT_ENTRY, GUM_ERROR, gum::IBayesNetFactory::NETWORK, gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::PARENTS, gum::IBayesNetFactory::RAW_CPT, gum::BayesNetFactory< GUM_SCALAR >::state(), and gum::IBayesNetFactory::VARIABLE.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::addModality(), gum::BayesNetFactory< GUM_SCALAR >::addParent(), gum::BayesNetFactory< GUM_SCALAR >::endFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::endFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endNetworkDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::rawConditionalTable(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPTImplementation(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValues(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startNetworkDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::variableDescription(), and gum::BayesNetFactory< GUM_SCALAR >::variableName().
|
private |
Increment a modality counter for the __fillProbaWithValuesTable method.
Definition at line 495 of file BayesNetFactory_tpl.h.
References gum::List< Val, Alloc >::size().
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable().
|
private |
Reset the different parts used to constructed the BayesNet.
Definition at line 896 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bar_flag, gum::BayesNetFactory< GUM_SCALAR >::__foo_flag, and gum::BayesNetFactory< GUM_SCALAR >::__stringBag.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::endFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endRawProbabilityDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration().
|
private |
Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.
Definition at line 878 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::Variable::name(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().
Referenced by gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT().
|
finalvirtual |
Adds a modality to the current variable.
Implements gum::IBayesNetFactory.
Definition at line 228 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__checkModalityInBag(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::state(), and gum::IBayesNetFactory::VARIABLE.
Referenced by gum::prm::PRMSystem< double >::__groundAgg().
|
finalvirtual |
Tells the factory to add a property to the current network.
Implements gum::IBayesNetFactory.
Definition at line 163 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn.
Referenced by gum::prm::PRMSystem< double >::groundedBN().
|
finalvirtual |
Tells the factory for which variable we're declaring parents.
var | The parent's name. |
NotFound | Raised if var does not exists. |
Implements gum::IBayesNetFactory.
Definition at line 346 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::IBayesNetFactory::PARENTS, and gum::BayesNetFactory< GUM_SCALAR >::state().
Referenced by gum::prm::PRMSystem< double >::__groundRef().
INLINE BayesNet< GUM_SCALAR > * gum::BayesNetFactory< GUM_SCALAR >::bayesNet | ( | ) |
Returns the BayesNet created by this factory.
OperationNotAllowed | Raise if the state of the factory is different than NONE. |
Definition at line 100 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn.
|
finalvirtual |
Returns the domainSize of the cpt for the node n.
NotFound | raised if no such NodeId exists. |
Implements gum::IBayesNetFactory.
Definition at line 142 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn.
|
finalvirtual |
Tells the factory that we end an entry of a factorized conditional probability table.
Implements gum::IBayesNetFactory.
Definition at line 570 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__parents, gum::BayesNetFactory< GUM_SCALAR >::__states, gum::IBayesNetFactory::FACT_ENTRY, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Tells the factory that we finished declaring a conditional probability table.
Implements gum::IBayesNetFactory.
Definition at line 697 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::IBayesNetFactory::FACT_CPT, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Tells the factory that we're out of a network declaration.
Implements gum::IBayesNetFactory.
Definition at line 170 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::IBayesNetFactory::NETWORK, gum::BayesNetFactory< GUM_SCALAR >::state(), and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::groundedBN().
|
finalvirtual |
Tells the factory that we've finished declaring parents for some variable.
Implements gum::IBayesNetFactory.
Definition at line 360 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::IBayesNetFactory::PARENTS, gum::BayesNetFactory< GUM_SCALAR >::state(), and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::__groundRef().
|
finalvirtual |
Tells the factory that we finished declaring a conditional probability table.
Implements gum::IBayesNetFactory.
Definition at line 530 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::IBayesNetFactory::RAW_CPT, gum::BayesNetFactory< GUM_SCALAR >::state(), and VERBOSITY.
|
finalvirtual |
Tells the factory that we're out of a variable declaration.
gum::OperationNotAllowed | Raised if the variable isn't defined (or / not enough defined). |
Implements gum::IBayesNetFactory.
Definition at line 270 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bar_flag, gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__foo_flag, gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__impl, gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::LabelizedVariable::addLabel(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::Variable::name(), gum::BayesNetFactory< GUM_SCALAR >::state(), gum::IBayesNetFactory::VARIABLE, and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::__groundAgg().
|
inlineinherited |
Definition at line 82 of file IBayesNetFactory.h.
References gum::IBayesNetFactory::__verbose, gum::IBayesNetFactory::addModality(), gum::IBayesNetFactory::addNetworkProperty(), gum::IBayesNetFactory::addParent(), gum::IBayesNetFactory::cptDomainSize(), gum::IBayesNetFactory::endFactorizedEntry(), gum::IBayesNetFactory::endFactorizedProbabilityDeclaration(), gum::IBayesNetFactory::endNetworkDeclaration(), gum::IBayesNetFactory::endParentsDeclaration(), gum::IBayesNetFactory::endRawProbabilityDeclaration(), gum::IBayesNetFactory::endVariableDeclaration(), gum::IBayesNetFactory::rawConditionalTable(), gum::IBayesNetFactory::setParentModality(), gum::IBayesNetFactory::setVariable(), gum::IBayesNetFactory::setVariableCPT(), gum::IBayesNetFactory::setVariableCPTImplementation(), gum::IBayesNetFactory::setVariableValues(), gum::IBayesNetFactory::setVariableValuesUnchecked(), gum::IBayesNetFactory::startFactorizedEntry(), gum::IBayesNetFactory::startFactorizedProbabilityDeclaration(), gum::IBayesNetFactory::startNetworkDeclaration(), gum::IBayesNetFactory::startParentsDeclaration(), gum::IBayesNetFactory::startRawProbabilityDeclaration(), gum::IBayesNetFactory::startVariableDeclaration(), gum::IBayesNetFactory::state(), gum::IBayesNetFactory::variableDescription(), gum::IBayesNetFactory::variableId(), gum::IBayesNetFactory::variableName(), and gum::IBayesNetFactory::varInBN().
|
private |
Copy operator is illegal, use only copy constructor.
Definition at line 783 of file BayesNetFactory_tpl.h.
References GUM_ERROR.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT().
|
finalvirtual |
Fills the variable's table with the values in rawTable.
Parse the parents in the same order in variables
Given a sequence [var, p_1, p_2, ...,p_n-1, p_n] of parents, modalities are parsed in the given order (if all p_i are binary):
* [0, 0, ..., 0, 0], * [0, 0, ..., 0, 1], * [0, 0, ..., 1, 0], * [0, 0, ..., 1, 1], * ..., * [1, 1, ..., 1, 0], * [1, 1, ..., 1, 1]. *
variables | the vector giving the order of parents |
rawTable | The raw table. |
Implements gum::IBayesNetFactory.
Definition at line 411 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::IBayesNetFactory::RAW_CPT, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Fills the variable's table with the values in rawTable.
use the canonical ordering for the variables (e.g. see BIF format) ...
rawTable | The raw table. |
Implements gum::IBayesNetFactory.
Definition at line 463 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::IBayesNetFactory::RAW_CPT, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
inlineinherited |
Definition at line 80 of file IBayesNetFactory.h.
References gum::IBayesNetFactory::__verbose.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory().
|
finalvirtual |
Tells the factory on which modality we want to instantiate one of variable's parent.
Implements gum::IBayesNetFactory.
Definition at line 583 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__checkVariableModality(), gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__parents, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::Instantiation::chgVal(), gum::IBayesNetFactory::FACT_ENTRY, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Define a variable.
You can only call this method is the factory is in the NONE or NETWORK state.
The variable is added by copy.
var | The pointer over a DiscreteVariable used to define a new variable in the built BayesNet. |
DuplicateElement | Raised if a variable with the same name already exists. |
OperationNotAllowed | Raised if redefineParents == false and if table is not a valid CPT for var in the current state of the BayesNet. |
Implements gum::IBayesNetFactory.
Definition at line 719 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::Variable::name(), gum::IBayesNetFactory::NONE, and gum::BayesNetFactory< GUM_SCALAR >::state().
Referenced by gum::prm::PRMSystem< double >::__groundAttr().
|
finalvirtual |
Define a variable's CPT.
You can only call this method if the factory is in the NONE or NETWORK state.
Be careful that table is given to the built BayesNet, so it will be deleted with it, and you should not directly access it after you call this method.
When the redefineParents flag is set to true the constructed BayesNet's DAG is changed to fit with table's definition.
varName | The name of the concerned variable. |
table | A pointer over the CPT used for var. |
redefineParents | If true redefine var's parents to match table's variables set. |
NotFound | Raised if no variable matches var. |
OperationNotAllowed | Raised if redefineParents == false and if table is not a valid CPT for var in the current state of the BayesNet. |
Implements gum::IBayesNetFactory.
Definition at line 751 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, GUM_ERROR, gum::IBayesNetFactory::NONE, gum::BayesNetFactory< GUM_SCALAR >::operator=(), and gum::BayesNetFactory< GUM_SCALAR >::state().
Referenced by gum::prm::PRMSystem< double >::__groundPotential().
|
finalvirtual |
Defines the implementation to use for var's Potential.
NotFound | Raised if no variable matches var. |
OperationNotAllowed | Raised if impl is not empty. |
OperationNotAllowed | If an implementation is already defined for the current variable. |
Implements gum::IBayesNetFactory.
Definition at line 248 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__impl, GUM_ERROR, gum::MultiDimImplementation< GUM_SCALAR >::nbrDim(), gum::BayesNetFactory< GUM_SCALAR >::state(), and gum::IBayesNetFactory::VARIABLE.
Referenced by gum::prm::PRMSystem< double >::__groundAgg().
|
finalvirtual |
same than below with gum::OperationNotAllowed exception if value's size not OK.
Implements gum::IBayesNetFactory.
Definition at line 674 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::DiscreteVariable::domainSize(), gum::IBayesNetFactory::FACT_ENTRY, GUM_ERROR, gum::Variable::name(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Gives the values of the variable with respect to precedent parents modality.
If some parents have no modality set, then we apply values for all instantiations of that parent.
This means you can declare a default value for the table by doing
as for rawProba, if value's size is different than the number of modalities of the current variable, we don't use the supplementary values and we fill by 0 the missing values.
Implements gum::IBayesNetFactory.
Definition at line 623 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__parents, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::Instantiation::contains(), gum::Instantiation::domainSize(), gum::Instantiation::end(), gum::IBayesNetFactory::FACT_ENTRY, gum::Instantiation::incIn(), gum::Instantiation::incOut(), gum::Variable::name(), gum::Instantiation::setFirst(), gum::Instantiation::setFirstIn(), gum::Instantiation::setFirstOut(), gum::Instantiation::setVals(), gum::BayesNetFactory< GUM_SCALAR >::state(), and gum::Instantiation::val().
Referenced by gum::BayesNetFactory< GUM_SCALAR >::setVariableValues().
|
inlineinherited |
|
finalvirtual |
Tells the factory that we start an entry of a factorized conditional probability table.
Implements gum::IBayesNetFactory.
Definition at line 558 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__parents, gum::BayesNetFactory< GUM_SCALAR >::__states, gum::IBayesNetFactory::FACT_CPT, gum::IBayesNetFactory::FACT_ENTRY, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Tells the factory that we're starting a factorized declaration.
Implements gum::IBayesNetFactory.
Definition at line 543 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::IBayesNetFactory::FACT_CPT, gum::IBayesNetFactory::NONE, and gum::BayesNetFactory< GUM_SCALAR >::state().
|
finalvirtual |
Tells the factory that we're in a network declaration.
Implements gum::IBayesNetFactory.
Definition at line 151 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::IBayesNetFactory::NETWORK, gum::IBayesNetFactory::NONE, gum::BayesNetFactory< GUM_SCALAR >::state(), and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::groundedBN().
|
finalvirtual |
Tells the factory that we're declaring parents for some variable.
var | The concerned variable's name. |
NotFound | Raised if var does not exists. |
Implements gum::IBayesNetFactory.
Definition at line 328 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::PARENTS, gum::BayesNetFactory< GUM_SCALAR >::state(), and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::__groundRef().
|
finalvirtual |
Tells the factory that we're declaring a conditional probability table for some variable.
var | The concerned variable's name. |
Implements gum::IBayesNetFactory.
Definition at line 386 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::RAW_CPT, gum::BayesNetFactory< GUM_SCALAR >::state(), and VERBOSITY.
|
finalvirtual |
Tells the factory that we're in a variable declaration.
Implements gum::IBayesNetFactory.
Definition at line 182 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__states, gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::IBayesNetFactory::NONE, gum::BayesNetFactory< GUM_SCALAR >::state(), gum::IBayesNetFactory::VARIABLE, and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::__groundAgg().
|
finalvirtual |
Returns the current state of the factory.
Implements gum::IBayesNetFactory.
Definition at line 113 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__states.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::addModality(), gum::BayesNetFactory< GUM_SCALAR >::addParent(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFactory< GUM_SCALAR >::endFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::endFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endNetworkDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::rawConditionalTable(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPTImplementation(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValues(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startNetworkDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::variableDescription(), and gum::BayesNetFactory< GUM_SCALAR >::variableName().
INLINE const DiscreteVariable & gum::BayesNetFactory< GUM_SCALAR >::variable | ( | const std::string & | name | ) | const |
Returns a constant reference on a variable given it's name.
NotFound | Raised if no variable matches the name. |
Definition at line 132 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn, GUM_ERROR, and gum::BayesNetFactory< GUM_SCALAR >::variableId().
Referenced by gum::prm::PRMSystem< double >::__groundPotential().
|
finalvirtual |
Tells the factory the current variable's description.
Implements gum::IBayesNetFactory.
Definition at line 215 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bar_flag, gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::state(), and gum::IBayesNetFactory::VARIABLE.
|
finalvirtual |
Returns the NodeId of a variable given it's name.
NotFound | Raised if no variable matches the name. |
Implements gum::IBayesNetFactory.
Definition at line 122 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, and GUM_ERROR.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::variable().
|
finalvirtual |
Tells the factory the current variable's name.
DuplicateElement | Raised if a variable with the same name already exist. |
Implements gum::IBayesNetFactory.
Definition at line 197 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__foo_flag, gum::BayesNetFactory< GUM_SCALAR >::__illegalStateError(), gum::BayesNetFactory< GUM_SCALAR >::__stringBag, gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, gum::HashTable< Key, Val, Alloc >::exists(), GUM_ERROR, gum::BayesNetFactory< GUM_SCALAR >::state(), gum::IBayesNetFactory::VARIABLE, and VERBOSITY.
Referenced by gum::prm::PRMSystem< double >::__groundAgg().
|
finalvirtual |
short-cut accessor for a DiscreveVariable in the BN
Implements gum::IBayesNetFactory.
Definition at line 106 of file BayesNetFactory_tpl.h.
References gum::BayesNetFactory< GUM_SCALAR >::__bn.
|
private |
Depending on the context this flag is used for some VERY important reasons.
Definition at line 395 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::variableDescription().
|
private |
The constructed BayesNet.
Definition at line 413 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__checkVariableModality(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::BayesNetFactory< GUM_SCALAR >::addNetworkProperty(), gum::BayesNetFactory< GUM_SCALAR >::bayesNet(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFactory< GUM_SCALAR >::cptDomainSize(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValues(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::BayesNetFactory< GUM_SCALAR >::variable(), and gum::BayesNetFactory< GUM_SCALAR >::varInBN().
|
private |
Depending on the context this flag is used for some VERY important reasons.
Definition at line 391 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::variableName().
|
private |
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls.
Definition at line 405 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPTImplementation(), and gum::BayesNetFactory< GUM_SCALAR >::~BayesNetFactory().
|
private |
Used when a factorized CPT is built.
Definition at line 401 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::endFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedEntry(), and gum::BayesNetFactory< GUM_SCALAR >::~BayesNetFactory().
|
private |
State stack.
Definition at line 410 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFactory< GUM_SCALAR >::endFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::endFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endNetworkDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedEntry(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startNetworkDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startVariableDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::state().
|
private |
Just to keep track of strings between two start/end calls.
Definition at line 398 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__checkModalityInBag(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::addModality(), gum::BayesNetFactory< GUM_SCALAR >::addParent(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValues(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::BayesNetFactory< GUM_SCALAR >::startFactorizedProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startRawProbabilityDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::startVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::variableDescription(), and gum::BayesNetFactory< GUM_SCALAR >::variableName().
|
private |
Mapping between a declared variable's name and it's node id.
Definition at line 416 of file BayesNetFactory.h.
Referenced by gum::BayesNetFactory< GUM_SCALAR >::__checkVariableModality(), gum::BayesNetFactory< GUM_SCALAR >::__checkVariableName(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValues(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::BayesNetFactory< GUM_SCALAR >::variableId(), and gum::BayesNetFactory< GUM_SCALAR >::variableName().