mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 15:16:59 +08:00
all: fix build and make tests pass with new streams
This commit is contained in:
@@ -65,7 +65,7 @@ func TestGradient(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
nDim: 40,
|
nDim: 40,
|
||||||
tol: 1e-6,
|
tol: 1e-5,
|
||||||
formula: Central,
|
formula: Central,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
@@ -112,8 +112,8 @@ func ExampleProfile_multiplex() {
|
|||||||
// Output:
|
// Output:
|
||||||
// Low:0.1 High:0.72 Score:26 Communities:[[0] [1 7 9 12] [2 8 11] [3 4 5 10] [6]] Q=[24.7 1.97]
|
// Low:0.1 High:0.72 Score:26 Communities:[[0] [1 7 9 12] [2 8 11] [3 4 5 10] [6]] Q=[24.7 1.97]
|
||||||
// Low:0.72 High:1.1 Score:24 Communities:[[0 6] [1 7 9 12] [2 8 11] [3 4 5 10]] Q=[16.9 14.1]
|
// Low:0.72 High:1.1 Score:24 Communities:[[0 6] [1 7 9 12] [2 8 11] [3 4 5 10]] Q=[16.9 14.1]
|
||||||
// Low:1.1 High:1.1 Score:18 Communities:[[0 2 6 11] [1 7 9 12] [3 4 5 8 10]] Q=[9.16 25.1]
|
// Low:1.1 High:1.2 Score:18 Communities:[[0 2 6 11] [1 7 9 12] [3 4 5 8 10]] Q=[9.16 25.1]
|
||||||
// Low:1.1 High:1.6 Score:10 Communities:[[0 3 4 5 6 10] [1 7 9 12] [2 8 11]] Q=[11.5 23.9]
|
// Low:1.2 High:1.6 Score:10 Communities:[[0 3 4 5 6 10] [1 7 9 12] [2 8 11]] Q=[10.5 26.5]
|
||||||
// Low:1.6 High:1.6 Score:8 Communities:[[0 1 6 7 9 12] [2 8 11] [3 4 5 10]] Q=[5.56 39.8]
|
// Low:1.6 High:1.6 Score:8 Communities:[[0 1 6 7 9 12] [2 8 11] [3 4 5 10]] Q=[5.56 39.8]
|
||||||
// Low:1.6 High:1.8 Score:2 Communities:[[0 2 3 4 5 6 10] [1 7 8 9 11 12]] Q=[-1.82 48.6]
|
// Low:1.6 High:1.8 Score:2 Communities:[[0 2 3 4 5 6 10] [1 7 8 9 11 12]] Q=[-1.82 48.6]
|
||||||
// Low:1.8 High:2.3 Score:-6 Communities:[[0 2 3 4 5 6 8 10 11] [1 7 9 12]] Q=[-5 57.5]
|
// Low:1.8 High:2.3 Score:-6 Communities:[[0 2 3 4 5 6 8 10 11] [1 7 9 12]] Q=[-5 57.5]
|
||||||
|
@@ -167,12 +167,11 @@ var communityDirectedQTests = []communityDirectedQTest{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
q: 0.32525510204081637,
|
q: 0.36862244897959184,
|
||||||
communities: [][]graph.Node{
|
communities: [][]graph.Node{
|
||||||
{simple.Node(0), simple.Node(3), simple.Node(5), simple.Node(7)},
|
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(4), simple.Node(5)},
|
||||||
{simple.Node(1), simple.Node(2), simple.Node(4), simple.Node(6)},
|
{simple.Node(3), simple.Node(6), simple.Node(7)},
|
||||||
{simple.Node(8), simple.Node(10), simple.Node(11), simple.Node(13), simple.Node(15)},
|
{simple.Node(8), simple.Node(9), simple.Node(10), simple.Node(11), simple.Node(12), simple.Node(13), simple.Node(14), simple.Node(15)},
|
||||||
{simple.Node(9), simple.Node(12), simple.Node(14)},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@@ -153,13 +153,16 @@ var communityUndirectedQTests = []communityUndirectedQTest{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
q: 0.39907955292570674,
|
q: 0.3496877054569362,
|
||||||
communities: [][]graph.Node{
|
communities: [][]graph.Node{
|
||||||
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(7), simple.Node(11), simple.Node(12), simple.Node(13), simple.Node(17), simple.Node(19), simple.Node(21)},
|
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(7), simple.Node(11), simple.Node(12), simple.Node(13), simple.Node(17), simple.Node(19), simple.Node(21)},
|
||||||
{simple.Node(4), simple.Node(10)},
|
{simple.Node(4), simple.Node(10)},
|
||||||
{simple.Node(5), simple.Node(6), simple.Node(16)},
|
{simple.Node(5), simple.Node(6), simple.Node(16)},
|
||||||
{simple.Node(8), simple.Node(9), simple.Node(14), simple.Node(15), simple.Node(18), simple.Node(20), simple.Node(22), simple.Node(26), simple.Node(29), simple.Node(30), simple.Node(32), simple.Node(33)},
|
{simple.Node(8), simple.Node(9), simple.Node(14), simple.Node(15), simple.Node(18), simple.Node(20), simple.Node(22), simple.Node(30), simple.Node(32), simple.Node(33)},
|
||||||
{simple.Node(23), simple.Node(24), simple.Node(25), simple.Node(27), simple.Node(28), simple.Node(31)},
|
{simple.Node(23), simple.Node(25)},
|
||||||
|
{simple.Node(24), simple.Node(27)},
|
||||||
|
{simple.Node(26), simple.Node(29)},
|
||||||
|
{simple.Node(28), simple.Node(31)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -226,7 +229,7 @@ var communityUndirectedQTests = []communityUndirectedQTest{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
q: 0.34630102040816324,
|
q: 0.3463010204081633,
|
||||||
communities: [][]graph.Node{
|
communities: [][]graph.Node{
|
||||||
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(4), simple.Node(5)},
|
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(4), simple.Node(5)},
|
||||||
{simple.Node(3), simple.Node(6), simple.Node(7)},
|
{simple.Node(3), simple.Node(6), simple.Node(7)},
|
||||||
|
@@ -533,7 +533,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
|
|||||||
a: a,
|
a: a,
|
||||||
evWant: ev,
|
evWant: ev,
|
||||||
valTol: 1e-12,
|
valTol: 1e-12,
|
||||||
vecTol: 1e-8,
|
vecTol: 1e-7,
|
||||||
}
|
}
|
||||||
testDgeev(t, impl, "random", test, jobvl, jobvr, 0, optimumWork)
|
testDgeev(t, impl, "random", test, jobvl, jobvr, 0, optimumWork)
|
||||||
}
|
}
|
||||||
@@ -543,7 +543,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testDgeev(t *testing.T, impl Dgeever, tc string, test dgeevTest, jobvl lapack.LeftEVJob, jobvr lapack.RightEVJob, extra int, wl worklen) {
|
func testDgeev(t *testing.T, impl Dgeever, tc string, test dgeevTest, jobvl lapack.LeftEVJob, jobvr lapack.RightEVJob, extra int, wl worklen) {
|
||||||
const defaultTol = 1e-13
|
const defaultTol = 1e-12
|
||||||
valTol := test.valTol
|
valTol := test.valTol
|
||||||
if valTol == 0 {
|
if valTol == 0 {
|
||||||
valTol = defaultTol
|
valTol = defaultTol
|
||||||
|
@@ -39,7 +39,7 @@ func Dlasy2Test(t *testing.T, impl Dlasy2er) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testDlasy2(t *testing.T, impl Dlasy2er, tranl, tranr bool, isgn, n1, n2, extra int, rnd *rand.Rand) {
|
func testDlasy2(t *testing.T, impl Dlasy2er, tranl, tranr bool, isgn, n1, n2, extra int, rnd *rand.Rand) {
|
||||||
const tol = 1e-11
|
const tol = 1e-10
|
||||||
|
|
||||||
tl := randomGeneral(n1, n1, n1+extra, rnd)
|
tl := randomGeneral(n1, n1, n1+extra, rnd)
|
||||||
tr := randomGeneral(n2, n2, n2+extra, rnd)
|
tr := randomGeneral(n2, n2, n2+extra, rnd)
|
||||||
|
@@ -96,7 +96,7 @@ func TestWishartRand(t *testing.T) {
|
|||||||
v: mat.NewSymDense(3, []float64{0.8, 0.3, 0.1, 0.3, 0.7, -0.1, 0.1, -0.1, 7}),
|
v: mat.NewSymDense(3, []float64{0.8, 0.3, 0.1, 0.3, 0.7, -0.1, 0.1, -0.1, 7}),
|
||||||
nu: 5,
|
nu: 5,
|
||||||
samples: 30000,
|
samples: 30000,
|
||||||
tol: 3e-2,
|
tol: 3e-1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: mat.NewSymDense(4, []float64{
|
v: mat.NewSymDense(4, []float64{
|
||||||
|
@@ -27,7 +27,7 @@ func TestBhattacharyyaNormal(t *testing.T) {
|
|||||||
bm: []float64{-1, 1},
|
bm: []float64{-1, 1},
|
||||||
bc: mat.NewSymDense(2, []float64{1.5, 0.2, 0.2, 0.9}),
|
bc: mat.NewSymDense(2, []float64{1.5, 0.2, 0.2, 0.9}),
|
||||||
samples: 100000,
|
samples: 100000,
|
||||||
tol: 1e-2,
|
tol: 3e-1,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
rnd := rand.New(rand.NewSource(1))
|
rnd := rand.New(rand.NewSource(1))
|
||||||
@@ -41,7 +41,7 @@ func TestBhattacharyyaNormal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
want := bhattacharyyaSample(a.Dim(), test.samples, a, b)
|
want := bhattacharyyaSample(a.Dim(), test.samples, a, b)
|
||||||
got := Bhattacharyya{}.DistNormal(a, b)
|
got := Bhattacharyya{}.DistNormal(a, b)
|
||||||
if math.Abs(want-got) > test.tol {
|
if !floats.EqualWithinAbsOrRel(want, got, test.tol, test.tol) {
|
||||||
t.Errorf("Bhattacharyya mismatch, case %d: got %v, want %v", cas, got, want)
|
t.Errorf("Bhattacharyya mismatch, case %d: got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ func TestBhattacharyyaUniform(t *testing.T) {
|
|||||||
a, b := test.a, test.b
|
a, b := test.a, test.b
|
||||||
want := bhattacharyyaSample(a.Dim(), test.samples, a, b)
|
want := bhattacharyyaSample(a.Dim(), test.samples, a, b)
|
||||||
got := Bhattacharyya{}.DistUniform(a, b)
|
got := Bhattacharyya{}.DistUniform(a, b)
|
||||||
if math.Abs(want-got) > test.tol {
|
if !floats.EqualWithinAbsOrRel(want, got, test.tol, test.tol) {
|
||||||
t.Errorf("Bhattacharyya mismatch, case %d: got %v, want %v", cas, got, want)
|
t.Errorf("Bhattacharyya mismatch, case %d: got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
// Bhattacharyya should by symmetric
|
// Bhattacharyya should by symmetric
|
||||||
@@ -136,7 +136,7 @@ func TestCrossEntropyNormal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ce /= float64(test.samples)
|
ce /= float64(test.samples)
|
||||||
got := CrossEntropy{}.DistNormal(a, b)
|
got := CrossEntropy{}.DistNormal(a, b)
|
||||||
if math.Abs(ce-got) > test.tol {
|
if !floats.EqualWithinAbsOrRel(ce, got, test.tol, test.tol) {
|
||||||
t.Errorf("CrossEntropy mismatch, case %d: got %v, want %v", cas, got, ce)
|
t.Errorf("CrossEntropy mismatch, case %d: got %v, want %v", cas, got, ce)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ func TestHellingerNormal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
want := math.Sqrt(0.5 * math.Exp(floats.LogSumExp(lAitchEDoubleHockeySticks)-math.Log(float64(test.samples))))
|
want := math.Sqrt(0.5 * math.Exp(floats.LogSumExp(lAitchEDoubleHockeySticks)-math.Log(float64(test.samples))))
|
||||||
got := Hellinger{}.DistNormal(a, b)
|
got := Hellinger{}.DistNormal(a, b)
|
||||||
if math.Abs(want-got) > test.tol {
|
if !floats.EqualWithinAbsOrRel(want, got, test.tol, test.tol) {
|
||||||
t.Errorf("Hellinger mismatch, case %d: got %v, want %v", cas, got, want)
|
t.Errorf("Hellinger mismatch, case %d: got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ func TestKullbackLeiblerUniform(t *testing.T) {
|
|||||||
a, b := test.a, test.b
|
a, b := test.a, test.b
|
||||||
want := klSample(a.Dim(), test.samples, a, b)
|
want := klSample(a.Dim(), test.samples, a, b)
|
||||||
got := KullbackLeibler{}.DistUniform(a, b)
|
got := KullbackLeibler{}.DistUniform(a, b)
|
||||||
if math.Abs(want-got) > test.tol {
|
if !floats.EqualWithinAbsOrRel(want, got, test.tol, test.tol) {
|
||||||
t.Errorf("Kullback-Leibler mismatch, case %d: got %v, want %v", cas, got, want)
|
t.Errorf("Kullback-Leibler mismatch, case %d: got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ func TestRenyiNormal(t *testing.T) {
|
|||||||
bc: mat.NewSymDense(2, []float64{1.5, 0.2, 0.2, 0.9}),
|
bc: mat.NewSymDense(2, []float64{1.5, 0.2, 0.2, 0.9}),
|
||||||
alpha: 0.3,
|
alpha: 0.3,
|
||||||
samples: 10000,
|
samples: 10000,
|
||||||
tol: 1e-2,
|
tol: 3e-1,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
rnd := rand.New(rand.NewSource(1))
|
rnd := rand.New(rand.NewSource(1))
|
||||||
@@ -297,19 +297,19 @@ func TestRenyiNormal(t *testing.T) {
|
|||||||
// Compare with Bhattacharyya.
|
// Compare with Bhattacharyya.
|
||||||
want = 2 * Bhattacharyya{}.DistNormal(a, b)
|
want = 2 * Bhattacharyya{}.DistNormal(a, b)
|
||||||
got = Renyi{Alpha: 0.5}.DistNormal(a, b)
|
got = Renyi{Alpha: 0.5}.DistNormal(a, b)
|
||||||
if math.Abs(want-got) > 1e-10 {
|
if !floats.EqualWithinAbsOrRel(want, got, 1e-10, 1e-10) {
|
||||||
t.Errorf("Case %d: Renyi mismatch with Bhattacharyya: got %v, want %v", cas, got, want)
|
t.Errorf("Case %d: Renyi mismatch with Bhattacharyya: got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare with KL in both directions.
|
// Compare with KL in both directions.
|
||||||
want = KullbackLeibler{}.DistNormal(a, b)
|
want = KullbackLeibler{}.DistNormal(a, b)
|
||||||
got = Renyi{Alpha: 0.9999999}.DistNormal(a, b) // very close to 1 but not equal to 1.
|
got = Renyi{Alpha: 0.9999999}.DistNormal(a, b) // very close to 1 but not equal to 1.
|
||||||
if math.Abs(want-got) > 1e-6 {
|
if !floats.EqualWithinAbsOrRel(want, got, 1e-6, 1e-6) {
|
||||||
t.Errorf("Case %d: Renyi mismatch with KL(a||b): got %v, want %v", cas, got, want)
|
t.Errorf("Case %d: Renyi mismatch with KL(a||b): got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
want = KullbackLeibler{}.DistNormal(b, a)
|
want = KullbackLeibler{}.DistNormal(b, a)
|
||||||
got = Renyi{Alpha: 0.9999999}.DistNormal(b, a) // very close to 1 but not equal to 1.
|
got = Renyi{Alpha: 0.9999999}.DistNormal(b, a) // very close to 1 but not equal to 1.
|
||||||
if math.Abs(want-got) > 1e-6 {
|
if !floats.EqualWithinAbsOrRel(want, got, 1e-6, 1e-6) {
|
||||||
t.Errorf("Case %d: Renyi mismatch with KL(b||a): got %v, want %v", cas, got, want)
|
t.Errorf("Case %d: Renyi mismatch with KL(b||a): got %v, want %v", cas, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,7 @@ func TestChiSquared(t *testing.T) {
|
|||||||
|
|
||||||
func testChiSquared(t *testing.T, c ChiSquared, i int) {
|
func testChiSquared(t *testing.T, c ChiSquared, i int) {
|
||||||
tol := 1e-2
|
tol := 1e-2
|
||||||
const n = 1e5
|
const n = 1e6
|
||||||
const bins = 50
|
const bins = 50
|
||||||
x := make([]float64, n)
|
x := make([]float64, n)
|
||||||
generateSamples(x, c)
|
generateSamples(x, c)
|
||||||
|
@@ -73,7 +73,7 @@ func TestF(t *testing.T) {
|
|||||||
func testF(t *testing.T, f F, i int) {
|
func testF(t *testing.T, f F, i int) {
|
||||||
const (
|
const (
|
||||||
tol = 1e-2
|
tol = 1e-2
|
||||||
n = 1e5
|
n = 1e6
|
||||||
bins = 50
|
bins = 50
|
||||||
)
|
)
|
||||||
x := make([]float64, n)
|
x := make([]float64, n)
|
||||||
|
@@ -54,7 +54,7 @@ func TestTriangle(t *testing.T) {
|
|||||||
f := NewTriangle(test.a, test.b, test.c)
|
f := NewTriangle(test.a, test.b, test.c)
|
||||||
f.Source = src
|
f.Source = src
|
||||||
tol := 1e-2
|
tol := 1e-2
|
||||||
const n = 1e5
|
const n = 1e6
|
||||||
x := make([]float64, n)
|
x := make([]float64, n)
|
||||||
generateSamples(x, f)
|
generateSamples(x, f)
|
||||||
sort.Float64s(x)
|
sort.Float64s(x)
|
||||||
|
@@ -94,15 +94,15 @@ func TestRejection(t *testing.T) {
|
|||||||
dim := 3
|
dim := 3
|
||||||
bounds := make([]distmv.Bound, dim)
|
bounds := make([]distmv.Bound, dim)
|
||||||
for i := 0; i < dim; i++ {
|
for i := 0; i < dim; i++ {
|
||||||
min := rand.NormFloat64()
|
min := src.NormFloat64()
|
||||||
max := rand.NormFloat64()
|
max := src.NormFloat64()
|
||||||
if min > max {
|
if min > max {
|
||||||
min, max = max, min
|
min, max = max, min
|
||||||
}
|
}
|
||||||
bounds[i].Min = min
|
bounds[i].Min = min
|
||||||
bounds[i].Max = max
|
bounds[i].Max = max
|
||||||
}
|
}
|
||||||
target := distmv.NewUniform(bounds, nil)
|
target := distmv.NewUniform(bounds, src)
|
||||||
mu := target.Mean(nil)
|
mu := target.Mean(nil)
|
||||||
|
|
||||||
muImp := make([]float64, dim)
|
muImp := make([]float64, dim)
|
||||||
|
@@ -206,7 +206,7 @@ func (r *Rejectioner) Sample(batch *mat.Dense) {
|
|||||||
// numbers, otherwise rand.Float64 will be used.
|
// numbers, otherwise rand.Float64 will be used.
|
||||||
//
|
//
|
||||||
// Rejection sampling generates points from the target distribution by using
|
// Rejection sampling generates points from the target distribution by using
|
||||||
// the proposal distribution. At each step of the algorithm, the proposaed point
|
// the proposal distribution. At each step of the algorithm, the proposed point
|
||||||
// is accepted with probability
|
// is accepted with probability
|
||||||
// p = target(x) / (proposal(x) * c)
|
// p = target(x) / (proposal(x) * c)
|
||||||
// where target(x) is the probability of the point according to the target distribution
|
// where target(x) is the probability of the point according to the target distribution
|
||||||
|
@@ -5,14 +5,16 @@
|
|||||||
package sampleuv
|
package sampleuv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gonum.org/v1/gonum/floats"
|
||||||
"gonum.org/v1/gonum/stat"
|
"gonum.org/v1/gonum/stat"
|
||||||
"gonum.org/v1/gonum/stat/distuv"
|
"gonum.org/v1/gonum/stat/distuv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const tol = 1e-2
|
||||||
|
|
||||||
type lhDist interface {
|
type lhDist interface {
|
||||||
Quantile(float64) float64
|
Quantile(float64) float64
|
||||||
CDF(float64) float64
|
CDF(float64) float64
|
||||||
@@ -48,7 +50,7 @@ func TestImportance(t *testing.T) {
|
|||||||
weights := make([]float64, nSamples)
|
weights := make([]float64, nSamples)
|
||||||
Importance(x, weights, target, proposal)
|
Importance(x, weights, target, proposal)
|
||||||
ev := stat.Mean(x, weights)
|
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)
|
t.Errorf("Mean mismatch: Want %v, got %v", trueMean, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +65,7 @@ func TestRejection(t *testing.T) {
|
|||||||
x := make([]float64, nSamples)
|
x := make([]float64, nSamples)
|
||||||
Rejection(x, target, proposal, 100, nil)
|
Rejection(x, target, proposal, 100, nil)
|
||||||
ev := stat.Mean(x, 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)
|
t.Errorf("Mean mismatch: Want %v, got %v", trueMean, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,7 @@ func TestMetropolisHastings(t *testing.T) {
|
|||||||
// Remove burnin
|
// Remove burnin
|
||||||
x = x[burnin:]
|
x = x[burnin:]
|
||||||
ev := stat.Mean(x, nil)
|
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)
|
t.Errorf("Mean mismatch: Want %v, got %v", trueMean, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ var (
|
|||||||
}
|
}
|
||||||
exp = newExp()
|
exp = newExp()
|
||||||
|
|
||||||
obt = []float64{973, 1937, 3898, 7897, 15769, 31284, 62176, 125408, 250295, 500363}
|
obt = []float64{1020, 1909, 3937, 7881, 15687, 31486, 62310, 124632, 250453, 500685}
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestWeighted() Weighted {
|
func newTestWeighted() Weighted {
|
||||||
@@ -92,7 +92,7 @@ func TestWeightedTimeSeeded(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log("Note: This test is stochastic and is expected to fail with probability ≈ 0.05.")
|
t.Log("Note: This test is stochastic and is expected to fail with probability ≈ 0.05.")
|
||||||
|
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(uint64(time.Now().Unix()))
|
||||||
|
|
||||||
f := make([]float64, len(obt))
|
f := make([]float64, len(obt))
|
||||||
for i := 0; i < 1e6; i++ {
|
for i := 0; i < 1e6; i++ {
|
||||||
|
@@ -72,8 +72,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacency,
|
locality: simpleAdjacency,
|
||||||
|
|
||||||
wantMoranI: -0.0019631298955953233,
|
wantMoranI: -0.04387221370785312,
|
||||||
wantZ: -0.03039477405151108,
|
wantZ: -1.3543515772206267,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -98,8 +98,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacency,
|
locality: simpleAdjacency,
|
||||||
|
|
||||||
wantMoranI: 0.031195199553564902,
|
wantMoranI: 0.0259414094549987,
|
||||||
wantZ: 1.0171161514080056,
|
wantZ: 0.8511426395944303,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -112,8 +112,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacency,
|
locality: simpleAdjacency,
|
||||||
|
|
||||||
wantMoranI: -0.016245135637562223,
|
wantMoranI: -0.0003533345592575677,
|
||||||
wantZ: -0.48157993864993476,
|
wantZ: 0.0204605353504713,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -126,8 +126,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacency,
|
locality: simpleAdjacency,
|
||||||
|
|
||||||
wantMoranI: -0.8565268969272998,
|
wantMoranI: -0.8587138204405251,
|
||||||
wantZ: -27.027057520918113,
|
wantZ: -27.09614459007475,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -150,8 +150,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacencyBand,
|
locality: simpleAdjacencyBand,
|
||||||
|
|
||||||
wantMoranI: -0.0019631298955953233,
|
wantMoranI: -0.04387221370785312,
|
||||||
wantZ: -0.03039477405151108,
|
wantZ: -1.3543515772206267,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -176,8 +176,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacencyBand,
|
locality: simpleAdjacencyBand,
|
||||||
|
|
||||||
wantMoranI: 0.031195199553564902,
|
wantMoranI: 0.0259414094549987,
|
||||||
wantZ: 1.0171161514080056,
|
wantZ: 0.8511426395944303,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -190,8 +190,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacencyBand,
|
locality: simpleAdjacencyBand,
|
||||||
|
|
||||||
wantMoranI: -0.016245135637562223,
|
wantMoranI: -0.0003533345592575677,
|
||||||
wantZ: -0.48157993864993476,
|
wantZ: 0.0204605353504713,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -204,8 +204,8 @@ var spatialTests = []struct {
|
|||||||
},
|
},
|
||||||
locality: simpleAdjacencyBand,
|
locality: simpleAdjacencyBand,
|
||||||
|
|
||||||
wantMoranI: -0.8565268969272998,
|
wantMoranI: -0.8587138204405251,
|
||||||
wantZ: -27.027057520918113,
|
wantZ: -27.09614459007475,
|
||||||
wantSegs: 0,
|
wantSegs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user