go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/matrix/polynomial_regression_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package matrix
     9  
    10  import (
    11  	"testing"
    12  
    13  	"go.charczuk.com/sdk/assert"
    14  )
    15  
    16  func Test_PolynomialRegression_first(t *testing.T) {
    17  	var xGiven = []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    18  	var yGiven = []float64{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
    19  	var degree = 1
    20  
    21  	c, err := PolynomialRegression(xGiven, yGiven, degree)
    22  	assert.ItsNil(t, err)
    23  	assert.ItsLen(t, c, 2)
    24  
    25  	assert.ItsEpsilon(t, c[0], 3, DefaultEpsilon)
    26  	assert.ItsEpsilon(t, c[1], 1, DefaultEpsilon)
    27  }
    28  
    29  func Test_PolynomialRegression_third(t *testing.T) {
    30  	var xGiven = []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    31  	var yGiven = []float64{1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321}
    32  	var degree = 2
    33  
    34  	c, err := PolynomialRegression(xGiven, yGiven, degree)
    35  	assert.ItsNil(t, err)
    36  	assert.ItsLen(t, c, 3)
    37  
    38  	assert.ItsEpsilon(t, c[0], 0.999999999, DefaultEpsilon)
    39  	assert.ItsEpsilon(t, c[1], 2, DefaultEpsilon)
    40  	assert.ItsEpsilon(t, c[2], 3, DefaultEpsilon)
    41  }