-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
LocalPermutationTest
to be used with TEShannon
estimated us…
…ing dedicated TE estimators (#350) * Fix issue #348 * More effective estimation for `Lindner` when doing e.g. surrogate tests partially addresses #344 * Typos * Add tests * Up patch version * Correctly scale * Make sure we have enough samples for tests * Better test organization * It is the estimator that controls what happens, not the measure * Add note to `LocalPermutationTest` docstring about transfer entropy * Error should occur only for `TransferEntropyEstimator`s * More tests * Improve test comments. * Fix #349 And also mention conditioning in `Zhu1` docs
- Loading branch information
Showing
14 changed files
with
250 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Test | ||
using CausalityTools | ||
using StableRNGs | ||
|
||
rng = StableRNG(123) | ||
x, y, z = rand(rng, 30), rand(rng, 30), rand(rng, 30) | ||
|
||
independence_test = LocalPermutationTest(CMIShannon(), FPVP()) | ||
# We should get back a convenience wrapper containing the result. | ||
res = independence(independence_test, x, z, y) | ||
@test res isa LocalPermutationTestResult | ||
|
||
# We should be able to compute p-values for the result. | ||
@test pvalue(res) isa Real | ||
@test pvalue(res) ≥ 0 | ||
|
||
# Only conditional analyses are possible, meaning that we need three inputs. | ||
# Pairwise analyses won't work, because only two inputs are given. | ||
@test_throws ArgumentError independence(independence_test, x, y) | ||
|
||
# Sampling with/without replacement | ||
test_cmi_replace = LocalPermutationTest(CMIShannon(), FPVP(), replace = true) | ||
test_cmi_nonreplace = LocalPermutationTest(CMIShannon(), FPVP(), replace = false) | ||
@test independence(test_cmi_replace, x, y, z) isa LocalPermutationTestResult | ||
@test independence(test_cmi_nonreplace, x, y, z) isa LocalPermutationTestResult | ||
|
||
# Measure definition AND estimator must be provided for info measures | ||
@test_throws ArgumentError LocalPermutationTest(TEShannon()) # estimator needed | ||
|
||
# The number of local neighbors can't exceed the number of input datapoints | ||
test_kperm_toolarge = LocalPermutationTest(CMIShannon(), FPVP(); kperm = 200, rng) | ||
@test_throws ArgumentError independence(test_kperm_toolarge, x, y, z) |
21 changes: 21 additions & 0 deletions
21
test/independence/LocalPermutationTest/conditional_mutual_information.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Test | ||
using CausalityTools | ||
using StableRNGs | ||
|
||
rng = StableRNG(123) | ||
x, y, z = rand(rng, 30), rand(rng, 30), rand(rng, 30) | ||
|
||
X = StateSpaceSet(x) | ||
Y = StateSpaceSet(y) | ||
Z = StateSpaceSet(z) | ||
|
||
nshuffles = 5 | ||
lptest_sp = LocalPermutationTest(CMIShannon(), SymbolicPermutation(); nshuffles, rng) | ||
lptest_vh = LocalPermutationTest(CMIShannon(), ValueHistogram(4); nshuffles, rng) | ||
lptest_dp = LocalPermutationTest(CMIShannon(), Dispersion(); nshuffles, rng) | ||
@test independence(lptest_sp, x, y, z) isa LocalPermutationTestResult | ||
@test independence(lptest_vh, x, y, z) isa LocalPermutationTestResult | ||
@test independence(lptest_dp, x, y, z) isa LocalPermutationTestResult | ||
@test independence(lptest_sp, X, Y, Z) isa LocalPermutationTestResult | ||
@test independence(lptest_vh, X, Y, Z) isa LocalPermutationTestResult | ||
@test independence(lptest_dp, X, Y, Z) isa LocalPermutationTestResult |
9 changes: 9 additions & 0 deletions
9
test/independence/LocalPermutationTest/distance_correlation.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Test | ||
using CausalityTools | ||
using StableRNGs | ||
|
||
rng = StableRNG(123) | ||
x, y, z = rand(rng, 30), rand(rng, 30), rand(rng, 30) | ||
|
||
independence_test = LocalPermutationTest(DistanceCorrelation()) | ||
@test independence(independence_test, x, y, z) isa LocalPermutationTestResult |
9 changes: 9 additions & 0 deletions
9
test/independence/LocalPermutationTest/local_permutation_test.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include("api.jl") | ||
|
||
# Measure-specific implementations. One file per method that is listed in the docstring | ||
# of `LocalPermutationTest`. | ||
include("conditional_mutual_information.jl") | ||
include("part_mutual_information.jl") | ||
include("transferentropy.jl") | ||
include("partial_correlation.jl") | ||
include("distance_correlation.jl") |
47 changes: 4 additions & 43 deletions
47
test/independence/LocalPermutation.jl → ...ermutationTest/part_mutual_information.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/independence/LocalPermutationTest/partial_correlation.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Test | ||
using CausalityTools | ||
using StableRNGs | ||
|
||
rng = StableRNG(123) | ||
x, y, z = rand(rng, 30), rand(rng, 30), rand(rng, 30) | ||
|
||
independence_test = LocalPermutationTest(PartialCorrelation()) | ||
@test independence(independence_test, x, y, z) isa LocalPermutationTestResult |
Oops, something went wrong.
477bd4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
477bd4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/92761
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: