49#ifndef GUM_PRM_FACTORY_H
50#define GUM_PRM_FACTORY_H
89 template < GUM_Numeric GUM_SCALAR >
251 void addImport(std::string_view name)
override;
268 void startDiscreteType(std::string_view name, std::string_view super =
"")
override;
283 void addLabel(std::string_view l, std::string_view ext =
"")
override;
308 void addTick(
double tick)
override;
330 void addRangeType(std::string_view name,
long minVal,
long maxVal)
override;
358 std::string_view ext =
"",
360 bool delayInheritance =
false)
override;
374 void endClass(
bool checkImplementations =
true)
override;
397 std::string_view ext =
"",
398 bool delayInheritance =
false)
override;
409 void addAttribute(std::string_view type, std::string_view name)
override;
449 std::string_view name,
450 bool scalar_atttr =
false)
override;
465 void addParent(std::string_view name)
override;
522 virtual void setCPFByRule(
const std::vector< std::string >& labels,
523 const std::vector< GUM_SCALAR >& values);
537 void setCPFByRule(
const std::vector< std::string >& labels,
538 const std::vector< std::string >& values)
override;
639 const std::vector< float >& values)
override;
664 void addParameter(std::string_view type, std::string_view name,
double value)
override;
694 std::string_view agg_type,
695 const std::vector< std::string >& chains,
696 const std::vector< std::string >& params,
697 std::string_view type =
"")
override;
709 std::string_view agg_type,
710 std::string_view rv_type,
711 const std::vector< std::string >& params);
749 const std::vector< std::string >& chains,
750 const std::vector< float >& numbers,
752 const std::vector< std::string >& label)
override;
763 void addReferenceSlot(std::string_view type, std::string_view name,
bool isArray)
override;
786 void addInstance(std::string_view type, std::string_view name)
override;
792 std::string_view name,
801 void addArray(std::string_view type, std::string_view name,
Size size)
override;
806 void incArray(std::string_view l_i, std::string_view r_i)
override;
823 std::string_view left_reference,
824 std::string_view right_instance)
override;
855 std::string
_addPrefix_(std::string_view str)
const;
921 std::string_view name);
945 const std::vector< std::string >& chains,
987 std::string_view name);
992 std::string_view 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...
void addLabel(std::string_view l, std::string_view ext="") override
Add a label to the current discrete type.
void addNoisyOrCompound(std::string_view 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>.
std::string _addPrefix_(std::string_view str) const
Adds prefix to str iff prefix != "".
PRMType & retrieveType(std::string_view name)
Returns a reference over a PRMType given its name.
void startDiscreteType(std::string_view name, std::string_view super="") override
Start a discrete subtype declaration.
void addReferenceSlot(std::string_view type, std::string_view name, bool isArray) override
Tells the factory that we started declaring a slot.
void endAggregator()
Finishes an aggregate declaration.
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
~PRMFactory() override
Destructor.
void endInterface() override
Tells the factory that we finished an interface declaration.
HashTable< PRMAggregate< GUM_SCALAR > *, std::vector< std::string > > _agg_params_
A mapping between aggregators and their parameters.
void setReferenceSlot(std::string_view left_instance, std::string_view left_reference, std::string_view right_instance) override
Instantiate a reference in the current model.
void startInterface(std::string_view i, std::string_view ext="", bool delayInheritance=false) override
Tells the factory that we start an interface declaration.
PRMFactory()
Default constructor.
std::string popPackage() override
Pop the current package from the package stack.
PRMSlotChain< GUM_SCALAR > * _buildSlotChain_(PRMClassElementContainer< GUM_SCALAR > *start, std::string_view name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
void _checkInterfaceImplementation_(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.
void setCPFByFloatRule(const std::vector< std::string > &labels, const std::vector< float > &values) override
Fills the CPF using a rule.
void endDiscretizedType() override
End the current discretized type declaration.
PRMFactory & operator=(const PRMFactory &from)=delete
Copy operator. Don't use it.
void continueAttribute(std::string_view name) override
Continues the declaration of an attribute.
void startDiscretizedType(std::string_view name) override
Start a discretized type declaration.
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
void addAttribute(std::string_view type, std::string_view name) override
Add an attribute to an interface.
bool _retrieveInputs_(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
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.
std::vector< PRMObject * > _stack_
A stack used to keep track of created PRMObject.
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
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...
PRMClass< GUM_SCALAR > * _retrieveClass_(std::string_view name) const
Returns a pointer on a class given it's name. Used when building models, meaning that the class name ...
PRMClass< GUM_SCALAR > & retrieveClass(std::string_view name)
Returns a reference over a Class<GUM_SCALAR> given its name.
void startSystem(std::string_view name) override
Tells the factory that we started declaring a model.
void _addInstance_(PRMClass< GUM_SCALAR > *type, std::string_view name)
Adds an instance to the current model.
void pushPackage(std::string_view name) override
Define the current package.
int _typeDepth_(const PRMType *t)
Returns the inheritance depth of a PRMType.
void addInstance(std::string_view type, std::string_view name) override
Add an instance to the model.
void addAggregator(std::string_view name, std::string_view agg_type, const std::vector< std::string > &chains, const std::vector< std::string > ¶ms, std::string_view type="") override
Add an aggregator in the current declared class.
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...
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.
void continueInterface(std::string_view name) override
Continue the declaration of an interface.
PRMObject * getCurrent() override
PRMFactory(const PRMFactory &from)=delete
Copy constructor. Don't use it.
void setRawCPFByFloatLines(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
bool isArrayInCurrentSystem(std::string_view name) const override
void startAttribute(std::string_view type, std::string_view name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
PRMObject::prm_type currentType() const override
void addImport(std::string_view name) override
Add an import for namespace lookup.
std::string currentPackage() const override
void addTick(double tick) override
Add a tick to the current discretized type.
std::vector< std::string > _packages_
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
PRMType * _retrieveCommonType_(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
void continueAggregator(std::string_view name)
Conitnues an aggregator declaration.
PRMObject * closeCurrent() override
Close current object being built.
PRMClassElementContainer< GUM_SCALAR > * _checkStackContainter_(Idx i)
Adds prefix to str iff prefix != "".
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...
void addRangeType(std::string_view name, long minVal, long maxVal) override
Add a range variable type declaration.
void addParameter(std::string_view type, std::string_view name, double value) override
Add a parameter to the current class with a default value.
void startClass(std::string_view c, std::string_view ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
PRMType & retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
void _addParent_(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, std::string_view name)
Add a parent to an attribute.
std::vector< List< std::string > * > _namespaces_
Set of all declared namespaces.
void endAttribute() override
Tells the factory that we finished declaring an attribute.
bool isClassOrInterface(std::string_view type) const override
void startAggregator(std::string_view name, std::string_view agg_type, std::string_view rv_type, const std::vector< std::string > ¶ms)
Start an aggregator declaration.
void endSystem() override
Tells the factory that we finished declaring a model.
PRMType * _retrieveType_(std::string_view name) const
Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local na...
void addArray(std::string_view type, std::string_view name, Size size) override
Creates an array with the given number of instances of the given type.
PRMInterface< GUM_SCALAR > * _retrieveInterface_(std::string_view name) const
Returns a pointer on an interface given it's name. Used when building models, meaning that the interf...
void incArray(std::string_view l_i, std::string_view r_i) override
Add an instance to an array.
void setRawCPFByFloatColumns(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
void addParent(std::string_view name) override
Tells the factory that we add a parent to the current declared attribute.
void continueClass(std::string_view c) override
Continue the declaration of a class.
void endDiscreteType() override
End the current discrete type declaration.
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