63 template <
typename GUM_SCALAR >
75 template <
typename GUM_SCALAR >
80 template <
typename GUM_SCALAR >
85 template <
typename GUM_SCALAR >
120 template <
typename GUM_SCALAR >
125 template <
typename GUM_SCALAR >
132 template <
typename GUM_SCALAR >
141 template <
typename GUM_SCALAR >
152 template <
typename GUM_SCALAR >
157 template <
typename GUM_SCALAR >
162 template <
typename GUM_SCALAR >
167 template <
typename GUM_SCALAR >
169 std::ifstream mod_stream(path.c_str(), std::ios::in);
171 if (!mod_stream.good()) {
173 "void InferenceEngine< GUM_SCALAR "
174 ">::insertModals(const std::string & path) : "
175 "could not open input file : "
181 std::string line, tmp;
184 while (mod_stream.good()) {
185 getline(mod_stream, line);
187 if (line.size() == 0)
continue;
189 cstr =
new char[line.size() + 1];
190 strcpy(cstr, line.c_str());
192 p = strtok(cstr,
" ");
195 std::vector< GUM_SCALAR > values;
196 p = strtok(
nullptr,
" ");
198 while (p !=
nullptr) {
199 values.push_back(GUM_SCALAR(atof(p)));
200 p = strtok(
nullptr,
" ");
203 modal_.insert(tmp, values);
214 template <
typename GUM_SCALAR >
216 const std::map< std::string, std::vector< GUM_SCALAR > >& modals) {
219 for (
auto it = modals.cbegin(), theEnd = modals.cend(); it != theEnd; ++it) {
223 id =
credalNet_->current_bn().idFromName(it->first);
230 auto dSize =
credalNet_->current_bn().variable(
id).domainSize();
232 if (dSize != it->second.size())
continue;
242 modal_.insert(it->first, it->second);
250 template <
typename GUM_SCALAR >
252 const std::map< std::string, std::vector< GUM_SCALAR > >& eviMap) {
255 for (
auto it = eviMap.cbegin(), theEnd = eviMap.cend(); it != theEnd; ++it) {
259 id =
credalNet_->current_bn().idFromName(it->first);
265 evidence_.insert(
id, it->second);
276 template <
typename GUM_SCALAR >
278 const NodeProperty< std::vector< GUM_SCALAR > >& evidence) {
282 for (
const auto& elt: evidence) {
298 template <
typename GUM_SCALAR >
300 std::ifstream evi_stream(path.c_str(), std::ios::in);
302 if (!evi_stream.good()) {
304 "void InferenceEngine< GUM_SCALAR "
305 ">::insertEvidence(const std::string & path) : could not "
310 if (!evidence_.empty()) evidence_.clear();
312 std::string line, tmp;
315 while (evi_stream.good() && std::strcmp(line.c_str(),
"[EVIDENCE]") != 0) {
316 getline(evi_stream, line);
319 while (evi_stream.good()) {
320 getline(evi_stream, line);
322 if (std::strcmp(line.c_str(),
"[QUERY]") == 0)
break;
324 if (line.size() == 0)
continue;
326 cstr =
new char[line.size() + 1];
327 strcpy(cstr, line.c_str());
329 p = strtok(cstr,
" ");
336 node =
credalNet_->current_bn().idFromName(tmp);
342 std::vector< GUM_SCALAR > values;
343 p = strtok(
nullptr,
" ");
345 while (p !=
nullptr) {
346 values.push_back(GUM_SCALAR(atof(p)));
347 p = strtok(
nullptr,
" ");
350 evidence_.insert(node, values);
363 template <
typename GUM_SCALAR >
368 for (
const auto& elt:
query) {
376 query_.insert(elt.first, elt.second);
380 template <
typename GUM_SCALAR >
382 std::ifstream evi_stream(path.c_str(), std::ios::in);
384 if (!evi_stream.good()) {
386 "void InferenceEngine< GUM_SCALAR >::insertQuery(const "
387 "std::string & path) : could not open input file : "
391 if (!query_.empty()) query_.clear();
393 std::string line, tmp;
396 while (evi_stream.good() && std::strcmp(line.c_str(),
"[QUERY]") != 0) {
397 getline(evi_stream, line);
400 while (evi_stream.good()) {
401 getline(evi_stream, line);
403 if (std::strcmp(line.c_str(),
"[EVIDENCE]") == 0)
break;
405 if (line.size() == 0)
continue;
407 cstr =
new char[line.size() + 1];
408 strcpy(cstr, line.c_str());
410 p = strtok(cstr,
" ");
417 node =
credalNet_->current_bn().idFromName(tmp);
423 auto dSize = credalNet_->current_bn().variable(node).domainSize();
425 p = strtok(
nullptr,
" ");
428 query_.insert(node, std::vector< bool >(dSize,
true));
430 std::vector< bool > values(dSize,
false);
432 while (p !=
nullptr) {
433 if ((
Size)atoi(p) >= dSize)
435 "void InferenceEngine< GUM_SCALAR "
436 ">::insertQuery(const std::string & path) : "
437 "query modality is higher or equal to "
440 values[atoi(p)] =
true;
441 p = strtok(
nullptr,
" ");
444 query_.insert(node, values);
454 template <
typename GUM_SCALAR >
455 INLINE Tensor< GUM_SCALAR >
460 template <
typename GUM_SCALAR >
461 INLINE Tensor< GUM_SCALAR >
466 template <
typename GUM_SCALAR >
469 Tensor< GUM_SCALAR > res;
470 res.add(
credalNet_->current_bn().variable(
id));
473 }
catch (
NotFound& err) {
throw(err); }
476 template <
typename GUM_SCALAR >
479 Tensor< GUM_SCALAR > res;
480 res.add(
credalNet_->current_bn().variable(
id));
483 }
catch (
NotFound& err) {
throw(err); }
486 template <
typename GUM_SCALAR >
491 }
catch (
NotFound& err) {
throw(err); }
494 template <
typename GUM_SCALAR >
502 template <
typename GUM_SCALAR >
509 template <
typename GUM_SCALAR >
516 template <
typename GUM_SCALAR >
517 const std::vector< GUM_SCALAR >&
519 std::string errTxt =
"const std::vector< GUM_SCALAR > & InferenceEngine< "
520 "GUM_SCALAR >::dynamicExpMin ( const std::string & "
521 "varName ) const : ";
532 template < typename GUM_SCALAR >
533 const
std::vector< GUM_SCALAR >&
535 std::string errTxt =
"const std::vector< GUM_SCALAR > & InferenceEngine< "
536 "GUM_SCALAR >::dynamicExpMax ( const std::string & "
537 "varName ) const : ";
548 template <
typename GUM_SCALAR >
549 const std::vector< std::vector< GUM_SCALAR > >&
554 template <
typename GUM_SCALAR >
556 std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
558 if (!m_stream.good()) {
560 "void InferenceEngine< GUM_SCALAR >::saveMarginals(const "
561 "std::string & path) const : could not open output file "
565 for (
const auto& elt: marginalMin_) {
568 for (
Size mod = 0; mod < esize; mod++) {
569 m_stream <<
credalNet_->current_bn().variable(elt.first).name() <<
" " << mod <<
" "
570 << (elt.second)[mod] <<
" " <<
marginalMax_[elt.first][mod] << std::endl;
577 template <
typename GUM_SCALAR >
586 std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
588 if (!m_stream.good()) {
590 "void InferenceEngine< GUM_SCALAR "
591 ">::saveExpectations(const std::string & path) : could "
592 "not open output file : "
596 for (
const auto& elt: dynamicExpMin_) {
597 m_stream << elt.first;
600 for (
const auto& elt2: elt.second) {
601 m_stream <<
" " << elt2;
604 m_stream << std::endl;
607 for (
const auto& elt: dynamicExpMax_) {
608 m_stream << elt.first;
611 for (
const auto& elt2: elt.second) {
612 m_stream <<
" " << elt2;
615 m_stream << std::endl;
621 template <
typename GUM_SCALAR >
623 std::stringstream output;
628 Size esize =
Size(elt.second.size());
630 for (
Size mod = 0; mod < esize; mod++) {
631 output <<
"P(" <<
credalNet_->current_bn().variable(elt.first).name() <<
"=" << mod
636 if (
query_.exists(elt.first) &&
query_[elt.first][mod]) output <<
" QUERY";
647 template <
typename GUM_SCALAR >
649 std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
651 if (!m_stream.good()) {
653 "void InferenceEngine< GUM_SCALAR >::saveVertices(const "
654 "std::string & path) : could not open outpul file : "
659 m_stream <<
credalNet_->current_bn().variable(elt.first).name() << std::endl;
661 for (
const auto& elt2: elt.second) {
665 for (
const auto& elt3: elt2) {
681 template <
typename GUM_SCALAR >
688 for (
auto node:
credalNet_->current_bn().nodes()) {
689 auto dSize =
credalNet_->current_bn().variable(node).domainSize();
690 marginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
693 marginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
702 template <
typename GUM_SCALAR >
708 for (
auto node:
credalNet_->current_bn().nodes())
709 marginalSets_.insert(node, std::vector< std::vector< GUM_SCALAR > >());
717 template <
typename GUM_SCALAR >
722 if (
modal_.empty())
return;
724 for (
auto node:
credalNet_->current_bn().nodes()) {
725 std::string var_name, time_step;
727 var_name =
credalNet_->current_bn().variable(node).name();
728 auto delim = var_name.find_first_of(
"_");
729 var_name = var_name.substr(0, delim);
731 if (!
modal_.exists(var_name))
continue;
738 template <
typename GUM_SCALAR >
743 template <
typename GUM_SCALAR >
757 outerMap expectationsMin, expectationsMax;
760 std::string var_name, time_step;
762 var_name =
credalNet_->current_bn().variable(elt.first).name();
763 auto delim = var_name.find_first_of(
"_");
764 time_step = var_name.substr(delim + 1, var_name.size());
765 var_name = var_name.substr(0, delim);
770 if (!
modal_.exists(var_name))
continue;
772 expectationsMin.getWithDefault(var_name, innerMap())
773 .getWithDefault(atoi(time_step.c_str()), 0)
775 expectationsMax.getWithDefault(var_name, innerMap())
776 .getWithDefault(atoi(time_step.c_str()), 0)
780 for (
const auto& elt: expectationsMin) {
781 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
783 for (
const auto& elt2: elt.second)
784 dynExp[elt2.first] = elt2.second;
789 for (
const auto& elt: expectationsMax) {
790 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
792 for (
const auto& elt2: elt.second) {
793 dynExp[elt2.first] = elt2.second;
800 template <
typename GUM_SCALAR >
807 for (
auto node:
credalNet_->current_bn().dag().nodes()) {
808 std::string var_name =
credalNet_->current_bn().variable(node).name();
809 auto delim = var_name.find_first_of(
"_");
811 if (delim > var_name.size()) {
813 "void InferenceEngine< GUM_SCALAR "
814 ">::repetitiveInit_() : the network does not "
815 "appear to be dynamic");
818 std::string time_step = var_name.substr(delim + 1, 1);
820 if (time_step.compare(
"0") == 0)
t0_.insert(node, std::vector< NodeId >());
824 for (
const auto& node:
credalNet_->current_bn().dag().nodes()) {
825 std::string var_name =
credalNet_->current_bn().variable(node).name();
826 auto delim = var_name.find_first_of(
"_");
827 std::string time_step = var_name.substr(delim + 1, var_name.size());
828 var_name = var_name.substr(0, delim);
829 delim = time_step.find_first_of(
"_");
830 time_step = time_step.substr(0, delim);
832 if (time_step.compare(
"1") == 0) {
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())
t0_[elt.first].push_back(node);
845 else t1_.insert(node, std::vector< NodeId >());
852 if (!found) {
t1_.insert(node, std::vector< NodeId >()); }
858 for (
auto node:
credalNet_->current_bn().dag().nodes()) {
859 std::string var_name =
credalNet_->current_bn().variable(node).name();
860 auto delim = var_name.find_first_of(
"_");
861 std::string time_step = var_name.substr(delim + 1, var_name.size());
862 var_name = var_name.substr(0, delim);
863 delim = time_step.find_first_of(
"_");
864 time_step = time_step.substr(0, delim);
866 if (time_step.compare(
"0") != 0 && time_step.compare(
"1") != 0) {
870 std::string var_0_name;
873 for (
const auto& elt:
t0_) {
874 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
875 delim = var_0_name.find_first_of(
"_");
876 var_0_name = var_0_name.substr(0, delim);
878 if (var_name.compare(var_0_name) == 0) {
879 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
880 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
882 if (tensor->domainSize() == tensor2->domainSize()) {
883 t0_[elt.first].push_back(node);
891 for (
const auto& elt:
t1_) {
892 std::string var_0_name =
credalNet_->current_bn().variable(elt.first).name();
893 auto delim = var_0_name.find_first_of(
"_");
894 var_0_name = var_0_name.substr(0, delim);
896 if (var_name.compare(var_0_name) == 0) {
897 const Tensor< GUM_SCALAR >* tensor(&
credalNet_->current_bn().cpt(node));
898 const Tensor< GUM_SCALAR >* tensor2(&
credalNet_->current_bn().cpt(elt.first));
900 if (tensor->domainSize() == tensor2->domainSize()) {
901 t1_[elt.first].push_back(node);
911 template <
typename GUM_SCALAR >
914 const std::vector< GUM_SCALAR >& vertex) {
915 std::string var_name =
credalNet_->current_bn().variable(
id).name();
916 auto delim = var_name.find_first_of(
"_");
918 var_name = var_name.substr(0, delim);
920 if (
modal_.exists(var_name) ) {
922 auto vsize = vertex.size();
924 for (
Size mod = 0; mod < vsize; mod++)
925 exp += vertex[mod] *
modal_[var_name][mod];
933 template <
typename GUM_SCALAR >
935 const std::vector< GUM_SCALAR >& vertex,
936 const bool& elimRedund) {
938 auto dsize = vertex.size();
942 for (
auto it = nodeCredalSet.cbegin(), itEnd = nodeCredalSet.cend(); it != itEnd; ++it) {
945 for (
Size i = 0; i < dsize; i++) {
946 if (std::fabs(vertex[i] - (*it)[i]) > 1e-6) {
955 if (!eq || nodeCredalSet.size() == 0) {
956 nodeCredalSet.push_back(vertex);
961 if (nodeCredalSet.size() == 1)
return;
966 auto itEnd = std::remove_if(
967 nodeCredalSet.begin(),
969 [&](
const std::vector< GUM_SCALAR >& v) ->
bool {
970 for (auto jt = v.cbegin(),
972 minIt = marginalMin_[id].cbegin(),
973 minItEnd = marginalMin_[id].cend(),
974 maxIt = marginalMax_[id].cbegin(),
975 maxItEnd = marginalMax_[id].cend();
976 jt != jtEnd && minIt != minItEnd && maxIt != maxItEnd;
977 ++jt, ++minIt, ++maxIt) {
978 if ((std::fabs(*jt - *minIt) < 1e-6 || std::fabs(*jt - *maxIt) < 1e-6)
979 && std::fabs(*minIt - *maxIt) > 1e-6)
985 nodeCredalSet.erase(itEnd, nodeCredalSet.end());
988 if (!elimRedund || nodeCredalSet.size() <= 2)
return;
995 lrsWrapper.
setUpV((
unsigned int)dsize, (
unsigned int)(nodeCredalSet.size()));
997 for (
const auto& vtx: nodeCredalSet)
998 lrsWrapper.
fillV(vtx);
1002 marginalSets_[id] = lrsWrapper.
getOutput();
1005 template <
typename GUM_SCALAR >
1011 template <
typename GUM_SCALAR >
1017 template <
typename GUM_SCALAR >
1023 std::vector< GUM_SCALAR > tEps(nb_threads, std::numeric_limits< GUM_SCALAR >::max());
1026 auto threadedEps = [
this, &tEps](
const std::size_t this_thread,
1027 const std::size_t nb_threads,
1028 const std::vector< std::pair< NodeId, Idx > >& ranges) {
1029 auto& this_tEps = tEps[this_thread];
1043 auto i = ranges[this_thread].first;
1044 auto j = ranges[this_thread].second;
1046 const auto end_i = ranges[this_thread + 1].first;
1047 auto end_j = ranges[this_thread + 1].second;
1048 const auto marginalMax_size = this->
marginalMax_.size();
1050 while ((i < end_i) || (j < end_j)) {
1053 delta = (delta < 0) ? (-delta) : delta;
1054 this_tEps = (this_tEps < delta) ? delta : this_tEps;
1058 delta = (delta < 0) ? (-delta) : delta;
1059 this_tEps = (this_tEps < delta) ? delta : this_tEps;
1064 if (++j == domain_size) {
1067 if (i < marginalMax_size) domain_size = this->
marginalMax_[i].size();
1077 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
1081 GUM_SCALAR eps = tEps[0];
1082 for (
const auto nb: tEps)
1083 if (eps < nb) eps = nb;
1097 int nsize = int(marginalMin_.size());
1101 for (int i = 0; i < nsize; i++) {
1102 auto dSize = marginalMin_[i].size();
1104 for (Size j = 0; j < dSize; j++) {
1106 delta = marginalMin_[i][j] - oldMarginalMin_[i][j];
1107 delta = (delta < 0) ? (-delta) : delta;
1108 tEps = (tEps < delta) ? delta : tEps;
1111 delta = marginalMax_[i][j] - oldMarginalMax_[i][j];
1112 delta = (delta < 0) ? (-delta) : delta;
1113 tEps = (tEps < delta) ? delta : tEps;
1115 oldMarginalMin_[i][j] = marginalMin_[i][j];
1116 oldMarginalMax_[i][j] = marginalMax_[i][j];
1118 } // end of : all variables
1120 #pragma omp critical(epsilon_max)
1122 #pragma omp flush(eps)
1123 eps = (eps < tEps) ? tEps : eps;
1132 template <
typename GUM_SCALAR >
1135 Size nb_elements = 0;
1136 const auto marginalMin_size = this->marginalMin_.size();
1137 for (
const auto& marg_i: this->marginalMin_)
1138 nb_elements += marg_i.second.size();
1142 if (nb_elements < nb_threads) nb_threads = nb_elements;
1152 Idx nb_elts_par_thread = nb_elements / nb_threads;
1153 Idx rest_elts = nb_elements - nb_elts_par_thread * nb_threads;
1156 Idx current_domain_index = 0;
1157 Size current_domain_size = this->marginalMin_[0].size();
1158 threadRanges_.emplace_back(current_node, current_domain_index);
1160 for (
Idx i =
Idx(0); i < nb_threads; ++i) {
1163 current_domain_index += nb_elts_par_thread;
1164 if (rest_elts !=
Idx(0)) {
1165 ++current_domain_index;
1172 while (current_domain_index >= current_domain_size) {
1173 current_domain_index -= current_domain_size;
1175 current_domain_index = 0;
1176 if (current_node != marginalMin_size) {
1177 current_domain_size = this->marginalMin_[current_node].size();
1182 threadRanges_.emplace_back(current_node, current_domain_index);
1185 if (current_domain_index == current_domain_size) {
1187 current_domain_index = 0;
1192 template <
typename GUM_SCALAR >
1194 const std::vector< GUM_SCALAR >& vals) {
1202 template <
typename GUM_SCALAR >
1204 std::vector< GUM_SCALAR > vals(this->
credalNet_->current_bn().variable(
id).domainSize(), 0);
1210 template <
typename GUM_SCALAR >
1216 template <
typename GUM_SCALAR >
1222 template <
typename GUM_SCALAR >
1224 const std::string& label) {
1229 template <
typename GUM_SCALAR >
1231 const std::vector< GUM_SCALAR >& vals) {
1235 template <
typename GUM_SCALAR >
1237 const auto id = this->
credalNet_->current_bn().idFromName(pot.variable(0).name());
1238 std::vector< GUM_SCALAR > vals(this->
credalNet_->current_bn().variable(
id).domainSize(), 0);
1241 vals[I.
val(0)] = pot[I];
ApproximationScheme(bool verbosity=false)
The class for generic Hash Tables.
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.
virtual Size getNumberOfThreads() const
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.
void saveVertices(const std::string &path) const
Saves vertices to file.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
const std::vector< GUM_SCALAR > & dynamicExpMin(const std::string &varName) const
Get the lower dynamic expectation of a given variable prefix (without the time step included,...
margi evidence_
Holds observed variables states.
virtual void insertEvidenceFile(const std::string &path)
Insert evidence from file.
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.
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
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.
void displatchMarginalsToThreads_()
computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads
void saveExpectations(const std::string &path) const
Saves expectations to file.
virtual const GUM_SCALAR computeEpsilon_()
Compute approximation scheme epsilon using the old marginals and the new ones.
void saveMarginals(const std::string &path) const
Saves marginals to file.
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(const std::string &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
void insertModalsFile(const std::string &path)
Insert variables modalities from file to compute expectations.
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.
void insertQueryFile(const std::string &path)
Insert query variables states 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.
virtual ~InferenceEngine()
Destructor.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this creadal 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 usefull 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_.
#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