aGrUM  0.16.3
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 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 DiscreteVariablevarInBN (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 DiscreteVariablevariable (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...
 

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 45 of file BayesNet.h.

Member Enumeration Documentation

◆ factory_state

enum 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 60 of file IBayesNetFactory.h.

60  : char {
61  NONE,
62  NETWORK,
63  VARIABLE,
64  PARENTS,
65  RAW_CPT,
66  FACT_CPT,
67  FACT_ENTRY
68  };

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 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().

45  :
46  __parents(0),
47  __impl(0), __bn(bn) {
48  GUM_CONSTRUCTOR(BayesNetFactory);
49  __states.push_back(factory_state::NONE);
50 
51  for (auto node : bn->nodes()) {
52  if (__varNameMap.exists(bn->variable(node).name()))
53  GUM_ERROR(DuplicateElement,
54  "Name already used: " << bn->variable(node).name());
55 
56  __varNameMap.insert(bn->variable(node).name(), node);
57  }
58 
59  resetVerbose();
60  }
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< factory_state > __states
State stack.
Instantiation * __parents
Used when a factorized CPT is built.
MultiDimImplementation< GUM_SCALAR > * __impl
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call 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 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().

66  :
67  __parents(0),
68  __impl(0), __bn(0) {
69  GUM_CONS_CPY(BayesNetFactory);
70 
71  if (source.state() != factory_state::NONE) {
72  GUM_ERROR(OperationNotAllowed, "Illegal state to proceed make a copy.");
73  } else {
74  __states = source.__states;
75  __bn = new BayesNet< GUM_SCALAR >(*(source.__bn));
76  }
77  }
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< factory_state > __states
State stack.
Instantiation * __parents
Used when a factorized CPT is built.
MultiDimImplementation< GUM_SCALAR > * __impl
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 81 of file BayesNetFactory_tpl.h.

References gum::BayesNetFactory< GUM_SCALAR >::__impl, and gum::BayesNetFactory< GUM_SCALAR >::__parents.

81  {
82  GUM_DESTRUCTOR(BayesNetFactory);
83 
84  if (__parents != 0) delete __parents;
85 
86  if (__impl != 0) {
87  //@todo better than throwing an exception from inside a destructor but
88  // still ...
89  std::cerr
90  << "[BN factory] Implementation defined for a variable but not used. "
91  "You should call endVariableDeclaration() before "
92  "deleting me."
93  << std::endl;
94  exit(1000);
95  }
96  }
BayesNetFactory(BayesNet< GUM_SCALAR > *bn)
Use this constructor if you want to use an already created BayesNet.
Instantiation * __parents
Used when a factorized CPT is built.
MultiDimImplementation< GUM_SCALAR > * __impl
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls...

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

References gum::BayesNetFactory< GUM_SCALAR >::__stringBag, and GUM_ERROR.

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

867  {
868  for (size_t i = 2; i < __stringBag.size(); ++i) {
869  if (mod == __stringBag[i]) {
870  GUM_ERROR(DuplicateElement, "Label already used: " << mod);
871  }
872  }
873  }
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 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().

853  {
854  __checkVariableName(name);
855  const DiscreteVariable& var = __bn->variable(__varNameMap[name]);
856 
857  for (Idx i = 0; i < var.domainSize(); ++i) {
858  if (mod == var.label(i)) { return i; }
859  }
860 
861  GUM_ERROR(NotFound, mod);
862  }
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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)
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().

845  {
846  if (!__varNameMap.exists(name)) { GUM_ERROR(NotFound, name); }
847  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ 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< std::string > &  variables,
const std::vector< float > &  rawTable 
)
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().

424  {
425  const Potential< GUM_SCALAR >& table = __bn->cpt(__varNameMap[__stringBag[0]]);
426  Instantiation cptInst(table);
427 
428  List< const DiscreteVariable* > varList;
429 
430  for (size_t i = 0; i < variables.size(); ++i) {
431  varList.pushBack(&(__bn->variable(__varNameMap[variables[i]])));
432  }
433 
434  // varList.pushFront(&(__bn->variable(__varNameMap[__stringBag[0]])));
435 
436  Idx nbrVar = varList.size();
437 
438  std::vector< Idx > modCounter;
439 
440  // initializing the array
441  for (NodeId i = 0; i < nbrVar; i++) {
442  modCounter.push_back(Idx(0));
443  }
444 
445  Idx j = 0;
446 
447  do {
448  for (NodeId i = 0; i < nbrVar; i++) {
449  cptInst.chgVal(*(varList[i]), modCounter[i]);
450  }
451 
452  if (j < rawTable.size()) {
453  table.set(cptInst, (GUM_SCALAR)rawTable[j]);
454  } else {
455  table.set(cptInst, (GUM_SCALAR)0);
456  }
457 
458  j++;
459  } while (__increment(modCounter, varList));
460  }
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
Size Idx
Type for indexes.
Definition: types.h:53
bool __increment(std::vector< gum::Idx > &modCounter, List< const DiscreteVariable * > &varList)
Increment a modality counter for the __fillProbaWithValuesTable method.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __fillProbaWithValuesTable() [2/2]

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

474  {
475  const Potential< GUM_SCALAR >& table = __bn->cpt(__varNameMap[__stringBag[0]]);
476 
477  Instantiation cptInst(table);
478 
479  // the main loop is on the first variables. The others are in the right
480  // order.
481  const DiscreteVariable& first = table.variable(0);
482  Idx j = 0;
483 
484  for (cptInst.setFirstVar(first); !cptInst.end(); cptInst.incVar(first)) {
485  for (cptInst.setFirstNotVar(first); !cptInst.end(); cptInst.incNotVar(first))
486  table.set(cptInst,
487  (j < rawTable.size()) ? (GUM_SCALAR)rawTable[j++]
488  : (GUM_SCALAR)0);
489 
490  cptInst.unsetEnd();
491  }
492  }
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
+ Here is the call 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 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().

792  {
793  std::string msg = "Illegal state call (";
794  msg += s;
795  msg += ") in state ";
796 
797  switch (state()) {
798  case factory_state::NONE: {
799  msg += "NONE";
800  break;
801  }
802 
803  case factory_state::NETWORK: {
804  msg += "NETWORK";
805  break;
806  }
807 
809  msg += "VARIABLE";
810  break;
811  }
812 
813  case factory_state::PARENTS: {
814  msg += "PARENTS";
815  break;
816  }
817 
818  case factory_state::RAW_CPT: {
819  msg += "RAW_CPT";
820  break;
821  }
822 
824  msg += "FACT_CPT";
825  break;
826  }
827 
829  msg += "FACT_ENTRY";
830  break;
831  }
832 
833  default: {
834  msg += "Unknown state";
835  }
836  }
837 
838  GUM_ERROR(OperationNotAllowed, msg);
839  }
factory_state state() const final
Returns the current state of the factory.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 
)
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().

