62 template <
typename GUM_SCALAR >
64 const std::string& extends,
66 bool delayInheritance) {
68 if (
_prm_->_classMap_.exists(real_name) ||
_prm_->_interfaceMap_.exists(real_name)) {
75 if (implements != 0) {
76 for (
const auto& imp: *implements) {
83 if ((extends.empty()) && impl.
empty()) {
85 }
else if ((extends !=
"") && impl.
empty()) {
87 }
else if ((extends.empty()) && (!impl.
empty())) {
89 }
else if ((extends !=
"") && (!impl.
empty())) {
94 _prm_->_classes_.insert(c);
98 template <
typename GUM_SCALAR >
101 if (!(
_prm_->_classMap_.exists(real_name))) {
102 std::stringstream msg;
103 msg <<
"'" << real_name <<
"' not found";
109 template <
typename GUM_SCALAR >
119 template <
typename GUM_SCALAR >
125 for (
const auto& node: i->containerDag().nodes()) {
126 std::string name = i->get(node).name();
128 switch (i->get(node).elt_type()) {
132 || (c->
get(name).elt_type()
134 if (!c->
get(name).type().isSubTypeOf(i->get(name).type())) {
135 std::stringstream msg;
136 msg <<
"class " << c->
name() <<
" does not respect interface ";
140 std::stringstream msg;
141 msg <<
"class " << c->
name() <<
" does not respect interface ";
156 std::stringstream msg;
157 msg <<
"class " << c->
name() <<
" does not respect interface ";
161 std::stringstream msg;
162 msg <<
"class " << c->
name() <<
" does not respect interface ";
175 std::string msg =
"unexpected ClassElement<GUM_SCALAR> in interface ";
181 std::stringstream msg;
182 msg <<
"class " << c->
name() <<
" does not respect interface ";
192 template <
typename GUM_SCALAR >
194 const std::string& extends,
195 bool delayInheritance) {
197 if (
_prm_->_classMap_.exists(real_name) ||
_prm_->_interfaceMap_.exists(real_name)) {
205 if (super !=
nullptr) {
211 _prm_->_interfaceMap_.insert(i->
name(), i);
212 _prm_->_interfaces_.insert(i);
216 template <
typename GUM_SCALAR >
219 if (!
_prm_->_interfaceMap_.exists(real_name)) {
227 template <
typename GUM_SCALAR >
237 if (vars.
exists(&(c->
get(node).type().variable()))) {
247 if (count != attr->
cpf().variablesSequence().size()) {
252 template <
typename GUM_SCALAR >
255 const std::string& name) {
262 "can not add a reference slot as a parent of an attribute")
291 std::string msg =
"found no ClassElement<GUM_SCALAR> with the given name ";
299 "Impossible to add a multiple reference slot as"
300 " direct parent of an PRMAttribute<GUM_SCALAR>.");
305 template <
typename GUM_SCALAR >
320 template <
typename GUM_SCALAR >
328 std::vector< GUM_SCALAR > array2(array.begin(), array.end());
329 a->
cpf().fillWith(array2);
332 template <
typename GUM_SCALAR >
338 if (a->cpf().domainSize() != array.size()) {
342 a->cpf().fillWith(array);
345 template <
typename GUM_SCALAR >
351 if (a->
cpf().domainSize() != array.size()) {
355 std::vector< GUM_SCALAR > array2(array.begin(), array.end());
359 template <
typename GUM_SCALAR >
365 if (a->
cpf().domainSize() != array.size()) {
369 if (a->
cpf().nbrDim() == 1) {
381 auto idx = (std::size_t)0;
382 while ((!jnst.
end()) && idx < array.size()) {
384 a->
cpf().set(inst, array[idx]);
391 template <
typename GUM_SCALAR >
394 const std::vector< float >& values) {
398 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
402 if (values.size() != a->type().variable().domainSize()) {
406 std::vector< GUM_SCALAR > values2(values.begin(), values.end());
410 template <
typename GUM_SCALAR >
412 const std::vector< GUM_SCALAR >& values) {
416 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
420 if (values.size() != a->type().variable().domainSize()) {
433 for (
Idx i = 0; i < parents.size(); ++i) {
434 var = form->formulas().variablesSequence().atPos(1 + i);
436 if (parents[i] ==
"*") {
444 if (var->
label(j) == parents[i]) {
445 jnst.chgVal(*var, j);
452 std::string msg =
"could not find label ";
461 for (
Size i = 0; i < form->type()->domainSize(); ++i) {
462 inst.
chgVal(form->type().variable(), i);
465 form->formulas().set(inst, std::to_string(values[i]));
474 template <
typename GUM_SCALAR >
476 const std::vector< std::string >& values) {
480 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
484 if (values.size() != a->type().variable().domainSize()) {
497 for (
Idx i = 0; i < parents.size(); ++i) {
498 var = form->formulas().variablesSequence().atPos(1 + i);
500 if (parents[i] ==
"*") {
508 if (var->
label(j) == parents[i]) {
509 jnst.chgVal(*var, j);
516 std::string msg =
"could not find label ";
525 for (
Size i = 0; i < form->type()->domainSize(); ++i) {
526 inst.
chgVal(form->type().variable(), i);
529 form->formulas().set(inst, values[i]);
538 template <
typename GUM_SCALAR >
540 const std::string& name,
549 }
else if (type ==
"real") {
560 template <
typename GUM_SCALAR >
563 const std::string& agg_type,
564 const std::string& rv_type,
565 const std::vector< std::string >& params) {
577 switch (agg->agg_type()) {
581 if (params.size() != 1) {
584 agg->setLabel(params.front());
594 template <
typename GUM_SCALAR >
600 auto& agg = c->
get(name);
607 template <
typename GUM_SCALAR >
610 const std::string& name) {
611 auto chains = std::vector< std::string >{name};
612 auto inputs = std::vector< PRMClassElement< GUM_SCALAR >* >();
632 while (label_idx < inputs.front()->type()->domainSize()) {
633 if (inputs.front()->type()->label(label_idx) == param) {
break; }
638 if (label_idx == inputs.front()->type()->domainSize()) {
664 template <
typename GUM_SCALAR >
670 template <
typename GUM_SCALAR >
672 const std::string& agg_type,
673 const std::vector< std::string >& chains,
674 const std::vector< std::string >& params,
680 if (chains.size() == 0) {
685 std::vector< PRMClassElement< GUM_SCALAR >* > inputs;
695 if (inputs.size() > 1) {
696 for (
auto iter = inputs.begin() + 1; iter != inputs.end(); ++iter) {
697 if ((**(iter - 1)).type() != (**iter).type()) {
716 inputs.front()->type());
727 while (label_idx < inputs.front()->type()->domainSize()) {
728 if (inputs.front()->type()->label(label_idx) == params.front()) {
break; }
733 if (label_idx == inputs.front()->type()->domainSize()) {
769 while (label_idx < inputs.front()->type()->domainSize()) {
770 if (inputs.front()->type()->label(label_idx) == params.front()) {
break; }
775 if (label_idx == inputs.front()->type()->domainSize()) {
795 std::string safe_name = agg->
safeName();
818 for (
const auto& elt: inputs) {
819 c->
addArc(elt->safeName(), safe_name);
823 template <
typename GUM_SCALAR >
825 const std::string& name,
848 template <
typename GUM_SCALAR >
850 const std::string& name,
860 for (
Size i = 0; i < size; ++i) {
861 std::stringstream elt_name;
862 elt_name << name <<
"[" << i <<
"]";
864 model->
add(name, inst);
875 template <
typename GUM_SCALAR >
882 model->
add(l_i, model->
get(r_i));
891 template <
typename GUM_SCALAR >
893 const std::string& l_ref,
894 const std::string& r_i) {
897 std::vector< PRMInstance< GUM_SCALAR >* > lefts;
898 std::vector< PRMInstance< GUM_SCALAR >* > rights;
900 if (model->isInstance(l_i)) {
901 lefts.push_back(&(model->get(l_i)));
902 }
else if (model->isArray(l_i)) {
903 for (
const auto& elt: model->getArray(l_i))
904 lefts.push_back(elt);
909 if (model->isInstance(r_i)) {
910 rights.push_back(&(model->get(r_i)));
911 }
else if (model->isArray(r_i)) {
912 for (
const auto& elt: model->getArray(r_i))
913 rights.push_back(elt);
918 for (
const auto l: lefts) {
919 for (
const auto r: rights) {
920 auto& elt = l->type().get(l_ref);
922 l->add(elt.id(), *r);
931 template <
typename GUM_SCALAR >
934 const std::string& name) {
935 std::vector< std::string > v;
941 for (
size_t i = 0; i < v.size(); ++i) {
943 switch (current->
get(v[i]).elt_type()) {
953 if (i == v.size() - 1) {
964 }
catch (
NotFound const&) {
return nullptr; }
967 GUM_ASSERT(v.size() == elts.
size());
974 template <
typename GUM_SCALAR >
977 const std::vector< std::string >& chains,
981 for (
size_t i = 0; i < chains.size(); ++i) {
983 inputs.push_back(&(c->
get(chains[i])));
990 c->
add(inputs.back());
1002 for (
const auto& elt: inputs) {
1003 if ((*elt).type() != (*t)) {
1006 std::stringstream name;
1008 for (
Size idx = 0; idx < sc->
chain().size() - 1; ++idx) {
1009 name << sc->
chain().atPos(idx)->name() <<
".";
1012 name <<
".(" << t->
name() <<
")" << sc->
lastElt().name();
1015 toAdd.push_back(std::make_pair(elt, &(c->
get(name.str()))));
1020 std::stringstream name;
1021 name <<
"(" << t->
name() <<
")" << elt->name();
1022 toAdd.push_back(std::make_pair(elt, &(c->
get(name.str()))));
1030 template <
typename GUM_SCALAR >
1033 const PRMType* current =
nullptr;
1037 for (
const auto& elt: elts) {
1039 current = &((*elt).type());
1041 while (current != 0) {
1044 ++(counters[current->
name()]);
1050 if (current->isSubType()) {
1051 current = &(current->superType());
1066 int current_depth = 0;
1068 for (
const auto& elt: counters) {
1069 if ((elt.second) == elts.size()) {
1072 if (current_depth > max_depth) {
1073 max_depth = current_depth;
1079 if (current) {
return const_cast< PRMType*
>(current); }
1084 template <
typename GUM_SCALAR >
1087 const std::vector< std::string >& chains,
1088 const std::vector< float >& numbers,
1090 const std::vector< std::string >& labels) {
1092 GUM_ERROR(gum::FactoryInvalidState,
"invalid state to add a noisy-or")
1097 std::vector< PRMClassElement< GUM_SCALAR >* > parents;
1099 for (
const auto& elt: chains)
1100 parents.push_back(&(c->
get(elt)));
1104 for (
size_t idx = 0; idx < parents.size(); ++idx) {
1105 if (parents[idx]->type() != (*common_type)) {
1109 std::string safe_name = parent->
cast(*common_type);
1111 if (!c->
exists(safe_name)) {
1114 c->
add(parents[idx]);
1119 parents[idx] = &(c->
get(safe_name));
1124 if (numbers.size() == 1) {
1128 }
else if (numbers.size() == parents.size()) {
1134 for (
size_t idx = 0; idx < numbers.size(); ++idx) {
1135 noisy->
causalWeight(parents[idx]->type().variable(), numbers[idx]);
1143 if (!labels.empty()) {
1148 template <
typename GUM_SCALAR >
1151 std::string full_name;
1154 if (
_prm_->_typeMap_.exists(name)) {
1155 type =
_prm_->_typeMap_[name];
1161 if (
_prm_->_typeMap_.exists(prefixed)) {
1163 type =
_prm_->_typeMap_[prefixed];
1164 full_name = prefixed;
1165 }
else if (full_name != prefixed) {
1172 size_t last_dot = relatif_ns.find_last_of(
'.');
1173 if (last_dot != std::string::npos) {
1174 relatif_ns = relatif_ns.substr(0, last_dot) +
'.' + name;
1175 if (
_prm_->_typeMap_.exists(relatif_ns)) {
1177 type =
_prm_->_typeMap_[relatif_ns];
1178 full_name = relatif_ns;
1179 }
else if (full_name != relatif_ns) {
1181 "Type name '" << name <<
"' is ambiguous: specify full name.");
1190 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1191 std::string ns = (*ns_list)[i];
1192 std::string ns_name = ns +
"." + name;
1193 if (
_prm_->_typeMap_.exists(ns_name)) {
1195 type =
_prm_->_typeMap_[ns_name];
1196 full_name = ns_name;
1197 }
else if (full_name != ns_name) {
1199 "Type name '" << name <<
"' is ambiguous: specify full name.");
1205 if (type == 0) {
GUM_ERROR(
NotFound,
"Type '" << name <<
"' not found, check imports.") }
1210 template <
typename GUM_SCALAR >
1214 std::string full_name;
1217 if (
_prm_->_classMap_.exists(name)) {
1218 a_class =
_prm_->_classMap_[name];
1224 if (
_prm_->_classMap_.exists(prefixed)) {
1225 if (a_class ==
nullptr) {
1226 a_class =
_prm_->_classMap_[prefixed];
1227 full_name = prefixed;
1228 }
else if (full_name != prefixed) {
1230 "Class name '" << name <<
"' is ambiguous: specify full name.");
1237 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1238 std::string ns = (*ns_list)[i];
1239 std::string ns_name = ns +
"." + name;
1240 if (
_prm_->_classMap_.exists(ns_name)) {
1242 a_class =
_prm_->_classMap_[ns_name];
1243 full_name = ns_name;
1244 }
else if (full_name != ns_name) {
1246 "Class name '" << name <<
"' is ambiguous: specify full name.");
1252 if (a_class == 0) {
GUM_ERROR(
NotFound,
"Class '" << name <<
"' not found, check imports.") }
1257 template <
typename GUM_SCALAR >
1261 std::string full_name;
1264 if (
_prm_->_interfaceMap_.exists(name)) {
1265 interface =
_prm_->_interfaceMap_[name];
1271 if (
_prm_->_interfaceMap_.exists(prefixed)) {
1272 if (interface ==
nullptr) {
1273 interface =
_prm_->_interfaceMap_[prefixed];
1274 full_name = prefixed;
1275 }
else if (full_name != prefixed) {
1277 "Interface name '" << name <<
"' is ambiguous: specify full name.");
1285 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1286 std::string ns = (*ns_list)[i];
1287 std::string ns_name = ns +
"." + name;
1289 if (
_prm_->_interfaceMap_.exists(ns_name)) {
1290 if (interface ==
nullptr) {
1291 interface =
_prm_->_interfaceMap_[ns_name];
1292 full_name = ns_name;
1293 }
else if (full_name != ns_name) {
1295 "Interface name '" << name <<
"' is ambiguous: specify full name.");
1301 if (interface ==
nullptr) {
1308 template <
typename GUM_SCALAR >
1314 template <
typename GUM_SCALAR >
1320 template <
typename GUM_SCALAR >
1330 template <
typename GUM_SCALAR >
1335 template <
typename GUM_SCALAR >
1339 return _stack_.back()->obj_type();
1342 template <
typename GUM_SCALAR >
1349 template <
typename GUM_SCALAR >
1356 template <
typename GUM_SCALAR >
1367 template <
typename GUM_SCALAR >
1372 template <
typename GUM_SCALAR >
1374 std::string super) {
1376 if (
_prm_->_typeMap_.exists(real_name)) {
1379 if (super.empty()) {
1385 t->_label_map_ =
new std::vector< Idx >();
1390 template <
typename GUM_SCALAR >
1392 if (extends.empty()) {
1398 }
else if (t->_superType_) {
1413 }
else if (!t->_superType_) {
1419 for (
Idx i = 0; i < t->_superType_->_var_->
domainSize(); ++i) {
1420 if (t->_superType_->_var_->
label(i) == extends) {
1427 t->_label_map_->push_back(i);
1438 template <
typename GUM_SCALAR >
1442 if (!t->_isValid_()) {
1450 _prm_->_types_.insert(t);
1454 template <
typename GUM_SCALAR >
1457 if (
_prm_->_typeMap_.exists(real_name)) {
1465 template <
typename GUM_SCALAR >
1470 if (!var) {
GUM_ERROR(
FatalError,
"the current type's variable is not a LabelizedVariable.") }
1479 template <
typename GUM_SCALAR >
1489 _prm_->_types_.insert(t);
1493 template <
typename GUM_SCALAR >
1497 if (
_prm_->_typeMap_.exists(real_name)) {
1498 std::stringstream msg;
1499 msg <<
"\"" << real_name <<
"' is already used.";
1506 if (t->variable().domainSize() < 2) {
1510 _prm_->_typeMap_.insert(t->name(), t);
1511 _prm_->_types_.insert(t);
1514 template <
typename GUM_SCALAR >
1520 template <
typename GUM_SCALAR >
1522 const std::string& name) {
1528 template <
typename GUM_SCALAR >
1530 const std::string& name,
1544 std::string dot =
".";
1551 if (a !=
nullptr && (!c->
exists(a->
id()))) {
delete a; }
1557 template <
typename GUM_SCALAR >
1563 auto& a = c->
get(name);
1571 template <
typename GUM_SCALAR >
1577 template <
typename GUM_SCALAR >
1579 if (
_prm_->_systemMap_.exists(name)) {
1584 _prm_->_systemMap_.insert(model->
name(), model);
1585 _prm_->_systems_.insert(model);
1588 template <
typename GUM_SCALAR >
1598 template <
typename GUM_SCALAR >
1600 const std::string& name) {
1604 if (c->parameters().size() > 0) {
1613 template <
typename GUM_SCALAR >
1616 const std::string& name,
1620 if (c->parameters().empty()) {
1621 if (params.
empty()) {
1628 auto my_params = params;
1630 for (
const auto& p: c->parameters()) {
1631 if (!my_params.exists(p->name())) { my_params.insert(p->name(), p->value()); }
1635 std::stringstream sBuff;
1636 sBuff << c->name() <<
"<";
1638 for (
const auto& p: my_params) {
1639 sBuff << p.first <<
"=" << p.second <<
",";
1643 std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) +
">";
1653 for (
auto p: my_params) {
1675 template <
typename GUM_SCALAR >
1677 const std::string& name) {
1686 if (i) {
delete i; }
1691 template <
typename GUM_SCALAR >
1695 full_name.append(
".");
1696 full_name.append(str);
1703 template <
typename GUM_SCALAR >
1719 template <
typename GUM_SCALAR >
1737 template <
typename GUM_SCALAR >
1758 template <
typename GUM_SCALAR >
1763 while (current->isSubType()) {
1765 current = &(current->superType());
1771 template <
typename GUM_SCALAR >
1777 template <
typename GUM_SCALAR >
1795 template <
typename GUM_SCALAR >
1802 template <
typename GUM_SCALAR >
1804 const std::string& r_i) {
1805 size_t pos = l_i.find_last_of(
'.');
1807 if (pos != std::string::npos) {
1808 std::string l_ref = l_i.substr(pos + 1, std::string::npos);
1815 template <
typename GUM_SCALAR >
1821 template <
typename GUM_SCALAR >
1826 template <
typename GUM_SCALAR >
1832 template <
typename GUM_SCALAR >
1851 template <
typename GUM_SCALAR >
1855 return (system && system->
isArray(name));
1858 template <
typename GUM_SCALAR >
1866 if (a->formulas().domainSize() != array.size()) {
1870 if (a->formulas().nbrDim() == 1) {
1882 auto idx = (std::size_t)0;
1883 while ((!jnst.
end()) && idx < array.size()) {
1885 a->formulas().set(inst, array[idx]);
1895 template <
typename GUM_SCALAR >
1903 if (a->formulas().domainSize() != array.size()) {
Headers of gum::PRMAttribute.
Exception : default in label.
Base class for discrete random variable.
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
virtual Size domainSize() const =0
Class for discretized random variable.
DiscretizedVariable & addTick(const T_TICKS &aTick)
add a tick.
Exception : a similar element already exists.
Base class for all aGrUM's exceptions.
Exception : invalid state error.
Exception : fatal (unknown ?) error.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool empty() const noexcept
Indicates whether the hash table is empty.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Class for assigning/browsing values to tuples of discrete variables.
const Sequence< const DiscreteVariable * > & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
void incIn(const Instantiation &i)
Operator increment for the variables in i.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
bool end() const
Returns true if the Instantiation reached the end.
void setFirstIn(const Instantiation &i)
Assign the first values in the Instantiation for the variables in i.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
void inc()
Operator increment.
void setFirst()
Assign the first values to the tuple of the Instantiation.
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
virtual void populate(const std::vector< GUM_SCALAR > &v) const
Automatically fills this MultiDimContainer with the values in v.
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
Exception : wrong subtype or subclass.
Defines a discrete random variable over an integer interval.
Size size() const noexcept
Returns the size of the sequence.
bool exists(const Key &k) const
Check the existence of k in the sequence.
const Key & back() const
Returns the last element of the sequence.
void insert(const Key &k)
Insert an element at the end of the sequence.
The generic class for storing (ordered) sequences of objects.
void insert(const Key &k)
Inserts a new element into the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
Exception : wrong type for this operation.
const std::string & name() const
returns the name of the variable
Exception: wrong PRMClassElement for this operation.
Idx label() const
Returns the label's index on which this aggregate applies.
virtual PRMType & type()
See gum::PRMClassElement::type().
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
AggregateType agg_type() const
Returns the aggregate of *this.
bool hasLabel() const
Returns true if the label is defined.
void setLabel(Idx idx)
Set the aggregator's label.
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate.
const std::string & labelValue() const
See gum::PRMClassElement::elt_type().
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>
virtual NodeId overload(PRMClassElement< GUM_SCALAR > *elt)=0
Add a PRMClassElement<GUM_SCALAR> which overload an inherited PRMClassElement<GUM_SCALAR>.
virtual PRMClassElement< GUM_SCALAR > & get(const std::string &name)=0
Getter on a member of this PRMClassElementContainer.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
virtual void addArc(const std::string &tail, const std::string &head)=0
Add an arc between two PRMClassElement<GUM_SCALAR>.
virtual NodeId add(PRMClassElement< GUM_SCALAR > *elt)=0
Add a PRMClassElement<GUM_SCALAR> to this PRMClassElementContainer.
virtual bool exists(const std::string &name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
virtual void setOutputNode(const PRMClassElement< GUM_SCALAR > &elt, bool b)
Set the output flag value of id at b.
Abstract class representing an element of PRM class.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
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...
virtual void addArc(const std::string &tail, const std::string &head)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::addArc().
PRMClassElement< GUM_SCALAR > & get(NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
virtual NodeId add(PRMClassElement< GUM_SCALAR > *elt)
See gum::prm::add(PRMClassElement<GUM_SCALAR>*).
const Set< PRMInterface< GUM_SCALAR > * > & implements() const
Returns the Set of PRMInterface<GUM_SCALAR> implemented by this Class<GUM_SCALAR>.
virtual NodeId overload(PRMClassElement< GUM_SCALAR > *elt)
See gum::prm::overload(PRMClassElement<GUM_SCALAR>*).
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.
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.
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.
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.
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 _addParent_(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.
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.
<agrum/PRM/elements/funcAttribute.h>
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.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
virtual prm_type obj_type() const =0
Returns the type of this object.
PRMParameter is a member of a Class in a PRM.
ParameterType valueType() const
See gum::PRMClassElement::elt_type().
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
PRMClassElementContainer< GUM_SCALAR > & slotType()
Returns the type of this slot, which is a PRMClassElementContainer (it is not the type of PRMObject).
<agrum/PRM/elements/scalarAttribute.h>
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Sequence< PRMClassElement< GUM_SCALAR > * > & chain()
Return the sequence representing the chain of elements in this PRMSlotChain.
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
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.
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 isArray(const std::string &name) const
Returns true if an array with the given name exists.
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
This is a decoration of the DiscreteVariable class.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
namespace for all probabilistic relational models entities
void decomposePath(const std::string &path, std::vector< std::string > &v)
Decompose a string in a vector of strings using "." as separators.
gum is the global namespace for all aGrUM entities
non-template interface-like parent for every PRM Factory