Fix NewNormalChol to actually set the Cholesky decomposition
MODIFY
distmv/normal.go
distmv/normal.go
@@ -77,6 +77,7 @@ func NewNormalChol(mu []float64, chol *mat64.Cholesky, src *rand.Rand) *Normal {
dim: dim,
mu: make([]float64, dim),
}
+ n.chol.Clone(chol)
copy(n.mu, mu)
n.lower.LFromCholesky(chol)
n.logSqrtDet = 0.5 * n.chol.LogDet()

MODIFY
distmv/normal_test.go
distmv/normal_test.go
@@ -50,6 +50,29 @@ func TestNormProbs(t *testing.T) {
})
}
+func TestNewNormalChol(t *testing.T) {
+ for _, test := range []struct {
+ mean []float64
+ cov *mat64.SymDense
+ }{
+ {
+ mean: []float64{2, 3},
+ cov: mat64.NewSymDense(2, []float64{1, 0.1, 0.1, 1}),
+ },
+ } {
+ var chol mat64.Cholesky
+ ok := chol.Factorize(test.cov)
+ if !ok {
+ panic("bad test")
+ }
+ n := NewNormalChol(test.mean, &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)
+ }
+}
+
func TestNormRand(t *testing.T) {
for _, test := range []struct {
mean []float64

Fix NewNormalChol to actually set the Cholesky decomposition