Skip to content

Commit e377fe3

Browse files
committed
Use StableRNG for test that sometimes fails due to random data generation
1 parent a3cf9ce commit e377fe3

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

test/independence/JointDistanceDistributionTest.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using Random: MersenneTwister
2-
rng = MersenneTwister(12346)
2+
rng = StableRNG(12346)
33
x, y = randn(rng, 1000), randn(rng, 1000)
4-
m = JointDistanceDistribution(D = 3, B = 5)
5-
test = JointDistanceDistributionTest(m)
4+
m = JointDistanceDistribution(D=3, B=5)
5+
test = JointDistanceDistributionTest(m)
66
@test test isa JointDistanceDistributionTest
77
@test independence(test, x, y) isa Associations.JDDTestResult
88

99
# Don't reject null at significance level (1 - α) when there is no coupling.
1010
α = 0.05
11-
@test pvalue(independence(test, x, y)) > α
11+
@test pvalue(independence(test, x, y)) > α
1212

1313
# Reject null at significance level (1 - α) when there is coupling
1414
z = y .+ x

test/independence/SurrogateAssociationTest/LMeasure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Analytical tests (in the limit of a lot of samples)
22
# ------------------------------------------------------------
33
using Random
4-
rng = MersenneTwister(1234)
4+
rng = StableRNG(1234)
55
n = 100
66
x, y = rand(rng, n), rand(rng, n)
77
z = x .+ y
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
using Test
22
using Random
3-
rng = Xoshiro(1234)
3+
rng = StableRNG(1234)
44

55
# We can use surrogate tests and p-values to further verify the correctness of the
66
# algorithm.
7-
test = SurrogateAssociationTest(AzadkiaChatterjeeCoefficient(), nshuffles = 19, rng = rng)
7+
test = SurrogateAssociationTest(AzadkiaChatterjeeCoefficient(), nshuffles=19, rng=rng)
88
n = 200
99
# We expect that we *cannot* reject the null hypothesis for independent variables
1010
x = rand(rng, n)
1111
y = rand(rng, n)
1212
α = 0.05
13-
@test pvalue(independence(test, x, y)) > α
13+
@test pvalue(independence(test, x, y)) > α
1414

1515
# We expect that we *can* reject the null hypothesis for for dependent variables.
1616
x = rand(rng, n)
1717
y = rand(rng, n) .* x
18-
@test pvalue(independence(test, x, y )) < α
18+
@test pvalue(independence(test, x, y)) < α
1919

2020
# We expect that we *cannot* reject the null hypothesis for two extremal variables
2121
# connected by an intermediate variable when conditioning on the intermediate variable.
2222
x = rand(rng, n)
2323
y = rand(rng, n) .+ x
2424
z = rand(rng, n) .* y
25-
@test pvalue(independence(test, x, z, y)) > α
25+
@test pvalue(independence(test, x, z, y)) > α
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using Test
22
using Random
3-
rng = Xoshiro(1234)
3+
using StableRNGs
4+
rng = StableRNG(1234)
45

56
# We can use surrogate tests and p-values to further verify the correctness of the
67
# algorithm.
7-
test = SurrogateAssociationTest(ChatterjeeCorrelation(), nshuffles = 19, rng = rng)
8+
test = SurrogateAssociationTest(ChatterjeeCorrelation(), nshuffles=19, rng=rng)
89

910
# We expect that we *cannot* reject the null hypothesis for independent variables
1011
x = rand(rng, 1:10, 200)
1112
y = rand(rng, 1:10, 200)
1213
α = 0.05
13-
@test pvalue(independence(test, x, y)) > α
14+
@test pvalue(independence(test, x, y)) > α
1415

1516
# We expect that we *can* reject the null hypothesis for for dependent variables.
1617
w = rand(rng, 1:10, 200)
1718
z = rand(rng, 1:10, 200) .* sin.(w) .+ cos.(w)
18-
@test pvalue(independence(test, z, w)) < α
19+
@test pvalue(independence(test, z, w)) < α

0 commit comments

Comments
 (0)