2017-04-26 03:27:11 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-10-27 22:52:38 -04:00
|
|
|
"git.smarteching.com/zeni/go-chart/v2/matrix"
|
|
|
|
"git.smarteching.com/zeni/go-chart/v2/testutil"
|
2017-04-26 03:27:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPolynomialRegression(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2017-04-26 03:27:11 -04:00
|
|
|
|
|
|
|
var xv []float64
|
|
|
|
var yv []float64
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
xv = append(xv, float64(i))
|
|
|
|
yv = append(yv, float64(i*i))
|
|
|
|
}
|
|
|
|
|
|
|
|
values := ContinuousSeries{
|
|
|
|
XValues: xv,
|
|
|
|
YValues: yv,
|
|
|
|
}
|
|
|
|
|
|
|
|
poly := &PolynomialRegressionSeries{
|
|
|
|
InnerSeries: values,
|
|
|
|
Degree: 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
2017-05-12 20:12:23 -04:00
|
|
|
_, y := poly.GetValues(i)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertInDelta(t, float64(i*i), y, matrix.DefaultEpsilon)
|
2017-04-26 03:27:11 -04:00
|
|
|
}
|
|
|
|
}
|