49#ifndef GUM_PRM_FACTORY_H
50#define GUM_PRM_FACTORY_H
87 template <
typename GUM_SCALAR >
221 virtual void pushPackage(
const std::string& name)
override;
249 virtual void addImport(
const std::string& name)
override;
266 virtual void startDiscreteType(
const std::string& name, std::string super =
"")
override;
281 virtual void addLabel(
const std::string& l, std::string ext =
"")
override;
306 virtual void addTick(
double tick)
override;
328 virtual void addRangeType(
const std::string& name,
long minVal,
long maxVal)
override;
356 const std::string& ext =
"",
358 bool delayInheritance =
false)
override;
372 virtual void endClass(
bool checkImplementations =
true)
override;
395 const std::string& ext =
"",
396 bool delayInheritance =
false)
override;
407 virtual void addAttribute(
const std::string& type,
const std::string& name)
override;
447 const std::string& name,
448 bool scalar_atttr =
false)
override;
463 virtual void addParent(
const std::string& name)
override;
520 virtual void setCPFByRule(
const std::vector< std::string >& labels,
521 const std::vector< GUM_SCALAR >& values);
535 virtual void setCPFByRule(
const std::vector< std::string >& labels,
536 const std::vector< std::string >& values)
override;
622 virtual void setRawCPFByLines(
const std::vector< std::string >& array)
override;
637 const std::vector< float >& values)
override;
662 void addParameter(
const std::string& type,
const std::string& name,
double value)
override;
692 const std::string& agg_type,
693 const std::vector< std::string >& chains,
694 const std::vector< std::string >& params,
695 std::string type =
"")
override;
707 const std::string& agg_type,
708 const std::string& rv_type,
709 const std::vector< std::string >& params);
747 const std::vector< std::string >& chains,
748 const std::vector< float >& numbers,
750 const std::vector< std::string >& label)
override;
762 addReferenceSlot(
const std::string& type,
const std::string& name,
bool isArray)
override;
774 virtual void startSystem(
const std::string& name)
override;
785 virtual void addInstance(
const std::string& type,
const std::string& name)
override;
791 const std::string& name,
800 virtual void addArray(
const std::string& type,
const std::string& name,
Size size)
override;
805 virtual void incArray(
const std::string& l_i,
const std::string& r_i)
override;
822 const std::string& left_reference,
823 const std::string& right_instance)
override;
839 virtual void setReferenceSlot(
const std::string& l_i,
const std::string& r_i)
override;
854 std::string
_addPrefix_(
const std::string& str)
const;
920 const std::string& name);
944 const std::vector< std::string >& chains,
986 const std::string& name);
991 const std::string& name);
Inline implementation of PRMFactory.
The generic class for storing (ordered) sequences of objects.
PRMAttribute is a member of a Class in a PRM.
<agrum/PRM/classElementContainer.h>
Abstract class representing an element of PRM class.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
virtual bool isArrayInCurrentSystem(const std::string &name) const override
PRMClassElementContainer< GUM_SCALAR > * _checkStackContainter_(Idx i)
Adds prefix to str iff prefix != "".
virtual void startAttribute(const std::string &type, const std::string &name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
PRMObject * _checkStack_(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at stack.size() - i position after checking the type of the object gi...
virtual ~PRMFactory()
Destructor.
void endAggregator()
Finishes an aggregate declaration.
virtual void addImport(const std::string &name) override
Add an import for namespace lookup.
HashTable< PRMAggregate< GUM_SCALAR > *, std::vector< std::string > > _agg_params_
A mapping between aggregators and their parameters.
std::string _addPrefix_(const std::string &str) const
Adds prefix to str iff prefix != "".
virtual void addAggregator(const std::string &name, const std::string &agg_type, const std::vector< std::string > &chains, const std::vector< std::string > ¶ms, std::string type="") override
Add an aggregator in the current declared class.
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
void addParameter(const std::string &type, const std::string &name, double value) override
Add a parameter to the current class with a default value.
virtual void incArray(const std::string &l_i, const std::string &r_i) override
Add an instance to an array.
PRMSlotChain< GUM_SCALAR > * _buildSlotChain_(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
virtual void addParent(const std::string &name) override
Tells the factory that we add a parent to the current declared attribute.
virtual void pushPackage(const std::string &name) override
Define the current package.
virtual std::string currentPackage() const override
virtual bool isClassOrInterface(const std::string &type) const override
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
PRMFactory & operator=(const PRMFactory &from)=delete
Copy operator. Don't use it.
void startAggregator(const std::string &name, const std::string &agg_type, const std::string &rv_type, const std::vector< std::string > ¶ms)
Start an aggregator declaration.
virtual void addTick(double tick) override
Add a tick to the current discretized type.
PRMType & retrieveType(const std::string &name)
Returns a reference over a PRMType given its name.
virtual void endSystem() override
Tells the factory that we finished declaring a model.
virtual void addRangeType(const std::string &name, long minVal, long maxVal) override
Add a range variable type declaration.
virtual void setReferenceSlot(const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
Instantiate a reference in the current model.
PRMType * _retrieveCommonType_(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
virtual void setCPFByFloatRule(const std::vector< std::string > &labels, const std::vector< float > &values) override
Fills the CPF using a rule.
void _instantiateSlotChain_(PRMSystem< GUM_SCALAR > *model, PRMInstance< GUM_SCALAR > *inst, PRMReferenceSlot< GUM_SCALAR > *ref, PRMSlotChain< GUM_SCALAR > *sc)
Instantiate a slot chain in the given instance.
PRMFactory()
Default constructor.
virtual void addArray(const std::string &type, const std::string &name, Size size) override
Creates an array with the given number of instances of the given type.
PRMClass< GUM_SCALAR > & retrieveClass(const std::string &name)
Returns a reference over a Class<GUM_SCALAR> given its name.
virtual void addNoisyOrCompound(const std::string &name, const std::vector< std::string > &chains, const std::vector< float > &numbers, float leak, const std::vector< std::string > &label) override
Add a compound noisy-or as an PRMAttribute<GUM_SCALAR> to the current Class<GUM_SCALAR>.
PRMInterface< GUM_SCALAR > * _retrieveInterface_(const std::string &name) const
Returns a pointer on an interface given it's name. Used when building models, meaning that the interf...
std::vector< PRMObject * > _stack_
A stack used to keep track of created PRMObject.
PRM< GUM_SCALAR > * _prm_
The pointer on the PRM<GUM_SCALAR> built by this factory.
std::string _retrieveInstanceSequence_(PRMInstance< GUM_SCALAR > *inst, Sequence< PRMInstance< GUM_SCALAR > * > &seq, PRMSlotChain< GUM_SCALAR > *sc)
Fill seq with the sequence of instance build using inst as the instantiation of sc-> class and seekin...
virtual void setRawCPFByFloatColumns(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
PRMClass< GUM_SCALAR > * _retrieveClass_(const std::string &name) const
Returns a pointer on a class given it's name. Used when building models, meaning that the class name ...
PRMType & retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
bool _retrieveInputs_(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
void _buildAggregateCPF_(PRMSystem< GUM_SCALAR > *model)
Builds all Aggregates CPF in the given model. This must be called after all the slot chains have been...
void _addParent_(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.
PRMFactory(const PRMFactory &from)=delete
Copy constructor. Don't use it.
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.
virtual void addReferenceSlot(const std::string &type, const std::string &name, bool isArray) override
Tells the factory that we started declaring a slot.
virtual void endAttribute() override
Tells the factory that we finished declaring an attribute.
virtual void startClass(const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
virtual std::string popPackage() override
Pop the current package from the package stack.
virtual PRMObject::prm_type currentType() const override
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
int _typeDepth_(const PRMType *t)
Returns the inheritance depth of a PRMType.
virtual PRMObject * getCurrent() override
virtual void continueClass(const std::string &c) override
Continue the declaration of a class.
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
virtual void startSystem(const std::string &name) override
Tells the factory that we started declaring a model.
virtual void setRawCPFByFloatLines(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
std::vector< std::string > _packages_
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
void continueAggregator(const std::string &name)
Conitnues an aggregator declaration.
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.
virtual void continueAttribute(const std::string &name) override
Continues the declaration of an attribute.
virtual void endDiscretizedType() override
End the current discretized type declaration.
virtual void endInterface() override
Tells the factory that we finished an interface declaration.
virtual void startDiscreteType(const std::string &name, std::string super="") override
Start a discrete subtype declaration.
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
PRMType * _retrieveType_(const std::string &name) const
Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local na...
virtual void startDiscretizedType(const std::string &name) override
Start a discretized type declaration.
void _addInstance_(PRMClass< GUM_SCALAR > *type, const std::string &name)
Adds a instance to the current model.
std::vector< List< std::string > * > _namespaces_
Set of all declared namespaces.
virtual PRMObject * closeCurrent() override
Close current object being built.
virtual void startInterface(const std::string &i, const std::string &ext="", bool delayInheritance=false) override
Tells the factory that we start an interface declaration.
virtual void endDiscreteType() override
End the current discrete type declaration.
virtual void continueInterface(const std::string &name) override
Continue the declaration of an interface.
void _checkInterfaceImplementation_(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.
virtual void addLabel(const std::string &l, std::string ext="") override
Add a label to the current discrete type.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
Abstract base class for any element defined in a PRM.
prm_type
Enumeration of the different types of objects handled by a PRM.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
This is a decoration of the DiscreteVariable class.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities
non-template interface-like parent for every PRM Factory