aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::BayesNetFactory< GUM_SCALAR > Class Template Reference

A factory class to ease BayesNet construction. More...

#include <agrum/BN/BayesNetFactory.h>

Inheritance diagram for gum::BayesNetFactory< GUM_SCALAR >:
Collaboration diagram for gum::BayesNetFactory< GUM_SCALAR >:

Public Types

enum class  factory_state : char {
  NONE , NETWORK , VARIABLE , PARENTS ,
  RAW_CPT , FACT_CPT , FACT_ENTRY
}
 The enumeration of states in which the factory can be in. More...

Public Member Functions

Constructor & destructor.
 BayesNetFactory (BayesNet< GUM_SCALAR > *bn)
 Use this constructor if you want to use an already created BayesNet.
 BayesNetFactory (const BayesNetFactory< GUM_SCALAR > &source)
 Copy constructor.
virtual ~BayesNetFactory ()
 Destructor.
Getter and setters.
BayesNet< GUM_SCALAR > * bayesNet ()
 Returns the BayesNet created by this factory.
const DiscreteVariablevarInBN (NodeId id) final
 short-cut accessor for a DiscreveVariable in the BN
factory_state state () const final
 Returns the current state of the factory.
NodeId variableId (const std::string &name) const final
 Returns the NodeId of a variable given it's name.
const DiscreteVariablevariable (const std::string &name) const
 Returns a constant reference on a variable given it's name.
Size cptDomainSize (NodeId n) const final
 Returns the domainSize of the cpt for the node n.
Network declaration methods (NONE -> NETWORK)
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 addNetworkProperty (const std::string &propName, const std::string &propValue) final
 Tells the factory to add a property to the current network.
void endNetworkDeclaration () final
 Tells the factory that we're out of a network declaration.
Variable declaration methods (NONE -> VARIABLE)
void startVariableDeclaration () final
 Tells the factory that we're in a variable declaration.
void variableName (const std::string &name) final
 Tells the factory the current variable's name.
void variableDescription (const std::string &desc) final
 Tells the factory the current variable's description.
void addModality (const std::string &name) final
 Adds a modality to the current labelized variable.
void addMin (const long &min)
 Adds the min value of the current range variable.
void addMax (const long &max)
 Adds the max value of the current range variable.
void addTick (const GUM_SCALAR &tick)
 Adds a tick to the current Discretized variable.
void setVariableCPTImplementation (MultiDimAdressable *adressable) final
 Defines the implementation to use for var's Tensor.
NodeId endVariableDeclaration () final
 Tells the factory that we're out of a variable declaration.
Parents declaration methods (NONE -> PARENTS)
void startParentsDeclaration (const std::string &var) final
 Tells the factory that we're declaring parents for some variable.
void addParent (const std::string &var) final
 Tells the factory for which variable we're declaring parents.
void endParentsDeclaration () final
 Tells the factory that we've finished declaring parents for some variable.
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.
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 rawConditionalTable (const std::vector< float > &rawTable) final
 Fills the variable's table with the values in rawTable.
void endRawProbabilityDeclaration () final
 Tells the factory that we finished declaring a conditional probability table.
Factorized probability table declaration methods
void startFactorizedProbabilityDeclaration (const std::string &var) final
 Tells the factory that we're starting a factorized declaration.
void startFactorizedEntry () final
 Tells the factory that we start an entry of a factorized conditional probability table.
void endFactorizedEntry () final
 Tells the factory that we end an entry of a factorized conditional probability table.
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 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 endFactorizedProbabilityDeclaration () final
 Tells the factory that we finished declaring a conditional probability table.
Delegated CPT definitions methods

(NONE, NETWORK)

void setVariable (const DiscreteVariable &var) final
 Define a variable.
void setVariableCPT (const std::string &varName, MultiDimAdressable *table, bool redefineParents) final
 Define a variable's CPT.
verbosity control
void setVerbose ()
void resetVerbose ()
bool isVerbose ()

Private Member Functions

BayesNetFactory< GUM_SCALAR > & operator= (const BayesNetFactory< GUM_SCALAR > &source)=delete
 Copy operator is illegal, use only copy constructor.
void _illegalStateError_ (const std::string &s)
 Raise an OperationNotAllowed with the message "Illegal state.".
void _checkVariableName_ (const std::string &name) const
 Check if a variable with the given name exists, if not raise an NotFound exception.
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 _checkModalityInBag_ (const std::string &mod)
 Check if in stringBag there is no other modality with the same name.
void _setCPTAndParents_ (const DiscreteVariable &var, Tensor< GUM_SCALAR > *table)
 Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.
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 _fillProbaWithValuesTable_ (const std::vector< float > &rawTable)
 Fill a tensor from a raw CPT.(using the canonical order of vars).
bool _increment_ (std::vector< gum::Idx > &modCounter, List< const DiscreteVariable * > &varList) const
 Increment a modality counter for the fillProbaWithValuesTable method.

Private Attributes

std::vector< factory_state_states_
 State stack.
BayesNet< GUM_SCALAR > * _bn_
 The constructed BayesNet.
HashTable< std::string, NodeId_varNameMap_
 Mapping between a declared variable's name and it's node id.
bool _verbose_
Current constructed BayesNet's parts.
bool _foo_flag_
 Depending on the context this flag is used for some VERY important reasons.
bool _bar_flag_
 Depending on the context this flag is used for some VERY important reasons.
std::vector< std::string > _stringBag_
 Just to keep track of strings between two start/end calls.
Instantiation_parents_
 Used when a factorized CPT is built.
MultiDimImplementation< GUM_SCALAR > * _impl_
 Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls.

Detailed Description

template<typename GUM_SCALAR>
class gum::BayesNetFactory< GUM_SCALAR >

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 81 of file BayesNetFactory.h.

Member Enumeration Documentation

◆ factory_state

enum class gum::IBayesNetFactory::factory_state : char
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 79 of file IBayesNetFactory.h.

79 : char {
80 NONE,
81 NETWORK,
83 PARENTS,
84 RAW_CPT,
85 FACT_CPT,
86 FACT_ENTRY
87 };

Constructor & Destructor Documentation

◆ BayesNetFactory() [1/2]

template<typename GUM_SCALAR>
INLINE gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory ( BayesNet< GUM_SCALAR > * bn)
explicit

