JuliaDynamics / Associations.jl

Algorithms for quantifying associations, independence testing and causal inference from data.
https://juliadynamics.github.io/Associations.jl/stable/
Other
148 stars 12 forks source link

Type declarations in `te_embed` (and likely other parts of the code) are too restrictive #347

Open Datseris opened 11 months ago

Datseris commented 11 months ago

I am working on using CausalityTools.jl on 32-bit climate data. I do not bother to convert data to 64 bit. I just noticed that out of the box te_embed doesn't work. I would speculate that this would happen in other parts of the library. Here is a MWE:

using CausalityTools
x = rand(Float32, 100)
y = rand(Float32, 100)
z = copy(y)
embedding = EmbeddingTE(; dS = 4, dT = 4, dC = 4)
independence_test = LocalPermutationTest(TEShannon(; embedding), FPVP(), nshuffles = 50)
independence(independence_test, x, y, z)

which gives on latest stable 2.9.1:

ERROR: MethodError: no method matching te_embed(::EmbeddingTE, ::Vector{Float64}, ::Vector{Float32}, ::Vector{Float32})

Closest candidates are:
  te_embed(::Any, ::Any, ::Any, ::EmbeddingTE)
   @ CausalityTools deprecated.jl:103
  te_embed(::EmbeddingTE, ::AbstractVector{T}, ::AbstractVector{T}) where T
   @ CausalityTools C:\Users\gd419\.julia\dev\CausalityTools\src\methods\infomeasures\transferentropy\utils.jl:146 
  te_embed(::EmbeddingTE, ::AbstractVector{T}, ::AbstractVector{T}, ::AbstractVector{T}) where T
   @ CausalityTools C:\Users\gd419\.julia\dev\CausalityTools\src\methods\infomeasures\transferentropy\utils.jl:184 
  ...

Stacktrace:
 [1] individual_marginals_te(::EmbeddingTE, ::Vector{Float64}, ::Vararg{AbstractVector})
   @ CausalityTools C:\Users\gd419\.julia\dev\CausalityTools\src\methods\infomeasures\transferentropy\transferentropy.jl:151
 [2] independence(::LocalPermutationTest{TEShannon{Shannon{Int64}, EmbeddingTE}, FPVP{Chebyshev, Chebyshev}, CausalityTools.NeighborCloseness, TaskLocalRNG}, ::Vector{Float64}, ::Vector{Float32}, ::Vector{Float32})
   @ CausalityTools C:\Users\gd419\.julia\dev\CausalityTools\src\independence_tests\local_permutation\transferentropy.jl:14
 [3] top-level scope
   @ c:\Users\gd419\OneDrive - University of Exeter\Projects\CloudControlingRTSA\_research\ccf_basic_te_analysis.jl:47
kahaaga commented 11 months ago

Yep, te_embed(::EmbeddingTE, ::AbstractVector{T}, ::AbstractVector{T}) where T (and the conditional variant) requires that all input timeseries have the same element type. This shouldn't be necessary.