Commit 60d0e17a authored by Christophe Gonzales's avatar Christophe Gonzales

improved error messages in ParamEstimator by Max likekihood

parent 90332188
Pipeline #24119720 passed with stages
in 64 minutes 20 seconds
......@@ -32,6 +32,8 @@
#ifndef GUM_LEARNING_PARAM_ESTIMATOR_ML_H
#define GUM_LEARNING_PARAM_ESTIMATOR_ML_H
#include <sstream>
#include <agrum/agrum.h>
#include <agrum/learning/paramUtils/paramEstimator.h>
#include <agrum/learning/scores_and_tests/scoreInternalNoApriori.h>
......
......@@ -91,7 +91,8 @@ namespace gum {
this->_getAllNodes(nodeset_index);
const std::vector< Idx, IdSetAlloc >* conditioning_nodes =
this->_getConditioningNodes(nodeset_index);
const Idx target_modal = this->modalities()[all_nodes[all_nodes.size() - 1]];
const auto& modals = this->modalities();
const Idx target_modal = modals[all_nodes[all_nodes.size() - 1]];
std::vector< double, CountAlloc >& N_ijk =
const_cast< std::vector< double, CountAlloc >& >(
this->_getAllCounts(nodeset_index));
......@@ -116,9 +117,34 @@ namespace gum {
// check that all conditioning nodes have strictly positive counts
for (Idx j = 0; j < conditioning_size; ++j) {
if (N_ij[j] + N_prime_ij[j] == 0) {
GUM_ERROR(CPTError,
"A conditioning set has a value that never "
"appears in the database");
const std::size_t cond_nb = conditioning_nodes->size ();
std::vector<Idx> offsets ( cond_nb );
Idx offset = 1;
std::size_t i;
for ( i = std::size_t(0); i < cond_nb; ++i ) {
offsets[i] = offset;
offset *= modals[conditioning_nodes->operator[](i)];
}
std::vector<Idx> values ( cond_nb );
i = 0;
offset = j;
for ( Idx jj = cond_nb - 1; i < cond_nb; ++i, --j ) {
values[jj] = offset / offsets[jj];
offset %= offsets[jj];
}
std::stringstream str;
str << "The conditioning set <";
bool deja = false;
for ( i = std::size_t(0); i < cond_nb; ++i ) {
if ( deja ) str << ", ";
else deja = false;
str << "Node #" << conditioning_nodes->operator[](i)
<< "=" << values[i];
}
str << "> for target node #" << all_nodes[all_nodes.size() - 1]
<< " never appears in the database";
GUM_ERROR(CPTError, str.str());
}
}
......@@ -132,9 +158,34 @@ namespace gum {
// check that all conditioning nodes have strictly positive counts
for (Idx j = 0; j < conditioning_size; ++j) {
if (!N_ij[j]) {
GUM_ERROR(CPTError,
"A conditioning set has a value that never "
"appears in the database");
const std::size_t cond_nb = conditioning_nodes->size ();
std::vector<Idx> offsets ( cond_nb );
Idx offset = 1;
std::size_t i;
for ( i = std::size_t(0); i < cond_nb; ++i ) {
offsets[i] = offset;
offset *= modals[conditioning_nodes->operator[](i)];
}
std::vector<Idx> values ( cond_nb );
i = 0;
offset = j;
for ( Idx jj = cond_nb - 1; i < cond_nb; ++i, --j ) {
values[jj] = offset / offsets[jj];
offset %= offsets[jj];
}
std::stringstream str;
str << "The conditioning set <";
bool deja = false;
for ( i = std::size_t(0); i < cond_nb; ++i ) {
if ( deja ) str << ", ";
else deja = false;
str << "Node #" << conditioning_nodes->operator[](i)
<< "=" << values[i];
}
str << "> for target node #" << all_nodes[all_nodes.size() - 1]
<< " never appears in the database";
GUM_ERROR(CPTError, str.str());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment