mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[app/reg] Model layouts are accessible through virtual method
This commit is contained in:
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * CubicModel::Layout() {
|
||||
ExpressionLayout * CubicModel::layout() {
|
||||
static ExpressionLayout * layout = nullptr;
|
||||
if (layout == nullptr) {
|
||||
const ExpressionLayout * layoutChildren[] = {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class CubicModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * ExponentialModel::Layout() {
|
||||
ExpressionLayout * ExponentialModel::layout() {
|
||||
static ExpressionLayout * layout = nullptr;
|
||||
if (layout == nullptr) {
|
||||
const ExpressionLayout * layoutChildren[] = {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class ExponentialModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * LinearModel::Layout() {
|
||||
ExpressionLayout * LinearModel::layout() {
|
||||
static ExpressionLayout * layout = LayoutEngine::createStringLayout("aX+b", 4, KDText::FontSize::Small);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class LinearModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * LogarithmicModel::Layout() {
|
||||
ExpressionLayout * LogarithmicModel::layout() {
|
||||
static ExpressionLayout * layout = LayoutEngine::createStringLayout("aln(X)+b", 8, KDText::FontSize::Small);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class LogarithmicModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * LogisticModel::Layout() {
|
||||
ExpressionLayout * LogisticModel::layout() {
|
||||
static ExpressionLayout * layout = nullptr;
|
||||
if (layout == nullptr) {
|
||||
const ExpressionLayout * layoutChildren[] = {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class LogisticModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
static constexpr int k_numberOfModels = 9;
|
||||
static constexpr int k_maxNumberOfCoefficients = 5;
|
||||
virtual ~Model() = default;
|
||||
virtual Poincare::ExpressionLayout * layout() = 0;
|
||||
virtual double evaluate(double * modelCoefficients, double x) const = 0;
|
||||
virtual double levelSet(double * modelCoefficients, double y) const = 0;
|
||||
virtual void fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context);
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * PowerModel::Layout() {
|
||||
ExpressionLayout * PowerModel::layout() {
|
||||
static ExpressionLayout * layout = nullptr;
|
||||
if (layout == nullptr) {
|
||||
const ExpressionLayout * layoutChildren[] = {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class PowerModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * QuadraticModel::Layout() {
|
||||
ExpressionLayout * QuadraticModel::layout() {
|
||||
static ExpressionLayout * layout = nullptr;
|
||||
if (layout == nullptr) {
|
||||
const ExpressionLayout * layoutChildren[] = {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class QuadraticModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * QuarticModel::Layout() {
|
||||
ExpressionLayout * QuarticModel::layout() {
|
||||
static ExpressionLayout * layout = nullptr;
|
||||
if (layout == nullptr) {
|
||||
const ExpressionLayout * layoutChildren[] = {
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class QuarticModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -8,7 +8,7 @@ using namespace Poincare;
|
||||
|
||||
namespace Regression {
|
||||
|
||||
ExpressionLayout * TrigonometricModel::Layout() {
|
||||
ExpressionLayout * TrigonometricModel::layout() {
|
||||
static ExpressionLayout * layout = LayoutEngine::createStringLayout("asin(bX+c)", 10, KDText::FontSize::Small);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Regression {
|
||||
class TrigonometricModel : public Model {
|
||||
public:
|
||||
using Model::Model;
|
||||
static Poincare::ExpressionLayout * Layout();
|
||||
Poincare::ExpressionLayout * layout() override;
|
||||
double evaluate(double * modelCoefficients, double x) const override;
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
|
||||
@@ -79,39 +79,7 @@ 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;
|
||||
}
|
||||
castedCell->setExpressionLayout(m_store->regressionModel((Model::Type) j)->layout());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ public:
|
||||
/* Return the closest dot to given dot, on the right if direction > 0,
|
||||
* on the left otherwise */
|
||||
int nextDot(int series, int direction, int dot);
|
||||
Model * regressionModel(Model::Type type) {
|
||||
return m_regressionModels[(int) type];
|
||||
}
|
||||
|
||||
// Window
|
||||
void setDefault() override;
|
||||
|
||||
Reference in New Issue
Block a user