Adaptation to performance and accuracy improvements

Improvement of the FullTS performance and accuracy
This commit is contained in:
Jaap van Ekris 2023-12-03 20:34:03 +01:00 committed by GitHub
parent 57cde02953
commit c1d365ac4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 233 additions and 272 deletions

View File

@ -1,32 +1,32 @@
'use strict'
/*
Open Rowing Monitor, https://github.com/laberning/openrowingmonitor
Open Rowing Monitor, https://github.com/jaapvanekris/openrowingmonitor
This tests the Quadratic Theil-Senn Regression algorithm. As regression is an estimation and methods have biasses,
This tests the Theil-Senn estimator Quadratic Regression algorithm. As linear 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 './FullTSQuadraticSeries.js'
import { createTSQuadraticSeries } from './ExtremeTSQuadraticSeries.js'
test('Quadratic Approximation startup behaviour', () => {
const dataSeries = createTSQuadraticSeries(10)
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 0)
testCoefficientC(dataSeries, 0)
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()}`)
dataSeries.push(-1, 2)
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 0)
testCoefficientC(dataSeries, 0)
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()}`)
dataSeries.push(0, 2)
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 0)
testCoefficientC(dataSeries, 0)
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()}`)
dataSeries.push(1, 6)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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()}`)
})
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)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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()}`)
})
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)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 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()}`)
dataSeries.push(1, 6)
dataSeries.push(2, 14)
dataSeries.push(3, 26)
@ -85,9 +85,10 @@ 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)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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
})
test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, noisefree', () => {
@ -96,85 +97,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)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-8, 228)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-7, 172)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-6, 124)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-5, 84)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-4, 52)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-3, 28)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-2, 12)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-1, 4)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 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()}`)
dataSeries.push(0, 4)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 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()}`)
dataSeries.push(1, 12)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(2, 28)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(3, 52)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(4, 84)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(5, 124)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(6, 172)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(7, 228)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(8, 292)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(9, 364)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(10, 444)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
})
test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, with some noise (+/- 1)', () => {
@ -183,85 +184,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)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, -36)
testCoefficientC(dataSeries, -195)
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()}`)
dataSeries.push(-8, 229)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 3.6666666666666643) // This is quite acceptable as ORM ignores the C
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()}`)
dataSeries.push(-7, 171)
testCoefficientA(dataSeries, 3.666666666666667)
testCoefficientB(dataSeries, -1.8333333333333335)
testCoefficientC(dataSeries, -20.916666666666682)
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()}`)
dataSeries.push(-6, 125)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 3.799999999999997) // This is quite acceptable as ORM ignores the C
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()}`)
dataSeries.push(-5, 83)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-4, 53)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 3.8571428571428577) // This is quite acceptable as ORM ignores the C
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()}`)
dataSeries.push(-3, 27)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(-2, 13)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 3.8888888888888893) // This is quite acceptable as ORM ignores the C
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()}`)
dataSeries.push(-1, 3)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(0, 5)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(1, 11)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(2, 29)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(3, 51)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(4, 85)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(5, 123)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(6, 173)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(7, 227)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(8, 293)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(9, 363)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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()}`)
dataSeries.push(10, 444)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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)
})
test('Quadratic Approximation on function y = 4 * Math.pow(x, 2) + 4 * x + 4, with some noise (+/- 1) and spikes (+/- 9)', () => {
@ -275,65 +276,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)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 3.8571428571428577)
dataSeries.push(-3, 37) // FIRST SPIKE +9
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
dataSeries.push(-2, 3) // SECOND SPIKE -9
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4.142857142857142) // Coefficient B seems to take a hit anyway
testCoefficientC(dataSeries, 5.9999999999999964) // We get a 5.9999999999999964 instead of 4, which is quite acceptable (especially since ORM ignores the C)
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)
dataSeries.push(-1, 3)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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)
dataSeries.push(0, 5)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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)
dataSeries.push(1, 11)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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)
dataSeries.push(2, 29)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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)
dataSeries.push(3, 51)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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
dataSeries.push(4, 85)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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
dataSeries.push(5, 123)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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
dataSeries.push(6, 173)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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
dataSeries.push(7, 227)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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
dataSeries.push(8, 293)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 3) // This is quite acceptable as ORM ignores the C
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
dataSeries.push(9, 363)
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)
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)
dataSeries.push(10, 444)
testCoefficientA(dataSeries, 4)
testCoefficientB(dataSeries, 4)
testCoefficientC(dataSeries, 4)
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)
})
test('Quadratic TS Estimation should be decent for standard real-life example from MathBits with some noise', () => {
@ -352,9 +353,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)
testCoefficientA(dataSeries, -0.17785023090944152) // In the example, the TI084 results in -0.1737141137, which we consider acceptably close
testCoefficientB(dataSeries, 15.115602960635863) // In the example, the TI084 results in 14.52117133, which we consider acceptably close
testCoefficientC(dataSeries, -35.639987946994665) // In the example, the TI084 results in -21.89774466, which we consider acceptably close
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
})
test('Quadratic TS Estimation should be decent for standard real-life example from VarsityTutors with some noise', () => {
@ -367,9 +368,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)
testCoefficientA(dataSeries, 1.1166666666666667) // The example results in 1.1071 for OLS, which we consider acceptably close
testCoefficientB(dataSeries, 0.966666666666667) // The example results in 1 for OLS, which we consider acceptably close
testCoefficientC(dataSeries, 0.44722222222222213) // The example results in 0.5714 for OLS, which we consider acceptably close
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
})
test('Quadratic TS Estimation should be decent for standard example from VTUPulse with some noise, without the vertex being part of the dataset', () => {
@ -380,9 +381,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)
testCoefficientA(dataSeries, 0.9500000000000005) // The example results in 0.7642857 for OLS, which we consider acceptably close given the small sample size
testCoefficientB(dataSeries, -7.483333333333338) // The example results in -5.5128571 for OLS, which we consider acceptably close given the small sample size
testCoefficientC(dataSeries, 17.275000000000006) // The example results in 12.4285714 for OLS, which we consider acceptably close given the small sample size
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
})
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', () => {
@ -413,9 +414,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)
testCoefficientA(dataSeries, -3.13052236289358)
testCoefficientB(dataSeries, 1.5907039702198331)
testCoefficientC(dataSeries, 0.12896850914578195)
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()}`)
})
test('Quadratic TS Estimation should be decent for standard real-life example from Statology.org with some noise and chaotic X values', () => {
@ -432,27 +433,9 @@ 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)
testCoefficientA(dataSeries, -0.10466531440162272) // The example results in -0.1012 for R after two rounds, which we consider acceptably close
testCoefficientB(dataSeries, 6.98670916642519) // The example results in 6.7444 for R after two rounds, which we consider acceptably close
testCoefficientC(dataSeries, -21.826295759683177) // 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.0004480669511301859) // The example results in -0.00045 through QR decomposition by Givens rotations, which we consider acceptably close
testCoefficientB(dataSeries, 2.373459636061883) // The example results in 2.39893 for QR decomposition by Givens rotations, which we consider acceptably close
testCoefficientC(dataSeries, -1178.1630473732216) // The example results in -1216.143887 for QR decomposition by Givens rotations, but for ORM, this factor is irrelevant
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
})
test('Quadratic Approximation with a clean function and a reset', () => {
@ -464,9 +447,9 @@ test('Quadratic Approximation with a clean function and a reset', () => {
dataSeries.push(-7, 86)
dataSeries.push(-6, 62)
dataSeries.push(-5, 42)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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()}`)
dataSeries.push(-4, 26)
dataSeries.push(-3, 14) // Pi ;)
dataSeries.push(-2, 6)
@ -474,9 +457,9 @@ test('Quadratic Approximation with a clean function and a reset', () => {
dataSeries.push(0, 2)
dataSeries.push(1, 6)
dataSeries.push(2, 14)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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()}`)
dataSeries.push(3, 26)
dataSeries.push(4, 42)
dataSeries.push(5, 62)
@ -485,29 +468,29 @@ test('Quadratic Approximation with a clean function and a reset', () => {
dataSeries.push(8, 146)
dataSeries.push(9, 182)
dataSeries.push(10, 222)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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()}`)
dataSeries.reset()
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 0)
testCoefficientC(dataSeries, 0)
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()}`)
dataSeries.push(-1, 2)
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 0)
testCoefficientC(dataSeries, 0)
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()}`)
dataSeries.push(0, 2)
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 0)
testCoefficientC(dataSeries, 0)
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()}`)
dataSeries.push(1, 6)
testCoefficientA(dataSeries, 2)
testCoefficientB(dataSeries, 2)
testCoefficientC(dataSeries, 2)
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()}`)
})
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
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
const dataSeries = createTSQuadraticSeries(7)
dataSeries.push(0, 0)
dataSeries.push(1, 1)
@ -516,31 +499,9 @@ test('Quadratic TS Estimation should result in a straight line for function y =
dataSeries.push(4, 4)
dataSeries.push(5, 5)
dataSeries.push(6, 6)
testCoefficientA(dataSeries, 0)
testCoefficientB(dataSeries, 1)
testCoefficientC(dataSeries, 0)
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()}`)
})
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()