60 template < GUM_Numeric GUM_SCALAR >
65 template < GUM_Numeric GUM_SCALAR >
69 for (
const auto& elt: *
this)
76 delete elt.second.second;
79 template < GUM_Numeric GUM_SCALAR >
86 template < GUM_Numeric GUM_SCALAR >
90 "an Instance<GUM_SCALAR> with the same is already in this System");
102 (*p_inst)->insert(i);
107 template < GUM_Numeric GUM_SCALAR >
124 template < GUM_Numeric GUM_SCALAR >
127 for (
const auto node: instance.
type().containerDag()) {
132 switch (instance.
type().get(node).elt_type()) {
137 std::format(
"{}.{}", instance.
name(), instance.
type().get(node).safeName()));
145 std::format(
"{}.{}", instance.
name(), instance.
type().get(node).safeName()),
158 template < GUM_Numeric GUM_SCALAR >
160 std::string_view
name,
174 for (
Idx i = 0; i < l.domainSize(); ++i) {
181 for (
Idx i = 0; i < l.domainSize(); ++i) {
188 for (
Idx i = 0; i < l.domainSize(); ++i) {
194 const auto d =
static_cast< const DiscretizedVariable< double >&
>(agg_var);
195 for (
Idx i = 0; i < d.domainSize(); ++i) {
201 const auto r =
static_cast< const RangeVariable&
>(agg_var);
202 factory.
addMin(r.minVal());
203 factory.
addMax(r.maxVal());
208 "PRM aggregator grounding does not support yet continuous variables");
263 default :
GUM_ERROR(OperationNotAllowed,
"Aggregator not handled yet for " << agg.name())
269 template < GUM_Numeric GUM_SCALAR >
272 for (
const auto& elt: instance) {
274 std::format(
"{}.{}", instance.
name(), elt.second->
safeName()));
276 for (
const auto par: instance.
type().containerDag().parents(elt.second->
id())) {
277 switch (instance.
type().get(par).elt_type()) {
281 std::format(
"{}.{}", instance.
name(), instance.
get(par).safeName()));
286 std::string parent_name
293 factory.
addParent(std::format(
"{}.{}", ref->name(), parent_name));
318 template < GUM_Numeric GUM_SCALAR >
323 std::string var_name = std::format(
"{}.{}", instance.
name(), attr.
safeName());
326 for (
const auto parent: instance.
type().containerDag().parents(attr.
id())) {
327 switch (instance.
type().get(parent).elt_type()) {
331 = std::format(
"{}.{}", instance.
name(), instance.
get(parent).safeName());
332 bijection.
insert(&(instance.
get(parent).type().variable()),
340 auto parent_name = std::format(
"{}.{}",
360 for (auto var: attr.cpf().variablesSequence()) {
363 Instantiation inst(attr.
cpf()), jnst(*p);
364 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
365 p->set(jnst, attr.
cpf().get(inst));
367 GUM_ASSERT(inst.end() && jnst.end());
371 template < GUM_Numeric GUM_SCALAR >
373 return add(array, &i);
376 template < GUM_Numeric GUM_SCALAR >
381 template < GUM_Numeric GUM_SCALAR >
384 if (!p)
GUM_ERROR(
NotFound,
"found no Instance<GUM_SCALAR> matching the given id")
388 template < GUM_Numeric GUM_SCALAR >
391 if (!p)
GUM_ERROR(
NotFound,
"found no Instance<GUM_SCALAR> matching the given id")
395 template < GUM_Numeric GUM_SCALAR >
404 template < GUM_Numeric GUM_SCALAR >
409 template < GUM_Numeric GUM_SCALAR >
414 template < GUM_Numeric GUM_SCALAR >
419 template < GUM_Numeric GUM_SCALAR >
424 template < GUM_Numeric GUM_SCALAR >
429 template < GUM_Numeric GUM_SCALAR >
431 for (
auto iter =
begin(); iter !=
end(); ++iter) {
432 (*(iter.val())).instantiate();
436 template < GUM_Numeric GUM_SCALAR >
439 if (!p)
GUM_ERROR(
NotFound,
"found no Instance<GUM_SCALAR> matching the given name")
443 template < GUM_Numeric GUM_SCALAR >
446 if (!p)
GUM_ERROR(
NotFound,
"found no Instance<GUM_SCALAR> matching the given name")
450 template < GUM_Numeric GUM_SCALAR >
455 if (!p)
GUM_ERROR(
NotFound,
"the given Class<GUM_SCALAR> has no instantiation in this System")
459 template < GUM_Numeric GUM_SCALAR >
468 template < GUM_Numeric GUM_SCALAR >
476 template < GUM_Numeric GUM_SCALAR >
484 template < GUM_Numeric GUM_SCALAR >
488 if (i->
type().isSubTypeOf(*(p_arr->first))) {
490 p_arr->second->insert(i);
494 "the given Instance<GUM_SCALAR> is of an incorrect "
495 "Class<GUM_SCALAR> type");
499 template < GUM_Numeric GUM_SCALAR >
511 template < GUM_Numeric GUM_SCALAR >
516 template < GUM_Numeric GUM_SCALAR >
521 template < GUM_Numeric GUM_SCALAR >
526 template < GUM_Numeric GUM_SCALAR >
531 template < GUM_Numeric GUM_SCALAR >
536 return p->second->begin();
539 template < GUM_Numeric GUM_SCALAR >
544 return p->second->end();
547 template < GUM_Numeric GUM_SCALAR >
552 return p->second->begin();
555 template < GUM_Numeric GUM_SCALAR >
560 return p->second->end();
563 template < GUM_Numeric GUM_SCALAR >
Headers of gum::prm::PRMInstance<GUM_SCALAR>.
A factory class to ease BayesNet construction.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
void setVariableCPT(std::string_view varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
void addModality(std::string_view name) final
Adds a modality to the current labelized variable.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
const DiscreteVariable & variable(std::string_view name) const
Returns a constant reference on a variable given it's name.
void addParent(std::string_view var) final
Tells the factory for which variable we're declaring parents.
void setVariable(const DiscreteVariable &var) final
Define a variable.
void addMax(const long &max) override
Adds the max value of the current range variable.
void variableType(const VarType &type) override
Tells the factory the current variable's type.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
void startParentsDeclaration(std::string_view var) final
Tells the factory that we're declaring parents for some variable.
void addNetworkProperty(std::string_view propName, std::string_view propValue) final
Tells the factory to add a property to the current network.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Tensor.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void addMin(const long &min) override
Adds the min value of the current range variable.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void variableName(std::string_view name) final
Tells the factory the current variable's name.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
Base class for all oriented graphs.
Base class for discrete random variable.
VarType varType() const override=0
returns the varType of variable
Exception : a similar element already exists.
Exception : fatal (unknown ?) error.
void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
Exception : the element we looked for cannot be found.
Exception : there is something wrong with an implementation.
class NumericalDiscreteVariable
Defines an aggregate in a PRM.
Exception : wrong subtype or subclass.
The generic class for storing (ordered) sequences of objects.
aGrUM's Tensor is a multi-dimensional array with tensor operators.
void setName(std::string_view theValue)
sets the name of the variable
PRMAttribute is a member of a Class in a PRM.
const Tensor< GUM_SCALAR > & cpf() const override=0
See gum::PRMClassElement::cpf().
PRMType & type() override=0
See gum::PRMClassElement::type().
<agrum/PRM/classElementContainer.h>
Abstract class representing an element of PRM class.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
const Set< PRMInstance< GUM_SCALAR > * > & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
PRMObject(std::string_view name)
Constructor.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
PRMClassElementContainer< GUM_SCALAR > & getArrayType(std::string_view name)
Returns the type of the given array.
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::const_iterator const_iterator
Constant Iterator over the PRMInstance of this PRMSystem.
PRMObject::prm_type obj_type() const override
Returns the PRM type of this object.
HashTable< PRMClass< GUM_SCALAR > *, Set< PRMInstance< GUM_SCALAR > * > * > instanceMap_
Mapping between a class and all it's PRMInstance in this system.
typename Sequence< PRMInstance< GUM_SCALAR > * >::iterator array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
void addArray(std::string_view array, PRMClassElementContainer< GUM_SCALAR > &type)
Add an array of instances in this system. If the array doesn't exists it is created.
const iterator & end()
Returns an iterator at the end of the set of PRMInstance in this PRMSystem.
void _groundAgg_(const PRMClassElement< GUM_SCALAR > &elt, std::string_view name, BayesNetFactory< GUM_SCALAR > &factory) const
typename Sequence< PRMInstance< GUM_SCALAR > * >::const_iterator const_array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
~PRMSystem() override
Destructor.
iterator begin()
Returns an iterator over the instances in this system.
DiGraph skeleton_
The relational skeleton of this PRMSystem.
bool exists(std::string_view name) const
Retruns true either if name is an instance or an array in this PRMSystem.
PRMSystem(std::string_view name)
Default constructor.
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::iterator iterator
Iterator over the PRMInstance of this PRMSystem.
HashTable< std::string, PRMInstance< GUM_SCALAR > * > nameMap_
The mapping between PRMInstance and their names.
const Sequence< PRMInstance< GUM_SCALAR > * > & getArray(std::string_view name) const
Returns the sequence of instances of a given array.
void _groundTensor_(const PRMInstance< GUM_SCALAR > &instance, const PRMAttribute< GUM_SCALAR > &attr, BayesNetFactory< GUM_SCALAR > &factory) const
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it's NodeId in the relational skeleton.
const DiGraph & skeleton() const
Returns the relation skeleton of this PRMSystem.
bool isInstantiated(const PRMClass< GUM_SCALAR > &c) const
Returns true if the given Class<GUM_SCALAR> has at least one PRMInstance in this PRMSystem.
Size size() const
Returns the number of PRMInstance in this PRMSystem.
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
bool isInstance(std::string_view name) const
Returns true if an PRMInstance with the given name exists.
std::pair< PRMClassElementContainer< GUM_SCALAR > *, Sequence< PRMInstance< GUM_SCALAR > * > * > model_pair
Type for the pair of a Class<GUM_SCALAR> and the sequence of it's instantiation.
NodeProperty< PRMInstance< GUM_SCALAR > * > nodeIdMap_
The mapping between PRMInstance and their NodeId in the relational skeleton of this PRMSystem.
HashTable< std::string, model_pair > arrayMap_
Mapping between arrays and their name. The first element of the pair is the type of the array.
void _groundRef_(const PRMInstance< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
bool isArray(std::string_view name) const
Returns true if an array with the given name exists.
void _groundAttr_(const PRMInstance< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
Method which ground Atttributes and Aggregators of an PRMInstance.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities