JuliaDynamics/DelayEmbeddings.jl

Binning problem in mutualinformation?

Datseris opened this issue · 1 comments

Very rarely this can happen:

using DynamicalSystems
ds = Systems.gissinger(ones(3)) # 3D continuous chaotic system, also shown in orbit diagrams tutorial
dt = 0.05
data = trajectory(ds, 1000.0, dt = dt)
s = data[:, 1]

τ = estimate_delay(s, "mi_min", 0:1:400)
ERROR: BoundsError: attempt to access 98-element Array{Float64,1} at index [99]
Stacktrace:
 [1] getindex at .\array.jl:729 [inlined]
 [2] _frequencies!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\datseris\.julia\dev\DelayEmbeddings\src\estimate_delay.jl:269
 [3] _mutualinfo!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Int64,1}, ::Array{Float64,1}) at C:\Users\datseris\.julia\dev\DelayEmbeddings\src\estimate_delay.jl:240
 [4] #mutualinformation#56(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{Float64,1}, ::StepRange{Int64,Int64}) at C:\Users\datseris\.julia\dev\DelayEmbeddings\src\estimate_delay.jl:207
 [5] mutualinformation at C:\Users\datseris\.julia\dev\DelayEmbeddings\src\estimate_delay.jl:197 [inlined]
 [6] #estimate_delay#39(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{Float64,1}, ::String, ::StepRange{Int64,Int64}) at C:\Users\datseris\.julia\dev\DelayEmbeddings\src\estimate_delay.jl:50
 [7] estimate_delay(::Array{Float64,1}, ::String, ::StepRange{Int64,Int64}) at C:\Users\datseris\.julia\dev\DelayEmbeddings\src\estimate_delay.jl:33
 [8] top-level scope at none:0

Increasing the total integration time seems to fix it, but I do not know where the bug is coming from.

I cannot reproduce the issue. The same code in my machine just returns 52 without any error or warning. May the integration yield such different results in different machines??!!

Testing on Julia 1.0.1 in an Intel(R) Core(TM) i3-4100M CPU @ 2.50GHz, 8GiB SODIMM DDR3 1600 MHz, running Ubuntu 16.04.5-LTS. Status of ~/.julia/environments/v1.0/Project.toml
[6e4b80f9] BenchmarkTools v0.4.1
[336ed68f] CSV v0.4.2
[5d742f6a] CSVFiles v0.10.0
[608a59af] ChaosTools v1.3.1+ [~/.julia/dev/ChaosTools]
[a93c6f00] DataFrames v0.14.1
[5732040d] DelayEmbeddings v1.0.0+ [~/.julia/dev/DelayEmbeddings]
[b4f34e82] Distances v0.7.3
[6e36e845] DynamicalSystemsBase v1.1.1+ [~/.julia/dev/DynamicalSystemsBase]
[4c0ca9eb] Gtk v0.16.4
[86fae568] ImageView v0.8.0
[916415d5] Images v0.16.1
[5ab0869b] KernelDensity v0.5.1
[91a5bcdd] Plots v0.20.6
[ee283ea6] Rebugger v0.1.4
[639c3291] RecurrenceAnalysis v0.12.0+ [~/.julia/dev/RecurrenceAnalysis]
[295af30f] Revise v0.7.15
[44d3d7a6] Weave v0.6.2

Anyway, the error message gives the hint. For some reason there was one or more values of the trajectory greater than the greatest edge that had been defined for the histogram, and the line 269 of estimate_delay.jl tried to find a bin for the histogram that does not exist.

I must investigate why there may be values outside the bounds of the edges defined for the histogram (that work is done by _bisect or _equalbins); but in the meantime, a non-breaking fix is to stop the loop when the limit is reached (#19).