Skip to content
Permalink
Browse files

Datafilter vectors - stddev() and variance()

.. both take a single parameter (a vector) and compute the standard
   deviation and variance accordingly. sigma and sigma^2.
  • Loading branch information
liversedge committed Mar 24, 2020
1 parent 74c8fdd commit 8ee52edeee317c7232b57f73003f56138ce22097
Showing with 29 additions and 10 deletions.
  1. +21 −1 src/Core/DataFilter.cpp
  2. +8 −9 src/Metrics/Statistic.h
@@ -17,6 +17,7 @@
*/

#include "Utils.h"
#include "Statistic.h"
#include "DataFilter.h"
#include "Context.h"
#include "Athlete.h"
@@ -200,6 +201,9 @@ static struct {
// not need the data to be sorted, as it uses argsort internally. As
// you can pass multiple vectors they are uniqued in sync with the first list.

{ "variance", 1 }, // variance(v) - calculates the variance for the elements in the vector.
{ "stddev", 1 }, // stddev(v) - calculates the standard deviation for elements in the vector.


// add new ones above this line
{ "", -1 }
@@ -2948,6 +2952,7 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem
return returning;
}

// uniq
if (leaf->function == "uniq") {

// evaluate all the lists
@@ -2968,7 +2973,7 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem

// diff length?
if (current.vector.count() != len) {
fprintf(stderr, "sort list '%s': not the same length, ignored\n", symbol.toStdString().c_str()); fflush(stderr);
fprintf(stderr, "uniq list '%s': not the same length, ignored\n", symbol.toStdString().c_str()); fflush(stderr);
continue;
}

@@ -3211,6 +3216,21 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem
return returning;
}

// stddev
if (leaf->function == "variance") {
// array
Result v = eval(df,leaf->fparms[0],x, it, m, p, c, s, d);
Statistic calc;
return calc.variance(v.vector, v.vector.count());
}

if (leaf->function == "stddev") {
// array
Result v = eval(df,leaf->fparms[0],x, it, m, p, c, s, d);
Statistic calc;
return calc.standarddeviation(v.vector, v.vector.count());
}

// pmc
if (leaf->function == "pmc") {

@@ -40,15 +40,6 @@ class Statistic
double corr(QVector<double> &Xi, QVector<double> &Yi,int n);
double average(QVector<double> &Xi,int n);

protected:
long points;
double sumX, sumY;
double sumXsquared,
sumYsquared;
double sumXY;
double a, b, c; // a = intercept, b = slope, c = r2

private:
// Maths functions used by the plots
QVector<double> array_temp; //Déclaration d'un tableau temporaire

@@ -70,6 +61,14 @@ class Statistic
double variance(QVector<double> &val,int n);
double standarddeviation(QVector<double> &val,int n);

protected:
long points;
double sumX, sumY;
double sumXsquared,
sumYsquared;
double sumXY;
double a, b, c; // a = intercept, b = slope, c = r2

};

#endif

0 comments on commit 8ee52ed

Please sign in to comment.
You can’t perform that action at this time.