65 template < GUM_Numeric GUM_SCALAR >
67 std::string_view extends,
69 bool delayInheritance) {
71 if (
_prm_->_classMap_.exists(real_name) ||
_prm_->_interfaceMap_.exists(real_name)) {
78 if (implements != 0) {
79 for (
const auto& imp: *implements) {
86 if ((extends.empty()) && impl.
empty()) {
88 }
else if ((extends !=
"") && impl.
empty()) {
90 }
else if ((extends.empty()) && (!impl.
empty())) {
92 }
else if ((extends !=
"") && (!impl.
empty())) {
97 _prm_->_classes_.insert(c);
101 template < GUM_Numeric GUM_SCALAR >
104 if (!(
_prm_->_classMap_.exists(real_name))) {
110 template < GUM_Numeric GUM_SCALAR >
120 template < GUM_Numeric GUM_SCALAR >
125 for (
const auto& i: interfaces) {
126 for (
const auto& node: i->containerDag().nodes()) {
127 std::string name = i->get(node).name();
131 std::format(
"class {} does not respect interface {}", c->
name(), i->name()))
134 switch (i->get(node).elt_type()) {
139 if (!c->
get(name).type().isSubTypeOf(i->get(name).type())) {
142 std::format(
"class {} does not respect interface {}", c->
name(), i->name()))
147 std::format(
"class {} does not respect interface {}", c->
name(), i->name()))
163 std::format(
"class {} does not respect interface {}", c->
name(), i->name()))
168 std::format(
"class {} does not respect interface {}", c->
name(), i->name()))
180 std::string msg =
"unexpected ClassElement<GUM_SCALAR> in interface ";
191 template < GUM_Numeric GUM_SCALAR >
193 std::string_view extends,
194 bool delayInheritance) {
196 if (
_prm_->_classMap_.exists(real_name) ||
_prm_->_interfaceMap_.exists(real_name)) {
204 if (super !=
nullptr) {
210 _prm_->_interfaceMap_.insert(i->
name(), i);
211 _prm_->_interfaces_.insert(i);
215 template < GUM_Numeric GUM_SCALAR >
218 if (!
_prm_->_interfaceMap_.exists(real_name)) {
226 template < GUM_Numeric GUM_SCALAR >
236 if (vars.
exists(&(c->
get(node).type().variable()))) {
246 if (count != attr->
cpf().variablesSequence().size()) {
251 template < GUM_Numeric GUM_SCALAR >
254 std::string_view name) {
261 "can not add a reference slot as a parent of an attribute")
290 GUM_ERROR(
NotFound,
"found no ClassElement<GUM_SCALAR> with the given name " << name)
297 "Impossible to add a multiple reference slot as"
298 " direct parent of an PRMAttribute<GUM_SCALAR>.");
303 template < GUM_Numeric GUM_SCALAR >
318 template < GUM_Numeric GUM_SCALAR >
326 std::vector< GUM_SCALAR > array2(array.begin(), array.end());
327 a->
cpf().fillWith(array2);
330 template < GUM_Numeric GUM_SCALAR >
336 if (a->cpf().domainSize() != array.size()) {
340 a->cpf().fillWith(array);
343 template < GUM_Numeric GUM_SCALAR >
348 if (a->
cpf().domainSize() != array.size()) {
352 std::vector< GUM_SCALAR > array2(array.begin(), array.end());
356 template < GUM_Numeric GUM_SCALAR >
361 if (a->
cpf().domainSize() != array.size()) {
365 if (a->
cpf().nbrDim() == 1) {
377 auto idx = (std::size_t)0;
378 while ((!jnst.
end()) && idx < array.size()) {
380 a->
cpf().set(inst, array[idx]);
387 template < GUM_Numeric GUM_SCALAR >
389 const std::vector< float >& values) {
393 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
397 if (values.size() != a->type().variable().domainSize()) {
401 std::vector< GUM_SCALAR > values2(values.begin(), values.end());
405 template < GUM_Numeric GUM_SCALAR >
407 const std::vector< GUM_SCALAR >& values) {
411 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
415 if (values.size() != a->type().variable().domainSize()) {
428 for (
Idx i = 0; i < parents.size(); ++i) {
429 var = form->formulas().variablesSequence().atPos(1 + i);
431 if (parents[i] ==
"*") {
439 if (var->
label(j) == parents[i]) {
440 jnst.chgVal(*var, j);
447 std::string msg =
"could not find label ";
456 for (
Size i = 0; i < form->type()->domainSize(); ++i) {
457 inst.
chgVal(form->type().variable(), i);
460 form->formulas().set(inst, std::to_string(values[i]));
469 template < GUM_Numeric GUM_SCALAR >
471 const std::vector< std::string >& values) {
475 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
479 if (values.size() != a->type().variable().domainSize()) {
492 for (
Idx i = 0; i < parents.size(); ++i) {
493 var = form->formulas().variablesSequence().atPos(1 + i);
495 if (parents[i] ==
"*") {
503 if (var->
label(j) == parents[i]) {
504 jnst.chgVal(*var, j);
511 std::string msg =
"could not find label ";
520 for (
Size i = 0; i < form->type()->domainSize(); ++i) {
521 inst.
chgVal(form->type().variable(), i);
524 form->formulas().set(inst, values[i]);
533 template < GUM_Numeric GUM_SCALAR >
535 std::string_view name,
544 }
else if (type ==
"real") {
555 template < GUM_Numeric GUM_SCALAR >
557 std::string_view agg_type,
558 std::string_view rv_type,
559 const std::vector< std::string >& params) {
571 switch (agg->agg_type()) {
575 if (params.size() != 1) {
578 agg->setLabel(params.front());
588 template < GUM_Numeric GUM_SCALAR >
594 auto& agg = c->
get(name);
601 template < GUM_Numeric GUM_SCALAR >
604 std::string_view name) {
605 auto chains = std::vector< std::string >{std::string(name)};
606 auto inputs = std::vector< PRMClassElement< GUM_SCALAR >* >();
626 while (label_idx < inputs.front()->type()->domainSize()) {
627 if (inputs.front()->type()->label(label_idx) == param) {
break; }
632 if (label_idx == inputs.front()->type()->domainSize()) {
658 template < GUM_Numeric GUM_SCALAR >
664 template < GUM_Numeric GUM_SCALAR >
666 std::string_view agg_type,
667 const std::vector< std::string >& chains,
668 const std::vector< std::string >& params,
669 std::string_view type) {
673 std::string name_s(name), agg_type_s(agg_type), type_s(type);
675 if (chains.size() == 0) {
680 std::vector< PRMClassElement< GUM_SCALAR >* > inputs;
690 if (inputs.size() > 1) {
691 for (
auto iter = inputs.begin() + 1; iter != inputs.end(); ++iter) {
692 if ((**(iter - 1)).type() != (**iter).type()) {
711 inputs.front()->type());
722 while (label_idx < inputs.front()->type()->domainSize()) {
723 if (inputs.front()->type()->label(label_idx) == params.front()) {
break; }
728 if (label_idx == inputs.front()->type()->domainSize()) {
764 while (label_idx < inputs.front()->type()->domainSize()) {
765 if (inputs.front()->type()->label(label_idx) == params.front()) {
break; }
770 if (label_idx == inputs.front()->type()->domainSize()) {
790 std::string safe_name = agg->
safeName();
818 for (
const auto& elt: inputs) {
819 c->
addArc(elt->safeName(), safe_name);
823 template < GUM_Numeric GUM_SCALAR >
825 std::string_view name,
848 template < GUM_Numeric GUM_SCALAR >
850 std::string_view name,
858 std::string name_str(name);
861 for (
Size i = 0; i < size; ++i) {
863 model->
add(name_str, inst);
875 template < GUM_Numeric GUM_SCALAR >
880 if (model->
isArray(std::string(l_i))) {
882 model->
add(std::string(l_i), model->
get(r_i));
891 template < GUM_Numeric GUM_SCALAR >
893 std::string_view l_ref,
894 std::string_view r_i) {
897 std::vector< PRMInstance< GUM_SCALAR >* > lefts;
898 std::vector< PRMInstance< GUM_SCALAR >* > rights;
900 if (model->isInstance(std::string(l_i))) {
901 lefts.push_back(&(model->get(l_i)));
902 }
else if (model->isArray(std::string(l_i))) {
903 for (
const auto& elt: model->getArray(std::string(l_i)))
904 lefts.push_back(elt);
909 if (model->isInstance(std::string(r_i))) {
910 rights.push_back(&(model->get(r_i)));
911 }
else if (model->isArray(std::string(r_i))) {
912 for (
const auto& elt: model->getArray(std::string(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 < GUM_Numeric GUM_SCALAR >
934 std::string_view name) {
935 std::vector< std::string > v;
941 for (
size_t i = 0; i < v.size(); ++i) {
942 if (!current->
exists(v[i]))
return nullptr;
943 switch (current->
get(v[i]).elt_type()) {
953 if (i == v.size() - 1) {
966 GUM_ASSERT(v.size() == elts.
size());
973 template < GUM_Numeric GUM_SCALAR >
976 const std::vector< std::string >& chains,
980 for (
size_t i = 0; i < chains.size(); ++i) {
981 if (c->
exists(chains[i])) {
982 inputs.push_back(&(c->
get(chains[i])));
989 c->
add(inputs.back());
1001 for (
const auto& elt: inputs) {
1002 if ((*elt).type() != (*t)) {
1005 std::stringstream name;
1007 for (
Size idx = 0; idx < sc->
chain().size() - 1; ++idx) {
1008 name << sc->
chain().atPos(idx)->name() <<
".";
1011 name <<
".(" << t->
name() <<
")" << sc->
lastElt().name();
1013 if (c->
exists(name.str())) {
1014 toAdd.push_back(std::make_pair(elt, &(c->
get(name.str()))));
1020 std::make_pair(elt, &(c->
get(std::format(
"({}){}", t->
name(), elt->name())))));
1028 template < GUM_Numeric GUM_SCALAR >
1031 const PRMType* current =
nullptr;
1035 for (
const auto& elt: elts) {
1037 current = &((*elt).type());
1039 while (current != 0) {
1041 if (
auto p = counters.
tryGet(current->
name())) {
1048 if (current->isSubType()) {
1049 current = &(current->superType());
1064 int current_depth = 0;
1066 for (
const auto& elt: counters) {
1067 if ((elt.second) == elts.size()) {
1070 if (current_depth > max_depth) {
1071 max_depth = current_depth;
1077 if (result) {
return result; }
1082 template < GUM_Numeric GUM_SCALAR >
1084 const std::vector< std::string >& chains,
1085 const std::vector< float >& numbers,
1087 const std::vector< std::string >& labels) {
1089 GUM_ERROR(gum::FactoryInvalidState,
"invalid state to add a noisy-or")
1094 std::vector< PRMClassElement< GUM_SCALAR >* > parents;
1096 for (
const auto& elt: chains)
1097 parents.push_back(&(c->
get(elt)));
1101 for (
size_t idx = 0; idx < parents.size(); ++idx) {
1102 if (parents[idx]->type() != (*common_type)) {
1106 std::string safe_name = parent->
cast(*common_type);
1108 if (!c->
exists(safe_name)) {
1111 c->
add(parents[idx]);
1116 parents[idx] = &(c->
get(safe_name));
1121 if (numbers.size() == 1) {
1125 }
else if (numbers.size() == parents.size()) {
1131 for (
size_t idx = 0; idx < numbers.size(); ++idx) {
1132 noisy->
causalWeight(parents[idx]->type().variable(), numbers[idx]);
1140 if (!labels.empty()) {
1145 template < GUM_Numeric GUM_SCALAR >
1148 std::string full_name;
1151 if (
auto p =
_prm_->_typeMap_.tryGet(name)) {
1158 if (
auto p =
_prm_->_typeMap_.tryGet(prefixed)) {
1161 full_name = prefixed;
1162 }
else if (full_name != prefixed) {
1169 if (
auto last_dot = relatif_ns.find_last_of(
'.'); last_dot != std::string::npos) {
1170 relatif_ns = relatif_ns.substr(0, last_dot) +
'.' + std::string(name);
1171 if (
auto p =
_prm_->_typeMap_.tryGet(relatif_ns)) {
1174 full_name = relatif_ns;
1175 }
else if (full_name != relatif_ns) {
1177 "Type name '" << name <<
"' is ambiguous: specify full name.");
1186 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1187 std::string ns = (*ns_list)[i];
1188 std::string ns_name = ns +
"." + std::string(name);
1189 if (
auto p =
_prm_->_typeMap_.tryGet(ns_name)) {
1192 full_name = ns_name;
1193 }
else if (full_name != ns_name) {
1195 "Type name '" << name <<
"' is ambiguous: specify full name.");
1201 if (type == 0) {
GUM_ERROR(
NotFound,
"Type '" << name <<
"' not found, check imports.") }
1206 template < GUM_Numeric GUM_SCALAR >
1209 std::string full_name;
1212 if (
auto p =
_prm_->_classMap_.tryGet(name)) {
1219 if (
auto p =
_prm_->_classMap_.tryGet(prefixed)) {
1220 if (a_class ==
nullptr) {
1222 full_name = prefixed;
1223 }
else if (full_name != prefixed) {
1225 "Class name '" << name <<
"' is ambiguous: specify full name.");
1232 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1233 std::string ns = (*ns_list)[i];
1234 std::string ns_name = ns +
"." + std::string(name);
1235 if (
auto p =
_prm_->_classMap_.tryGet(ns_name)) {
1238 full_name = ns_name;
1239 }
else if (full_name != ns_name) {
1241 "Class name '" << name <<
"' is ambiguous: specify full name.");
1247 if (a_class == 0) {
GUM_ERROR(
NotFound,
"Class '" << name <<
"' not found, check imports.") }
1252 template < GUM_Numeric GUM_SCALAR >
1256 std::string full_name;
1259 if (
auto p =
_prm_->_interfaceMap_.tryGet(name)) {
1266 if (
auto p =
_prm_->_interfaceMap_.tryGet(prefixed)) {
1267 if (a_interface ==
nullptr) {
1269 full_name = prefixed;
1270 }
else if (full_name != prefixed) {
1272 "Interface name '" << name <<
"' is ambiguous: specify full name.");
1280 for (
gum::Size i = 0; i < ns_list->size(); ++i) {
1281 std::string ns = (*ns_list)[i];
1282 std::string ns_name = ns +
"." + std::string(name);
1284 if (
auto p =
_prm_->_interfaceMap_.tryGet(ns_name)) {
1285 if (a_interface ==
nullptr) {
1287 full_name = ns_name;
1288 }
else if (full_name != ns_name) {
1290 "Interface name '" << name <<
"' is ambiguous: specify full name.");
1296 if (a_interface ==
nullptr) {
1303 template < GUM_Numeric GUM_SCALAR >
1309 template < GUM_Numeric GUM_SCALAR >
1314 template < GUM_Numeric GUM_SCALAR >
1324 template < GUM_Numeric GUM_SCALAR >
1329 template < GUM_Numeric GUM_SCALAR >
1333 return _stack_.back()->obj_type();
1336 template < GUM_Numeric GUM_SCALAR >
1343 template < GUM_Numeric GUM_SCALAR >
1350 template < GUM_Numeric GUM_SCALAR >
1361 template < GUM_Numeric GUM_SCALAR >
1366 template < GUM_Numeric GUM_SCALAR >
1368 std::string_view super) {
1370 if (
_prm_->_typeMap_.exists(real_name)) {
1373 if (super.empty()) {
1379 t->_label_map_ =
new std::vector< Idx >();
1384 template < GUM_Numeric GUM_SCALAR >
1386 if (extends.empty()) {
1392 }
else if (t->_superType_) {
1407 }
else if (!t->_superType_) {
1413 for (
Idx i = 0; i < t->_superType_->_var_->
domainSize(); ++i) {
1414 if (t->_superType_->_var_->
label(i) == extends) {
1421 t->_label_map_->push_back(i);
1432 template < GUM_Numeric GUM_SCALAR >
1436 if (!t->_isValid_()) {
1444 _prm_->_types_.insert(t);
1448 template < GUM_Numeric GUM_SCALAR >
1451 if (
_prm_->_typeMap_.exists(real_name)) {
1459 template < GUM_Numeric GUM_SCALAR >
1464 if (!var) {
GUM_ERROR(
FatalError,
"the current type's variable is not a LabelizedVariable.") }
1473 template < GUM_Numeric GUM_SCALAR >
1483 _prm_->_types_.insert(t);
1487 template < GUM_Numeric GUM_SCALAR >
1490 if (
_prm_->_typeMap_.exists(real_name)) {
1497 if (t->variable().domainSize() < 2) {
1501 _prm_->_typeMap_.insert(t->name(), t);
1502 _prm_->_types_.insert(t);
1505 template < GUM_Numeric GUM_SCALAR >
1511 template < GUM_Numeric GUM_SCALAR >
1518 template < GUM_Numeric GUM_SCALAR >
1520 std::string_view name,
1534 std::string dot =
".";
1541 if (a !=
nullptr && (!c->
exists(a->
id()))) {
delete a; }
1547 template < GUM_Numeric GUM_SCALAR >
1553 auto& a = c->
get(name);
1561 template < GUM_Numeric GUM_SCALAR >
1567 template < GUM_Numeric GUM_SCALAR >
1569 if (
_prm_->_systemMap_.exists(name)) {
1574 _prm_->_systemMap_.insert(model->
name(), model);
1575 _prm_->_systems_.insert(model);
1578 template < GUM_Numeric GUM_SCALAR >
1588 template < GUM_Numeric GUM_SCALAR >
1593 if (c->parameters().size() > 0) {
1602 template < GUM_Numeric GUM_SCALAR >
1604 std::string_view name,
1608 if (c->parameters().empty()) {
1609 if (params.
empty()) {
1616 auto my_params = params;
1618 for (
const auto& p: c->parameters()) {
1619 if (!my_params.exists(p->name())) { my_params.insert(p->name(), p->value()); }
1623 std::stringstream sBuff;
1624 sBuff << c->name() <<
"<";
1626 for (
const auto& p: my_params) {
1627 sBuff << p.first <<
"=" << p.second <<
",";
1631 std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) +
">";
1641 for (
auto p: my_params) {
1663 template < GUM_Numeric GUM_SCALAR >
1665 std::string_view name) {
1674 if (i) {
delete i; }
1679 template < GUM_Numeric GUM_SCALAR >
1683 full_name.append(
".");
1684 full_name.append(str);
1687 return std::string(str);
1691 template < GUM_Numeric GUM_SCALAR >
1707 template < GUM_Numeric GUM_SCALAR >
1725 template < GUM_Numeric GUM_SCALAR >
1746 template < GUM_Numeric GUM_SCALAR >
1751 while (current->isSubType()) {
1753 current = &(current->superType());
1759 template < GUM_Numeric GUM_SCALAR >
1765 template < GUM_Numeric GUM_SCALAR >
1783 template < GUM_Numeric GUM_SCALAR >
1790 template < GUM_Numeric GUM_SCALAR >
1792 if (
auto pos = l_i.find_last_of(
'.'); pos != std::string_view::npos) {
1793 std::string_view l_ref = l_i.substr(pos + 1);
1800 template < GUM_Numeric GUM_SCALAR >
1805 template < GUM_Numeric GUM_SCALAR >
1810 template < GUM_Numeric GUM_SCALAR >
1816 template < GUM_Numeric GUM_SCALAR >
1835 template < GUM_Numeric GUM_SCALAR >
1839 return (system && system->
isArray(name));
1842 template < GUM_Numeric GUM_SCALAR >
1849 if (a->formulas().domainSize() != array.size()) {
1853 if (a->formulas().nbrDim() == 1) {
1865 auto idx = (std::size_t)0;
1866 while ((!jnst.
end()) && idx < array.size()) {
1868 a->formulas().set(inst, array[idx]);
1878 template < GUM_Numeric GUM_SCALAR >
1885 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.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.
optional_ref< Val > tryGet(const Key &key)
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
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.
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 inc()
Operator increment.
void setFirstIn(const Instantiation &i)
Assign the first values in the Instantiation for the variables in i.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void incIn(const Instantiation &i)
Operator increment for the variables in i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
LabelizedVariable & addLabel(std::string_view aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
virtual void populate(const std::vector< GUM_ELEMENT > &v) const
Automatically fills this MultiDimContainer with the values in v.
GUM_ELEMENT 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.
void insert(const Key &k)
Insert an element at the end of the sequence.
const Key & back() const
Returns the last element of the sequence.
bool exists(const Key &k) const
Check the existence of k in the sequence.
Size size() const noexcept
Returns the size of the sequence.
The generic class for storing (ordered) sequences of objects.
bool empty() const noexcept
Indicates whether the set is the empty set.
void insert(const Key &k)
Inserts a new element into the set.
Exception : wrong type for this operation.
const std::string & name() const
returns the name of the variable
Exception: wrong PRMClassElement for this operation.
PRMType & type() override
See gum::PRMClassElement::type().
void setLabel(Idx idx)
Set the aggregator's label.
bool hasLabel() const
Returns true if the label is defined.
AggregateType agg_type() const
Returns the aggregate of *this.
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().
static AggregateType str2enum(std::string_view str)
Static method which returns the AggregateType given its string representation.
Idx label() const
Returns the label's index on which this aggregate applies.
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>
virtual NodeId overload(PRMClassElement< GUM_SCALAR > *elt)=0
Add a PRMClassElement<GUM_SCALAR> which overload an inherited PRMClassElement<GUM_SCALAR>.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
virtual bool exists(std::string_view name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
virtual NodeId add(PRMClassElement< GUM_SCALAR > *elt)=0
Add a PRMClassElement<GUM_SCALAR> to this PRMClassElementContainer.
virtual void addArc(std::string_view tail, std::string_view head)=0
Add an arc between two PRMClassElement<GUM_SCALAR>.
virtual void setOutputNode(const PRMClassElement< GUM_SCALAR > &elt, bool b)
Set the output flag value of id at b.
virtual PRMClassElement< GUM_SCALAR > & get(std::string_view name)=0
Getter on a member of this PRMClassElementContainer.
Abstract class representing an element of PRM class.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
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...
const Set< PRMInterface< GUM_SCALAR > * > & implements() const
Returns the Set of PRMInterface<GUM_SCALAR> implemented by this Class<GUM_SCALAR>.
NodeId add(PRMClassElement< GUM_SCALAR > *elt) override
See gum::prm::add(PRMClassElement<GUM_SCALAR>*).
PRMClassElement< GUM_SCALAR > & get(NodeId id) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
void addArc(std::string_view tail, std::string_view head) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::addArc().
NodeId overload(PRMClassElement< GUM_SCALAR > *elt) override
See gum::prm::overload(PRMClassElement<GUM_SCALAR>*).
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.
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.
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.
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.
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.
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
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.
<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...
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
Sequence< PRMClassElement< GUM_SCALAR > * > & chain()
Return the sequence representing the chain of elements in this PRMSlotChain.
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.
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.
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it's NodeId in the relational skeleton.
bool isInstance(std::string_view name) const
Returns true if an PRMInstance with the given name exists.
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.
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(std::string_view 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