[apps/reg] Prevent fitting when data not suitable

This commit is contained in:
Léa Saviot
2018-06-08 16:48:59 +02:00
committed by Émilie Feral
parent 4b8462ed8a
commit a8b2183afa
8 changed files with 51 additions and 18 deletions

View File

@@ -11,7 +11,17 @@ using namespace Shared;
namespace Regression {
void Model::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {
fitLevenbergMarquardt(store, series, modelCoefficients, context);
if (dataSuitableForFit(store, series)) {
fitLevenbergMarquardt(store, series, modelCoefficients, context);
} else {
for (int i = 0; i < numberOfCoefficients(); i++) {
modelCoefficients[i] = NAN; //TODO undef /inf ?
}
}
}
bool Model::dataSuitableForFit(Store * store, int series) const {
return !store->seriesIsEmpty(series) && !std::isinf(store->slope(series)) && !std::isnan(store->slope(series));
}
void Model::fitLevenbergMarquardt(Store * store, int series, double * modelCoefficients, Context * context) {