Use this constructor if you want to use an already created BayesNet.

Parameters
bnA pointer over the BayesNet filled by this factory.
Exceptions
DuplicateElementRaised if two variables in bn share the same name.

Definition at line 60 of file BayesNetFactory_tpl.h.

60 :
61 _parents_(nullptr), _impl_(0), _bn_(bn) {
64
65 for (auto node: bn->nodes()) {
66 if (_varNameMap_.exists(bn->variable(node).name()))
67 GUM_ERROR(DuplicateElement, "Name already used: " << bn->variable(node).name())
68
70 }
71
73 }
A factory class to ease BayesNet construction.
std::vector< factory_state > _states_
State stack.
const DiscreteVariable & variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
HashTable< std::string, NodeId > _varNameMap_
Mapping between a declared variable's name and it's node id.
BayesNet< GUM_SCALAR > * _bn_
The constructed BayesNet.
Instantiation * _parents_
Used when a factorized CPT is built.
MultiDimImplementation< GUM_SCALAR > * _impl_
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls.
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References BayesNetFactory(), _bn_, _impl_, _parents_, _states_, _varNameMap_, GUM_ERROR, gum::IBayesNetFactory::NONE, and gum::IBayesNetFactory::resetVerbose().

Referenced by BayesNetFactory(), BayesNetFactory(), ~BayesNetFactory(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BayesNetFactory() [2/2]

template<typename GUM_SCALAR>
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.

Warning
You can only copy a factory if its current state is NONE or NETWORK.
Exceptions
OperationNotAllowedRaised if the state of source is not NONE or NETWORK.

Definition at line 79 of file BayesNetFactory_tpl.h.

79 :
80 _parents_(nullptr), _impl_(nullptr), _bn_(nullptr) {
82
84 GUM_ERROR(OperationNotAllowed, "Illegal state to proceed make a copy.")
85 } else {
88 }
89 }
factory_state state() const final
Returns the current state of the factory.

References BayesNetFactory(), _bn_, _impl_, _parents_, _states_, GUM_ERROR, gum::IBayesNetFactory::NONE, and state().

Here is the call graph for this function:

◆ ~BayesNetFactory()

template<typename GUM_SCALAR>
INLINE gum::BayesNetFactory< GUM_SCALAR >::~BayesNetFactory ( )
virtual

Destructor.

To prevent strange behaviour you should always destroy a BayesNetFactory when it's state equals NONE.

Exceptions
FatalErrorRaised if the state of the factory prevents it to die peacefully.

Definition at line 93 of file BayesNetFactory_tpl.h.

93 {
95
96 if (_parents_ != nullptr) delete _parents_;
97
98 if (_impl_ != nullptr) {
99 //@todo better than throwing an exception from inside a destructor but
100 // still ...
101 std::cerr << "[BN factory] Implementation defined for a variable but not used. "
102 "You should call endVariableDeclaration() before "
103 "deleting me."
104 << std::endl;
105 exit(1);
106 }
107 }

References BayesNetFactory(), _impl_, and _parents_.

Here is the call graph for this function:

Member Function Documentation

◆ _checkModalityInBag_()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_checkModalityInBag_ ( const std::string & mod)
private

Check if in stringBag there is no other modality with the same name.

Definition at line 917 of file BayesNetFactory_tpl.h.

917 {
918 for (size_t i = 3; i < _stringBag_.size(); ++i) {
919 if (mod == _stringBag_[i]) { GUM_ERROR(DuplicateElement, "Label already used: " << mod) }
920 }
921 }
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.

References _stringBag_, and GUM_ERROR.

Referenced by addModality().

Here is the caller graph for this function:

◆ _checkVariableModality_()

template<typename GUM_SCALAR>
INLINE Idx gum::BayesNetFactory< GUM_SCALAR >::_checkVariableModality_ ( const std::string & name,
const std::string & mod )
private

Check if var exists and if mod is one of it's modality, if not raise an NotFound exception.

Definition at line 903 of file BayesNetFactory_tpl.h.

904 {
906 const DiscreteVariable& var = _bn_->variable(_varNameMap_[name]);
907
908 for (Idx i = 0; i < var.domainSize(); ++i) {
909 if (mod == var.label(i)) { return i; }
910 }
911
913 }
void _checkVariableName_(const std::string &name) const
Check if a variable with the given name exists, if not raise an NotFound exception.

References _bn_, _checkVariableName_(), _varNameMap_, gum::DiscreteVariable::domainSize(), GUM_ERROR, and gum::DiscreteVariable::label().

Referenced by setParentModality().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkVariableName_()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_checkVariableName_ ( const std::string & name) const
private

Check if a variable with the given name exists, if not raise an NotFound exception.

Definition at line 896 of file BayesNetFactory_tpl.h.

896 {
897 if (!_varNameMap_.exists(name)) { GUM_ERROR(NotFound, name) }
898 }

References _varNameMap_, and GUM_ERROR.

Referenced by _checkVariableModality_(), _setCPTAndParents_(), addParent(), setParentModality(), setVariable(), setVariableCPT(), startFactorizedProbabilityDeclaration(), startParentsDeclaration(), and startRawProbabilityDeclaration().

Here is the caller graph for this function:

◆ _fillProbaWithValuesTable_() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_ ( const std::vector< float > & rawTable)
private

Fill a tensor from a raw CPT.(using the canonical order of vars).

Definition at line 546 of file BayesNetFactory_tpl.h.

547 {
549
551
552 // the main loop is on the first variables. The others are in the right
553 // order.
555 Idx j = 0;
556
557 for (cptInst.setFirstVar(first); !cptInst.end(); cptInst.incVar(first)) {
558 for (cptInst.setFirstNotVar(first); !cptInst.end(); cptInst.incNotVar(first))
559 table.set(cptInst,
560 (j < rawTable.size()) ? static_cast< GUM_SCALAR >(rawTable[j++])
561 : static_cast< GUM_SCALAR >(0));
562
563 cptInst.unsetEnd();
564 }
565 }

References _bn_, _stringBag_, _varNameMap_, gum::Instantiation::end(), gum::Instantiation::incNotVar(), gum::Instantiation::incVar(), gum::Instantiation::setFirstNotVar(), gum::Instantiation::setFirstVar(), and gum::Instantiation::unsetEnd().

Here is the call graph for this function:

◆ _fillProbaWithValuesTable_() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_ ( const std::vector< std::string > & variables,
const std::vector< float > & rawTable )
private

Fill a tensor from a raw CPT.

Definition at line 503 of file BayesNetFactory_tpl.h.

505 {
508
510 table.fillWith(GUM_SCALAR(0.0));
511
512 for (size_t i = 0; i < variables.size(); ++i) {
513 varList.pushBack(&(_bn_->variable(_varNameMap_[variables[i]])));
514 }
515
516 Idx nbrVar = varList.size();
517
519
520 // initializing the array
521 for (NodeId i = 0; i < nbrVar; i++) {
522 modCounter.push_back(Idx(0));
523 }
524
525 for (Idx j = 0; j < rawTable.size(); j++) {
526 for (NodeId i = 0; i < nbrVar; i++) {
527 cptInst.chgVal(*(varList[i]), modCounter[i]);
528 }
529
530 table.set(cptInst, static_cast< GUM_SCALAR >(rawTable[j]));
531 if (!_increment_(modCounter, varList)) { break; } // too many values (just not read)
532 }
533 }
bool _increment_(std::vector< gum::Idx > &modCounter, List< const DiscreteVariable * > &varList) const
Increment a modality counter for the fillProbaWithValuesTable method.

References _bn_, _increment_(), _stringBag_, _varNameMap_, gum::Instantiation::chgVal(), gum::List< Val >::pushBack(), and gum::List< Val >::size().

Referenced by rawConditionalTable(), and rawConditionalTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _illegalStateError_()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_illegalStateError_ ( const std::string & s)
private

Raise an OperationNotAllowed with the message "Illegal state.".

Definition at line 844 of file BayesNetFactory_tpl.h.

844 {
845 std::string msg = "Illegal state call (";
846 msg += s;
847 msg += ") in state ";
848
849 switch (state()) {
850 case factory_state::NONE : {
851 msg += "NONE";
852 break;
853 }
854
856 msg += "NETWORK";
857 break;
858 }
859
861 msg += "VARIABLE";
862 break;
863 }
864
866 msg += "PARENTS";
867 break;
868 }
869
871 msg += "RAW_CPT";
872 break;
873 }
874
876 msg += "FACT_CPT";
877 break;
878 }
879
881 msg += "FACT_ENTRY";
882 break;
883 }
884
885 default : {
886 msg += "Unknown state";
887 }
888 }
889
891 }

References gum::IBayesNetFactory::FACT_CPT, gum::IBayesNetFactory::FACT_ENTRY, GUM_ERROR, gum::IBayesNetFactory::NETWORK, gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::PARENTS, gum::IBayesNetFactory::RAW_CPT, state(), and gum::IBayesNetFactory::VARIABLE.

Referenced by addMax(), addMin(), addModality(), addParent(), addTick(), endFactorizedEntry(), endFactorizedProbabilityDeclaration(), endNetworkDeclaration(), endParentsDeclaration(), endRawProbabilityDeclaration(), endVariableDeclaration(), rawConditionalTable(), rawConditionalTable(), setParentModality(), setVariable(), setVariableCPT(), setVariableCPTImplementation(), setVariableValues(), setVariableValuesUnchecked(), startFactorizedEntry(), startFactorizedProbabilityDeclaration(), startNetworkDeclaration(), startParentsDeclaration(), startRawProbabilityDeclaration(), startVariableDeclaration(), variableDescription(), variableName(), and variableType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _increment_()

template<typename GUM_SCALAR>
INLINE bool gum::BayesNetFactory< GUM_SCALAR >::_increment_ ( std::vector< gum::Idx > & modCounter,
List< const DiscreteVariable * > & varList ) const
private

Increment a modality counter for the fillProbaWithValuesTable method.

Definition at line 569 of file BayesNetFactory_tpl.h.

570 {
571 bool last = true;
572
573 for (NodeId j = 0; j < modCounter.size(); j++) {
574 last = (modCounter[j] == (varList[j]->domainSize() - 1)) && last;
575
576 if (!last) break;
577 }
578
579 if (last) { return false; }
580
581 bool add = false;
582
583 auto i = NodeId(varList.size() - 1);
584
585 do {
586 if (modCounter[i] == (varList[i]->domainSize() - 1)) {
587 modCounter[i] = 0;
588 add = true;
589 } else {
590 modCounter[i] += 1;
591 add = false;
592 }
593
594 i--;
595 } while (add);
596
597 return true;
598 }

References gum::List< Val >::size().

Referenced by _fillProbaWithValuesTable_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _resetParts_()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_resetParts_ ( )
private

Reset the different parts used to constructed the BayesNet.

Definition at line 944 of file BayesNetFactory_tpl.h.

944 {
945 _foo_flag_ = false;
946 _bar_flag_ = false;
947 _stringBag_.clear();
948 }
bool _bar_flag_
Depending on the context this flag is used for some VERY important reasons.
bool _foo_flag_
Depending on the context this flag is used for some VERY important reasons.

References _bar_flag_, _foo_flag_, and _stringBag_.

Referenced by endFactorizedProbabilityDeclaration(), endParentsDeclaration(), endRawProbabilityDeclaration(), and endVariableDeclaration().

Here is the caller graph for this function:

◆ _setCPTAndParents_()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::_setCPTAndParents_ ( const DiscreteVariable & var,
Tensor< GUM_SCALAR > * table )
private

Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.

Definition at line 926 of file BayesNetFactory_tpl.h.

927 {
928 NodeId varId = _varNameMap_[var.name()];
929 _bn_->dag_.eraseParents(varId);
930
931 for (auto v: table->variablesSequence()) {
932 if (v != (&var)) {
933 _checkVariableName_(v->name());
934 _bn_->dag_.addArc(_varNameMap_[v->name()], varId);
935 }
936 }
937
938 // CPT are created when a variable is added.
939 _bn_->_unsafeChangeTensor_(varId, table);
940 }

References _bn_, _checkVariableName_(), _varNameMap_, and gum::Variable::name().

Referenced by setVariableCPT().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMax()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::addMax ( const long & max)
virtual

Adds the max value of the current range variable.

Implements gum::IBayesNetFactory.

Definition at line 272 of file BayesNetFactory_tpl.h.

