Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

estimator Lindner errors with Nothing #348

Closed
Datseris opened this issue Oct 3, 2023 · 3 comments · Fixed by #350
Closed

estimator Lindner errors with Nothing #348

Datseris opened this issue Oct 3, 2023 · 3 comments · Fixed by #350
Assignees
Labels
bug Something isn't working

Comments

@Datseris
Copy link
Member

Datseris commented Oct 3, 2023

MWE

x = rand(1000)
y = rand(1000)
z = rand(1000)
ηTf = 1
embedding = EmbeddingTE(; dS = 3, dT = 3, dC = 3, ηTf)
estimator = Lindner(k=10)
independence_test = LocalPermutationTest(TEShannon(; embedding), estimator, nshuffles = 100)
independence(independence_test, x, y, z)

throws

ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type Float64

Closest candidates are:
  convert(::Type{T}, ::ColorTypes.Gray24) where T<:Real
   @ ColorTypes C:\Users\gd419\.julia\packages\ColorTypes\1dGw6\src\conversions.jl:114
  convert(::Type{T}, ::ColorTypes.Gray) where T<:Real
   @ ColorTypes C:\Users\gd419\.julia\packages\ColorTypes\1dGw6\src\conversions.jl:113
  convert(::Type{T}, ::Union{Static.StaticBool{N}, Static.StaticFloat64{N}, Static.StaticInt{N}} where N) where T<:Number
   @ Static C:\Users\gd419\.julia\packages\Static\dLrtk\src\Static.jl:414
  ...

Stacktrace:
 [1] setindex!(A::Vector{Float64}, x::Nothing, i1::Int64)
   @ Base .\array.jl:969
 [2] permuted_Îs(X::StateSpaceSet{1, Float64}, Y::StateSpaceSet{3, Float64}, Z::StateSpaceSet{6, Float64}, measure::CMIShannon{Shannon{Int64}}, est::Lindner{Int64}, test::LocalPermutationTest{TEShannon{Shannon{Int64}, EmbeddingTE}, Lindner{Int64}, CausalityTools.NeighborCloseness, TaskLocalRNG})
   @ CausalityTools C:\Users\gd419\.julia\dev\CausalityTools\src\independence_tests\local_permutation\LocalPermutationTest.jl:201     
 [3] independence(::LocalPermutationTest{TEShannon{Shannon{Int64}, EmbeddingTE}, Lindner{Int64}, CausalityTools.NeighborCloseness, TaskLocalRNG}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64})
   @ CausalityTools C:\Users\gd419\.julia\dev\CausalityTools\src\independence_tests\local_permutation\transferentropy.jl:23
 [4] top-level scope
   @ c:\Users\gd419\OneDrive - University of Exeter\Projects\CloudControlingRTSA\_research\ccf_basic_te_analysis.jl:68

Using estimator = FPVP() instead works.

@Datseris Datseris added the bug Something isn't working label Oct 3, 2023
@Datseris
Copy link
Member Author

Datseris commented Oct 3, 2023

I also get error for Zhu1. I don't understand. Is this because of my pr #343 ? Tests pass there and I didn't really change the estimation code.

@Datseris
Copy link
Member Author

Datseris commented Oct 3, 2023

Additionally, I would say the documentation around Lindner can be improved. It doesn't refer to a conditional timeseries and its documentation says that it computes $TE(X→Y)$. But then if I use it with LocalPermutationTest I must have a conditional timeseries.

@kahaaga
Copy link
Member

kahaaga commented Oct 3, 2023

Good catch! This is not an error on your part. It is an actual bug. It happens because for all the low-level estimators (entropy-based, mutual-info based, CMI-based), the cmi = te_to_cmi(measure) line in independence_tests/local_permutation/transferentropy.jl converts the incoming TEShannon measure to a CMIShannon measure. This is a trick that avoids some code duplication internally, but it fails to consider that the estimator might be defined only for TEShannon, not for CMIShannon.

This is a quick fix.

@kahaaga kahaaga self-assigned this Oct 3, 2023
kahaaga added a commit that referenced this issue Oct 3, 2023
kahaaga added a commit that referenced this issue Oct 4, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants