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