272 {
274 _illegalStateError_("addMax");
275 } else {
276 _stringBag_.push_back(std::to_string(max));
277 }
278 }
void _illegalStateError_(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".

References _illegalStateError_(), _stringBag_, state(), and gum::IBayesNetFactory::VARIABLE.

Here is the call graph for this function:

◆ addMin()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::addMin ( const long & min)
virtual

Adds the min value of the current range variable.

Implements gum::IBayesNetFactory.

Definition at line 260 of file BayesNetFactory_tpl.h.

260 {
262 _illegalStateError_("addMin");
263 } else {
264 _stringBag_.push_back(std::to_string(min));
265 }
266 }

References _illegalStateError_(), _stringBag_, state(), and gum::IBayesNetFactory::VARIABLE.

Here is the call graph for this function:

◆ addModality()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::addModality ( const std::string & name)
finalvirtual

Adds a modality to the current labelized variable.

Implements gum::IBayesNetFactory.

Definition at line 247 of file BayesNetFactory_tpl.h.

247 {
249 _illegalStateError_("addModality");
250 } else {
252 _stringBag_.push_back(name);
253 }
254 }
void _checkModalityInBag_(const std::string &mod)
Check if in stringBag there is no other modality with the same name.

References _checkModalityInBag_(), _illegalStateError_(), _stringBag_, state(), and gum::IBayesNetFactory::VARIABLE.

Referenced by gum::prm::PRMSystem< double >::getArrayType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNetworkProperty()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::addNetworkProperty ( const std::string & propName,
const std::string & propValue )
finalvirtual

Tells the factory to add a property to the current network.

Implements gum::IBayesNetFactory.

Definition at line 166 of file BayesNetFactory_tpl.h.

167 {
168 _bn_->setProperty(propName, propValue);
169 }

References _bn_.

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::groundedBN().

Here is the caller graph for this function:

◆ addParent()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::addParent ( const std::string & var)
finalvirtual

Tells the factory for which variable we're declaring parents.

Parameters
varThe parent's name.
Exceptions
NotFoundRaised if var does not exists.

Implements gum::IBayesNetFactory.

Definition at line 433 of file BayesNetFactory_tpl.h.

433 {
434 if (state() != factory_state::PARENTS) {
435 _illegalStateError_("addParent");
436 } else {
438 _stringBag_.push_back(var);
439 }
440 }

References _checkVariableName_(), _illegalStateError_(), _stringBag_, gum::IBayesNetFactory::PARENTS, and state().

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::_groundRef_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTick()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::addTick ( const GUM_SCALAR & tick)

Adds a tick to the current Discretized variable.

Definition at line 284 of file BayesNetFactory_tpl.h.

284 {
286 _illegalStateError_("addTick");
287 } else {
288 _stringBag_.push_back(std::to_string(tick));
289 }
290 }

References _illegalStateError_(), _stringBag_, state(), and gum::IBayesNetFactory::VARIABLE.

Here is the call graph for this function:

◆ bayesNet()

template<typename GUM_SCALAR>
INLINE BayesNet< GUM_SCALAR > * gum::BayesNetFactory< GUM_SCALAR >::bayesNet ( )

Returns the BayesNet created by this factory.

Exceptions
OperationNotAllowedRaise if the state of the factory is different than NONE.

Definition at line 111 of file BayesNetFactory_tpl.h.

111 {
112 return _bn_;
113 }

References _bn_.

◆ cptDomainSize()

template<typename GUM_SCALAR>
INLINE Size gum::BayesNetFactory< GUM_SCALAR >::cptDomainSize ( NodeId n) const
finalvirtual

Returns the domainSize of the cpt for the node n.

Exceptions
NotFoundraised if no such NodeId exists.

Implements gum::IBayesNetFactory.

Definition at line 150 of file BayesNetFactory_tpl.h.

150 {
151 return _bn_->cpt(n).domainSize();
152 }

References _bn_.

◆ endFactorizedEntry()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::endFactorizedEntry ( )
finalvirtual

Tells the factory that we end an entry of a factorized conditional probability table.

Implements gum::IBayesNetFactory.

Definition at line 640 of file BayesNetFactory_tpl.h.

640 {
642 _illegalStateError_("endFactorizedEntry");
643 } else {
644 delete _parents_;
645 _parents_ = nullptr;
646 _states_.pop_back();
647 }
648 }

References _illegalStateError_(), _parents_, _states_, gum::IBayesNetFactory::FACT_ENTRY, and state().

Here is the call graph for this function:

◆ endFactorizedProbabilityDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::endFactorizedProbabilityDeclaration ( )
finalvirtual

Tells the factory that we finished declaring a conditional probability table.

Implements gum::IBayesNetFactory.

Definition at line 759 of file BayesNetFactory_tpl.h.

759 {
761 _illegalStateError_("endFactorizedProbabilityDeclaration");
762 } else {
763 _resetParts_();
764 _states_.pop_back();
765 }
766 }
void _resetParts_()
Reset the different parts used to constructed the BayesNet.

References _illegalStateError_(), _resetParts_(), _states_, gum::IBayesNetFactory::FACT_CPT, and state().

Here is the call graph for this function:

◆ endNetworkDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::endNetworkDeclaration ( )
finalvirtual

Tells the factory that we're out of a network declaration.

Implements gum::IBayesNetFactory.

Definition at line 173 of file BayesNetFactory_tpl.h.

173 {
174 if (state() != factory_state::NETWORK) {
175 _illegalStateError_("endNetworkDeclaration");
176 } else {
177 _states_.pop_back();
178 }
179 }

References _illegalStateError_(), _states_, gum::IBayesNetFactory::NETWORK, and state().

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::groundedBN().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endParentsDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::endParentsDeclaration ( )
finalvirtual

Tells the factory that we've finished declaring parents for some variable.

Warning
When parents exist, endParentsDeclaration creates some arcs. Due to the order used in BIF file for probability specification, these arcs are created in the inverse order of the order of the parent specifications.

Implements gum::IBayesNetFactory.

Definition at line 447 of file BayesNetFactory_tpl.h.

447 {
448 if (state() != factory_state::PARENTS) {
449 _illegalStateError_("endParentsDeclaration");
450 } else {
452
453 // PLEASE NOTE THAT THE ORDER IS INVERSE
454
455 for (size_t i = _stringBag_.size() - 1; i > 0; --i) {
456 _bn_->addArc(_varNameMap_[_stringBag_[i]], id);
457 }
458
459 _resetParts_();
460
461 _states_.pop_back();
462 }
463 }

References _bn_, _illegalStateError_(), _resetParts_(), _states_, _stringBag_, _varNameMap_, gum::IBayesNetFactory::PARENTS, and state().

Here is the call graph for this function:

◆ endRawProbabilityDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::endRawProbabilityDeclaration ( )
finalvirtual

Tells the factory that we finished declaring a conditional probability table.

Implements gum::IBayesNetFactory.

Definition at line 603 of file BayesNetFactory_tpl.h.

603 {
604 if (state() != factory_state::RAW_CPT) {
605 _illegalStateError_("endRawProbabilityDeclaration");
606 } else {
607 _resetParts_();
608 _states_.pop_back();
609 }
610 }

References _illegalStateError_(), _resetParts_(), _states_, gum::IBayesNetFactory::RAW_CPT, and state().

Here is the call graph for this function:

◆ endVariableDeclaration()

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration ( )
finalvirtual

Tells the factory that we're out of a variable declaration.

Returns
The Node id of the created variable.
Exceptions
gum::OperationNotAllowedRaised if the variable isn't defined (or / not enough defined).

Implements gum::IBayesNetFactory.

Definition at line 324 of file BayesNetFactory_tpl.h.

324 {
326 _illegalStateError_("endVariableDeclaration");
327 } else if (_foo_flag_ && (_stringBag_.size() > 4)) {
328 DiscreteVariable* var = nullptr;
329
330 // if the current variable is a LabelizedVariable
331 if (_stringBag_[2] == "L") {
332 const auto l = new LabelizedVariable(_stringBag_[0], (_bar_flag_) ? _stringBag_[1] : "", 0);
333
334 for (size_t i = 3; i < _stringBag_.size(); ++i) {
335 l->addLabel(_stringBag_[i]);
336 }
337
338 var = l;
339 // if the current variable is a RangeVariable
340 } else if (_stringBag_[2] == "I") {
341 // try to create the domain of the variable
343 for (size_t i = 3; i < _stringBag_.size(); ++i) {
344 domain.push_back(std::stoi(_stringBag_[i]));
345 }
346
347 const auto v
349 var = v;
350 } else if (_stringBag_[2] == "R") {
351 const auto r = new RangeVariable(_stringBag_[0],
352 _bar_flag_ ? _stringBag_[1] : "",
355
356 var = r;
357 // if the current variable is a DiscretizedVariable
358 } else if (_stringBag_[2] == "D") {
360 _bar_flag_ ? _stringBag_[1] : "");
361
362 for (size_t i = 3; i < _stringBag_.size(); ++i) {
364 }
365
366 var = d;
367 }
368
369 if (var == nullptr) {
370 GUM_ERROR(OperationNotAllowed, "Unknown variable type for variable " + _stringBag_[0])
371 }
372
373 if (_impl_ != 0) {
374 _varNameMap_.insert(var->name(), _bn_->add(*var, _impl_));
375 _impl_ = 0;
376 } else {
377 _varNameMap_.insert(var->name(), _bn_->add(*var));
378 }
379
380 NodeId retVal = _varNameMap_[var->name()];
381
382 delete var;
383
384 _resetParts_();
385 _states_.pop_back();
386
387 return retVal;
388 } else {
390 msg << "Not enough modalities (";
391
392 if (_stringBag_.size() > 3) {
393 msg << _stringBag_.size() - 3;
394 } else {
395 msg << 0;
396 }
397
398 msg << ") declared for variable ";
399
400 if (_foo_flag_) {
401 msg << _stringBag_[0];
402 } else {
403 msg << "unknown";
404 }
405
406 _resetParts_();
407
408 _states_.pop_back();
410 }
411
412 // For noisy compilers
413 return 0;
414 }
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.

References _bar_flag_, _bn_, _foo_flag_, _illegalStateError_(), _impl_, _resetParts_(), _states_, _stringBag_, _varNameMap_, GUM_ERROR, gum::Variable::name(), state(), and gum::IBayesNetFactory::VARIABLE.

Here is the call graph for this function:

◆ isVerbose()

bool gum::IBayesNetFactory::isVerbose ( )
inlineinherited

Definition at line 101 of file IBayesNetFactory.h.

101{ return _verbose_; };

References _verbose_.

◆ operator=()

template<typename GUM_SCALAR>
BayesNetFactory< GUM_SCALAR > & gum::BayesNetFactory< GUM_SCALAR >::operator= ( const BayesNetFactory< GUM_SCALAR > & source)
privatedelete

Copy operator is illegal, use only copy constructor.

References BayesNetFactory().

Here is the call graph for this function:

◆ rawConditionalTable() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::rawConditionalTable ( const std::vector< float > & rawTable)
finalvirtual

Fills the variable's table with the values in rawTable.

use the canonical ordering for the variables (e.g. see BIF format) ...

Parameters
rawTableThe raw table.

Implements gum::IBayesNetFactory.

Definition at line 537 of file BayesNetFactory_tpl.h.

537 {
538 if (state() != factory_state::RAW_CPT) {
539 _illegalStateError_("rawConditionalTable");
540 } else {
542 }
543 }
void _fillProbaWithValuesTable_(const std::vector< std::string > &variables, const std::vector< float > &rawTable)
Fill a tensor from a raw CPT.

References _fillProbaWithValuesTable_(), _illegalStateError_(), gum::IBayesNetFactory::RAW_CPT, and state().

Here is the call graph for this function:

◆ rawConditionalTable() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::rawConditionalTable ( const std::vector< std::string > & variables,
const std::vector< float > & rawTable )
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].
* 
Parameters
variablesthe vector giving the order of parents
rawTableThe raw table.

Implements gum::IBayesNetFactory.

Definition at line 492 of file BayesNetFactory_tpl.h.

494 {
495 if (state() != factory_state::RAW_CPT) {
496 _illegalStateError_("rawConditionalTable");
497 } else {
499 }
500 }

References _fillProbaWithValuesTable_(), _illegalStateError_(), gum::IBayesNetFactory::RAW_CPT, and state().

