[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

@@ -1,4 +1,5 @@
#include "logarithmic_model.h"
#include "../store.h"
#include <math.h>
#include <poincare/layout_engine.h>
#include <assert.h>
@@ -35,6 +36,7 @@ double LogarithmicModel::levelSet(double * modelCoefficients, double y) const {
double LogarithmicModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
if (derivateCoefficientIndex == 0) {
// Derivate: ln(x)
assert(x >0);
return log(x);
}
if (derivateCoefficientIndex == 1) {
@@ -45,4 +47,17 @@ double LogarithmicModel::partialDerivate(double * modelCoefficients, int derivat
return 0.0;
}
bool LogarithmicModel::dataSuitableForFit(Store * store, int series) const {
if (!Model::dataSuitableForFit(store, series)) {
return false;
}
int numberOfPairs = store->numberOfPairsOfSeries(series);
for (int j = 0; j < numberOfPairs; j++) {
if (store->get(series, 0, j) <= 0) {
return false;
}
}
return true;
}
}