mirror of
https://github.com/gonum/gonum.git
synced 2025-10-18 13:10:47 +08:00
stat: allow tolerance in TestCovarianceMatrix
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCovarianceMatrix(t *testing.T) {
|
func TestCovarianceMatrix(t *testing.T) {
|
||||||
|
const tol = 1e-15
|
||||||
|
|
||||||
// An alternative way to test this is to call the Variance and
|
// An alternative way to test this is to call the Variance and
|
||||||
// Covariance functions and ensure that the results are identical.
|
// Covariance functions and ensure that the results are identical.
|
||||||
for i, test := range []struct {
|
for i, test := range []struct {
|
||||||
@@ -47,7 +49,7 @@ func TestCovarianceMatrix(t *testing.T) {
|
|||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
ans: mat.NewDense(2, 2, []float64{
|
ans: mat.NewDense(2, 2, []float64{
|
||||||
.8, 3.2,
|
0.8, 3.2,
|
||||||
3.2, 13.142857142857146,
|
3.2, 13.142857142857146,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -64,7 +66,7 @@ func TestCovarianceMatrix(t *testing.T) {
|
|||||||
|
|
||||||
var cov mat.SymDense
|
var cov mat.SymDense
|
||||||
CovarianceMatrix(&cov, test.data, test.weights)
|
CovarianceMatrix(&cov, test.data, test.weights)
|
||||||
if !mat.Equal(&cov, test.ans) {
|
if !mat.EqualApprox(&cov, test.ans, tol) {
|
||||||
t.Errorf("%d: expected cov %v, found %v", i, test.ans, &cov)
|
t.Errorf("%d: expected cov %v, found %v", i, test.ans, &cov)
|
||||||
}
|
}
|
||||||
if !floats.Equal(d, r.Data) {
|
if !floats.Equal(d, r.Data) {
|
||||||
|
Reference in New Issue
Block a user