Here is the call graph for this function:

◆ resetVerbose()

void gum::IBayesNetFactory::resetVerbose ( )
inlineinherited

Definition at line 99 of file IBayesNetFactory.h.

99{ _verbose_ = false; };

References _verbose_.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory().

Here is the caller graph for this function:

◆ setParentModality()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::setParentModality ( const std::string & parent,
const std::string & modality )
finalvirtual

Tells the factory on which modality we want to instantiate one of variable's parent.

Implements gum::IBayesNetFactory.

Definition at line 653 of file BayesNetFactory_tpl.h.

654 {
656 _illegalStateError_("string");
657 } else {
660 (*_parents_) << _bn_->variable(_varNameMap_[parent]);
661 _parents_->chgVal(_bn_->variable(_varNameMap_[parent]), id);
662 }
663 }
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.

References _bn_, _checkVariableModality_(), _checkVariableName_(), _illegalStateError_(), _parents_, _varNameMap_, gum::IBayesNetFactory::FACT_ENTRY, and state().

Here is the call graph for this function:

◆ setVariable()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::setVariable ( const DiscreteVariable & var)
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.

Parameters
varThe pointer over a DiscreteVariable used to define a new variable in the built BayesNet.
Exceptions
DuplicateElementRaised if a variable with the same name already exists.
OperationNotAllowedRaised 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 780 of file BayesNetFactory_tpl.h.

780 {
781 if (state() != factory_state::NONE) {
782 _illegalStateError_("setVariable");
783 } else {
784 try {
785 _checkVariableName_(var.name());
786 GUM_ERROR(DuplicateElement, "Name already used: " << var.name())
787 } catch (NotFound const&) {
788 // The var name is unused
789 _varNameMap_.insert(var.name(), _bn_->add(var));
790 }
791 }
792 }

References _bn_, _checkVariableName_(), _illegalStateError_(), _varNameMap_, GUM_ERROR, gum::Variable::name(), gum::IBayesNetFactory::NONE, and state().

Here is the call graph for this function:

◆ setVariableCPT()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::setVariableCPT ( const std::string & varName,
MultiDimAdressable * table,
bool redefineParents )
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.

Parameters
varNameThe name of the concerned variable.
tableA pointer over the CPT used for var.
redefineParentsIf true redefine var's parents to match table's variables set.
Exceptions
NotFoundRaised if no variable matches var.
OperationNotAllowedRaised 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 813 of file BayesNetFactory_tpl.h.

815 {
816 auto pot = dynamic_cast< Tensor< GUM_SCALAR >* >(table);
817
818 if (state() != factory_state::NONE) {
819 _illegalStateError_("setVariableCPT");
820 } else {
822 const DiscreteVariable& var = _bn_->variable(_varNameMap_[varName]);
824 // If we have to change the structure of the BayesNet, then we call a sub
825 // method.
826
827 if (redefineParents) {
829 } else if (pot->contains(var)) {
830 for (auto node: _bn_->parents(varId)) {
831 if (!pot->contains(_bn_->variable(node))) {
832 GUM_ERROR(OperationNotAllowed, "The CPT is not valid in the current BayesNet.")
833 }
834 }
835
836 // CPT are created when a variable is added.
837 _bn_->_unsafeChangeTensor_(varId, pot);
838 }
839 }
840 }
void _setCPTAndParents_(const DiscreteVariable &var, Tensor< GUM_SCALAR > *table)
Sub method of setVariableCPT() which redefine the BayesNet's DAG with respect to table.

References _bn_, _checkVariableName_(), _illegalStateError_(), _setCPTAndParents_(), _varNameMap_, GUM_ERROR, gum::IBayesNetFactory::NONE, and state().

Here is the call graph for this function:

◆ setVariableCPTImplementation()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::setVariableCPTImplementation ( MultiDimAdressable * adressable)
finalvirtual

Defines the implementation to use for var's Tensor.

Warning
The implementation must be empty.
The pointer is always delegated to var's Tensor! No copy of it is made.
Todo
When copy of a MultiDimImplementation is available use a copy behaviour for this method.
Exceptions
NotFoundRaised if no variable matches var.
OperationNotAllowedRaised if impl is not empty.
OperationNotAllowedIf an implementation is already defined for the current variable.

Implements gum::IBayesNetFactory.

Definition at line 304 of file BayesNetFactory_tpl.h.

304 {
306
308 _illegalStateError_("setVariableCPTImplementation");
309 } else {
310 if (impl == nullptr) {
312 "An implementation for this variable is already "
313 "defined.")
314 } else if (impl->nbrDim() > 0) {
315 GUM_ERROR(OperationNotAllowed, "This implementation is not empty.")
316 }
317
318 _impl_ = impl;
319 }
320 }

References _illegalStateError_(), _impl_, GUM_ERROR, state(), and gum::IBayesNetFactory::VARIABLE.

Referenced by gum::prm::PRMSystem< double >::begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setVariableValues()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::setVariableValues ( const std::vector< float > & values)
finalvirtual

same than below with gum::OperationNotAllowed exception if value's size not OK.

Implements gum::IBayesNetFactory.

Definition at line 740 of file BayesNetFactory_tpl.h.

740 {
742 _illegalStateError_("setVariableValues");
743 } else {
744 // Checking consistency between values and var.
745 if (const DiscreteVariable& var = _bn_->variable(_varNameMap_[_stringBag_[0]]);
746 values.size() != var.domainSize()) {
748 var.name() << " : invalid number of modalities: found " << values.size()
749 << " while needed " << var.domainSize())
750 }
751
753 }
754 }
void setVariableValuesUnchecked(const std::vector< float > &values) final
Gives the values of the variable with respect to precedent parents modality.

References _bn_, _illegalStateError_(), _stringBag_, _varNameMap_, gum::IBayesNetFactory::FACT_ENTRY, GUM_ERROR, setVariableValuesUnchecked(), and state().

Here is the call graph for this function:

◆ setVariableValuesUnchecked()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked ( const std::vector< float > & values)
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

