all: fix build and make tests pass with new streams

This commit is contained in:
kortschak
2017-11-17 12:38:53 +10:30
parent fa0c5aa7bc
commit 54a5f6f081
16 changed files with 59 additions and 55 deletions

View File

@@ -5,14 +5,16 @@
package sampleuv
import (
"math"
"sort"
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/stat"
"gonum.org/v1/gonum/stat/distuv"
)
const tol = 1e-2
type lhDist interface {
Quantile(float64) float64
CDF(float64) float64
@@ -48,7 +50,7 @@ func TestImportance(t *testing.T) {
weights := make([]float64, nSamples)
Importance(x, weights, target, proposal)
ev := stat.Mean(x, weights)
if math.Abs(ev-trueMean) > 1e-2 {
if !floats.EqualWithinAbsOrRel(ev, trueMean, tol, tol) {
t.Errorf("Mean mismatch: Want %v, got %v", trueMean, ev)
}
}
@@ -63,7 +65,7 @@ func TestRejection(t *testing.T) {
x := make([]float64, nSamples)
Rejection(x, target, proposal, 100, nil)
ev := stat.Mean(x, nil)
if math.Abs(ev-trueMean) > 2e-2 {
if !floats.EqualWithinAbsOrRel(ev, trueMean, tol, tol) {
t.Errorf("Mean mismatch: Want %v, got %v", trueMean, ev)
}
}
@@ -93,7 +95,7 @@ func TestMetropolisHastings(t *testing.T) {
// Remove burnin
x = x[burnin:]
ev := stat.Mean(x, nil)
if math.Abs(ev-trueMean) > 1e-2 {
if !floats.EqualWithinAbsOrRel(ev, trueMean, tol, tol) {
t.Errorf("Mean mismatch: Want %v, got %v", trueMean, ev)
}
}