59 template <
typename GUM_SCALAR >
64 template <
typename GUM_SCALAR >
68 for (
const auto& elt: *
this)
75 delete elt.second.second;
78 template <
typename GUM_SCALAR >
85 template <
typename GUM_SCALAR >
89 "an Instance<GUM_SCALAR> with the same is already in this System");
92 NodeId id = skeleton_.addNode();
93 nodeIdMap_.insert(
id, i);
94 nameMap_.insert(i->
name(), i);
100 instanceMap_[&(i->
type())]->insert(i);
106 template <
typename GUM_SCALAR >
123 template <
typename GUM_SCALAR >
126 for (
const auto node: instance.
type().containerDag()) {
131 switch (instance.
type().get(node).elt_type()) {
134 std::stringstream elt_name;
135 elt_name << instance.
name() <<
"." << instance.
type().get(node).safeName();
144 std::stringstream elt_name;
145 elt_name << instance.
name() <<
"." << instance.
type().get(node).safeName();
158 template <
typename GUM_SCALAR >
160 const std::string&
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 <
typename GUM_SCALAR >
272 for (
const auto& elt: instance) {
273 std::stringstream elt_name;
274 elt_name << instance.
name() <<
"." << elt.second->
safeName();
277 for (
const auto par: instance.
type().containerDag().parents(elt.second->
id())) {
278 switch (instance.
type().get(par).elt_type()) {
281 std::stringstream parent_name;
282 parent_name << instance.
name() <<
"." << instance.
get(par).safeName();
288 std::string parent_name
295 std::stringstream sBuff;
296 sBuff << ref->name() <<
"." << parent_name;
322 template <
typename GUM_SCALAR >
327 std::stringstream var_name;
331 for (
const auto parent: instance.
type().containerDag().parents(attr.
id())) {
332 switch (instance.
type().get(parent).elt_type()) {
335 std::stringstream parent_name;
336 parent_name << instance.
name() <<
"." << instance.
get(parent).safeName();
337 bijection.
insert(&(instance.
get(parent).type().variable()),
338 &(factory.
variable(parent_name.str())));
343 std::stringstream parent_name;
349 &(factory.
variable(parent_name.str())));
364 for (auto var: attr.cpf().variablesSequence()) {
367 Instantiation inst(attr.
cpf()), jnst(*p);
368 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
369 p->set(jnst, attr.
cpf().get(inst));
371 GUM_ASSERT(inst.end() && jnst.end());
375 template <
typename GUM_SCALAR >
378 return add(array, &i);
381 template <
typename GUM_SCALAR >
386 template <
typename GUM_SCALAR >
395 template <
typename GUM_SCALAR >
404 template <
typename GUM_SCALAR >
413 template <
typename GUM_SCALAR >
418 template <
typename GUM_SCALAR >
423 template <
typename GUM_SCALAR >
428 template <
typename GUM_SCALAR >
433 template <
typename GUM_SCALAR >
438 template <
typename GUM_SCALAR >
440 for (
auto iter =
begin(); iter !=
end(); ++iter) {
441 (*(iter.val())).instantiate();
445 template <
typename GUM_SCALAR >
454 template <
typename GUM_SCALAR >
464 template <
typename GUM_SCALAR >
471 GUM_ERROR(
NotFound,
"the given Class<GUM_SCALAR> has no instantiation in this System");
475 template <
typename GUM_SCALAR >
484 template <
typename GUM_SCALAR >
492 template <
typename GUM_SCALAR >
500 template <
typename GUM_SCALAR >
510 "the given Instance<GUM_SCALAR> is of an incorrect "
511 "Class<GUM_SCALAR> type");
516 template <
typename GUM_SCALAR >
528 template <
typename GUM_SCALAR >
533 template <
typename GUM_SCALAR >
538 template <
typename GUM_SCALAR >
543 template <
typename GUM_SCALAR >
549 template <
typename GUM_SCALAR >
557 template <
typename GUM_SCALAR >
565 template <
typename GUM_SCALAR >
573 template <
typename GUM_SCALAR >
581 template <
typename GUM_SCALAR >
Headers of gum::prm::PRMInstance<GUM_SCALAR>.
A factory class to ease BayesNet construction.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
const DiscreteVariable & variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
void startParentsDeclaration(const std::string &var) final
Tells the factory that we're declaring parents for some variable.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
void variableType(const VarType &type)
Tells the factory the current variable's type.
void addModality(const std::string &name) final
Adds a modality to the current labelized variable.
void setVariableCPT(const std::string &varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
void addMin(const long &min)
Adds the min value of the current range variable.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Tensor.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void setVariable(const DiscreteVariable &var) final
Define a variable.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void addNetworkProperty(const std::string &propName, const std::string &propValue) final
Tells the factory to add a property to the current network.
void variableName(const std::string &name) final
Tells the factory the current variable's name.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
void addParent(const std::string &var) final
Tells the factory for which variable we're declaring parents.
void addMax(const long &max)
Adds the max value of the current range variable.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
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.
virtual 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(const std::string &theValue)
sets the name of the variable
PRMAttribute is a member of a Class in a PRM.
virtual const Tensor< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
virtual PRMType & type()=0
See gum::PRMClassElement::type().
<agrum/PRM/classElementContainer.h>
Abstract class representing an element of PRM class.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
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.
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.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
PRMObject(const std::string &name)
Constructor.
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...
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::const_iterator const_iterator
Constant Iterator over the PRMInstance 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.
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.
const DiGraph & skeleton() const
Returns the relation skeleton of this PRMSystem.
iterator begin()
Returns an iterator over the instances in this system.
typename Sequence< PRMInstance< GUM_SCALAR > * >::const_iterator const_array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it's NodeId in the relational skeleton.
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
const iterator & end()
Returns a iterator at the end of the set of PRMInstance in this PRMSystem.
PRMSystem(const std::string &name)
Default constructor.
Size size() const
Returns the number of PRMInstance in this PRMSystem.
bool isInstance(const std::string &name) const
Returns true if an PRMInstance with the given name exists.
void addArray(const std::string &array, PRMClassElementContainer< GUM_SCALAR > &type)
Add an array of instances in this system. If the array doesn't exists it is created.
bool exists(const std::string &name) const
Retruns true either if name is an instance or an array in this PRMSystem.
DiGraph skeleton_
The relational skeleton of this PRMSystem.
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::iterator iterator
Iterator over the PRMInstance of this PRMSystem.
const Sequence< PRMInstance< GUM_SCALAR > * > & getArray(const std::string &name) const
Returns the sequence of instances of a given array.
HashTable< std::string, PRMInstance< double > * > nameMap_
void _groundTensor_(const PRMInstance< double > &instance, const PRMAttribute< double > &attr, BayesNetFactory< double > &factory) const
bool isArray(const std::string &name) const
Returns true if an array with the given name exists.
virtual ~PRMSystem()
Destructor.
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
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< double > &instance, BayesNetFactory< double > &factory) const
void _groundAgg_(const PRMClassElement< double > &elt, const std::string &name, BayesNetFactory< double > &factory) const
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
PRMClassElementContainer< GUM_SCALAR > & getArrayType(const std::string &name)
Returns the type of the given array.
virtual PRMObject::prm_type obj_type() const
Returns the PRM type of this object.
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