Skip to content

Commit

Permalink
stat/distmv: rename NewNormalChol and add Sigma as an input argument
Browse files Browse the repository at this point in the history
  • Loading branch information
btracey committed Sep 30, 2017
1 parent 1f58387 commit d4200c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions stat/distmv/normal.go
Expand Up @@ -64,19 +64,25 @@ func NewNormal(mu []float64, sigma mat.Symmetric, src *rand.Rand) (*Normal, bool
return n, true
}

// NewNormalChol creates a new Normal distribution with the given mean and
// covariance matrix represented by its Cholesky decomposition. NewNormalChol
// panics if len(mu) is not equal to chol.Size().
func NewNormalChol(mu []float64, chol *mat.Cholesky, src *rand.Rand) *Normal {
// NewNormalData creates a new Normal distribution with the given mean and
// covariance matrix when the Cholesky decomposition of the covariance matrix
// is already known. NewNormalChol panics if len(mu) is not equal to chol.Size()
// or sigma.Symmetric().
func NewNormalData(mu []float64, sigma mat.Symmetric, chol *mat.Cholesky, src *rand.Rand) *Normal {
dim := len(mu)
if dim != chol.Size() {
panic(badSizeMismatch)
}
if dim != sigma.Symmetric() {
panic(badSizeMismatch)
}
n := &Normal{
src: src,
dim: dim,
mu: make([]float64, dim),
}
n.sigma = *mat.NewSymDense(dim, nil)
n.sigma.CopySym(sigma)
n.chol.Clone(chol)
copy(n.mu, mu)
chol.LTo(&n.lower)
Expand Down
3 changes: 2 additions & 1 deletion stat/distmv/normal_test.go
Expand Up @@ -66,11 +66,12 @@ func TestNewNormalChol(t *testing.T) {
if !ok {
panic("bad test")
}
n := NewNormalChol(test.mean, &chol, nil)
n := NewNormalData(test.mean, test.cov, &chol, nil)
// Generate a random number and calculate probability to ensure things
// have been set properly. See issue #426.
x := n.Rand(nil)
_ = n.Prob(x)
_, _ = n.ConditionNormal([]int{0}, []float64{8.7}, nil)
}
}

Expand Down

0 comments on commit d4200c3

Please sign in to comment.