diff --git a/app/engine/utils/FullTSQuadraticSeries.test.js b/app/engine/utils/FullTSQuadraticSeries.test.js index 32f77f8..bccc400 100644 --- a/app/engine/utils/FullTSQuadraticSeries.test.js +++ b/app/engine/utils/FullTSQuadraticSeries.test.js @@ -1,32 +1,32 @@ 'use strict' /* - Open Rowing Monitor, https://github.com/jaapvanekris/openrowingmonitor + Open Rowing Monitor, https://github.com/laberning/openrowingmonitor - This tests the Theil-Senn estimator Quadratic Regression algorithm. As linear regression is an estimation and methods have biasses, + This tests the Quadratic Theil-Senn Regression algorithm. As regression is an estimation and methods have biasses, we need to accept some slack with respect to real-life examples */ import { test } from 'uvu' import * as assert from 'uvu/assert' -import { createTSQuadraticSeries } from './ExtremeTSQuadraticSeries.js' +import { createTSQuadraticSeries } from './FullTSQuadraticSeries.js' test('Quadratic Approximation startup behaviour', () => { const dataSeries = createTSQuadraticSeries(10) - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should be 0 at initialisation, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0, `coefficientB should be 0 at initialisation, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should be 0 at initialisation, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 0) + testCoefficientC(dataSeries, 0) dataSeries.push(-1, 2) - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should remain 0 with one datapoint, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0, `coefficientB should remain 0 with one datapoint, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should remain 0 with one datapoint, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 0) + testCoefficientC(dataSeries, 0) dataSeries.push(0, 2) - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should remain 0 with two datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0, `coefficientB should remain 0 with two datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should remain 0 with two datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 0) + testCoefficientC(dataSeries, 0) dataSeries.push(1, 6) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 with three datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2 with three datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2 with three datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) }) test('Quadratic Approximation on a perfect noisefree function y = 2 * Math.pow(x, 2) + 2 * x + 2, 21 datapoints', () => { @@ -53,9 +53,9 @@ test('Quadratic Approximation on a perfect noisefree function y = 2 * Math.pow(x dataSeries.push(8, 146) dataSeries.push(9, 182) dataSeries.push(10, 222) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) }) test('Quadratic Approximation on a perfect noisefree function y = 2 * Math.pow(x, 2) + 2 * x + 2, with 10 datapoints and some shifting in the series', () => { @@ -72,9 +72,9 @@ test('Quadratic Approximation on a perfect noisefree function y = 2 * Math.pow(x dataSeries.push(-2, 6) dataSeries.push(-1, 2) dataSeries.push(0, 2) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 after 11 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2 after 11 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2 after 11 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) dataSeries.push(1, 6) dataSeries.push(2, 14) dataSeries.push(3, 26) @@ -85,10 +85,9 @@ test('Quadratic Approximation on a perfect noisefree function y = 2 * Math.pow(x dataSeries.push(8, 146) dataSeries.push(9, 182) dataSeries.push(10, 222) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 after 21 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2 after 21 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2 after 21 datapoints, is ${dataSeries.coefficientC()}`) - // ToDo: Test after moving several points + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) }) test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, noisefree', () => { @@ -97,85 +96,85 @@ test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, no dataSeries.push(-11, 444) dataSeries.push(-10, 364) dataSeries.push(-9, 292) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 3 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 3 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 3 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-8, 228) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 4 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 4 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 4 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-7, 172) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 5 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 5 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 5 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-6, 124) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 6 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 6 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 6 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-5, 84) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 7 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 7 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 7 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-4, 52) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 8 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 8 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 8 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-3, 28) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 9 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 9 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 9 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-2, 12) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 10 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 10 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 10 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-1, 4) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 11 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 11 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 11 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(0, 4) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 12 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 12 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 12 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(1, 12) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 13 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 13 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 13 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(2, 28) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 14 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 14 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 14 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(3, 52) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 15 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 15 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 15 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(4, 84) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 16 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 16 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 16 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(5, 124) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 17 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 17 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 17 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(6, 172) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 18 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 18 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 18 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(7, 228) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 19 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 19 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 19 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(8, 292) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 20 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 20 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 20 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(9, 364) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 21 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 21 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 21 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(10, 444) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 22 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 22 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 4, `coefficientC should be 4 after 22 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) }) test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, with some noise (+/- 1)', () => { @@ -184,85 +183,85 @@ test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, wi dataSeries.push(-11, 443) dataSeries.push(-10, 365) dataSeries.push(-9, 291) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 after 3 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === -36, `coefficientB should be 4 after 3 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === -195, `coefficientC should be 4 after 3 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, -36) + testCoefficientC(dataSeries, -195) dataSeries.push(-8, 229) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 4 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.666666666666666, `coefficientB should be 4.666666666666666 after 4 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 10.333333333333332, `coefficientC should be 10.333333333333332 after 4 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 3.6666666666666643) // This is quite acceptable as ORM ignores the C dataSeries.push(-7, 171) - assert.ok(dataSeries.coefficientA() === 3.666666666666667, `coefficientA should be 3.666666666666667 after 5 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === -2.3333333333333335, `coefficientB should be -2.3333333333333335 after 5 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === -25, `coefficientC should be -25 after 5 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 3.3333333333333335) + testCoefficientB(dataSeries, -7.999999999999995) + testCoefficientC(dataSeries, -48.999999999999964) dataSeries.push(-6, 125) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 6 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.533333333333333, `coefficientB should be 4.533333333333333 after 6 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 8.2, `coefficientC should be 8.2 after 6 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 3.799999999999997) // This is quite acceptable as ORM ignores the C dataSeries.push(-5, 83) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 7 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 3.3333333333333335, `coefficientB should be 3.3333333333333335 after 7 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === -0.3333333333333339, `coefficientC should be -0.3333333333333339 after 7 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 3.8666666666666667) + testCoefficientB(dataSeries, 1.8666666666666742) + testCoefficientC(dataSeries, -4.111111111111047) dataSeries.push(-4, 53) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 8 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.4, `coefficientB should be 4 after 8 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 6.6000000000000005, `coefficientC should be 3 after 8 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 3.8571428571428577) // This is quite acceptable as ORM ignores the C dataSeries.push(-3, 27) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 9 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 3.5999999999999996, `coefficientB should be 4 after 9 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 1.4, `coefficientC should be 1.4 after 9 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(-2, 13) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 10 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.285714285714286, `coefficientB should be 4.285714285714286 after 10 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 5.685714285714285, `coefficientC should be 5.685714285714285 after 10 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 3.8888888888888893) // This is quite acceptable as ORM ignores the C dataSeries.push(-1, 3) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 11 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 3.7142857142857144, `coefficientB should be 3.7142857142857144 after 11 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3, `coefficientC should be 3 after 11 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(0, 5) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 12 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.253968253968254, `coefficientB should be 4.253968253968254 after 12 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 5, `coefficientC should be 5 after 12 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(1, 11) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 13 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 3.7777777777777777, `coefficientB should be 3.7777777777777777 after 13 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.857142857142857, `coefficientC should be 3.857142857142857 after 13 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(2, 29) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 14 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.222222222222222, `coefficientB should be 4.222222222222222 after 14 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.933333333333333, `coefficientC should be 3.933333333333333 after 14 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(3, 51) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 15 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 15 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.022222222222222, `coefficientC should be 4.022222222222222 after 15 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(4, 85) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 16 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 16 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.022222222222222, `coefficientC should be 4.022222222222222 after 16 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(5, 123) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 17 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 17 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.933333333333333, `coefficientC should be 3.933333333333333 after 17 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(6, 173) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 18 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 18 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.111111111111111, `coefficientC should be 4.111111111111111 after 18 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(7, 227) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 19 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 19 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.933333333333333, `coefficientC should be 3.933333333333333 after 19 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(8, 293) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 20 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 20 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.111111111111111, `coefficientC should be 4.111111111111111 after 20 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(9, 363) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 21 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 21 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.933333333333333, `coefficientC should be 3.933333333333333 after 21 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(10, 444) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 22 datapoints, is ${dataSeries.coefficientA()}`) - // assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 22 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.111111111111111, `coefficientC should be 4.111111111111111 after 22 datapoints, is ${dataSeries.coefficientC()}`) // We get a 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) }) test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, with some noise (+/- 1) and spikes (+/- 9)', () => { @@ -276,65 +275,65 @@ test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, wi dataSeries.push(-6, 125) dataSeries.push(-5, 83) dataSeries.push(-4, 53) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 8 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.4, `coefficientB should be 4.4 after 8 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 6.6000000000000005, `coefficientC should be 6.6000000000000005 after 8 datapoints, is ${dataSeries.coefficientC()}`) // We get a 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) - dataSeries.push(-3, 37) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 9 datapoints (first spike, +9), is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.666666666666666, `coefficientB should be 4.666666666666666 after 9 datapoints (first spike, +9), is ${dataSeries.coefficientB()}`) // Coefficient B seems to take a hit anyway - assert.ok(dataSeries.coefficientC() === 9.666666666666666, `coefficientC should remain 9.666666666666666 after 9 datapoints (first spike, +9), is ${dataSeries.coefficientC()}`) // We get a 11.4 instead of 4, which is quite acceptable (especially since ORM ignores the C) - dataSeries.push(-2, 3) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should return to 4 after 10 datapoints (second spike, -9), is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.342857142857143, `coefficientB should be 4.342857142857143 after 10 datapoints (second spike, -9), is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 6.371428571428572, `coefficientC should be 6.371428571428572 after 10 datapoints (second spike, -9), is ${dataSeries.coefficientC()}`) // We get 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 3.8571428571428577) + dataSeries.push(-3, 37) // FIRST SPIKE +9 + testCoefficientA(dataSeries, 4.215277777777778) + testCoefficientB(dataSeries, 7.321527777777776) + testCoefficientC(dataSeries, 15.671874999999993) + dataSeries.push(-2, 3) // SECOND SPIKE -9 + testCoefficientA(dataSeries, 3.9714285714285715) + testCoefficientB(dataSeries, 3.78571428571429) // Coefficient B seems to take a hit anyway + testCoefficientC(dataSeries, 5.09047619047621) // We get a 5.9999999999999964 instead of 4, which is quite acceptable (especially since ORM ignores the C) dataSeries.push(-1, 3) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 11 datapoints, is ${dataSeries.coefficientA()}`) // Coefficient A seems to take a hit anyway - assert.ok(dataSeries.coefficientB() === 3.8476190476190473, `coefficientB should be 3.8476190476190473 after 11 datapoints, is ${dataSeries.coefficientB()}`) // Coefficient B seems to take a hit anyway - assert.ok(dataSeries.coefficientC() === 2.8412698412698414, `coefficientC should be 2.8412698412698414 after 11 datapoints, is ${dataSeries.coefficientC()}`) // We get a 2.3333333333333357 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 3.9555555555555557) + testCoefficientB(dataSeries, 3.37777777777778) + testCoefficientC(dataSeries, 2.2000000000000064) dataSeries.push(0, 5) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 12 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.2253968253968255, `coefficientB should be 3.8095238095238093 after 12 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 5, `coefficientC should be 5 after 12 datapoints, is ${dataSeries.coefficientC()}`) // We get a 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(1, 11) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 13 datapoints, is ${dataSeries.coefficientA()}`) // Coefficient A seems to take a small hit anyway - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should return to 4 after 13 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 5, `coefficientC should be 5 after 13 datapoints, is ${dataSeries.coefficientC()}`) // We get a 3.719999999999997 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(2, 29) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 14 datapoints, is ${dataSeries.coefficientA()}`) // Coefficient A seems to take a small hit anyway - assert.ok(dataSeries.coefficientB() === 4.165079365079365, `coefficientB should be 4.165079365079365 after 14 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 5, `coefficientC should be 5 after 14 datapoints, is ${dataSeries.coefficientC()}`) // We get a 5 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(3, 51) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should be 4 after 15 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should be 4 after 15 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.648888888888889, `coefficientC should be 3.648888888888889 after 15 datapoints, is ${dataSeries.coefficientC()}`) // This is quite acceptable as ORM ignores the C + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(4, 85) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 16 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.156190476190476, `coefficientB should be 4.156190476190476 after 16 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.648888888888889, `coefficientC should be 3.6488888888888877 after 16 datapoints, is ${dataSeries.coefficientC()}`) // This is quite acceptable as ORM ignores the C + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(5, 123) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 17 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should remain 4 after 17 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.72, `coefficientC should be 3.72 after 17 datapoints, is ${dataSeries.coefficientC()}`) // This is quite acceptable as ORM ignores the C + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(6, 173) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 18 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.152380952380953, `coefficientB should remain 4.152380952380953 after 18 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.111111111111111, `coefficientC should be 4.111111111111111 after 18 datapoints, is ${dataSeries.coefficientC()}`) // This is quite acceptable as ORM ignores the C + testCoefficientA(dataSeries, 4.044444444444444) + testCoefficientB(dataSeries, 3.8222222222222215) + testCoefficientC(dataSeries, 3.711111111111112) dataSeries.push(7, 227) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 19 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should remain 4 after 19 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.7885714285714287, `coefficientC should be 3.7885714285714287 after 19 datapoints, is ${dataSeries.coefficientC()}`) // This is quite acceptable as ORM ignores the C + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) dataSeries.push(8, 293) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 20 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 3.8666666666666663, `coefficientB should BE 3.8666666666666663 after 20 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.4380952380952383, `coefficientC should be 3.4380952380952383 after 20 datapoints, is ${dataSeries.coefficientC()}`) // This is quite acceptable as ORM ignores the C + testCoefficientA(dataSeries, 3.9047619047619047) + testCoefficientB(dataSeries, 4.761904761904762) + testCoefficientC(dataSeries, 2.47619047619048) // This is quite acceptable as ORM ignores the C dataSeries.push(9, 363) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 21 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4, `coefficientB should remain 4 after 21 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 3.72, `coefficientC should remain 3.72 after 21 datapoints, is ${dataSeries.coefficientC()}`) // We get a 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) // We get a 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) dataSeries.push(10, 444) - assert.ok(dataSeries.coefficientA() === 4, `coefficientA should remain 4 after 22 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 4.16, `coefficientB should be 4 after 22 datapoints, is ${dataSeries.coefficientB()}`) - // assert.ok(dataSeries.coefficientC() === 4.533333333333333, `coefficientC should be 4.533333333333333 after 22 datapoints, is ${dataSeries.coefficientC()}`) // We get a 3 instead of 4, which is quite acceptable (especially since ORM ignores the C) + testCoefficientA(dataSeries, 4) + testCoefficientB(dataSeries, 4) + testCoefficientC(dataSeries, 4) }) test('Quadratic TS Estimation should be decent for standard real-life example from MathBits with some noise', () => { @@ -353,9 +352,9 @@ test('Quadratic TS Estimation should be decent for standard real-life example fr dataSeries.push(58, 244.2) dataSeries.push(60, 231.4) dataSeries.push(64, 180.4) - assert.ok(dataSeries.coefficientA() === -0.17785023090944152, `coefficientA should be -0.1762309523809523, is ${dataSeries.coefficientA()}`) // In the example, the TI084 results in -0.1737141137, which we consider acceptably close - assert.ok(dataSeries.coefficientB() === 15.005518925518913, `coefficientB should be 15.005518925518913, is ${dataSeries.coefficientB()}`) // In the example, the TI084 results in 14.52117133, which we consider acceptably close - assert.ok(dataSeries.coefficientC() === -38.95847069597062, `coefficientC should be -38.95847069597062, is ${dataSeries.coefficientC()}`) // In the example, the TI084 results in -21.89774466, which we consider acceptably close + testCoefficientA(dataSeries, -0.17702838827838824) // In the example, the TI084 results in -0.1737141137, which we consider acceptably close + testCoefficientB(dataSeries, 15.059093406593405) // In the example, the TI084 results in 14.52117133, which we consider acceptably close + testCoefficientC(dataSeries, -34.880354853479844) // In the example, the TI084 results in -21.89774466, which we consider acceptably close }) test('Quadratic TS Estimation should be decent for standard real-life example from VarsityTutors with some noise', () => { @@ -368,9 +367,9 @@ test('Quadratic TS Estimation should be decent for standard real-life example fr dataSeries.push(1, 3) dataSeries.push(2, 6) dataSeries.push(3, 14) - assert.ok(dataSeries.coefficientA() === 1.1166666666666667, `coefficientA should be 1.0666666666666667, is ${dataSeries.coefficientA()}`) // The example results in 1.1071 for OLS, which we consider acceptably close - assert.ok(dataSeries.coefficientB() === 1.125, `coefficientB should be 1.1666666666666667, is ${dataSeries.coefficientB()}`) // The example results in 1 for OLS, which we consider acceptably close - assert.ok(dataSeries.coefficientC() === 1, `coefficientC should be 1, is ${dataSeries.coefficientC()}`) // The example results in 0.5714 for OLS, which we consider acceptably close + testCoefficientA(dataSeries, 1.0833333333333333) // The example results in 1.1071 for OLS, which we consider acceptably close + testCoefficientB(dataSeries, 0.9166666666666667) // The example results in 1 for OLS, which we consider acceptably close + testCoefficientC(dataSeries, 0.527777777777778) // The example results in 0.5714 for OLS, which we consider acceptably close }) test('Quadratic TS Estimation should be decent for standard example from VTUPulse with some noise, without the vertex being part of the dataset', () => { @@ -381,9 +380,9 @@ test('Quadratic TS Estimation should be decent for standard example from VTUPuls dataSeries.push(5, 3.8) dataSeries.push(6, 6.5) dataSeries.push(7, 11.5) - assert.ok(dataSeries.coefficientA() === 0.9500000000000005, `coefficientA should be 0.9500000000000005, is ${dataSeries.coefficientA()}`) // The example results in 0.7642857 for OLS, which we consider acceptably close - assert.ok(dataSeries.coefficientB() === -7.574999999999999, `coefficientB should be -7.574999999999999, is ${dataSeries.coefficientB()}`) // The example results in -5.5128571 for OLS, which we consider acceptably close - assert.ok(dataSeries.coefficientC() === 17.92500000000001, `coefficientC should be 17.925000000000004, is ${dataSeries.coefficientC()}`) // The example results in 12.4285714 for OLS, which we consider acceptably close + testCoefficientA(dataSeries, 0.8583333333333334) // The example results in 0.7642857 for OLS, which we consider acceptably close given the small sample size + testCoefficientB(dataSeries, -6.566666666666666) // The example results in -5.5128571 for OLS, which we consider acceptably close given the small sample size + testCoefficientC(dataSeries, 15.12083333333333) // The example results in 12.4285714 for OLS, which we consider acceptably close given the small sample size }) test('Quadratic TS Estimation should be decent for standard real-life example from Uni Berlin with some noise without the vertex being part of the dataset', () => { @@ -414,9 +413,9 @@ test('Quadratic TS Estimation should be decent for standard real-life example fr dataSeries.push(0.102696671, 0.27621694) dataSeries.push(0.715372314, -1.20379729) dataSeries.push(0.681745393, -0.83059624) - assert.ok(dataSeries.coefficientA() === -3.13052236289358, `coefficientA should be -3.13052236289358, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0.8866733959812066, `coefficientB should be 0.8866733959812066, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0.4378745643345563, `coefficientC should be 0.4378745643345563, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, -2.030477132951317) + testCoefficientB(dataSeries, 0.6253742507247935) + testCoefficientC(dataSeries, 0.2376050557383506) }) test('Quadratic TS Estimation should be decent for standard real-life example from Statology.org with some noise and chaotic X values', () => { @@ -433,9 +432,27 @@ test('Quadratic TS Estimation should be decent for standard real-life example fr dataSeries.push(51, 59) dataSeries.push(55, 44) dataSeries.push(60, 27) - assert.ok(dataSeries.coefficientA() === -0.10466531440162272, `coefficientA should be -0.10466531440162272, is ${dataSeries.coefficientA()}`) // The example results in -0.1012 for R after two rounds, which we consider acceptably close - assert.ok(dataSeries.coefficientB() === 7.049898580121704, `coefficientB should be 6.854724080267559, is ${dataSeries.coefficientB()}`) // The example results in 6.7444 for R after two rounds, which we consider acceptably close - assert.ok(dataSeries.coefficientC() === -24.531440162271807, `coefficientC should be -24.531440162271807, is ${dataSeries.coefficientC()}`) // The example results in 18.2536 for R after two rounds, but for ORM, this factor is irrelevant + testCoefficientA(dataSeries, -0.10119047619047619) // The example results in -0.1012 for R after two rounds, which we consider acceptably close + testCoefficientB(dataSeries, 6.767857142857142) // The example results in 6.7444 for R after two rounds, which we consider acceptably close + testCoefficientC(dataSeries, -19.458333333333314) // The example results in 18.2536 for R after two rounds, but for ORM, this factor is irrelevant +}) + +test('Quadratic TS Estimation should be decent for standard real-life example from StatsDirect.com with some noise and chaotic X values', () => { + // Test based on https://www.statsdirect.com/help/regression_and_correlation/polynomial.htm + const dataSeries = createTSQuadraticSeries(10) + dataSeries.push(1290, 1182) + dataSeries.push(1350, 1172) + dataSeries.push(1470, 1264) + dataSeries.push(1600, 1493) + dataSeries.push(1710, 1571) + dataSeries.push(1840, 1711) + dataSeries.push(1980, 1804) + dataSeries.push(2230, 1840) + dataSeries.push(2400, 1956) + dataSeries.push(2930, 1954) + testCoefficientA(dataSeries, -0.00046251263566907585) // The example results in -0.00045 through QR decomposition by Givens rotations, which we consider acceptably close + testCoefficientB(dataSeries, 2.429942262608943) // The example results in 2.39893 for QR decomposition by Givens rotations, which we consider acceptably close + testCoefficientC(dataSeries, -1230.9398743132388) // The example results in -1216.143887 for QR decomposition by Givens rotations, but for ORM, this factor is irrelevant }) test('Quadratic Approximation with a clean function and a reset', () => { @@ -447,9 +464,9 @@ test('Quadratic Approximation with a clean function and a reset', () => { dataSeries.push(-7, 86) dataSeries.push(-6, 62) dataSeries.push(-5, 42) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 after 6 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2 after 6 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2 after 6 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) dataSeries.push(-4, 26) dataSeries.push(-3, 14) // Pi ;) dataSeries.push(-2, 6) @@ -457,9 +474,9 @@ test('Quadratic Approximation with a clean function and a reset', () => { dataSeries.push(0, 2) dataSeries.push(1, 6) dataSeries.push(2, 14) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 after 13 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2 after 13 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2 after 13 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) dataSeries.push(3, 26) dataSeries.push(4, 42) dataSeries.push(5, 62) @@ -468,29 +485,29 @@ test('Quadratic Approximation with a clean function and a reset', () => { dataSeries.push(8, 146) dataSeries.push(9, 182) dataSeries.push(10, 222) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2 after 21 datapoints, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2 after 21 datapoints, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2 after 21 datapoints, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) dataSeries.reset() - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should be 0 after reset, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0, `coefficientB should be 0 after reset, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should be 0 after reset, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 0) + testCoefficientC(dataSeries, 0) dataSeries.push(-1, 2) - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should remain 0 with one datapoint, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0, `coefficientB should remain 0 with one datapoint, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should remain 0 with one datapoint, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 0) + testCoefficientC(dataSeries, 0) dataSeries.push(0, 2) - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should remain 0 with two datapoint, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 0, `coefficientB should remain 0 with two datapoint, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should remain 0 with two datapoint, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 0) + testCoefficientC(dataSeries, 0) dataSeries.push(1, 6) - assert.ok(dataSeries.coefficientA() === 2, `coefficientA should be 2, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 2, `coefficientB should be 2, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 2, `coefficientC should be 2, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 2) + testCoefficientB(dataSeries, 2) + testCoefficientC(dataSeries, 2) }) -test('Quadratic TS Estimation should result in a line for y = x (edge case!)', () => { - // As ORM might encounter straight lines, we need to test this as well +test('Quadratic TS Estimation should result in a straight line for function y = x', () => { + // As ORM will encounter straight lines (when forces are balanced on the flywheel, there is no acceleration/deceleration), so we need to test this as well const dataSeries = createTSQuadraticSeries(7) dataSeries.push(0, 0) dataSeries.push(1, 1) @@ -499,9 +516,31 @@ test('Quadratic TS Estimation should result in a line for y = x (edge case!)', ( dataSeries.push(4, 4) dataSeries.push(5, 5) dataSeries.push(6, 6) - assert.ok(dataSeries.coefficientA() === 0, `coefficientA should be 0, is ${dataSeries.coefficientA()}`) - assert.ok(dataSeries.coefficientB() === 1, `coefficientB should be 1, is ${dataSeries.coefficientB()}`) - assert.ok(dataSeries.coefficientC() === 0, `coefficientC should be 0, is ${dataSeries.coefficientC()}`) + testCoefficientA(dataSeries, 0) + testCoefficientB(dataSeries, 1) + testCoefficientC(dataSeries, 0) }) +function testCoefficientA (series, expectedValue) { + assert.ok(series.coefficientA() === expectedValue, `Expected value for coefficientA at X-position ${series.xAtSeriesEnd()} is ${expectedValue}, encountered a ${series.coefficientA()}`) +} + +function testCoefficientB (series, expectedValue) { + assert.ok(series.coefficientB() === expectedValue, `Expected value for coefficientB at X-position ${series.xAtSeriesEnd()} is ${expectedValue}, encountered a ${series.coefficientB()}`) +} + +function testCoefficientC (series, expectedValue) { + assert.ok(series.coefficientC() === expectedValue, `Expected value for coefficientC at X-position ${series.xAtSeriesEnd()} is ${expectedValue}, encountered a ${series.coefficientC()}`) +} + +/* +function testSlope (series, position, expectedValue) { + assert.ok(series.slope(position) === expectedValue, `Expected value for Slope-${position} at X-position ${series.xAtSeriesEnd()} (slope at X-position ${series.xAtPosition(position)}) is ${expectedValue}, encountered a ${series.slope(position)}`) +} + +function reportAll (series) { + assert.ok(series.coefficientA() === 99, `time: ${series.xAtSeriesEnd()}, coefficientA: ${series.coefficientA()}, coefficientB: ${series.coefficientB()}, coefficientC: ${series.coefficientC()}, Slope-10: ${series.slope(10)}, Slope-9: ${series.slope(9)}, Slope-8: ${series.slope(8)}, Slope-7: ${series.slope(7)}, Slope-6: ${series.slope(6)}, Slope-5: ${series.slope(5)}, Slope-4: ${series.slope(4)}, Slope-3: ${series.slope(3)}, Slope-2: ${series.slope(2)}, Slope-1: ${series.slope(1)}, Slope-0: ${series.slope(0)}`) +} +*/ + test.run()