mirror of
https://github.com/gonum/gonum.git
synced 2025-10-29 01:33:14 +08:00
stat: use scaled SymOuterK
This commit is contained in:
@@ -44,15 +44,10 @@ func CovarianceMatrix(cov *mat64.SymDense, x mat64.Matrix, weights []float64) *m
|
|||||||
floats.AddConst(-mean, v)
|
floats.AddConst(-mean, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
var n float64
|
|
||||||
if weights == nil {
|
if weights == nil {
|
||||||
|
// Calculate the normalization factor
|
||||||
n = float64(r)
|
// scaled by the sample size.
|
||||||
|
cov.SymOuterK(1/(float64(r)-1), &xt)
|
||||||
cov.SymOuterK(&xt)
|
|
||||||
|
|
||||||
// Scale by the sample size.
|
|
||||||
cov.ScaleSym(1/(n-1), cov)
|
|
||||||
return cov
|
return cov
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,12 +65,9 @@ func CovarianceMatrix(cov *mat64.SymDense, x mat64.Matrix, weights []float64) *m
|
|||||||
floats.Mul(v, sqrtwts)
|
floats.Mul(v, sqrtwts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the normalization factor.
|
// Calculate the normalization factor
|
||||||
n = floats.Sum(weights)
|
// scaled by the weighted sample size.
|
||||||
cov.SymOuterK(&xt)
|
cov.SymOuterK(1/(floats.Sum(weights)-1), &xt)
|
||||||
|
|
||||||
// Scale by the sample size.
|
|
||||||
cov.ScaleSym(1/(n-1), cov)
|
|
||||||
return cov
|
return cov
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user