64 template < GUM_Numeric GUM_SCALAR >
76 template < GUM_Numeric GUM_SCALAR >
81 template < GUM_Numeric GUM_SCALAR >
86 template < GUM_Numeric GUM_SCALAR >
121 template < GUM_Numeric GUM_SCALAR >
126 template < GUM_Numeric GUM_SCALAR >
133 template < GUM_Numeric GUM_SCALAR >
142 template < GUM_Numeric GUM_SCALAR >
153 template < GUM_Numeric GUM_SCALAR >
158 template < GUM_Numeric GUM_SCALAR >
163 template < GUM_Numeric GUM_SCALAR >
168 template < GUM_Numeric GUM_SCALAR >
170 std::ifstream mod_stream(std::string(path), std::ios::in);
172 if (!mod_stream.good()) {
174 "void InferenceEngine< GUM_SCALAR "
175 ">::insertModals(const std::string & path) : "
176 "could not open input file : "
182 std::string line, tmp;
185 while (mod_stream.good()) {
186 getline(mod_stream, line);
188 if (line.size() == 0)
continue;
190 cstr =
new char[line.size() + 1];
191 strcpy(cstr, line.c_str());
193 p = strtok(cstr,
" ");
196 std::vector< GUM_SCALAR > values;
197 p = strtok(
nullptr,
" ");
199 while (p !=
nullptr) {
200 values.push_back(GUM_SCALAR(atof(p)));
201 p = strtok(
nullptr,
" ");
215 template < GUM_Numeric GUM_SCALAR >
217 const std::map< std::string, std::vector< GUM_SCALAR > >& modals) {
220 for (
auto it = modals.cbegin(), theEnd = modals.cend(); it != theEnd; ++it) {
221 if (!
credalNet_->current_bn().exists(it->first))
continue;
226 auto dSize =
credalNet_->current_bn().variable(
id).domainSize();
228 if (dSize != it->second.size())
continue;
238 modal_.insert(it->first, it->second);
246 template < GUM_Numeric GUM_SCALAR >
248 const std::map< std::string, std::vector< GUM_SCALAR > >& eviMap) {
251 for (
auto it = eviMap.cbegin(), theEnd = eviMap.cend(); it != theEnd; ++it) {
252 if (!
credalNet_->current_bn().exists(it->first))
continue;
267 template < GUM_Numeric GUM_SCALAR >
269 const NodeProperty< std::vector< GUM_SCALAR > >& evidence) {
273 for (
const auto& elt: evidence) {
274 if (!
credalNet_->current_bn().exists(elt.first))
continue;
284 template < GUM_Numeric GUM_SCALAR >
286 std::ifstream evi_stream(std::string(path), std::ios::in);
288 if (!evi_stream.good()) {
290 "void InferenceEngine< GUM_SCALAR "
291 ">::insertEvidence(const std::string & path) : could not "
298 std::string line, tmp;
301 while (evi_stream.good() && std::strcmp(line.c_str(),
"[EVIDENCE]") != 0) {
302 getline(evi_stream, line);
305 while (evi_stream.good()) {
306 getline(evi_stream, line);
308 if (std::strcmp(line.c_str(),
"[QUERY]") == 0)
break;
310 if (line.size() == 0)
continue;
312 cstr =
new char[line.size() + 1];
313 strcpy(cstr, line.c_str());
315 p = strtok(cstr,
" ");
321 if (!
credalNet_->current_bn().exists(tmp))
continue;
324 std::vector< GUM_SCALAR > values;
325 p = strtok(
nullptr,
" ");
327 while (p !=
nullptr) {
328 values.push_back(GUM_SCALAR(atof(p)));
329 p = strtok(
nullptr,
" ");
332 evidence_.insert(node, values);
345 template < GUM_Numeric GUM_SCALAR >
350 for (
const auto& elt:
query) {
351 if (!
credalNet_->current_bn().exists(elt.first))
continue;
353 query_.insert(elt.first, elt.second);
357 template < GUM_Numeric GUM_SCALAR >
359 std::ifstream evi_stream(std::string(path), std::ios::in);
361 if (!evi_stream.good()) {
363 "void InferenceEngine< GUM_SCALAR >::insertQuery(const "
364 "std::string & path) : could not open input file : "
368 if (!query_.empty()) query_.clear();
370 std::string line, tmp;
373 while (evi_stream.good() && std::strcmp(line.c_str(),
"[QUERY]") != 0) {
374 getline(evi_stream, line);
377 while (evi_stream.good()) {
378 getline(evi_stream, line);
380 if (std::strcmp(line.c_str(),
"[EVIDENCE]") == 0)
break;
382 if (line.size() == 0)
continue;
384 cstr =
new char[line.size() + 1];
385 strcpy(cstr, line.c_str());
387 p = strtok(cstr,
" ");
393 if (!
credalNet_->current_bn().exists(tmp))
continue;
394 node =
credalNet_->current_bn().idFromName(tmp);
396 auto dSize =
credalNet_->current_bn().variable(node).domainSize();
398 p = strtok(
nullptr,
" ");
401 query_.insert(node, std::vector< bool >(dSize,
true));
403 std::vector< bool > values(dSize,
false);
405 while (p !=
nullptr) {
406 if ((
Size)atoi(p) >= dSize)
408 "void InferenceEngine< GUM_SCALAR "
409 ">::insertQuery(const std::string & path) : "
410 "query modality is higher or equal to "
413 values[atoi(p)] =
true;
414 p = strtok(
nullptr,
" ");
417 query_.insert(node, values);
427 template < GUM_Numeric GUM_SCALAR >
433 template < GUM_Numeric GUM_SCALAR >
439 template < GUM_Numeric GUM_SCALAR >
441 Tensor< GUM_SCALAR > res;
442 res.add(
credalNet_->current_bn().variable(
id));
447 template < GUM_Numeric GUM_SCALAR >
449 Tensor< GUM_SCALAR > res;
455 template < GUM_Numeric GUM_SCALAR >
461 template < GUM_Numeric GUM_SCALAR >
467 template < GUM_Numeric GUM_SCALAR >
472 template < GUM_Numeric GUM_SCALAR >
477 template < GUM_Numeric GUM_SCALAR >
478 const std::vector< GUM_SCALAR >&
480 std::string errTxt =
"const std::vector< GUM_SCALAR > & InferenceEngine< "
481 "GUM_SCALAR >::dynamicExpMin ( const std::string & "
482 "varName ) const : ";
495 const
std::vector< GUM_SCALAR >&
497 std::string errTxt =
"const std::vector< GUM_SCALAR > & InferenceEngine< "
498 "GUM_SCALAR >::dynamicExpMax ( const std::string & "
499 "varName ) const : ";
511 template < GUM_Numeric GUM_SCALAR >
512 const std::vector< std::vector< GUM_SCALAR > >&
517 template < GUM_Numeric GUM_SCALAR >
519 std::ofstream m_stream(std::string(path), std::ios::out | std::ios::trunc);
521 if (!m_stream.good()) {
523 "void InferenceEngine< GUM_SCALAR >::saveMarginals(const "
524 "std::string & path) const : could not open output file "
528 for (
const auto& elt: marginalMin_) {
531 for (
Size mod = 0; mod < esize; mod++) {
532 m_stream <<
credalNet_->current_bn().variable(elt.first).name() <<
" " << mod <<
" "
533 << (elt.second)[mod] <<
" " <<
marginalMax_[elt.first][mod] << std::endl;
540 template < GUM_Numeric GUM_SCALAR >
549 std::ofstream m_stream(std::string(path), std::ios::out | std::ios::trunc);
551 if (!m_stream.good()) {
553 "void InferenceEngine< GUM_SCALAR "
554 ">::saveExpectations(const std::string & path) : could "
555 "not open output file : "
559 for (
const auto& elt: dynamicExpMin_) {
560 m_stream << elt.first;
563 for (
const auto& elt2: elt.second) {
564 m_stream <<
" " << elt2;
567 m_stream << std::endl;
570 for (
const auto& elt: dynamicExpMax_) {
571 m_stream << elt.first;
574 for (
const auto& elt2: elt.second) {
575 m_stream <<
" " << elt2;
578 m_stream << std::endl;
584 template < GUM_Numeric GUM_SCALAR >
586 std::stringstream output;
591 Size esize =
Size(elt.second.size());
593 for (
Size mod = 0; mod < esize; mod++) {
594 output <<
"P(" <<
credalNet_->current_bn().variable(elt.first).name() <<
"=" << mod
599 if (
auto p_query =
query_.tryGet(elt.first); p_query && (*p_query)[mod])
612 template < GUM_Numeric GUM_SCALAR >
614 std::ofstream m_stream(std::string(path), std::ios::out | std::ios::trunc);
616 if (!m_stream.good()) {
618 "void InferenceEngine< GUM_SCALAR >::saveVertices(const "
619 "std::string & path) : could not open outpul file : "
624 m_stream <<
credalNet_->current_bn().variable(elt.first).name() << std::endl;
626 for (
const auto& elt2: elt.second) {
630 for (
const auto& elt3: elt2) {
631 if (!first) { m_stream <<
","; }
643 template < GUM_Numeric GUM_SCALAR >
650 for (
auto node:
credalNet_->current_bn().nodes()) {
651 auto dSize =
credalNet_->current_bn().variable(node).domainSize();
652 marginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
655 marginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
664 template < GUM_Numeric GUM_SCALAR >
670 for (
auto node:
credalNet_->current_bn().nodes())
671 marginalSets_.insert(node, std::vector< std::vector< GUM_SCALAR > >());
679 template < GUM_Numeric GUM_SCALAR >
684 if (
modal_.empty())
return;
686 for (
auto node:
credalNet_->current_bn().nodes()) {
687 std::string var_name, time_step;
689 var_name =
credalNet_->current_bn().variable(node).name();
690 auto delim = var_name.find_first_of(
"_");
691 var_name = var_name.substr(0, delim);
693 auto p_modal =
modal_.tryGet(var_name);
694 if (!p_modal)
continue;
701 template < GUM_Numeric GUM_SCALAR >
706 template < GUM_Numeric GUM_SCALAR >
720 outerMap expectationsMin, expectationsMax;
723 std::string var_name, time_step;
725 var_name =
credalNet_->current_bn().variable(elt.first).name();
726 auto delim = var_name.find_first_of(
"_");
727 time_step = var_name.substr(delim + 1, var_name.size());
728 var_name = var_name.substr(0, delim);
733 if (!
modal_.exists(var_name))
continue;
735 expectationsMin.getWithDefault(var_name, innerMap())
736 .getWithDefault(atoi(time_step.c_str()), 0)
738 expectationsMax.getWithDefault(var_name, innerMap())
739 .getWithDefault(atoi(time_step.c_str()), 0) =
expectationMax_[elt.first];
742 for (
const auto& elt: expectationsMin) {
743 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
745 for (
const auto& elt2: elt.second)
746 dynExp[elt2.first] = elt2.second;
751 for (
const auto& elt: expectationsMax) {
752 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
754 for (
const auto& elt2: elt.second) {
755 dynExp[elt2.first] = elt2.second;
762 template < GUM_Numeric GUM_SCALAR >
769 for (
auto node:
credalNet_->current_bn().internalDag().nodes()) {
770 std::string var_name =
credalNet_->current_bn().variable(node).name();
771 auto delim = var_name.find_first_of(
"_");
773 if (delim > var_name.size()) {
775 "void InferenceEngine< GUM_SCALAR "
776 ">::repetitiveInit_() : the network does not "
777 "appear to be dynamic");
780 std::string time_step = var_name.substr(delim + 1, 1);
782 if (time_step.compare(
"0") == 0)
t0_.insert(node, std::vector< NodeId >());
786 for (
const auto& node:
credalNet_->current_bn().internalDag().nodes()) {
787 std::string var_name =
credalNet_->current_bn().variable(node).name();
788 auto delim = var_name.find_first_of(
"_");
789 std::string time_step = var_name.substr(delim + 1, var_name.size());
790 var_name = var_name.substr(0, delim);
791 delim = time_step.find_first_of(
"_");
792 time_step = time_step.substr(0, delim);
794 if (time_step.compare(
"1") == 0) {
797 for (
const auto& elt:
t0_) {
798 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
799 delim = var_0_name.find_first_of(
"_");
800 var_0_name = var_0_name.substr(0, delim);
802 if (var_name.compare(var_0_name) == 0) {
803 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
804 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
806 if (tensor->domainSize() == tensor2->domainSize())
t0_[elt.first].push_back(node);
807 else t1_.insert(node, std::vector< NodeId >());
814 if (!found) {
t1_.insert(node, std::vector< NodeId >()); }
820 for (
auto node:
credalNet_->current_bn().internalDag().nodes()) {
821 std::string var_name =
credalNet_->current_bn().variable(node).name();
822 auto delim = var_name.find_first_of(
"_");
823 std::string time_step = var_name.substr(delim + 1, var_name.size());
824 var_name = var_name.substr(0, delim);
825 delim = time_step.find_first_of(
"_");
826 time_step = time_step.substr(0, delim);
828 if (time_step.compare(
"0") != 0 && time_step.compare(
"1") != 0) {
832 std::string var_0_name;
835 for (
const auto& elt:
t0_) {
836 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
837 delim = var_0_name.find_first_of(
"_");
838 var_0_name = var_0_name.substr(0, delim);
840 if (var_name.compare(var_0_name) == 0) {
841 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
842 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
844 if (tensor->domainSize() == tensor2->domainSize()) {
845 t0_[elt.first].push_back(node);
853 for (
const auto& elt:
t1_) {
854 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
855 auto delim = var_0_name.find_first_of(
"_");
856 var_0_name = var_0_name.substr(0, delim);
858 if (var_name.compare(var_0_name) == 0) {
859 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
860 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
862 if (tensor->domainSize() == tensor2->domainSize()) {
863 t1_[elt.first].push_back(node);
873 template < GUM_Numeric GUM_SCALAR >
876 const std::vector< GUM_SCALAR >& vertex) {
877 std::string var_name =
credalNet_->current_bn().variable(
id).name();
878 auto delim = var_name.find_first_of(
"_");
880 var_name = var_name.substr(0, delim);
882 if (
auto p_modal =
modal_.tryGet(var_name)) {
884 auto vsize = vertex.size();
886 for (
Size mod = 0; mod < vsize; mod++)
887 exp += vertex[mod] * (*p_modal)[mod];
895 template < GUM_Numeric GUM_SCALAR >
897 const std::vector< GUM_SCALAR >& vertex,
898 const bool& elimRedund) {
900 auto dsize = vertex.size();
904 for (
auto it = nodeCredalSet.cbegin(), itEnd = nodeCredalSet.cend(); it != itEnd; ++it) {
907 for (
Size i = 0; i < dsize; i++) {
908 if (std::fabs(vertex[i] - (*it)[i]) > 1e-6) {
917 if (!eq || nodeCredalSet.size() == 0) {
918 nodeCredalSet.push_back(vertex);
922 if (nodeCredalSet.size() == 1)
return;
927 auto itEnd = std::remove_if(
928 nodeCredalSet.begin(),
930 [&](
const std::vector< GUM_SCALAR >& v) ->
bool {
931 for (auto jt = v.cbegin(),
933 minIt = marginalMin_[id].cbegin(),
934 minItEnd = marginalMin_[id].cend(),
935 maxIt = marginalMax_[id].cbegin(),
936 maxItEnd = marginalMax_[id].cend();
937 jt != jtEnd && minIt != minItEnd && maxIt != maxItEnd;
938 ++jt, ++minIt, ++maxIt) {
939 if ((std::fabs(*jt - *minIt) < 1e-6 || std::fabs(*jt - *maxIt) < 1e-6)
940 && std::fabs(*minIt - *maxIt) > 1e-6)
946 nodeCredalSet.erase(itEnd, nodeCredalSet.end());
949 if (!elimRedund || nodeCredalSet.size() <= 2)
return;
956 lrsWrapper.
setUpV((
unsigned int)dsize, (
unsigned int)(nodeCredalSet.size()));
958 for (
const auto& vtx: nodeCredalSet)
959 lrsWrapper.
fillV(vtx);
963 marginalSets_[id] = lrsWrapper.
getOutput();
966 template < GUM_Numeric GUM_SCALAR >
972 template < GUM_Numeric GUM_SCALAR >
978 template < GUM_Numeric GUM_SCALAR >
984 std::vector< GUM_SCALAR > tEps(nb_threads, std::numeric_limits< GUM_SCALAR >::max());
987 auto threadedEps = [
this, &tEps](
const std::size_t this_thread,
988 const std::size_t nb_threads,
989 const std::vector< std::pair< NodeId, Idx > >& ranges) {
990 auto& this_tEps = tEps[this_thread];
1004 auto i = ranges[this_thread].first;
1005 auto j = ranges[this_thread].second;
1007 const auto end_i = ranges[this_thread + 1].first;
1008 auto end_j = ranges[this_thread + 1].second;
1009 const auto marginalMax_size = this->
marginalMax_.size();
1011 while ((i < end_i) || (j < end_j)) {
1014 delta = (delta < 0) ? (-delta) : delta;
1015 this_tEps = (this_tEps < delta) ? delta : this_tEps;
1019 delta = (delta < 0) ? (-delta) : delta;
1020 this_tEps = (this_tEps < delta) ? delta : this_tEps;
1025 if (++j == domain_size) {
1028 if (i < marginalMax_size) domain_size = this->
marginalMax_[i].size();
1038 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
1042 GUM_SCALAR eps = tEps[0];
1043 for (
const auto nb: tEps)
1044 if (eps < nb) eps = nb;
1058 int nsize = int(marginalMin_.size());
1062 for (int i = 0; i < nsize; i++) {
1063 auto dSize = marginalMin_[i].size();
1065 for (Size j = 0; j < dSize; j++) {
1067 delta = marginalMin_[i][j] - oldMarginalMin_[i][j];
1068 delta = (delta < 0) ? (-delta) : delta;
1069 tEps = (tEps < delta) ? delta : tEps;
1072 delta = marginalMax_[i][j] - oldMarginalMax_[i][j];
1073 delta = (delta < 0) ? (-delta) : delta;
1074 tEps = (tEps < delta) ? delta : tEps;
1076 oldMarginalMin_[i][j] = marginalMin_[i][j];
1077 oldMarginalMax_[i][j] = marginalMax_[i][j];
1079 } // end of : all variables
1081 #pragma omp critical(epsilon_max)
1083 #pragma omp flush(eps)
1084 eps = (eps < tEps) ? tEps : eps;
1093 template < GUM_Numeric GUM_SCALAR >
1096 Size nb_elements = 0;
1097 const auto marginalMin_size = this->marginalMin_.size();
1098 for (
const auto& marg_i: this->marginalMin_)
1099 nb_elements += marg_i.second.size();
1103 if (nb_elements < nb_threads) nb_threads = nb_elements;
1113 Idx nb_elts_par_thread = nb_elements / nb_threads;
1114 Idx rest_elts = nb_elements - nb_elts_par_thread * nb_threads;
1117 Idx current_domain_index = 0;
1118 Size current_domain_size = this->marginalMin_[0].size();
1119 threadRanges_.emplace_back(current_node, current_domain_index);
1121 for (
Idx i =
Idx(0); i < nb_threads; ++i) {
1124 current_domain_index += nb_elts_par_thread;
1125 if (rest_elts !=
Idx(0)) {
1126 ++current_domain_index;
1133 while (current_domain_index >= current_domain_size) {
1134 current_domain_index -= current_domain_size;
1136 current_domain_index = 0;
1137 if (current_node != marginalMin_size) {
1138 current_domain_size = this->marginalMin_[current_node].size();
1143 threadRanges_.emplace_back(current_node, current_domain_index);
1146 if (current_domain_index == current_domain_size) {
1148 current_domain_index = 0;
1153 template < GUM_Numeric GUM_SCALAR >
1155 const std::vector< GUM_SCALAR >& vals) {
1163 template < GUM_Numeric GUM_SCALAR >
1165 std::vector< GUM_SCALAR > vals(this->
credalNet_->current_bn().variable(
id).domainSize(), 0);
1171 template < GUM_Numeric GUM_SCALAR >
1177 template < GUM_Numeric GUM_SCALAR >
1183 template < GUM_Numeric GUM_SCALAR >
1185 std::string_view label) {
1190 template < GUM_Numeric GUM_SCALAR >
1192 const std::vector< GUM_SCALAR >& vals) {
1196 template < GUM_Numeric GUM_SCALAR >
1198 const auto id = this->
credalNet_->current_bn().idFromName(pot.variable(0).name());
1199 std::vector< GUM_SCALAR > vals(this->
credalNet_->current_bn().variable(
id).domainSize(), 0);
1202 vals[I.
val(0)] = pot[I];
1207 template < GUM_Numeric GUM_SCALAR >
ApproximationScheme(bool verbosity=false)
The class for generic Hash Tables.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
Exception : input/output problem.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
void inc()
Operator increment.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
Exception: at least one argument passed to a function is not what was expected.
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
Exception : out of bound.
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Size getNumberOfThreads() const override
returns the current max number of threads used by the class containing this ThreadNumberManager
Class template representing a Credal Network.
void updateExpectations_(const NodeId &id, const std::vector< GUM_SCALAR > &vertex)
Given a node id and one of it's possible vertex obtained during inference, update this node lower and...
void repetitiveInit_()
Initialize t0_ and t1_ clusters.
void dynamicExpectations()
Compute dynamic expectations.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
const std::string getApproximationSchemeMsg()
Get approximation scheme state.
margi evidence_
Holds observed variables states.
const std::vector< GUM_SCALAR > & dynamicExpMin(std::string_view varName) const
Get the lower dynamic expectation of a given variable prefix (without the time step included,...
void dispatchMarginalsToThreads_()
computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads
cluster t1_
Clusters of nodes used with dynamic networks.
dynExpe dynamicExpMin_
Lower dynamic expectations.
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.
~InferenceEngine() override
Destructor.
void saveExpectations(std::string_view path) const
Saves expectations to file.
void insertModalsFile(std::string_view path)
Insert variables modalities from file to compute expectations.
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
void saveVertices(std::string_view path) const
Saves vertices to file.
void insertQueryFile(std::string_view path)
Insert query variables states from file.
void updateCredalSets_(const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
Given a node id and one of it's possible vertex, update it's credal set.
bool repetitiveInd_
True if using repetitive independence ( dynamic network only ), False otherwise.
const NodeProperty< std::vector< NodeId > > & getT1Cluster() const
Get the t1_ cluster.
virtual const GUM_SCALAR computeEpsilon_()
Compute approximation scheme epsilon using the old marginals and the new ones.
const std::vector< std::vector< GUM_SCALAR > > & vertices(const NodeId id) const
Get the vertice of a given node id.
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
void initMarginalSets_()
Initialize credal set vertices with empty sets.
margi oldMarginalMin_
Old lower marginals used to compute epsilon.
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
dynExpe dynamicExpMax_
Upper dynamic expectations.
const std::vector< GUM_SCALAR > & dynamicExpMax(std::string_view varName) const
Get the upper dynamic expectation of a given variable prefix (without the time step included,...
std::string toString() const
Print all nodes marginals to standart output.
void insertQuery(const NodeProperty< std::vector< bool > > &query)
Insert query variables and states from Property.
bool repetitiveInd() const
Get the current independence status.
NodeProperty< std::vector< bool > > query
void dynamicExpectations_()
Rearrange lower and upper expectations to suit dynamic networks.
bool storeVertices() const
Get the number of iterations without changes used to stop some algorithms.
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
void setRepetitiveInd(const bool repetitive)
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void eraseAllEvidence()
removes all the evidence entered into the network
expe expectationMax_
Upper expectations, if some variables modalities were inserted.
void insertEvidence(const std::map< std::string, std::vector< GUM_SCALAR > > &eviMap)
Insert evidence from map.
void insertModals(const std::map< std::string, std::vector< GUM_SCALAR > > &modals)
Insert variables modalities from map to compute expectations.
query query_
Holds the query nodes states.
virtual void insertEvidenceFile(std::string_view path)
Insert evidence from file.
credalSet marginalSets_
Credal sets vertices, if enabled.
Tensor< GUM_SCALAR > marginalMin(const NodeId id) const
Get the lower marginals of a given node id.
void saveMarginals(std::string_view path) const
Saves marginals to file.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this credal network.
VarMod2BNsMap< GUM_SCALAR > * getVarMod2BNsMap()
Get optimum IBayesNet.
margi marginalMin_
Lower marginals.
cluster t0_
Clusters of nodes used with dynamic networks.
const GUM_SCALAR & expectationMin(const NodeId id) const
Get the lower expectation of a given node id.
dynExpe modal_
Variables modalities used to compute expectations.
expe expectationMin_
Lower expectations, if some variables modalities were inserted.
Tensor< GUM_SCALAR > marginalMax(const NodeId id) const
Get the upper marginals of a given node id.
const GUM_SCALAR & expectationMax(const NodeId id) const
Get the upper expectation of a given node id.
int timeSteps_
The number of time steps of this network (only useful for dynamic networks).
std::vector< std::pair< NodeId, Idx > > threadRanges_
the ranges of elements of marginalMin_ and marginalMax_ processed by each thread
const NodeProperty< std::vector< NodeId > > & getT0Cluster() const
Get the t0_ cluster.
void initMarginals_()
Initialize lower and upper old marginals and marginals before inference, with the lower marginal bein...
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.
Class template acting as a wrapper for Lexicographic Reverse Search by David Avis.
const matrix & getOutput() const
Get the output matrix solution of the problem.
void setUpV(const Size &card, const Size &vertices)
Sets up a V-representation.
void elimRedundVrep()
V-Redundancy elimination.
void fillV(const std::vector< GUM_SCALAR > &vertex)
Creates the V-representation of a polytope by adding a vertex to the problem input _input_.
Complete concept for GUM_SCALAR template parameter.
#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.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Abstract class representing CredalNet inference engines.
namespace for all credal networks entities
gum is the global namespace for all aGrUM entities
static void execute(std::size_t nb_threads, FUNCTION exec_func, ARGS &&... func_args)
executes a function using several threads
static int nbRunningThreadsExecutors()
indicates how many threadExecutors are currently running