Unit testing for def/ module.
Added unit tests to test code in def/ module.
This commit is contained in:
parent
e24b8a08c9
commit
bac60e872a
396 changed files with 83991 additions and 13209 deletions
33
vendor/github.com/montanaflynn/stats/correlation.go
generated
vendored
33
vendor/github.com/montanaflynn/stats/correlation.go
generated
vendored
|
@ -1,6 +1,8 @@
|
|||
package stats
|
||||
|
||||
import "math"
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// Correlation describes the degree of relationship between two sets of data
|
||||
func Correlation(data1, data2 Float64Data) (float64, error) {
|
||||
|
@ -9,7 +11,7 @@ func Correlation(data1, data2 Float64Data) (float64, error) {
|
|||
l2 := data2.Len()
|
||||
|
||||
if l1 == 0 || l2 == 0 {
|
||||
return math.NaN(), EmptyInput
|
||||
return math.NaN(), EmptyInputErr
|
||||
}
|
||||
|
||||
if l1 != l2 {
|
||||
|
@ -27,7 +29,32 @@ func Correlation(data1, data2 Float64Data) (float64, error) {
|
|||
return covp / (sdev1 * sdev2), nil
|
||||
}
|
||||
|
||||
// Pearson calculates the Pearson product-moment correlation coefficient between two variables.
|
||||
// Pearson calculates the Pearson product-moment correlation coefficient between two variables
|
||||
func Pearson(data1, data2 Float64Data) (float64, error) {
|
||||
return Correlation(data1, data2)
|
||||
}
|
||||
|
||||
// Autocorrelation is the correlation of a signal with a delayed copy of itself as a function of delay
|
||||
func AutoCorrelation(data Float64Data, lags int) (float64, error) {
|
||||
if len(data) < 1 {
|
||||
return 0, EmptyInputErr
|
||||
}
|
||||
|
||||
mean, _ := Mean(data)
|
||||
|
||||
var result, q float64
|
||||
|
||||
for i := 0; i < lags; i++ {
|
||||
v := (data[0] - mean) * (data[0] - mean)
|
||||
for i := 1; i < len(data); i++ {
|
||||
delta0 := data[i-1] - mean
|
||||
delta1 := data[i] - mean
|
||||
q += (delta0*delta1 - q) / float64(i+1)
|
||||
v += (delta1*delta1 - v) / float64(i+1)
|
||||
}
|
||||
|
||||
result = q / v
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
|
Reference in a new issue