I have just found this bound error when working with my data. Here is a MWE:
julia> using EmpiricalDistributions, Distributions, StatsBase
julia> X = [2.583154269578564, 1.1743972342882214, 1.8364306990593289, 1.897397733775406, 2.015147087719347, 1.7440784071445519, 1.1198740268055243, 1.6101393177758048, 3.304973053680988, 2.593783923551583]
10-element Vector{Float64}:
2.583154269578564
1.1743972342882214
1.8364306990593289
1.897397733775406
2.015147087719347
1.7440784071445519
1.1198740268055243
1.6101393177758048
3.304973053680988
2.593783923551583
julia> h = fit(Histogram, X)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}}}
edges:
1.0:0.5:3.5
weights: [2, 4, 1, 2, 1]
closed: left
isdensity: false
julia> d = UvBinnedDist(h)
UvBinnedDist{Float64, Float64, Vector{Float64}, Vector{Float64}}(
_edge: [1.0, 1.5, 2.0, 2.5, 3.0, 3.5]
_edge_cdf: [0.0, 0.19999999999999996, 0.5999999999999999, 0.6999999999999998, 0.8999999999999998, 1.0]
_bin_pdf: [0.4, 0.8, 0.2, 0.4, 0.2]
_bin_probmass: [0.19999999999999996, 0.3999999999999999, 0.09999999999999998, 0.19999999999999996, 0.09999999999999998]
_closed_left: true
_mean: 2.05
_mode: 1.75
_var: 0.4099999999999999
)
julia> pdf(d, 3.4)
0.2
julia> pdf(d, 3.5)
ERROR: BoundsError: attempt to access 5-element Vector{Float64} at index [6]
Stacktrace:
[1] getindex
@ ./array.jl:801 [inlined]
[2] pdf(d::UvBinnedDist{Float64, Float64, Vector{Float64}, Vector{Float64}}, x::Float64)
@ EmpiricalDistributions ~/.julia/packages/EmpiricalDistributions/95uOW/src/uv_binned_dist.jl:100
[3] top-level scope
@ REPL[6]:1
julia> pdf(d, 3.6)
0.0
I hope it could help to solve the issue.
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
[31c24e10] Distributions v0.24.18
[0bbb1fad] EmpiricalDistributions v0.3.3
[2913bbd2] StatsBase v0.33.6