Update stat for the new API of MulTrans and MulVec

This commit is contained in:
btracey
2015-08-02 22:56:09 -06:00
parent f1b9c02aa9
commit 55a603be8c
2 changed files with 5 additions and 4 deletions

View File

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

View File

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