497  {
498  bool last = true;
499 
500  for (NodeId j = 0; j < modCounter.size(); j++) {
501  last = (modCounter[j] == (varList[j]->domainSize() - 1)) && last;
502 
503  if (!last) break;
504  }
505 
506  if (last) { return false; }
507 
508  bool add = false;
509 
510  NodeId i = NodeId(varList.size() - 1);
511 
512  do {
513  if (modCounter[i] == (varList[i]->domainSize() - 1)) {
514  modCounter[i] = 0;
515  add = true;
516  } else {
517  modCounter[i] += 1;
518  add = false;
519  }
520 
521  i--;
522  } while (add);
523 
524  return true;
525  }
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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 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().

896  {
897  __foo_flag = false;
898  __bar_flag = false;
899  __stringBag.clear();
900  }
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
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.
+ Here is the caller graph for this function:

◆ __setCPTAndParents()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents ( const DiscreteVariable var,
Potential< GUM_SCALAR > *  table 
)
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().

879  {
880  NodeId varId = __varNameMap[var.name()];
881  __bn->_dag.eraseParents(varId);
882 
883  for (auto v : table->variablesSequence()) {
884  if (v != (&var)) {
885  __checkVariableName(v->name());
886  __bn->_dag.addArc(__varNameMap[v->name()], varId);
887  }
888  }
889 
890  // CPT are created when a variable is added.
891  __bn->_unsafeChangePotential(varId, table);
892  }
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller 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 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().

