mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[Regression] Switched affine and linear
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user