[apps/regression] Better initialisation of logistic model coefficients

It provides a better fit for:
x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}
y = {5.0, 9.0, 40.0, 64.0, 144.0, 200.0, 269.0, 278.0, 290.0, 295.0}
(coeffs should be {64.9, 1.0, 297.4})
This commit is contained in:
Léa Saviot
2019-11-21 15:05:46 +01:00
parent 3747b5a4b0
commit a8ead6b66e
2 changed files with 15 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
#include "logistic_model.h"
#include "../store.h"
#include <math.h>
#include <assert.h>
#include <poincare/code_point_layout.h>
@@ -81,4 +82,16 @@ double LogisticModel::partialDerivate(double * modelCoefficients, int derivateCo
return 0.0;
}
void LogisticModel::specializedInitCoefficientsForFit(double * modelCoefficients, double defaultValue, Store * store, int series) const {
assert(store != nullptr && series >= 0 && series < Store::k_numberOfSeries && !store->seriesIsEmpty(series));
modelCoefficients[0] = defaultValue;
modelCoefficients[1] = defaultValue;
/* If the data is a standard logistic function, the ordinates are between 0
* and c. Twice the standard vertical deviation is a rough estimate of c
* that is "close enough" to c to seed the coefficient, without being too
* dependent on outliers.*/
modelCoefficients[2] = 2.0*store->standardDeviationOfColumn(series, 1);
}
}

View File

@@ -15,6 +15,8 @@ public:
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
int numberOfCoefficients() const override { return 3; }
int bannerLinesCount() const override { return 3; }
private:
void specializedInitCoefficientsForFit(double * modelCoefficients, double defaultValue, Store * store, int series) const override;
};
}