228  {
229  if (state() != factory_state::VARIABLE) {
230  __illegalStateError("addModality");
231  } else {
232  __checkModalityInBag(name);
233  __stringBag.push_back(name);
234  }
235  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void __checkModalityInBag(const std::string &mod)
Check if in __stringBag there is no other modality with the same name.
+ 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 163 of file BayesNetFactory_tpl.h.

References gum::BayesNetFactory< GUM_SCALAR >::__bn.

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

164  {
165  __bn->setProperty(propName, propValue);
166  }
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
+ 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 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().

346  {
347  if (state() != factory_state::PARENTS) {
348  __illegalStateError("addParent");
349  } else {
350  __checkVariableName(var);
351  __stringBag.push_back(var);
352  }
353  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
+ Here is the call graph for this function:
+ Here is the caller 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 100 of file BayesNetFactory_tpl.h.

References gum::BayesNetFactory< GUM_SCALAR >::__bn.

100  {
101  return __bn;
102  }
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.

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

References gum::BayesNetFactory< GUM_SCALAR >::__bn.

142  {
143  // (from PH) nowhere in the code, I see a check type if (__bn) __bn->. I
144  // assume
145  // __bn is forced not to be nullptr ...
146  return __bn->cpt(n).domainSize();
147  }
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.

◆ 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 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().

570  {
571  if (state() != factory_state::FACT_ENTRY) {
572  __illegalStateError("endFactorizedEntry");
573  } else {
574  delete __parents;
575  __parents = 0;
576  __states.pop_back();
577  }
578  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
Instantiation * __parents
Used when a factorized CPT is built.
+ 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 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().

697  {
698  if (state() != factory_state::FACT_CPT) {
699  __illegalStateError("endFactorizedProbabilityDeclaration");
700  } else {
701  __resetParts();
702  __states.pop_back();
703  }
704  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
void __resetParts()
Reset the different parts used to constructed the BayesNet.
+ 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 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().

170  {
171  if (state() != factory_state::NETWORK) {
172  __illegalStateError("endNetworkDeclaration");
173  } else {
174  __states.pop_back();
175  }
176 
177  VERBOSITY("network OK");
178  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
+ 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 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().

360  {
361  if (state() != factory_state::PARENTS) {
362  __illegalStateError("endParentsDeclaration");
363  } else {
365 
366  // PLEASE NOTE THAT THE ORDER IS INVERSE
367 
368  for (size_t i = __stringBag.size() - 1; i > 0; --i) {
369  __bn->addArc(__varNameMap[__stringBag[i]], id);
370  VERBOSITY(" adding parent " << __stringBag[i] << " for "
371  << __stringBag[0]);
372  }
373 
374  __resetParts();
375 
376  __states.pop_back();
377  }
378 
379  VERBOSITY("end of parents for " << __stringBag[0]);
380  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void __resetParts()
Reset the different parts used to constructed the BayesNet.
+ Here is the call graph for this function:
+ Here is the caller 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 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.

530  {
531  if (state() != factory_state::RAW_CPT) {
532  __illegalStateError("endRawProbabilityDeclaration");
533  } else {
534  __resetParts();
535  __states.pop_back();
536  }
537 
538  VERBOSITY(" cpt ending for " << __stringBag[0]);
539  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void __resetParts()
Reset the different parts used to constructed the BayesNet.
+ 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 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().

270  {
271  if (state() != factory_state::VARIABLE) {
272  __illegalStateError("endVariableDeclaration");
273  } else if (__foo_flag && (__stringBag.size() > 3)) {
274  LabelizedVariable* var = new LabelizedVariable(
275  __stringBag[0], (__bar_flag) ? __stringBag[1] : "", 0);
276 
277  for (size_t i = 2; i < __stringBag.size(); ++i) {
278  var->addLabel(__stringBag[i]);
279  }
280 
281  if (__impl != 0) {
282  __varNameMap.insert(var->name(), __bn->add(*var, __impl));
283  __impl = 0;
284  } else {
285  __varNameMap.insert(var->name(), __bn->add(*var));
286  }
287 
288  NodeId retVal = __varNameMap[var->name()];
289 
290  delete var;
291 
292  __resetParts();
293  __states.pop_back();
294 
295  VERBOSITY(" variable " << var->name() << " OK");
296  return retVal;
297  } else {
298  std::stringstream msg;
299  msg << "Not enough modalities (";
300 
301  if (__stringBag.size() > 2) {
302  msg << __stringBag.size() - 2;
303  } else {
304  msg << 0;
305  }
306 
307  msg << ") declared for variable ";
308 
309  if (__foo_flag) {
310  msg << __stringBag[0];
311  } else {
312  msg << "unknown";
313  }
314 
315  __resetParts();
316 
317  __states.pop_back();
318  GUM_ERROR(OperationNotAllowed, msg.str());
319  }
320 
321  // For noisy compilers
322  return 0;
323  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
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.
MultiDimImplementation< GUM_SCALAR > * __impl
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void __resetParts()
Reset the different parts used to constructed the BayesNet.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isVerbose()

bool gum::IBayesNetFactory::isVerbose ( )
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().

82 { return __verbose; };
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
INLINE BayesNetFactory< GUM_SCALAR > & gum::BayesNetFactory< GUM_SCALAR >::operator= ( const BayesNetFactory< GUM_SCALAR > &  source)
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().

783  {
784  GUM_ERROR(OperationNotAllowed, "Illegal!");
785  // For noisy compilers
786  return *this;
787  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ rawConditionalTable() [1/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 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().

413  {
414  if (state() != factory_state::RAW_CPT) {
415  __illegalStateError("rawConditionalTable");
416  } else {
417  __fillProbaWithValuesTable(variables, rawTable);
418  }
419  }
factory_state state() const final
Returns the current state of the factory.
void __fillProbaWithValuesTable(const std::vector< std::string > &variables, const std::vector< float > &rawTable)
Fill a potential from a raw CPT.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal 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< 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 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().

464  {
465  if (state() != factory_state::RAW_CPT) {
466  __illegalStateError("rawConditionalTable");
467  } else {
468  __fillProbaWithValuesTable(rawTable);
469  }
470  }
factory_state state() const final
Returns the current state of the factory.
void __fillProbaWithValuesTable(const std::vector< std::string > &variables, const std::vector< float > &rawTable)
Fill a potential from a raw CPT.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
+ Here is the call graph for this function:

◆ resetVerbose()

void gum::IBayesNetFactory::resetVerbose ( )
inlineinherited

Definition at line 80 of file IBayesNetFactory.h.

References gum::IBayesNetFactory::__verbose.

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

80 { __verbose = false; };
+ 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 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().

584  {
585  if (state() != factory_state::FACT_ENTRY) {
586  __illegalStateError("string");
587  } else {
588  __checkVariableName(parent);
589  Idx id = __checkVariableModality(parent, modality);
590  (*__parents) << __bn->variable(__varNameMap[parent]);
591  __parents->chgVal(__bn->variable(__varNameMap[parent]), id);
592  }
593  }
factory_state state() const final
Returns the current state of the factory.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
Idx __checkVariableModality(const std::string &name, const std::string &mod)
Check if var exists and if mod is one of it&#39;s modality, if not raise an NotFound exception.
Instantiation * __parents
Used when a factorized CPT is built.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
+ 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 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().

719  {
720  if ((state() != factory_state::NONE)) {
721  __illegalStateError("setVariable");
722  } else {
723  try {
724  __checkVariableName(var.name());
725  GUM_ERROR(DuplicateElement, "Name already used: " << var.name());
726  } catch (NotFound&) {
727  // The var name is unused
728  __varNameMap.insert(var.name(), __bn->add(var));
729  }
730  }
731  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller 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 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().

752  {
753  auto pot = dynamic_cast< Potential< GUM_SCALAR >* >(table);
754 
755  if (state() != factory_state::NONE) {
756  __illegalStateError("setVariableCPT");
757  } else {
758  __checkVariableName(varName);
759  const DiscreteVariable& var = __bn->variable(__varNameMap[varName]);
760  NodeId varId = __varNameMap[varName];
761  // If we have to change the structure of the BayesNet, then we call a sub
762  // method.
763 
764  if (redefineParents) {
765  __setCPTAndParents(var, pot);
766  } else if (pot->contains(var)) {
767  for (auto node : __bn->parents(varId)) {
768  if (!pot->contains(__bn->variable(node))) {
769  GUM_ERROR(OperationNotAllowed,
770  "The CPT is not valid in the current BayesNet.");
771  }
772  }
773 
774  // CPT are created when a variable is added.
775  __bn->_unsafeChangePotential(varId, pot);
776  }
777  }
778  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
void __setCPTAndParents(const DiscreteVariable &var, Potential< GUM_SCALAR > *table)
Sub method of setVariableCPT() which redefine the BayesNet&#39;s DAG with respect to table.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller 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 Potential.

Warning
The implementation must be empty.
The pointer is always delegated to var's Potential! 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 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().

249  {
250  MultiDimImplementation< GUM_SCALAR >* impl =
251  dynamic_cast< MultiDimImplementation< GUM_SCALAR >* >(adressable);
252 
253  if (state() != factory_state::VARIABLE) {
254  __illegalStateError("setVariableCPTImplementation");
255  } else {
256  if (impl == 0) {
257  GUM_ERROR(OperationNotAllowed,
258  "An implementation for this variable is already "
259  "defined.");
260  } else if (impl->nbrDim() > 0) {
261  GUM_ERROR(OperationNotAllowed, "This implementation is not empty.");
262  }
263 
264  __impl = impl;
265  }
266  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
MultiDimImplementation< GUM_SCALAR > * __impl
Implementation of variable between two startVariableDeclaration/endVariableDeclaration calls...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 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().

675  {
676  if (state() != factory_state::FACT_ENTRY) {
677  __illegalStateError("setVariableValues");
678  } else {
679  const DiscreteVariable& var = __bn->variable(__varNameMap[__stringBag[0]]);
680  // Checking consistency between values and var.
681 
682  if (values.size() != var.domainSize()) {
683  GUM_ERROR(OperationNotAllowed,
684  var.name()
685  << " : invalid number of modalities: found " << values.size()
686  << " while needed " << var.domainSize());
687  }
688 
690  }
691  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void setVariableValuesUnchecked(const std::vector< float > &values) final
Gives the values of the variable with respect to precedent parents modality.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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.startVariableDeclaration();
factory.variableName("foo");
factory.endVariableDeclaration();
factory.startParentsDeclaration("foo");
// add parents
factory.endParentsDeclaration();
factory.startFactorizedProbabilityDeclaration("foo");
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
factory.endFactorizedProbabilityDeclaration();

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().

624  {
625  if (state() != factory_state::FACT_ENTRY) {
626  __illegalStateError("setVariableValues");
627  } else {
628  const DiscreteVariable& var = __bn->variable(__varNameMap[__stringBag[0]]);
629  NodeId varId = __varNameMap[__stringBag[0]];
630 
631  if (__parents->domainSize() > 0) {
632  Instantiation inst(__bn->cpt(__varNameMap[var.name()]));
633  inst.setVals(*__parents);
634  // Creating an instantiation containing all the variables not ins
635  // __parents.
636  Instantiation inst_default;
637  inst_default << var;
638 
639  for (auto node : __bn->parents(varId)) {
640  if (!__parents->contains(__bn->variable(node))) {
641  inst_default << __bn->variable(node);
642  }
643  }
644 
645  // Filling the variable's table.
646  for (inst.setFirstIn(inst_default); !inst.end();
647  inst.incIn(inst_default)) {
648  (__bn->cpt(varId))
649  .set(inst,
650  inst.val(var) < values.size() ? (GUM_SCALAR)values[inst.val(var)]
651  : (GUM_SCALAR)0);
652  }
653  } else {
654  Instantiation inst(__bn->cpt(__varNameMap[var.name()]));
655  Instantiation var_inst;
656  var_inst << var;
657 
658  for (var_inst.setFirst(); !var_inst.end(); ++var_inst) {
659  inst.setVals(var_inst);
660 
661  for (inst.setFirstOut(var_inst); !inst.end(); inst.incOut(var_inst)) {
662  (__bn->cpt(varId))
663  .set(inst,
664  inst.val(var) < values.size()
665  ? (GUM_SCALAR)values[inst.val(var)]
666  : (GUM_SCALAR)0);
667  }
668  }
669  }
670  }
671  }
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
Instantiation * __parents
Used when a factorized CPT is built.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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 78 of file IBayesNetFactory.h.

References gum::IBayesNetFactory::__verbose.

78 { __verbose = true; };

◆ 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 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().

558  {
559  if (state() != factory_state::FACT_CPT) {
560  __illegalStateError("startFactorizedEntry");
561  } else {
562  __parents = new Instantiation();
564  }
565  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
Instantiation * __parents
Used when a factorized CPT is built.
+ 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 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().

544  {
545  if (state() != factory_state::NONE) {
546  __illegalStateError("startFactorizedProbabilityDeclaration");
547  } else {
548  __checkVariableName(var);
549  std::vector< std::string >::iterator iter = __stringBag.begin();
550  __stringBag.insert(iter, var);
552  }
553  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
+ 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 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().

151  {
152  if (state() != factory_state::NONE) {
153  __illegalStateError("startNetworkDeclaration");
154  } else {
155  __states.push_back(factory_state::NETWORK);
156  }
157 
158  VERBOSITY("starting network");
159  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
+ 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 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().

329  {
330  if (state() != factory_state::NONE) {
331  __illegalStateError("startParentsDeclaration");
332  } else {
333  __checkVariableName(var);
334  std::vector< std::string >::iterator iter = __stringBag.begin();
335  __stringBag.insert(iter, var);
336  __states.push_back(factory_state::PARENTS);
337  }
338 
339  VERBOSITY("starting parents for " << var);
340  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
+ 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 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.

387  {
388  if (state() != factory_state::NONE) {
389  __illegalStateError("startRawProbabilityDeclaration");
390  } else {
391  __checkVariableName(var);
392  __stringBag.push_back(var);
393  __states.push_back(factory_state::RAW_CPT);
394  }
395 
396  VERBOSITY(" cpt starting for " << var);
397  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
void __checkVariableName(const std::string &name)
Check if a variable with the given name exists, if not raise an NotFound exception.
+ 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 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().

182  {
183  if (state() != factory_state::NONE) {
184  __illegalStateError("startVariableDeclaration");
185  } else {
187  __stringBag.push_back("name");
188  __stringBag.push_back("desc");
189  }
190 
191  VERBOSITY(" starting variable");
192  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< factory_state > __states
State stack.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state()

template<typename GUM_SCALAR >
INLINE IBayesNetFactory::factory_state gum::BayesNetFactory< GUM_SCALAR >::state ( ) const
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().

113  {
114  // This is ok because there is alway at least the state NONE in the stack.
115  return __states.back();
116  }
std::vector< factory_state > __states
State stack.
+ Here is the caller graph for this function:

◆ 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 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().

132  {
133  try {
134  return __bn->variable(variableId(name));
135  } catch (NotFound&) { GUM_ERROR(NotFound, name); }
136  }
NodeId variableId(const std::string &name) const final
Returns the NodeId of a variable given it&#39;s name.
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 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.

215  {
216  if (state() != factory_state::VARIABLE) {
217  __illegalStateError("variableDescription");
218  } else {
219  __bar_flag = true;
220  __stringBag[1] = desc;
221  }
222  }
factory_state state() const final
Returns the current state of the factory.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
bool __bar_flag
Depending on the context this flag is used for some VERY important reasons.
+ 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 122 of file BayesNetFactory_tpl.h.

References gum::BayesNetFactory< GUM_SCALAR >::__varNameMap, and GUM_ERROR.

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

122  {
123  try {
124  return __varNameMap[name];
125  } catch (NotFound&) { GUM_ERROR(NotFound, name); }
126  }
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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.

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().

197  {
198  if (state() != factory_state::VARIABLE) {
199  __illegalStateError("variableName");
200  } else {
201  if (__varNameMap.exists(name)) {
202  GUM_ERROR(DuplicateElement, "Name already used: " << name);
203  }
204 
205  __foo_flag = true;
206 
207  __stringBag[0] = name;
208  VERBOSITY(" -- variable " << name);
209  }
210  }
#define VERBOSITY(x)
factory_state state() const final
Returns the current state of the factory.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
HashTable< std::string, NodeId > __varNameMap
Mapping between a declared variable&#39;s name and it&#39;s node id.
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
bool __foo_flag
Depending on the context this flag is used for some VERY important reasons.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller 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 106 of file BayesNetFactory_tpl.h.

References gum::BayesNetFactory< GUM_SCALAR >::__bn.

106  {
107  return __bn->variable(id);
108  }
BayesNet< GUM_SCALAR > * __bn
The constructed BayesNet.

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

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::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 391 of file BayesNetFactory.h.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__resetParts(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), and gum::BayesNetFactory< GUM_SCALAR >::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 405 of file BayesNetFactory.h.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::setVariableCPTImplementation(), and gum::BayesNetFactory< GUM_SCALAR >::~BayesNetFactory().

◆ __parents

◆ __states

◆ __stringBag

◆ __varNameMap


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