stat: use scaled SymOuterK

This commit is contained in:
kortschak
2015-09-30 16:05:17 +09:30
parent 0d0395a9f6
commit c48cebcab1

View File

@@ -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
} }