Commit aca776e4 authored by Christophe Gonzales's avatar Christophe Gonzales

further improved error messages in ParamEstimator by Max likekihood

parent 60d0e17a
Pipeline #24125862 passed with stages
in 63 minutes 32 seconds
......@@ -561,6 +561,11 @@ namespace gum {
/// returns the number of variables (columns) of the database
virtual std::size_t nbVariables() const final;
/// returns a pointer on the database
/** @throw NullElement is raised if the handler does not point toward
* any database. */
virtual const IDatabaseTable< T_DATA, ALLOC >& database () const;
/// @}
......
......@@ -318,6 +318,7 @@ namespace gum {
return __db->variableNames();
}
// returns the number of variables (columns) of the database
template < typename T_DATA, template < typename > class ALLOC >
INLINE std::size_t
......@@ -329,6 +330,18 @@ namespace gum {
}
// returns a pointer on the database
template < typename T_DATA, template < typename > class ALLOC >
INLINE const IDatabaseTable< T_DATA, ALLOC >&
IDatabaseTable< T_DATA, ALLOC >::Handler::database () const {
if ( __db == nullptr ) {
GUM_ERROR ( NullElement,
"The database handler does not point toward a database" );
}
return *__db;
}
// ===========================================================================
// Safe handlers
// ===========================================================================
......
......@@ -34,6 +34,7 @@
#define GUM_LEARNING_PARAM_ESTIMATOR_H
#include <agrum/agrum.h>
#include <agrum/learning/database/databaseTable.h>
#include <agrum/learning/aprioris/apriori.h>
#include <agrum/learning/scores_and_tests/counter.h>
#include <agrum/learning/scores_and_tests/scoreInternalApriori.h>
......@@ -179,6 +180,9 @@ namespace gum {
/// the score that was use for structure learning (used for its apriori)
ScoreInternalApriori< IdSetAlloc, CountAlloc >* _score_internal_apriori;
/// the database
const DatabaseTable<std::allocator> *_database;
/// indicate whether we have already normalized the parameters
std::vector< bool > _is_normalized;
......
......@@ -132,16 +132,21 @@ namespace gum {
values[jj] = offset / offsets[jj];
offset %= offsets[jj];
}
//const DatabaseTable<>& da
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];
else deja = true;
auto id = conditioning_nodes->operator[](i);
const DiscreteVariable& var =
dynamic_cast<const DiscreteVariable&> ( this->_database->variable(id) );
str << var.name() << "=" << var.labels()[values[i]];
}
str << "> for target node #" << all_nodes[all_nodes.size() - 1]
auto id = all_nodes[all_nodes.size() - 1];
const Variable& var = this->_database->variable(id);
str << "> for target node " << var.name()
<< " never appears in the database";
GUM_ERROR(CPTError, str.str());
......@@ -175,14 +180,18 @@ namespace gum {
}
std::stringstream str;
str << "The conditioning set <";
bool deja = false;
bool deja = true;
for ( i = std::size_t(0); i < cond_nb; ++i ) {
if ( deja ) str << ", ";
else deja = false;
str << "Node #" << conditioning_nodes->operator[](i)
<< "=" << values[i];
else deja = true;
auto id = conditioning_nodes->operator[](i);
const DiscreteVariable& var =
dynamic_cast<const DiscreteVariable&> ( this->_database->variable(id) );
str << var.name() << "=" << var.labels()[values[i]];
}
str << "> for target node #" << all_nodes[all_nodes.size() - 1]
auto id = all_nodes[all_nodes.size() - 1];
const Variable& var = this->_database->variable(id);
str << "> for target node " << var.name()
<< " never appears in the database";
GUM_ERROR(CPTError, str.str());
......
......@@ -40,7 +40,9 @@ namespace gum {
score_internal_apriori) :
Counter< IdSetAlloc, CountAlloc >(filter, var_modalities),
_apriori(&apriori),
_score_internal_apriori(score_internal_apriori.copyFactory()) {
_score_internal_apriori(score_internal_apriori.copyFactory()),
_database ( dynamic_cast<const DatabaseTable<std::allocator> *>
( &( filter.handler().database () ) ) ) {
GUM_CONSTRUCTOR(ParamEstimator);
}
......@@ -51,9 +53,10 @@ namespace gum {
Counter< IdSetAlloc, CountAlloc >(from),
_apriori(from._apriori),
_score_internal_apriori(from._score_internal_apriori->copyFactory()),
_database ( from._database ),
_is_normalized(from._is_normalized),
__apriori_computed(from.__apriori_computed),
__score_apriori_inserted(from.__score_apriori_inserted) {
__score_apriori_inserted(from.__score_apriori_inserted) {
GUM_CONS_CPY(ParamEstimator);
}
......@@ -64,9 +67,10 @@ namespace gum {
Counter< IdSetAlloc, CountAlloc >(std::move(from)),
_apriori(std::move(from._apriori)),
_score_internal_apriori(std::move(from._score_internal_apriori)),
_database ( from._database ),
_is_normalized(std::move(from._is_normalized)),
__apriori_computed(std::move(from.__apriori_computed)),
__score_apriori_inserted(std::move(from.__score_apriori_inserted)) {
__score_apriori_inserted(std::move(from.__score_apriori_inserted)) {
from._score_internal_apriori = nullptr;
GUM_CONS_MOV(ParamEstimator);
}
......
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