[Regression] Switched affine and linear

This commit is contained in:
Joachim LF
2020-04-29 08:44:18 +02:00
committed by LeaNumworks
parent 833f6ec778
commit 5297f28ffa
5 changed files with 18 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
#include "affine_model.h"
#include "linear_model.h"
#include "../store.h"
#include <poincare/layout_helper.h>
#include <math.h>
@@ -10,7 +10,7 @@ namespace Regression {
Layout AffineModel::layout() {
if (m_layout.isUninitialized()) {
const char * s = "a·X";
const char * s = "a·X+b";
m_layout = LayoutHelper::String(s, strlen(s), k_layoutFont);
}
return m_layout;
@@ -18,7 +18,8 @@ Layout AffineModel::layout() {
double AffineModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
return a*x;
double b = modelCoefficients[1];
return a*x+b;
}
double AffineModel::levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) {
@@ -27,7 +28,7 @@ double AffineModel::levelSet(double * modelCoefficients, double xMin, double ste
if (a == 0) {
return NAN;
}
return y-b;
return (y-b)/a;
}
void AffineModel::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {

View File

@@ -1,5 +1,5 @@
#ifndef REGRESSION_AFFINE_MODEL_H
#define REGRESSION_AFFINE_MODEL_H
#ifndef REGRESSION_LINEAR_MODEL_H
#define REGRESSION_LINEAR_MODEL_H
#include "model.h"
@@ -14,8 +14,8 @@ public:
double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override;
void fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
int numberOfCoefficients() const override { return 1; }
int bannerLinesCount() const override { return 2; }
int numberOfCoefficients() const override { return 2; }
int bannerLinesCount() const override { return 3; }
};
}

View File

@@ -1,4 +1,4 @@
#include "linear_model.h"
#include "affine_model.h"
#include "../store.h"
#include <poincare/layout_helper.h>
#include <math.h>
@@ -10,7 +10,7 @@ namespace Regression {
Layout LinearModel::layout() {
if (m_layout.isUninitialized()) {
const char * s = "a·X+b";
const char * s = "a·X";
m_layout = LayoutHelper::String(s, strlen(s), k_layoutFont);
}
return m_layout;
@@ -18,8 +18,7 @@ Layout LinearModel::layout() {
double LinearModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];
return a*x+b;
return a*x;
}
double LinearModel::levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) {
@@ -28,7 +27,7 @@ double LinearModel::levelSet(double * modelCoefficients, double xMin, double ste
if (a == 0) {
return NAN;
}
return (y-b)/a;
return y-b;
}
void LinearModel::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {

View File

@@ -1,5 +1,5 @@
#ifndef REGRESSION_LINEAR_MODEL_H
#define REGRESSION_LINEAR_MODEL_H
#ifndef REGRESSION_AFFINE_MODEL_H
#define REGRESSION_AFFINE_MODEL_H
#include "model.h"
@@ -14,8 +14,8 @@ public:
double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override;
void fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
int numberOfCoefficients() const override { return 2; }
int bannerLinesCount() const override { return 3; }
int numberOfCoefficients() const override { return 1; }
int bannerLinesCount() const override { return 2; }
};
}

View File

@@ -285,7 +285,7 @@ double Store::squaredCorrelationCoefficient(int series) const {
}
Model * Store::regressionModel(int index) {
Model * models[Model::k_numberOfModels] = {&m_linearModel, &m_affineModel, &m_quadraticModel, &m_cubicModel, &m_quarticModel, &m_logarithmicModel, &m_exponentialModel, &m_powerModel, &m_trigonometricModel, &m_logisticModel};
Model * models[Model::k_numberOfModels] = {&m_affineModel, &m_linearModel, &m_quadraticModel, &m_cubicModel, &m_quarticModel, &m_logarithmicModel, &m_exponentialModel, &m_powerModel, &m_trigonometricModel, &m_logisticModel};
return models[index];
}