Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
make Corr2Cov and Cov2Corr unexported
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlawlor committed Feb 2, 2015
1 parent fc32bfa commit 8921c5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions covariancematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func CorrelationMatrix(corr *mat64.Dense, x mat64.Matrix, wts []float64) *mat64.

// This will panic if the sizes don't match, or if wts is the wrong size.
corr = CovarianceMatrix(corr, x, wts)
CovToCorr(corr)
covToCorr(corr)
return corr
}

// CovToCorr converts a covariance matrix to a correlation matrix.
func CovToCorr(cov *mat64.Dense) {
// covToCorr converts a covariance matrix to a correlation matrix.
func covToCorr(cov *mat64.Dense) {

// TODO(jonlawlor): use a *mat64.Symmetric as input.

Expand All @@ -121,11 +121,11 @@ func CovToCorr(cov *mat64.Dense) {
}
}

// CorrToCov converts a correlation matrix to a covariance matrix.
// corrToCov converts a correlation matrix to a covariance matrix.
// The input sigma should be vector of standard deviations corresponding
// to the covariance. It will panic if len(sigma) is not equal to the
// number of rows in the correlation matrix.
func CorrToCov(corr *mat64.Dense, sigma []float64) {
func corrToCov(corr *mat64.Dense, sigma []float64) {

// TODO(jonlawlor): use a *mat64.Symmetric as input.

Expand Down
10 changes: 5 additions & 5 deletions covariancematrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ func TestCorrCov(t *testing.T) {
}

covFromCorr := mat64.DenseCopyOf(corr)
CorrToCov(covFromCorr, sigmas)
corrToCov(covFromCorr, sigmas)
corrFromCov := mat64.DenseCopyOf(cov)
CovToCorr(corrFromCov)
covToCorr(corrFromCov)

if !corr.EqualsApprox(corrFromCov, 1e-14) {
t.Errorf("%d: CorrToCov did not match direct Correlation calculation. Want: %v, got: %v. ", i, corr, corrFromCov)
t.Errorf("%d: corrToCov did not match direct Correlation calculation. Want: %v, got: %v. ", i, corr, corrFromCov)
}
if !cov.EqualsApprox(covFromCorr, 1e-14) {
t.Errorf("%d: CovToCorr did not match direct Covariance calculation. Want: %v, got: %v. ", i, cov, covFromCorr)
t.Errorf("%d: covToCorr did not match direct Covariance calculation. Want: %v, got: %v. ", i, cov, covFromCorr)
}

if !Panics(func() { CorrToCov(mat64.NewDense(2, 2, nil), []float64{}) }) {
if !Panics(func() { corrToCov(mat64.NewDense(2, 2, nil), []float64{}) }) {
t.Errorf("CorrelationMatrix did not panic with sigma size mismatch")
}
}
Expand Down

0 comments on commit 8921c5b

Please sign in to comment.