65 template < GUM_Numeric GUM_SCALAR >
77 template < GUM_Numeric GUM_SCALAR >
82 template < GUM_Numeric GUM_SCALAR >
87 template < GUM_Numeric GUM_SCALAR >
122 template < GUM_Numeric GUM_SCALAR >
127 template < GUM_Numeric GUM_SCALAR >
134 template < GUM_Numeric GUM_SCALAR >
143 template < GUM_Numeric GUM_SCALAR >
154 template < GUM_Numeric GUM_SCALAR >
159 template < GUM_Numeric GUM_SCALAR >
164 template < GUM_Numeric GUM_SCALAR >
169 template < GUM_Numeric GUM_SCALAR >
171 std::ifstream mod_stream(std::string(path), std::ios::in);
173 if (!mod_stream.good()) {
175 "void InferenceEngine< GUM_SCALAR "
176 ">::insertModals(const std::string & path) : "
177 "could not open input file : "
183 std::string line, tmp;
186 while (mod_stream.good()) {
187 getline(mod_stream, line);
189 if (line.size() == 0)
continue;
191 cstr =
new char[line.size() + 1];
192 strcpy(cstr, line.c_str());
194 p = strtok(cstr,
" ");
197 std::vector< GUM_SCALAR > values;
198 p = strtok(
nullptr,
" ");
200 while (p !=
nullptr) {
201 values.push_back(GUM_SCALAR(atof(p)));
202 p = strtok(
nullptr,
" ");
205 modal_.insert(tmp, values);
216 template < GUM_Numeric GUM_SCALAR >
218 const std::map< std::string, std::vector< GUM_SCALAR > >& modals) {
221 for (
auto it = modals.cbegin(), theEnd = modals.cend(); it != theEnd; ++it) {
222 if (!
credalNet_->current_bn().exists(it->first))
continue;
227 auto dSize =
credalNet_->current_bn().variable(
id).domainSize();
229 if (dSize != it->second.size())
continue;
239 modal_.insert(it->first, it->second);
247 template < GUM_Numeric GUM_SCALAR >
249 const std::map< std::string, std::vector< GUM_SCALAR > >& eviMap) {
252 for (
auto it = eviMap.cbegin(), theEnd = eviMap.cend(); it != theEnd; ++it) {
268 template < GUM_Numeric GUM_SCALAR >
270 const NodeProperty< std::vector< GUM_SCALAR > >& evidence) {
274 for (
const auto& elt: evidence) {
275 if (!
credalNet_->current_bn().exists(elt.first))
continue;
285 template < GUM_Numeric GUM_SCALAR >
287 std::ifstream evi_stream(std::string(path), std::ios::in);
289 if (!evi_stream.good()) {
291 "void InferenceEngine< GUM_SCALAR "
292 ">::insertEvidence(const std::string & path) : could not "
299 std::string line, tmp;
302 while (evi_stream.good() && std::strcmp(line.c_str(),
"[EVIDENCE]") != 0) {
303 getline(evi_stream, line);
306 while (evi_stream.good()) {
307 getline(evi_stream, line);
309 if (std::strcmp(line.c_str(),
"[QUERY]") == 0)
break;
311 if (line.size() == 0)
continue;
313 cstr =
new char[line.size() + 1];
314 strcpy(cstr, line.c_str());
316 p = strtok(cstr,
" ");
323 node =
credalNet_->current_bn().idFromName(tmp);
325 std::vector< GUM_SCALAR > values;
326 p = strtok(
nullptr,
" ");
328 while (p !=
nullptr) {
329 values.push_back(GUM_SCALAR(atof(p)));
330 p = strtok(
nullptr,
" ");
346 template < GUM_Numeric GUM_SCALAR >
351 for (
const auto& elt:
query) {
352 if (!
credalNet_->current_bn().exists(elt.first))
continue;
354 query_.insert(elt.first, elt.second);
358 template < GUM_Numeric GUM_SCALAR >
360 std::ifstream evi_stream(std::string(path), std::ios::in);
362 if (!evi_stream.good()) {
364 "void InferenceEngine< GUM_SCALAR >::insertQuery(const "
365 "std::string & path) : could not open input file : "
369 if (!query_.empty()) query_.clear();
371 std::string line, tmp;
374 while (evi_stream.good() && std::strcmp(line.c_str(),
"[QUERY]") != 0) {
375 getline(evi_stream, line);
378 while (evi_stream.good()) {
379 getline(evi_stream, line);
381 if (std::strcmp(line.c_str(),
"[EVIDENCE]") == 0)
break;
383 if (line.size() == 0)
continue;
385 cstr =
new char[line.size() + 1];
386 strcpy(cstr, line.c_str());
388 p = strtok(cstr,
" ");
394 if (!
credalNet_->current_bn().exists(tmp))
continue;
395 node =
credalNet_->current_bn().idFromName(tmp);
397 auto dSize =
credalNet_->current_bn().variable(node).domainSize();
399 p = strtok(
nullptr,
" ");
402 query_.insert(node, std::vector< bool >(dSize,
true));
404 std::vector< bool > values(dSize,
false);
406 while (p !=
nullptr) {
407 if ((
Size)atoi(p) >= dSize)
409 "void InferenceEngine< GUM_SCALAR "
410 ">::insertQuery(const std::string & path) : "
411 "query modality is higher or equal to "
414 values[atoi(p)] =
true;
415 p = strtok(
nullptr,
" ");
418 query_.insert(node, values);
428 template < GUM_Numeric GUM_SCALAR >
434 template < GUM_Numeric GUM_SCALAR >
440 template < GUM_Numeric GUM_SCALAR >
442 Tensor< GUM_SCALAR > res;
443 res.add(
credalNet_->current_bn().variable(
id));
448 template < GUM_Numeric GUM_SCALAR >
450 Tensor< GUM_SCALAR > res;
451 res.add(
credalNet_->current_bn().variable(
id));
456 template < GUM_Numeric GUM_SCALAR >
462 template < GUM_Numeric GUM_SCALAR >
468 template < GUM_Numeric GUM_SCALAR >
473 template < GUM_Numeric GUM_SCALAR >
478 template < GUM_Numeric GUM_SCALAR >
479 const std::vector< GUM_SCALAR >&
481 std::string errTxt =
"const std::vector< GUM_SCALAR > & InferenceEngine< "
482 "GUM_SCALAR >::dynamicExpMin ( const std::string & "
483 "varName ) const : ";
496 const
std::vector< GUM_SCALAR >&
498 std::string errTxt =
"const std::vector< GUM_SCALAR > & InferenceEngine< "
499 "GUM_SCALAR >::dynamicExpMax ( const std::string & "
500 "varName ) const : ";
512 template < GUM_Numeric GUM_SCALAR >
513 const std::vector< std::vector< GUM_SCALAR > >&
518 template < GUM_Numeric GUM_SCALAR >
520 std::ofstream m_stream(std::string(path), std::ios::out | std::ios::trunc);
522 if (!m_stream.good()) {
524 "void InferenceEngine< GUM_SCALAR >::saveMarginals(const "
525 "std::string & path) const : could not open output file "
530 Size esize =
Size(elt.second.size());
532 for (
Size mod = 0; mod < esize; mod++) {
533 m_stream <<
credalNet_->current_bn().variable(elt.first).name() <<
" " << mod <<
" "
534 << (elt.second)[mod] <<
" " <<
marginalMax_[elt.first][mod] << std::endl;
541 template < GUM_Numeric GUM_SCALAR >
550 std::ofstream m_stream(std::string(path), std::ios::out | std::ios::trunc);
552 if (!m_stream.good()) {
554 "void InferenceEngine< GUM_SCALAR "
555 ">::saveExpectations(const std::string & path) : could "
556 "not open output file : "
560 for (
const auto& elt: dynamicExpMin_) {
561 m_stream << elt.first;
564 for (
const auto& elt2: elt.second) {
565 m_stream <<
" " << elt2;
568 m_stream << std::endl;
571 for (
const auto& elt: dynamicExpMax_) {
572 m_stream << elt.first;
575 for (
const auto& elt2: elt.second) {
576 m_stream <<
" " << elt2;
579 m_stream << std::endl;
585 template < GUM_Numeric GUM_SCALAR >
587 std::stringstream output;
592 Size esize =
Size(elt.second.size());
594 for (
Size mod = 0; mod < esize; mod++) {
595 output <<
"P(" <<
credalNet_->current_bn().variable(elt.first).name() <<
"=" << mod
600 if (
auto p_query =
query_.tryGet(elt.first); p_query && (*p_query)[mod])
613 template < GUM_Numeric GUM_SCALAR >
615 std::ofstream m_stream(std::string(path), std::ios::out | std::ios::trunc);
617 if (!m_stream.good()) {
619 "void InferenceEngine< GUM_SCALAR >::saveVertices(const "
620 "std::string & path) : could not open outpul file : "
625 m_stream <<
credalNet_->current_bn().variable(elt.first).name() << std::endl;
627 for (
const auto& elt2: elt.second) {
631 for (
const auto& elt3: elt2) {
632 if (!first) { m_stream <<
","; }
644 template < GUM_Numeric GUM_SCALAR >
651 for (
auto node:
credalNet_->current_bn().nodes()) {
652 auto dSize =
credalNet_->current_bn().variable(node).domainSize();
653 marginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
656 marginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
665 template < GUM_Numeric GUM_SCALAR >
671 for (
auto node:
credalNet_->current_bn().nodes())
672 marginalSets_.insert(node, std::vector< std::vector< GUM_SCALAR > >());
680 template < GUM_Numeric GUM_SCALAR >
685 if (
modal_.empty())
return;
687 for (
auto node:
credalNet_->current_bn().nodes()) {
688 std::string var_name, time_step;
690 var_name =
credalNet_->current_bn().variable(node).name();
691 auto delim = var_name.find_first_of(
"_");
692 var_name = var_name.substr(0, delim);
694 auto p_modal =
modal_.tryGet(var_name);
695 if (!p_modal)
continue;
702 template < GUM_Numeric GUM_SCALAR >
707 template < GUM_Numeric GUM_SCALAR >
721 outerMap expectationsMin, expectationsMax;
724 std::string var_name, time_step;
726 var_name =
credalNet_->current_bn().variable(elt.first).name();
727 auto delim = var_name.find_first_of(
"_");
728 time_step = var_name.substr(delim + 1, var_name.size());
729 var_name = var_name.substr(0, delim);
734 if (!
modal_.exists(var_name))
continue;
736 expectationsMin.getWithDefault(var_name, innerMap())
737 .getWithDefault(atoi(time_step.c_str()), 0)
739 expectationsMax.getWithDefault(var_name, innerMap())
740 .getWithDefault(atoi(time_step.c_str()), 0) =
expectationMax_[elt.first];
743 for (
const auto& elt: expectationsMin) {
744 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
746 for (
const auto& elt2: elt.second)
747 dynExp[elt2.first] = elt2.second;
752 for (
const auto& elt: expectationsMax) {
753 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
755 for (
const auto& elt2: elt.second) {
756 dynExp[elt2.first] = elt2.second;
763 template < GUM_Numeric GUM_SCALAR >
770 for (
auto node:
credalNet_->current_bn().internalDag().nodes()) {
771 std::string var_name =
credalNet_->current_bn().variable(node).name();
772 auto delim = var_name.find_first_of(
"_");
774 if (delim > var_name.size()) {
776 "void InferenceEngine< GUM_SCALAR "
777 ">::repetitiveInit_() : the network does not "
778 "appear to be dynamic");
781 std::string time_step = var_name.substr(delim + 1, 1);
783 if (time_step.compare(
"0") == 0)
t0_.insert(node, std::vector< NodeId >());
787 for (
const auto& node:
credalNet_->current_bn().internalDag().nodes()) {
788 std::string var_name =
credalNet_->current_bn().variable(node).name();
789 auto delim = var_name.find_first_of(
"_");
790 std::string time_step = var_name.substr(delim + 1, var_name.size());
791 var_name = var_name.substr(0, delim);
792 delim = time_step.find_first_of(
"_");
793 time_step = time_step.substr(0, delim);
795 if (time_step.compare(
"1") == 0) {
798 for (
const auto& elt:
t0_) {
799 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
800 delim = var_0_name.find_first_of(
"_");
801 var_0_name = var_0_name.substr(0, delim);
803 if (var_name.compare(var_0_name) == 0) {
804 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
805 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
807 if (tensor->domainSize() == tensor2->domainSize())
t0_[elt.first].push_back(node);
808 else t1_.insert(node, std::vector< NodeId >());
815 if (!found) {
t1_.insert(node, std::vector< NodeId >()); }
821 for (
auto node:
credalNet_->current_bn().internalDag().nodes()) {
822 std::string var_name =
credalNet_->current_bn().variable(node).name();
823 auto delim = var_name.find_first_of(
"_");
824 std::string time_step = var_name.substr(delim + 1, var_name.size());
825 var_name = var_name.substr(0, delim);
826 delim = time_step.find_first_of(
"_");
827 time_step = time_step.substr(0, delim);
829 if (time_step.compare(
"0") != 0 && time_step.compare(
"1") != 0) {
833 std::string var_0_name;
836 for (
const auto& elt:
t0_) {
837 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
838 delim = var_0_name.find_first_of(
"_");
839 var_0_name = var_0_name.substr(0, delim);
841 if (var_name.compare(var_0_name) == 0) {
842 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
843 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
845 if (tensor->domainSize() == tensor2->domainSize()) {
846 t0_[elt.first].push_back(node);
854 for (
const auto& elt:
t1_) {
855 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
856 auto delim = var_0_name.find_first_of(
"_");
857 var_0_name = var_0_name.substr(0, delim);
859 if (var_name.compare(var_0_name) == 0) {
860 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
861 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
863 if (tensor->domainSize() == tensor2->domainSize()) {
864 t1_[elt.first].push_back(node);
874 template < GUM_Numeric GUM_SCALAR >
877 const std::vector< GUM_SCALAR >& vertex) {
878 std::string var_name =
credalNet_->current_bn().variable(
id).name();
879 auto delim = var_name.find_first_of(
"_");
881 var_name = var_name.substr(0, delim);
883 if (
auto p_modal =
modal_.tryGet(var_name)) {
885 auto vsize = vertex.size();
887 for (
Size mod = 0; mod < vsize; mod++)
888 exp += vertex[mod] * (*p_modal)[mod];
896 template < GUM_Numeric GUM_SCALAR >
898 const std::vector< GUM_SCALAR >& vertex,
899 const bool& elimRedund) {
901 auto dsize = vertex.size();
906 for (
auto it = nodeCredalSet.cbegin(), itEnd = nodeCredalSet.cend(); it != itEnd; ++it) {
909 for (
Size i = 0; i < dsize; i++) {
910 if (std::fabs(vertex[i] - (*it)[i]) >
epsilon) {
919 if (!eq || nodeCredalSet.size() == 0) {
920 nodeCredalSet.push_back(vertex);
924 if (nodeCredalSet.size() == 1)
return;
929 auto itEnd = std::remove_if(
930 nodeCredalSet.begin(),
932 [&](
const std::vector< GUM_SCALAR >& v) ->
bool {
933 for (auto jt = v.cbegin(),
935 minIt = marginalMin_[id].cbegin(),
936 minItEnd = marginalMin_[id].cend(),
937 maxIt = marginalMax_[id].cbegin(),
938 maxItEnd = marginalMax_[id].cend();
939 jt != jtEnd && minIt != minItEnd && maxIt != maxItEnd;
940 ++jt, ++minIt, ++maxIt) {
941 if ((std::fabs(*jt - *minIt) < epsilon || std::fabs(*jt - *maxIt) < epsilon)
942 && std::fabs(*minIt - *maxIt) > epsilon)
948 nodeCredalSet.erase(itEnd, nodeCredalSet.end());
951 if (!elimRedund || nodeCredalSet.size() <= 2)
return;
958 lrsWrapper.
setUpV((
unsigned int)dsize, (
unsigned int)(nodeCredalSet.size()));
960 for (
const auto& vtx: nodeCredalSet)
961 lrsWrapper.
fillV(vtx);
965 marginalSets_[id] = lrsWrapper.
getOutput();
968 template < GUM_Numeric GUM_SCALAR >
974 template < GUM_Numeric GUM_SCALAR >
980 template < GUM_Numeric GUM_SCALAR >
986 std::vector< GUM_SCALAR > tEps(nb_threads, std::numeric_limits< GUM_SCALAR >::max());
989 auto threadedEps = [
this, &tEps](
const std::size_t this_thread,
990 const std::size_t nb_threads,
991 const std::vector< std::pair< NodeId, Idx > >& ranges) {
992 auto& this_tEps = tEps[this_thread];
1006 auto i = ranges[this_thread].first;
1007 auto j = ranges[this_thread].second;
1009 const auto end_i = ranges[this_thread + 1].first;
1010 auto end_j = ranges[this_thread + 1].second;
1011 const auto marginalMax_size = this->
marginalMax_.size();
1013 while ((i < end_i) || (j < end_j)) {
1016 delta = (delta < 0) ? (-delta) : delta;
1017 this_tEps = (this_tEps < delta) ? delta : this_tEps;
1021 delta = (delta < 0) ? (-delta) : delta;
1022 this_tEps = (this_tEps < delta) ? delta : this_tEps;
1027 if (++j == domain_size) {
1030 if (i < marginalMax_size) domain_size = this->
marginalMax_[i].size();
1040 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
1044 GUM_SCALAR eps = tEps[0];
1045 for (
const auto nb: tEps)
1046 if (eps < nb) eps = nb;
1060 int nsize = int(marginalMin_.size());
1064 for (int i = 0; i < nsize; i++) {
1065 auto dSize = marginalMin_[i].size();
1067 for (Size j = 0; j < dSize; j++) {
1069 delta = marginalMin_[i][j] - oldMarginalMin_[i][j];
1070 delta = (delta < 0) ? (-delta) : delta;
1071 tEps = (tEps < delta) ? delta : tEps;
1074 delta = marginalMax_[i][j] - oldMarginalMax_[i][j];
1075 delta = (delta < 0) ? (-delta) : delta;
1076 tEps = (tEps < delta) ? delta : tEps;
1078 oldMarginalMin_[i][j] = marginalMin_[i][j];
1079 oldMarginalMax_[i][j] = marginalMax_[i][j];
1081 } // end of : all variables
1083 #pragma omp critical(epsilon_max)
1085 #pragma omp flush(eps)
1086 eps = (eps < tEps) ? tEps : eps;
1095 template < GUM_Numeric GUM_SCALAR >
1098 Size nb_elements = 0;
1099 const auto marginalMin_size = this->marginalMin_.size();
1100 for (
const auto& marg_i: this->marginalMin_)
1101 nb_elements += marg_i.second.size();
1105 if (nb_elements < nb_threads) nb_threads = nb_elements;
1115 Idx nb_elts_par_thread = nb_elements / nb_threads;
1116 Idx rest_elts = nb_elements - nb_elts_par_thread * nb_threads;
1119 Idx current_domain_index = 0;
1120 Size current_domain_size = this->marginalMin_[0].size();
1121 threadRanges_.emplace_back(current_node, current_domain_index);
1123 for (
Idx i =
Idx(0); i < nb_threads; ++i) {
1126 current_domain_index += nb_elts_par_thread;
1127 if (rest_elts !=
Idx(0)) {
1128 ++current_domain_index;
1135 while (current_domain_index >= current_domain_size) {
1136 current_domain_index -= current_domain_size;
1138 current_domain_index = 0;
1139 if (current_node != marginalMin_size) {
1140 current_domain_size = this->marginalMin_[current_node].size();
1145 threadRanges_.emplace_back(current_node, current_domain_index);
1148 if (current_domain_index == current_domain_size) {
1150 current_domain_index = 0;
1155 template < GUM_Numeric GUM_SCALAR >
1157 const std::vector< GUM_SCALAR >& vals) {
1165 template < GUM_Numeric GUM_SCALAR >
1167 std::vector< GUM_SCALAR > vals(this->
credalNet_->current_bn().variable(
id).domainSize(), 0);
1173 template < GUM_Numeric GUM_SCALAR >
1179 template < GUM_Numeric GUM_SCALAR >
1185 template < GUM_Numeric GUM_SCALAR >
1187 std::string_view label) {
1192 template < GUM_Numeric GUM_SCALAR >
1194 const std::vector< GUM_SCALAR >& vals) {
1198 template < GUM_Numeric GUM_SCALAR >
1200 const auto id = this->
credalNet_->current_bn().idFromName(pot.variable(0).name());
1201 std::vector< GUM_SCALAR > vals(this->
credalNet_->current_bn().variable(
id).domainSize(), 0);
1204 vals[I.
val(0)] = pot[I];
1209 template < GUM_Numeric GUM_SCALAR >
ApproximationScheme()
Build a scheme whose parameters are read from the configuration.
double epsilon() const override
Returns the value of epsilon.
double epsilonStandard() const noexcept
The class for generic Hash Tables.
void clear()
Removes all the elements in the hash table.
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.
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.
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.
Typed, documented, sectioned configuration singleton read from an .ini content.
#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
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...
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