[apps/regression] Rename Affine -> Linear and Linear -> Proportional

This commit is contained in:
Léa Saviot
2020-05-13 13:41:05 +02:00
committed by LeaNumworks
parent 740e9e9d12
commit 2e5e2a3258
19 changed files with 87 additions and 87 deletions

View File

@@ -11,7 +11,7 @@ BannerView::BannerView(
) :
Shared::XYBannerView(parentResponder, inputEventHandlerDelegate, textFieldDelegate),
m_derivativeView(Font(), 0.5f, 0.5f, TextColor(), BackgroundColor()),
m_tangentEquationView(Font(), I18n::Message::AffineRegressionFormula, 0.0f, 0.5f, TextColor(), BackgroundColor()),
m_tangentEquationView(Font(), I18n::Message::LinearRegressionFormula, 0.0f, 0.5f, TextColor(), BackgroundColor()),
m_aView(Font(), 0.5f, 0.5f, TextColor(), BackgroundColor()),
m_bView(Font(), 0.5f, 0.5f, TextColor(), BackgroundColor()),
m_numberOfSubviews(Shared::XYBannerView::k_numberOfSubviews)

View File

@@ -8,7 +8,6 @@ app_regression_test_src += $(addprefix apps/regression/,\
)
app_regression_test_src += $(addprefix apps/regression/model/,\
affine_model.cpp \
cubic_model.cpp \
exponential_model.cpp \
linear_model.cpp \
@@ -16,6 +15,7 @@ app_regression_test_src += $(addprefix apps/regression/model/,\
logistic_model.cpp \
model.cpp \
power_model.cpp \
proportional_model.cpp \
quadratic_model.cpp \
quartic_model.cpp \
trigonometric_model.cpp \

View File

@@ -10,7 +10,7 @@ ValueNotReachedByRegression = "Wert in diesem Fenster nicht erreicht"
NumberOfDots = "Punktanzahl"
Covariance = "Kovarianz"
Linear = "Lineare"
Affine = "Affine"
Proportional = "Proportional"
Quadratic = "Quadratische"
Cubic = "Kubische"
Quartic = "Biquadratische"

View File

@@ -10,7 +10,7 @@ ValueNotReachedByRegression = "Value not reached in this window"
NumberOfDots = "Number of points"
Covariance = "Covariance"
Linear = "Linear"
Affine = "Affine"
Proportional = "Proportional"
Quadratic = "Quadratic"
Cubic = "Cubic"
Quartic = "Quartic"

View File

@@ -10,7 +10,7 @@ ValueNotReachedByRegression = "Valor no alcanzado en esta ventana"
NumberOfDots = "Número de puntos"
Covariance = "Covarianza"
Linear = "Lineal"
Affine = "Affine"
Proportional = "Proporcional"
Quadratic = "Cuadrática"
Cubic = "Cúbica"
Quartic = "Cuártica"

View File

@@ -10,7 +10,7 @@ ValueNotReachedByRegression = "Valeur non atteinte dans cette fenêtre"
NumberOfDots = "Nombre de points"
Covariance = "Covariance"
Linear = "Linéaire"
Affine = "Affine"
Proportional = "Proportionnelle"
Quadratic = "Quadratique"
Cubic = "Cubique"
Quartic = "Quartique"

View File

@@ -10,7 +10,7 @@ ValueNotReachedByRegression = "Valor não alcançado nesta janela"
NumberOfDots = "Número de pontos"
Covariance = "Covariancia"
Linear = "Linear"
Affine = "Affine"
Proportional = "Proporcional"
Quadratic = "Quadrática"
Cubic = "Cúbica"
Quartic = "Quarto grau"

View File

@@ -1,4 +1,4 @@
LinearRegressionFormula = " y=a·x "
ProportionalRegressionFormula = " y=a·x "
QuadraticRegressionFormula = " y=a·x^2+b·x+c "
CubicRegressionFormula = " y=a·x^3+b·x^2+c·x+d "
QuarticRegressionFormula = " y=a·x^4+b·x^3+c·x^2+d·x+e "

View File

@@ -187,7 +187,7 @@ void GraphController::reloadBannerView() {
coefficientName++;
}
if (m_store->seriesRegressionType(*m_selectedSeriesIndex) == Model::Type::Linear || m_store->seriesRegressionType(*m_selectedSeriesIndex) == Model::Type::Affine) {
if (m_store->seriesRegressionType(*m_selectedSeriesIndex) == Model::Type::Linear || m_store->seriesRegressionType(*m_selectedSeriesIndex) == Model::Type::Proportional) {
int index = model->numberOfCoefficients();
// Set "r=..."
numberOfChar = 0;

View File

@@ -1,52 +0,0 @@
#include "affine_model.h"
#include "../store.h"
#include <poincare/layout_helper.h>
#include <math.h>
#include <assert.h>
using namespace Poincare;
namespace Regression {
Layout AffineModel::layout() {
if (m_layout.isUninitialized()) {
const char * s = "a·X+b";
m_layout = LayoutHelper::String(s, strlen(s), k_layoutFont);
}
return m_layout;
}
double AffineModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];
return a*x+b;
}
double AffineModel::levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) {
double a = modelCoefficients[0];
double b = modelCoefficients[1];
if (a == 0) {
return NAN;
}
return (y-b)/a;
}
void AffineModel::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {
modelCoefficients[0] = store->slope(series);
modelCoefficients[1] = store->yIntercept(series);
}
double AffineModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
if (derivateCoefficientIndex == 0) {
// Derivate: x
return x;
}
if (derivateCoefficientIndex == 1) {
// Derivate: 1;
return 1;
}
assert(false);
return 0.0;
}
}

View File