// Do stuff
factory.variableName("foo");
factory.startParentsDeclaration("foo");
// add parents
std::vector<double> seq;
seq.insert(0.4); // if foo true
seq.insert(O.6); // if foo false
factory.setVariableValues(seq); // fills the table with a default value
// finish your stuff
void startFactorizedProbabilityDeclaration(const std::string &var) final
Tells the factory that we're starting a factorized declaration.
void startParentsDeclaration(const std::string &var) final
Tells the factory that we're declaring parents for some variable.
void endFactorizedProbabilityDeclaration() final
Tells the factory that we finished declaring a conditional probability table.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
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.
void setVariableValues(const std::vector< float > &values) final
same than below with gum::OperationNotAllowed exception if value's size not OK.

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 692 of file BayesNetFactory_tpl.h.

693 {
695 _illegalStateError_("setVariableValues");
696 } else {
697 const DiscreteVariable& var = _bn_->variable(_varNameMap_[_stringBag_[0]]);
699
700 if (_parents_->domainSize() > 0) {
701 Instantiation inst(_bn_->cpt(_varNameMap_[var.name()]));
702 inst.setVals(*_parents_);
703 // Creating an instantiation containing all the variables not ins
704 // _parents_.
706 inst_default << var;
707
708 for (auto node: _bn_->parents(varId)) {
709 if (!_parents_->contains(_bn_->variable(node))) { inst_default << _bn_->variable(node); }
710 }
711
712 // Filling the variable's table.
713 for (inst.setFirstIn(inst_default); !inst.end(); inst.incIn(inst_default)) {
714 (_bn_->cpt(varId))
715 .set(inst,
716 inst.val(var) < values.size() ? static_cast< GUM_SCALAR >(values[inst.val(var)])
717 : static_cast< GUM_SCALAR >(0));
718 }
719 } else {
720 Instantiation inst(_bn_->cpt(_varNameMap_[var.name()]));
722 var_inst << var;
723
724 for (var_inst.setFirst(); !var_inst.end(); ++var_inst) {
725 inst.setVals(var_inst);
726
727 for (inst.setFirstOut(var_inst); !inst.end(); inst.incOut(var_inst)) {
728 (_bn_->cpt(varId))
729 .set(inst,
730 inst.val(var) < values.size()
731 ? static_cast< GUM_SCALAR >(values[inst.val(var)])
732 : static_cast< GUM_SCALAR >(0));
733 }
734 }
735 }
736 }
737 }

References _bn_, _illegalStateError_(), _parents_, _stringBag_, _varNameMap_, 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(), state(), and gum::Instantiation::val().

Referenced by setVariableValues().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setVerbose()

void gum::IBayesNetFactory::setVerbose ( )
inlineinherited

Definition at line 97 of file IBayesNetFactory.h.

97{ _verbose_ = true; };

References _verbose_.

◆ startFactorizedEntry()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::startFactorizedEntry ( )
finalvirtual

Tells the factory that we start an entry of a factorized conditional probability table.

Implements gum::IBayesNetFactory.

Definition at line 628 of file BayesNetFactory_tpl.h.

628 {
630 _illegalStateError_("startFactorizedEntry");
631 } else {
632 _parents_ = new Instantiation();
634 }
635 }

References _illegalStateError_(), _parents_, _states_, gum::IBayesNetFactory::FACT_CPT, gum::IBayesNetFactory::FACT_ENTRY, and state().

Here is the call graph for this function:

◆ startFactorizedProbabilityDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::startFactorizedProbabilityDeclaration ( const std::string & var)
finalvirtual

Tells the factory that we're starting a factorized declaration.

Implements gum::IBayesNetFactory.

Definition at line 615 of file BayesNetFactory_tpl.h.

615 {
616 if (state() != factory_state::NONE) {
617 _illegalStateError_("startFactorizedProbabilityDeclaration");
618 } else {
620 _stringBag_.insert(_stringBag_.begin(), var);
622 }
623 }

References _checkVariableName_(), _illegalStateError_(), _states_, _stringBag_, gum::IBayesNetFactory::FACT_CPT, gum::IBayesNetFactory::NONE, and state().

Here is the call graph for this function:

◆ startNetworkDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::startNetworkDeclaration ( )
finalvirtual

Tells the factory that we're in a network declaration.

Implements gum::IBayesNetFactory.

Definition at line 156 of file BayesNetFactory_tpl.h.

156 {
157 if (state() != factory_state::NONE) {
158 _illegalStateError_("startNetworkDeclaration");
159 } else {
161 }
162 }

References _illegalStateError_(), _states_, gum::IBayesNetFactory::NETWORK, gum::IBayesNetFactory::NONE, and state().

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::groundedBN().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startParentsDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::startParentsDeclaration ( const std::string & var)
finalvirtual

Tells the factory that we're declaring parents for some variable.

Parameters
varThe concerned variable's name.
Exceptions
NotFoundRaised if var does not exists.

Implements gum::IBayesNetFactory.

Definition at line 419 of file BayesNetFactory_tpl.h.

419 {
420 if (state() != factory_state::NONE) {
421 _illegalStateError_("startParentsDeclaration");
422 } else {
424 _stringBag_.insert(_stringBag_.begin(), var);
426 }
427 }

References _checkVariableName_(), _illegalStateError_(), _states_, _stringBag_, gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::PARENTS, and state().

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::_groundRef_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startRawProbabilityDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::startRawProbabilityDeclaration ( const std::string & var)
finalvirtual

Tells the factory that we're declaring a conditional probability table for some variable.

Parameters
varThe concerned variable's name.

Implements gum::IBayesNetFactory.

Definition at line 470 of file BayesNetFactory_tpl.h.

470 {
471 if (state() != factory_state::NONE) {
472 _illegalStateError_("startRawProbabilityDeclaration");
473 } else {
475 _stringBag_.push_back(var);
477 }
478 }

References _checkVariableName_(), _illegalStateError_(), _states_, _stringBag_, gum::IBayesNetFactory::NONE, gum::IBayesNetFactory::RAW_CPT, and state().

Here is the call graph for this function:

◆ startVariableDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::startVariableDeclaration ( )
finalvirtual

Tells the factory that we're in a variable declaration.

Implements gum::IBayesNetFactory.

Definition at line 184 of file BayesNetFactory_tpl.h.

184 {
185 if (state() != factory_state::NONE) {
186 _illegalStateError_("startVariableDeclaration");
187 } else {
189 _stringBag_.emplace_back("name");
190 _stringBag_.emplace_back("desc");
191 _stringBag_.emplace_back("L");
192 }
193 }

