mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/reg] Prevent fitting when data not suitable
This commit is contained in:
@@ -84,10 +84,7 @@ void CalculationController::tableViewDidChangeSelection(SelectableTableView * t,
|
||||
}
|
||||
|
||||
bool CalculationController::isEmpty() const {
|
||||
if (m_store->numberOfPairs() == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return m_store->isEmpty();
|
||||
}
|
||||
|
||||
I18n::Message CalculationController::emptyMessage() {
|
||||
|
||||
@@ -27,22 +27,11 @@ ViewController * GraphController::initialisationParameterController() {
|
||||
}
|
||||
|
||||
bool GraphController::isEmpty() const {
|
||||
if (m_store->isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (int series = 0; series < DoublePairStore::k_numberOfSeries; series++) {
|
||||
if (!m_store->seriesIsEmpty(series) && !std::isinf(m_store->slope(series)) && !std::isnan(m_store->slope(series))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return m_store->isEmpty();
|
||||
}
|
||||
|
||||
I18n::Message GraphController::emptyMessage() {
|
||||
if (m_store->numberOfPairs() == 0) {
|
||||
return I18n::Message::NoDataToPlot;
|
||||
}
|
||||
return I18n::Message::NoEnoughDataForRegression;
|
||||
return I18n::Message::NoDataToPlot;
|
||||
}
|
||||
|
||||
void GraphController::viewWillAppear() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "logarithmic_model.h"
|
||||
#include "../store.h"
|
||||
#include <math.h>
|
||||
#include <poincare/layout_engine.h>
|
||||
#include <assert.h>
|
||||
@@ -35,6 +36,7 @@ double LogarithmicModel::levelSet(double * modelCoefficients, double y) const {
|
||||
double LogarithmicModel::partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const {
|
||||
if (derivateCoefficientIndex == 0) {
|
||||
// Derivate: ln(x)
|
||||
assert(x >0);
|
||||
return log(x);
|
||||
}
|
||||
if (derivateCoefficientIndex == 1) {
|
||||
@@ -45,4 +47,17 @@ double LogarithmicModel::partialDerivate(double * modelCoefficients, int derivat
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool LogarithmicModel::dataSuitableForFit(Store * store, int series) const {
|
||||
if (!Model::dataSuitableForFit(store, series)) {
|
||||
return false;
|
||||
}
|
||||
int numberOfPairs = store->numberOfPairsOfSeries(series);
|
||||
for (int j = 0; j < numberOfPairs; j++) {
|
||||
if (store->get(series, 0, j) <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
int numberOfCoefficients() const override { return 2; }
|
||||
protected:
|
||||
virtual bool dataSuitableForFit(Store * store, int series) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,17 @@ using namespace Shared;
|
||||
namespace Regression {
|
||||
|
||||
void Model::fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context) {
|
||||
fitLevenbergMarquardt(store, series, modelCoefficients, context);
|
||||
if (dataSuitableForFit(store, series)) {
|
||||
fitLevenbergMarquardt(store, series, modelCoefficients, context);
|
||||
} else {
|
||||
for (int i = 0; i < numberOfCoefficients(); i++) {
|
||||
modelCoefficients[i] = NAN; //TODO undef /inf ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Model::dataSuitableForFit(Store * store, int series) const {
|
||||
return !store->seriesIsEmpty(series) && !std::isinf(store->slope(series)) && !std::isnan(store->slope(series));
|
||||
}
|
||||
|
||||
void Model::fitLevenbergMarquardt(Store * store, int series, double * modelCoefficients, Context * context) {
|
||||
|
||||
@@ -33,6 +33,9 @@ public:
|
||||
virtual double levelSet(double * modelCoefficients, double y) const = 0;
|
||||
virtual void fit(Store * store, int series, double * modelCoefficients, Poincare::Context * context);
|
||||
virtual int numberOfCoefficients() const = 0;
|
||||
protected:
|
||||
// Fit
|
||||
virtual bool dataSuitableForFit(Store * store, int series) const;
|
||||
private:
|
||||
// Model attributes
|
||||
virtual double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const = 0;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "power_model.h"
|
||||
#include "../store.h"
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include "../../poincare/include/poincare_layouts.h"
|
||||
@@ -66,4 +67,18 @@ double PowerModel::partialDerivate(double * modelCoefficients, int derivateCoeff
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool PowerModel::dataSuitableForFit(Store * store, int series) const {
|
||||
if (!Model::dataSuitableForFit(store, series)) {
|
||||
return false;
|
||||
}
|
||||
int numberOfPairs = store->numberOfPairsOfSeries(series);
|
||||
for (int j = 0; j < numberOfPairs; j++) {
|
||||
if (store->get(series, 0, j) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
double levelSet(double * modelCoefficients, double y) const override;
|
||||
double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const override;
|
||||
int numberOfCoefficients() const override { return 2; }
|
||||
protected:
|
||||
virtual bool dataSuitableForFit(Store * store, int series) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user