Commit eaf1bd51 authored by Stefan Gerlach's avatar Stefan Gerlach
Browse files

[Smooth] switch to method 7 as default to be consistent with median smoothing

parent ee99aec3
......@@ -355,8 +355,8 @@ int nsl_smooth_percentile(double *data, size_t n, size_t points, double percenti
}
/*puts("");*/
/*using type 4 as default */
result[i] = nsl_stats_quantile(values, 1, np, percentile, nsl_stats_quantile_type4);
/*using type 7 as default */
result[i] = nsl_stats_quantile(values, 1, np, percentile, nsl_stats_quantile_type7);
free(values);
}
......
......@@ -42,7 +42,7 @@ extern const char* nsl_smooth_type_name[];
* interp: polynomial interpolation
* mirror: 3 2 | 1 2 3 4 5 | 4 3 (reflect)
* nearest: 1 1 | 1 2 3 4 5 | 5 5 (repeat)
* constant: V V | 1 2 3 4 5 | V V
* constant: L L | 1 2 3 4 5 | R R
* periodic: 4 5 | 1 2 3 4 5 | 1 2 (wrap)
*/
#define NSL_SMOOTH_PAD_MODE_COUNT 6
......
......@@ -78,6 +78,7 @@ double nsl_stats_median_sorted(const double sorted_data[], size_t stride, size_t
}
double nsl_stats_median_from_sorted_data(const double sorted_data[], size_t stride, size_t n) {
// default method is number 7
return nsl_stats_median_sorted(sorted_data, stride, n, nsl_stats_quantile_type7);
}
......@@ -89,7 +90,7 @@ double nsl_stats_quantile(double data[], size_t stride, size_t n, double p, nsl_
double nsl_stats_quantile_sorted(const double d[], size_t stride, size_t n, double p, nsl_stats_quantile_type type) {
switch(type) {
case nsl_stats_quantile_type1:
case nsl_stats_quantile_type1: // h = Np + 1/2, x[ceil(h – 1/2)]
if (p == 0.0)
return d[0];
else
......
......@@ -31,7 +31,8 @@
#include <stdlib.h>
/* estimation types of quantile (see https://en.wikipedia.org/wiki/Quantile) */
/* estimation types of quantile (see https://en.wikipedia.org/wiki/Quantile,
* https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mstats.mquantiles.html) */
#define NSL_STATS_QUANTILE_TYPE_COUNT 9
typedef enum {nsl_stats_quantile_type1=1, nsl_stats_quantile_type2, nsl_stats_quantile_type3, nsl_stats_quantile_type4,
nsl_stats_quantile_type5, nsl_stats_quantile_type6, nsl_stats_quantile_type7, nsl_stats_quantile_type8,
......
......@@ -2458,8 +2458,8 @@ bool XYFitCurve::load(XmlStreamReader* reader, bool preview) {
DEBUG("XYFitCurve::load() model type = " << d->fitData.modelType);
DEBUG("XYFitCurve::load() # params = " << d->fitData.paramNames.size());
DEBUG("XYFitCurve::load() # start values = " << d->fitData.paramStartValues.size());
for (const auto& value : d->fitData.paramStartValues)
DEBUG("XYFitCurve::load() # start value = " << value);
//for (const auto& value : d->fitData.paramStartValues)
// DEBUG("XYFitCurve::load() # start value = " << value);
if (preview)
return true;
......
......@@ -106,6 +106,7 @@ XYSmoothCurvePrivate::XYSmoothCurvePrivate(XYSmoothCurve* owner) : XYAnalysisCur
XYSmoothCurvePrivate::~XYSmoothCurvePrivate() = default;
void XYSmoothCurvePrivate::recalculate() {
DEBUG("XYSmoothCurvePrivate::recalculate()")
QElapsedTimer timer;
timer.start();
......@@ -213,35 +214,35 @@ void XYSmoothCurvePrivate::recalculate() {
const nsl_smooth_weight_type weight = smoothData.weight;
const double percentile = smoothData.percentile;
const int order = smoothData.order;
const nsl_smooth_pad_mode mode = smoothData.mode;
const nsl_smooth_pad_mode padMode = smoothData.mode;
const double lvalue = smoothData.lvalue;
const double rvalue = smoothData.rvalue;
DEBUG("type:"<<nsl_smooth_type_name[type]);
DEBUG("points ="<<points);
DEBUG("weight:"<<nsl_smooth_weight_type_name[weight]);
DEBUG("percentile ="<<percentile);
DEBUG("order ="<<order);
DEBUG("mode ="<<nsl_smooth_pad_mode_name[mode]);
DEBUG("const. values ="<<lvalue<<rvalue);
DEBUG(" smooth type:" << nsl_smooth_type_name[type]);
DEBUG(" points = " << points);
DEBUG(" weight: " << nsl_smooth_weight_type_name[weight]);
DEBUG(" percentile = " << percentile);
DEBUG(" order = " << order);
DEBUG(" pad mode = " << nsl_smooth_pad_mode_name[padMode]);
DEBUG(" const. values = " << lvalue << ' ' << rvalue);
///////////////////////////////////////////////////////////
int status = 0;
switch (type) {
case nsl_smooth_type_moving_average:
status = nsl_smooth_moving_average(ydata, n, points, weight, mode);
status = nsl_smooth_moving_average(ydata, n, points, weight, padMode);
break;
case nsl_smooth_type_moving_average_lagged:
status = nsl_smooth_moving_average_lagged(ydata, n, points, weight, mode);
status = nsl_smooth_moving_average_lagged(ydata, n, points, weight, padMode);
break;
case nsl_smooth_type_percentile:
status = nsl_smooth_percentile(ydata, n, points, percentile, mode);
status = nsl_smooth_percentile(ydata, n, points, percentile, padMode);
break;
case nsl_smooth_type_savitzky_golay:
if (mode == nsl_smooth_pad_constant)
if (padMode == nsl_smooth_pad_constant)
nsl_smooth_pad_constant_set(lvalue, rvalue);
status = nsl_smooth_savgol(ydata, n, points, order, mode);
status = nsl_smooth_savgol(ydata, n, points, order, padMode);
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment