diff --git a/stat/cca_example_test.go b/stat/cca_example_test.go index a8f738e5..60a1d1ed 100644 --- a/stat/cca_example_test.go +++ b/stat/cca_example_test.go @@ -32,7 +32,7 @@ func (s symView) At(i, j int) float64 { return s.sym.At(s.i+i, s.j+j) } -func (s symView) T() mat.Matrix { return mat.Transpose{s} } +func (s symView) T() mat.Matrix { return mat.Transpose{Matrix: s} } func ExampleCC() { // This example is directly analogous to Example 3.5 on page 87 of diff --git a/stat/distmv/normal.go b/stat/distmv/normal.go index 0ebeeb83..8ddd606e 100644 --- a/stat/distmv/normal.go +++ b/stat/distmv/normal.go @@ -110,7 +110,10 @@ func NewNormalPrecision(mu []float64, prec *mat.SymDense, src rand.Source) (norm return nil, false } var sigma mat.SymDense - chol.InverseTo(&sigma) + err := chol.InverseTo(&sigma) + if err != nil { + return nil, false + } return NewNormal(mu, &sigma, src) } @@ -341,7 +344,10 @@ func (n *Normal) ScoreInput(score, x []float64) []float64 { copy(tmp, x) floats.Sub(tmp, n.mu) - n.chol.SolveVecTo(mat.NewVecDense(len(score), score), mat.NewVecDense(len(tmp), tmp)) + err := n.chol.SolveVecTo(mat.NewVecDense(len(score), score), mat.NewVecDense(len(tmp), tmp)) + if err != nil { + panic(err) + } floats.Scale(-1, score) return score } diff --git a/stat/distmv/normal_test.go b/stat/distmv/normal_test.go index b4ed5738..6a676501 100644 --- a/stat/distmv/normal_test.go +++ b/stat/distmv/normal_test.go @@ -16,14 +16,6 @@ import ( "gonum.org/v1/gonum/stat" ) -type mvTest struct { - Mu []float64 - Sigma *mat.SymDense - Loc []float64 - Logprob float64 - Prob float64 -} - func TestNormProbs(t *testing.T) { dist1, ok := NewNormal([]float64{0, 0}, mat.NewSymDense(2, []float64{1, 0, 0, 1}), nil) if !ok { diff --git a/stat/distmv/statdist.go b/stat/distmv/statdist.go index 34fddae6..2a23c860 100644 --- a/stat/distmv/statdist.go +++ b/stat/distmv/statdist.go @@ -335,7 +335,10 @@ func (Wasserstein) DistNormal(l, r *Normal) float64 { // Compute Σ_l^(1/2) var ssl mat.SymDense - ssl.PowPSD(&l.sigma, 0.5) + err := ssl.PowPSD(&l.sigma, 0.5) + if err != nil { + panic(err) + } // Compute Σ_l^(1/2)*Σ_r*Σ_l^(1/2) var mean mat.Dense mean.Mul(&ssl, &r.sigma) @@ -343,7 +346,10 @@ func (Wasserstein) DistNormal(l, r *Normal) float64 { // Reinterpret as symdense, and take Σ^(1/2) meanSym := mat.NewSymDense(dim, mean.RawMatrix().Data) - ssl.PowPSD(meanSym, 0.5) + err = ssl.PowPSD(meanSym, 0.5) + if err != nil { + panic(err) + } tr := mat.Trace(&r.sigma) tl := mat.Trace(&l.sigma) diff --git a/stat/distmv/statdist_test.go b/stat/distmv/statdist_test.go index ec2bbde4..a1d94f32 100644 --- a/stat/distmv/statdist_test.go +++ b/stat/distmv/statdist_test.go @@ -62,14 +62,14 @@ func TestBhattacharyyaUniform(t *testing.T) { tol float64 }{ { - a: NewUniform([]r1.Interval{{-3, 2}, {-5, 8}}, rnd), - b: NewUniform([]r1.Interval{{-4, 1}, {-7, 10}}, rnd), + a: NewUniform([]r1.Interval{{Min: -3, Max: 2}, {Min: -5, Max: 8}}, rnd), + b: NewUniform([]r1.Interval{{Min: -4, Max: 1}, {Min: -7, Max: 10}}, rnd), samples: 100000, tol: 1e-2, }, { - a: NewUniform([]r1.Interval{{-3, 2}, {-5, 8}}, rnd), - b: NewUniform([]r1.Interval{{-5, -4}, {-7, 10}}, rnd), + a: NewUniform([]r1.Interval{{Min: -3, Max: 2}, {Min: -5, Max: 8}}, rnd), + b: NewUniform([]r1.Interval{{Min: -5, Max: -4}, {Min: -7, Max: 10}}, rnd), samples: 100000, tol: 1e-2, }, @@ -257,14 +257,14 @@ func TestKullbackLeiblerUniform(t *testing.T) { tol float64 }{ { - a: NewUniform([]r1.Interval{{-5, 2}, {-7, 12}}, rnd), - b: NewUniform([]r1.Interval{{-4, 1}, {-7, 10}}, rnd), + a: NewUniform([]r1.Interval{{Min: -5, Max: 2}, {Min: -7, Max: 12}}, rnd), + b: NewUniform([]r1.Interval{{Min: -4, Max: 1}, {Min: -7, Max: 10}}, rnd), samples: 100000, tol: 1e-2, }, { - a: NewUniform([]r1.Interval{{-5, 2}, {-7, 12}}, rnd), - b: NewUniform([]r1.Interval{{-9, -6}, {-7, 10}}, rnd), + a: NewUniform([]r1.Interval{{Min: -5, Max: 2}, {Min: -7, Max: 12}}, rnd), + b: NewUniform([]r1.Interval{{Min: -9, Max: -6}, {Min: -7, Max: 10}}, rnd), samples: 100000, tol: 1e-2, }, diff --git a/stat/distmv/studentst_test.go b/stat/distmv/studentst_test.go index f7159af7..02ef1ce3 100644 --- a/stat/distmv/studentst_test.go +++ b/stat/distmv/studentst_test.go @@ -206,7 +206,10 @@ func TestStudentsTConditional(t *testing.T) { newMuVec := mat.NewVecDense(len(muUnob), newMu) shiftVec := mat.NewVecDense(len(shift), shift) var tmp mat.VecDense - tmp.SolveVec(&sig22, shiftVec) + err := tmp.SolveVec(&sig22, shiftVec) + if err != nil { + t.Errorf("unexpected error from vector solve: %v", err) + } newMuVec.MulVec(sig12, &tmp) floats.Add(newMu, muUnob) @@ -215,7 +218,10 @@ func TestStudentsTConditional(t *testing.T) { } var tmp2 mat.Dense - tmp2.Solve(&sig22, sig12.T()) + err = tmp2.Solve(&sig22, sig12.T()) + if err != nil { + t.Errorf("unexpected error from dense solve: %v", err) + } var tmp3 mat.Dense tmp3.Mul(sig12, &tmp2) diff --git a/stat/distmv/uniform_test.go b/stat/distmv/uniform_test.go index 57d3af32..015255e9 100644 --- a/stat/distmv/uniform_test.go +++ b/stat/distmv/uniform_test.go @@ -17,11 +17,11 @@ func TestUniformEntropy(t *testing.T) { Entropy float64 }{ { - NewUniform([]r1.Interval{{0, 1}, {0, 1}}, nil), + NewUniform([]r1.Interval{{Min: 0, Max: 1}, {Min: 0, Max: 1}}, nil), 0, }, { - NewUniform([]r1.Interval{{-1, 3}, {2, 8}, {-5, -3}}, nil), + NewUniform([]r1.Interval{{Min: -1, Max: 3}, {Min: 2, Max: 8}, {Min: -5, Max: -3}}, nil), math.Log(48), }, } { diff --git a/stat/sampleuv/example_rate_test.go b/stat/sampleuv/example_rate_test.go index 13b452d6..54119c24 100644 --- a/stat/sampleuv/example_rate_test.go +++ b/stat/sampleuv/example_rate_test.go @@ -6,13 +6,6 @@ package sampleuv import "gonum.org/v1/gonum/stat/distuv" -func max(a, b int) int { - if a < b { - return b - } - return a -} - func ExampleMetropolisHastings_samplingRate() { // See Burnin example for a description of these quantities. n := 1000 diff --git a/stat/spatial/spatial_areal_example_test.go b/stat/spatial/spatial_areal_example_test.go index 889314fe..6190dce6 100644 --- a/stat/spatial/spatial_areal_example_test.go +++ b/stat/spatial/spatial_areal_example_test.go @@ -31,7 +31,7 @@ func (e Euclid) At(i, j int) float64 { y := float64(j/e.x - i/e.x) return 1 / math.Hypot(x, y) } -func (e Euclid) T() mat.Matrix { return mat.Transpose{e} } +func (e Euclid) T() mat.Matrix { return mat.Transpose{Matrix: e} } func ExampleGlobalMoransI_areal() { locality := Euclid{10, 10}