References _illegalStateError_(), _states_, _stringBag_, gum::IBayesNetFactory::NONE, state(), and gum::IBayesNetFactory::VARIABLE.

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::_groundAgg_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ state()

◆ variable()

template<typename GUM_SCALAR>
INLINE const DiscreteVariable & gum::BayesNetFactory< GUM_SCALAR >::variable ( const std::string & name) const

Returns a constant reference on a variable given it's name.

Exceptions
NotFoundRaised if no variable matches the name.

Definition at line 140 of file BayesNetFactory_tpl.h.

140 {
141 try {
142 return _bn_->variable(variableId(name));
143 } catch (NotFound const&) { GUM_ERROR(NotFound, name) }
144 }
NodeId variableId(const std::string &name) const final
Returns the NodeId of a variable given it's name.

References _bn_, GUM_ERROR, and variableId().

Referenced by gum::prm::PRMSystem< double >::_groundAgg_(), and gum::prm::PRMSystem< double >::_groundTensor_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ variableDescription()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::variableDescription ( const std::string & desc)
finalvirtual

Tells the factory the current variable's description.

Implements gum::IBayesNetFactory.

Definition at line 210 of file BayesNetFactory_tpl.h.

210 {
212 _illegalStateError_("variableDescription");
213 } else {
214 _bar_flag_ = true;
215 _stringBag_[1] = desc;
216 }
217 }

References _bar_flag_, _illegalStateError_(), _stringBag_, state(), and gum::IBayesNetFactory::VARIABLE.

Here is the call graph for this function:

◆ variableId()

template<typename GUM_SCALAR>
INLINE NodeId gum::BayesNetFactory< GUM_SCALAR >::variableId ( const std::string & name) const
finalvirtual

Returns the NodeId of a variable given it's name.

Exceptions
NotFoundRaised if no variable matches the name.

Implements gum::IBayesNetFactory.

Definition at line 130 of file BayesNetFactory_tpl.h.

130 {
131 try {
132 return _varNameMap_[name];
133 } catch (NotFound const&) { GUM_ERROR(NotFound, name) }
134 }

References _varNameMap_, and GUM_ERROR.

Referenced by variable().

Here is the caller graph for this function:

◆ variableName()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::variableName ( const std::string & name)
finalvirtual

Tells the factory the current variable's name.

Exceptions
DuplicateElementRaised if a variable with the same name already exist.

Implements gum::IBayesNetFactory.

Definition at line 197 of file BayesNetFactory_tpl.h.

197 {
199 _illegalStateError_("variableName");
200 } else {
201 if (_varNameMap_.exists(name)) { GUM_ERROR(DuplicateElement, "Name already used: " << name) }
202
203 _foo_flag_ = true;
204 _stringBag_[0] = name;
205 }
206 }

References _foo_flag_, _illegalStateError_(), _stringBag_, _varNameMap_, GUM_ERROR, state(), and gum::IBayesNetFactory::VARIABLE.

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::_groundAgg_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ variableType()

template<typename GUM_SCALAR>
INLINE void gum::BayesNetFactory< GUM_SCALAR >::variableType ( const VarType & type)
virtual

Tells the factory the current variable's type.

Implements gum::IBayesNetFactory.

Definition at line 225 of file BayesNetFactory_tpl.h.

225 {
227 _illegalStateError_("variableType");
228 } else {
229 switch (type) {
230 case VarType::DISCRETIZED : _stringBag_[2] = "D"; break;
231 case VarType::RANGE : _stringBag_[2] = "R"; break;
232 case VarType::INTEGER : _stringBag_[2] = "I"; break;
233 case VarType::LABELIZED : _stringBag_[2] = "L"; break;
236 "Continuous variable (" + _stringBag_[0]
237 + ") are not supported in Bayesian networks.")
238 default : GUM_ERROR(OperationNotAllowed, "Unknown type for (" + _stringBag_[0] + ")")
239 }
240 }
241 }

References _illegalStateError_(), _stringBag_, gum::CONTINUOUS, gum::DISCRETIZED, GUM_ERROR, gum::INTEGER, gum::LABELIZED, gum::RANGE, state(), and gum::IBayesNetFactory::VARIABLE.

Here is the call graph for this function:

◆ varInBN()

template<typename GUM_SCALAR>
INLINE const DiscreteVariable & gum::BayesNetFactory< GUM_SCALAR >::varInBN ( NodeId id)
finalvirtual

short-cut accessor for a DiscreveVariable in the BN

Implements gum::IBayesNetFactory.

Definition at line 116 of file BayesNetFactory_tpl.h.

116 {
117 return _bn_->variable(id);
118 }

References _bn_.

Member Data Documentation

◆ _bar_flag_

template<typename GUM_SCALAR>
bool gum::BayesNetFactory< GUM_SCALAR >::_bar_flag_
private

Depending on the context this flag is used for some VERY important reasons.

Definition at line 424 of file BayesNetFactory.h.

Referenced by _resetParts_(), endVariableDeclaration(), and variableDescription().

◆ _bn_

◆ _foo_flag_

template<typename GUM_SCALAR>
bool gum::BayesNetFactory< GUM_SCALAR >::_foo_flag_
private

Depending on the context this flag is used for some VERY important reasons.

Definition at line 420 of file BayesNetFactory.h.

Referenced by _resetParts_(), endVariableDeclaration(), and variableName().

◆ _impl_

template<typename GUM_SCALAR>
MultiDimImplementation< GUM_SCALAR >* gum::BayesNetFactory< GUM_SCALAR >::_impl_
private

Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls.

Definition at line 434 of file BayesNetFactory.h.

Referenced by BayesNetFactory(), BayesNetFactory(), ~BayesNetFactory(), endVariableDeclaration(), and setVariableCPTImplementation().

◆ _parents_

template<typename GUM_SCALAR>
Instantiation* gum::BayesNetFactory< GUM_SCALAR >::_parents_
private

◆ _states_

◆ _stringBag_

◆ _varNameMap_

◆ _verbose_

bool gum::IBayesNetFactory::_verbose_
privateinherited

Definition at line 149 of file IBayesNetFactory.h.

Referenced by IBayesNetFactory(), isVerbose(), resetVerbose(), and setVerbose().


The documentation for this class was generated from the following files: