mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user