mirror of
https://github.com/gonum/gonum.git
synced 2025-10-20 13:55:20 +08:00
fix weighted covariance implementation
Weighted covariance accidentally used squared weights. Added a test case and fixed implementation.
This commit is contained in:
@@ -128,6 +128,12 @@ func TestCovariance(t *testing.T) {
|
||||
weights: []float64{1, 1.5, 1},
|
||||
ans: 3.2,
|
||||
},
|
||||
{
|
||||
p: []float64{1, 4, 9},
|
||||
q: []float64{1, 4, 9},
|
||||
weights: []float64{1, 1.5, 1},
|
||||
ans: 13.142857142857146,
|
||||
},
|
||||
} {
|
||||
c := Covariance(test.p, test.q, test.weights)
|
||||
if math.Abs(c-test.ans) > 1e-14 {
|
||||
|
Reference in New Issue
Block a user