mirror of
https://github.com/gonum/gonum.git
synced 2025-10-29 01:33:14 +08:00
Update stat for the new API of MulTrans and MulVec
This commit is contained in:
@@ -5,9 +5,10 @@
|
||||
package stat
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/gonum/floats"
|
||||
"github.com/gonum/matrix/mat64"
|
||||
"math"
|
||||
)
|
||||
|
||||
// CovarianceMatrix calculates a covariance matrix (also known as a
|
||||
@@ -51,7 +52,7 @@ func CovarianceMatrix(cov *mat64.Dense, x mat64.Matrix, wts []float64) *mat64.De
|
||||
|
||||
n = float64(r)
|
||||
|
||||
cov.MulTrans(&xt, false, &xt, true)
|
||||
cov.Mul(&xt, (&xt).T())
|
||||
|
||||
// Scale by the sample size.
|
||||
cov.Scale(1/(n-1), cov)
|
||||
@@ -74,7 +75,7 @@ func CovarianceMatrix(cov *mat64.Dense, x mat64.Matrix, wts []float64) *mat64.De
|
||||
|
||||
// Calculate the normalization factor.
|
||||
n = floats.Sum(wts)
|
||||
cov.MulTrans(&xt, false, &xt, true)
|
||||
cov.Mul(&xt, (&xt).T())
|
||||
|
||||
// Scale by the sample size.
|
||||
cov.Scale(1/(n-1), cov)
|
||||
|
||||
@@ -120,7 +120,7 @@ func (n *Normal) Rand(x []float64) []float64 {
|
||||
}
|
||||
tmpVec := mat64.NewVector(n.dim, tmp)
|
||||
xVec := mat64.NewVector(n.dim, x)
|
||||
xVec.MulVec(n.chol, true, tmpVec)
|
||||
xVec.MulVec(n.chol.T(), tmpVec)
|
||||
floats.Add(x, n.mu)
|
||||
return x
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user