@@ -10,7 +10,7 @@ namespace Regression {
Layout LinearModel::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,19 +18,22 @@ Layout LinearModel::layout() {
double LinearModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
return a*x;
double b = modelCoefficients[1];
return a*x+b;
}
double LinearModel::levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) {
double a = modelCoefficients[0];
if (a == 0.0) {
double b = modelCoefficients[1];
if (a == 0) {
return NAN;
}
return y/a;
return (y-b)/a;
}
void LinearModel::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {
modelCoefficients[0] = store->slope(series);
modelCoefficients[1] = store->yIntercept(series);
}
double LinearModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
@@ -38,6 +41,10 @@ double LinearModel::partialDerivate(double * modelCoefficients, int derivateCoef
// Derivate: x
return x;
}
if (derivateCoefficientIndex == 1) {
// Derivate: 1;
return 1;
}
assert(false);
return 0.0;
}

View File

@@ -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

@@ -14,16 +14,16 @@ class Store;
class Model {
public:
enum class Type : uint8_t {
Linear = 0,
Affine = 1,
Quadratic = 2,
Cubic = 3,
Quartic = 4,
Logarithmic = 5,
Exponential = 6,
Power = 7,
Linear = 0,
Proportional = 1,
Quadratic = 2,
Cubic = 3,
Quartic = 4,
Logarithmic = 5,
Exponential = 6,
Power = 7,
Trigonometric = 8,
Logistic = 9
Logistic = 9
};
static constexpr int k_numberOfModels = 10;
static constexpr int k_maxNumberOfCoefficients = 5; // This has to verify: k_maxNumberOfCoefficients < Matrix::k_maxNumberOfCoefficients

View File

@@ -0,0 +1,45 @@
#include "proportional_model.h"
#include "../store.h"
#include <poincare/layout_helper.h>
#include <math.h>
#include <assert.h>
using namespace Poincare;
namespace Regression {
Layout ProportionalModel::layout() {
if (m_layout.isUninitialized()) {
const char * s = "a·X";
m_layout = LayoutHelper::String(s, strlen(s), k_layoutFont);
}
return m_layout;
}
double ProportionalModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
return a*x;
}
double ProportionalModel::levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) {
double a = modelCoefficients[0];
if (a == 0.0) {
return NAN;
}
return y/a;
}
void ProportionalModel::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {
modelCoefficients[0] = store->slope(series);
}
double ProportionalModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
if (derivateCoefficientIndex == 0) {
// Derivate: x
return x;
}
assert(false);
return 0.0;
}
}

View File

@@ -1,21 +1,21 @@
#ifndef REGRESSION_AFFINE_MODEL_H
#define REGRESSION_AFFINE_MODEL_H
#ifndef REGRESSION_PROPORTIONAL_MODEL_H
#define REGRESSION_PROPORTIONAL_MODEL_H
#include "model.h"
namespace Regression {
class AffineModel : public Model {
class ProportionalModel : public Model {
public:
using Model::Model;
Poincare::Layout layout() override;
I18n::Message formulaMessage() const override { return I18n::Message::AffineRegressionFormula; }
I18n::Message formulaMessage() const override { return I18n::Message::ProportionalRegressionFormula; }
double evaluate(double * modelCoefficients, double x) const override;
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

@@ -82,7 +82,7 @@ HighlightCell * RegressionController::reusableCell(int index, int type) {
void RegressionController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
assert(i == 0);
assert(j >= 0 && j < k_numberOfRows);
I18n::Message messages[k_numberOfRows] = {I18n::Message::Linear, I18n::Message::Affine, I18n::Message::Quadratic, I18n::Message::Cubic, I18n::Message::Quartic, I18n::Message::Logarithmic, I18n::Message::Exponential, I18n::Message::Power, I18n::Message::Trigonometrical, I18n::Message::Logistic};
I18n::Message messages[k_numberOfRows] = {I18n::Message::Linear, I18n::Message::Proportional, I18n::Message::Quadratic, I18n::Message::Cubic, I18n::Message::Quartic, I18n::Message::Logarithmic, I18n::Message::Exponential, I18n::Message::Power, I18n::Message::Trigonometrical, I18n::Message::Logistic};
MessageTableCellWithExpression * castedCell = static_cast<MessageTableCellWithExpression *>(cell);
castedCell->setMessage(messages[j]);
castedCell->setLayout(m_store->regressionModel((Model::Type) j)->layout());

View File

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

View File

@@ -8,10 +8,10 @@
#include "model/logarithmic_model.h"
#include "model/logistic_model.h"
#include "model/power_model.h"
#include "model/proportional_model.h"
#include "model/quadratic_model.h"
#include "model/quartic_model.h"
#include "model/trigonometric_model.h"
#include "model/affine_model.h"
#include "../shared/interactive_curve_view_range.h"
#include "../shared/double_pair_store.h"
#include <escher/responder.h>
@@ -80,7 +80,7 @@ private:
uint32_t m_seriesChecksum[k_numberOfSeries];
Model::Type m_regressionTypes[k_numberOfSeries];
LinearModel m_linearModel;
AffineModel m_affineModel;
ProportionalModel m_proportionalModel;
QuadraticModel m_quadraticModel;
CubicModel m_cubicModel;
QuarticModel m_quarticModel;

View File

@@ -119,7 +119,7 @@ InvSortCommandWithArg = "sort>(L)"
K = "k"
Lambda = "λ"
LcmCommandWithArg = "lcm(p,q)"
AffineRegressionFormula = " y=a·x+b "
LinearRegressionFormula = " y=a·x+b "
LogCommandWithArg = "log(x,a)"
MatrixCommand = "[[\x11]]"
MatrixCommandWithArg = "[[1,2][3,4]]"