[apps/reg] Display the regression layouts is RegressionController

This commit is contained in:
Léa Saviot
2018-06-06 15:09:36 +02:00
committed by Émilie Feral
parent 6ca4ecb635
commit e4fc5e8a64
21 changed files with 247 additions and 23 deletions

View File

@@ -1,9 +1,40 @@
#include "cubic_model.h"
#include <math.h>
#include <assert.h>
#include "../../poincare/include/poincare_layouts.h"
using namespace Poincare;
namespace Regression {
ExpressionLayout * CubicModel::Layout() {
static ExpressionLayout * layout = nullptr;
if (layout == nullptr) {
const ExpressionLayout * layoutChildren[] = {
new CharLayout('a', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('3', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('b', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('2', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('c', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('d', KDText::FontSize::Small),
};
layout = new HorizontalLayout(layoutChildren, 12, false);
}
return layout;
}
double CubicModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_CUBIC_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class CubicModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 4; }

View File

@@ -1,9 +1,31 @@
#include "exponential_model.h"
#include <math.h>
#include <assert.h>
#include "../../poincare/include/poincare_layouts.h"
using namespace Poincare;
namespace Regression {
ExpressionLayout * ExponentialModel::Layout() {
static ExpressionLayout * layout = nullptr;
if (layout == nullptr) {
const ExpressionLayout * layoutChildren[] = {
new CharLayout('a', KDText::FontSize::Small),
new CharLayout('e', KDText::FontSize::Small),
new VerticalOffsetLayout(
new HorizontalLayout(
new CharLayout('b', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
false),
VerticalOffsetLayout::Type::Superscript,
false)
};
layout = new HorizontalLayout(layoutChildren, 3, false);
}
return layout;
}
double ExponentialModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_EXPONENTIAL_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class ExponentialModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 2; }

View File

@@ -1,9 +1,17 @@
#include "linear_model.h"
#include <math.h>
#include <poincare/layout_engine.h>
#include <assert.h>
using namespace Poincare;
namespace Regression {
ExpressionLayout * LinearModel::Layout() {
static ExpressionLayout * layout = LayoutEngine::createStringLayout("aX+b", 4, KDText::FontSize::Small);
return layout;
}
double LinearModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_LINEAR_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class LinearModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 2; }

View File

@@ -1,9 +1,17 @@
#include "logarithmic_model.h"
#include <math.h>
#include <poincare/layout_engine.h>
#include <assert.h>
using namespace Poincare;
namespace Regression {
ExpressionLayout * LogarithmicModel::Layout() {
static ExpressionLayout * layout = LayoutEngine::createStringLayout("aln(X)+b", 8, KDText::FontSize::Small);
return layout;
}
double LogarithmicModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_LOGARITHMIC_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class LogarithmicModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 2; }

View File

@@ -1,9 +1,36 @@
#include "logistic_model.h"
#include <math.h>
#include <assert.h>
#include "../../poincare/include/poincare_layouts.h"
using namespace Poincare;
namespace Regression {
ExpressionLayout * LogisticModel::Layout() {
static ExpressionLayout * layout = nullptr;
if (layout == nullptr) {
const ExpressionLayout * layoutChildren[] = {
new CharLayout('a', KDText::FontSize::Small),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('e', KDText::FontSize::Small),
new VerticalOffsetLayout(
new HorizontalLayout(
new CharLayout('-', KDText::FontSize::Small),
new CharLayout('b', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
false),
VerticalOffsetLayout::Type::Superscript,
false)
};
layout = new FractionLayout(
new CharLayout('c', KDText::FontSize::Small),
new HorizontalLayout(layoutChildren, 4, false),
false);
}
return layout;
}
double LogisticModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_LOGISTIC_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class LogisticModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 3; }

View File

@@ -1,9 +1,28 @@
#include "power_model.h"
#include <math.h>
#include <assert.h>
#include "../../poincare/include/poincare_layouts.h"
using namespace Poincare;
namespace Regression {
ExpressionLayout * PowerModel::Layout() {
static ExpressionLayout * layout = nullptr;
if (layout == nullptr) {
const ExpressionLayout * layoutChildren[] = {
new CharLayout('a', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('b', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
};
layout = new HorizontalLayout(layoutChildren, 3, false);
}
return layout;
}
double PowerModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_POWER_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class PowerModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 2; }

View File

@@ -1,9 +1,33 @@
#include "quadratic_model.h"
#include <math.h>
#include <assert.h>
#include "../../poincare/include/poincare_layouts.h"
using namespace Poincare;
namespace Regression {
ExpressionLayout * QuadraticModel::Layout() {
static ExpressionLayout * layout = nullptr;
if (layout == nullptr) {
const ExpressionLayout * layoutChildren[] = {
new CharLayout('a', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('2', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('b', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('c', KDText::FontSize::Small),
};
layout = new HorizontalLayout(layoutChildren, 8, false);
}
return layout;
}
double QuadraticModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_QUADRATIC_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class QuadraticModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 3; }

View File

@@ -1,9 +1,47 @@
#include "quartic_model.h"
#include <math.h>
#include <assert.h>
#include "../../poincare/include/poincare_layouts.h"
using namespace Poincare;
namespace Regression {
ExpressionLayout * QuarticModel::Layout() {
static ExpressionLayout * layout = nullptr;
if (layout == nullptr) {
const ExpressionLayout * layoutChildren[] = {
new CharLayout('a', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('4', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('b', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('3', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('c', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('2', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Superscript,
false),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('d', KDText::FontSize::Small),
new CharLayout('X', KDText::FontSize::Small),
new CharLayout('+', KDText::FontSize::Small),
new CharLayout('e', KDText::FontSize::Small),
};
layout = new HorizontalLayout(layoutChildren, 16, false);
}
return layout;
}
double QuarticModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_QUARTIC_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class QuarticModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 5; }

View File

@@ -1,10 +1,18 @@
#include "trigonometric_model.h"
#include <math.h>
#include <poincare/preferences.h>
#include <poincare/layout_engine.h>
#include <assert.h>
using namespace Poincare;
namespace Regression {
ExpressionLayout * TrigonometricModel::Layout() {
static ExpressionLayout * layout = LayoutEngine::createStringLayout("asin(bX+c)", 10, KDText::FontSize::Small);
return layout;
}
double TrigonometricModel::evaluate(double * modelCoefficients, double x) const {
double a = modelCoefficients[0];
double b = modelCoefficients[1];

View File

@@ -2,12 +2,14 @@
#define REGRESSION_TRIGONOMETRIC_MODEL_H
#include "model.h"
#include <poincare/expression_layout.h>
namespace Regression {
class TrigonometricModel : public Model {
public:
using Model::Model;
static Poincare::ExpressionLayout * Layout();
double evaluate(double * modelCoefficients, double x) const override;
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
double numberOfCoefficients() const override { return 3; }

View File

@@ -1,4 +1,13 @@
#include "regression_controller.h"
#include "model/cubic_model.h"
#include "model/exponential_model.h"
#include "model/linear_model.h"
#include "model/logarithmic_model.h"
#include "model/logistic_model.h"
#include "model/power_model.h"
#include "model/quadratic_model.h"
#include "model/quartic_model.h"
#include "model/trigonometric_model.h"
#include <assert.h>
using namespace Poincare;
@@ -13,27 +22,6 @@ RegressionController::RegressionController(Responder * parentResponder, Store *
m_store(store),
m_series(-1)
{
/*// aX+b
m_regressionLayouts[0] = LayoutEngine::createStringLayout("aX+b");
// aX^2+bX+c
const ExpressionLayout * const * quadraticLayoutOperands[] = {
};
m_regressionLayouts[1]
// aX^3+bX^2+cX+d
//TODO
// aX^4+bX^3+cX^2+dX+e
//TODO
// aln(X)+b
m_regressionLayouts[4] = LayoutEngine::createStringLayout("aln(X)+b");
// ae^(bX)
//TODO
//aX^b
//TODO
// asin(bX+c)
m_regressionLayouts[7] = LayoutEngine::createStringLayout("asin(bX+c)");
// c/(1+ae^(-bX)
//TODO*/
}
const char * RegressionController::title() {
@@ -68,6 +56,39 @@ void RegressionController::willDisplayCellAtLocation(HighlightCell * cell, int i
I18n::Message messages[k_numberOfRows] = {I18n::Message::Linear, I18n::Message::Quadratic, I18n::Message::Cubic, I18n::Message::Quartic, I18n::Message::Logarithmic, I18n::Message::Exponential, I18n::Message::Power, I18n::Message::Trigonometric, I18n::Message::Logistic};
MessageTableCellWithExpression * castedCell = static_cast<MessageTableCellWithExpression *>(cell);
castedCell->setMessage(messages[j]);
switch ((Model::Type) j) {
// TODO virtualize ?
case Model::Type::Linear:
castedCell->setExpressionLayout(LinearModel::Layout());
break;
case Model::Type::Quadratic:
castedCell->setExpressionLayout(QuadraticModel::Layout());
break;
case Model::Type::Cubic:
castedCell->setExpressionLayout(CubicModel::Layout());
break;
case Model::Type::Quartic:
castedCell->setExpressionLayout(QuarticModel::Layout());
break;
case Model::Type::Logarithmic:
castedCell->setExpressionLayout(LogarithmicModel::Layout());
break;
case Model::Type::Exponential:
castedCell->setExpressionLayout(ExponentialModel::Layout());
break;
case Model::Type::Power:
castedCell->setExpressionLayout(PowerModel::Layout());
break;
case Model::Type::Trigonometric:
castedCell->setExpressionLayout(TrigonometricModel::Layout());
break;
case Model::Type::Logistic:
castedCell->setExpressionLayout(LogisticModel::Layout());
break;
default:
assert(false);
break;
}
}
}

View File

@@ -7,7 +7,7 @@
class MessageTableCellWithExpression : public MessageTableCell {
public:
MessageTableCellWithExpression(I18n::Message message = (I18n::Message)0, KDText::FontSize size = KDText::FontSize::Small);
View * subAccessoryView() const override;
View * accessoryView() const override;
void setHighlighted(bool highlight) override;
void setExpressionLayout(Poincare::ExpressionLayout * expressionLayout);
private:

View File

@@ -7,7 +7,7 @@ MessageTableCellWithExpression::MessageTableCellWithExpression(I18n::Message mes
{
}
View * MessageTableCellWithExpression::subAccessoryView() const {
View * MessageTableCellWithExpression::accessoryView() const {
return (View *)&m_subtitleView;
}