Giter VIP home page Giter VIP logo

empiricaldistributions.jl's Introduction

empiricaldistributions.jl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

empiricaldistributions.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Error defining a distribution with UvBinnedDist(Histogram(...))

Hi @oschulz, do you know why the following fails?

julia> UvBinnedDist(Histogram(0:5, [1,2,3,4,5]))

ERROR: ArgumentError: step cannot be zero
Stacktrace:
 [1] StepRange at ./range.jl:205 [inlined]
 [2] _rangestyle at ./range.jl:118 [inlined]
 [3] _range at ./range.jl:116 [inlined]
 [4] #range#43 at ./range.jl:91 [inlined]
 [5] -(::UnitRange{Int64}, ::UnitRange{Int64}) at ./range.jl:1059
 [6] broadcasted at ./broadcast.jl:1081 [inlined]
 [7] broadcasted at ./broadcast.jl:1263 [inlined]
 [8] _bin_widths(::UnitRange{Int64}) at /home/gipert/.julia/packages/EmpiricalDistributions/oc6hy/src/utils.jl:7
 [9] _broadcast_getindex_evalf at ./broadcast.jl:648 [inlined]
 [10] _broadcast_getindex at ./broadcast.jl:621 [inlined]
 [11] #19 at ./broadcast.jl:1046 [inlined]
 [12] ntuple at ./ntuple.jl:41 [inlined]
 [13] copy at ./broadcast.jl:1046 [inlined]
 [14] materialize at ./broadcast.jl:837 [inlined]
 [15] _mean(::Histogram{Float64,1,Tuple{UnitRange{Int64}}}) at /home/gipert/.julia/packages/EmpiricalDistributions/oc6hy/src/utils.jl:65
 [16] UvBinnedDist{Float64,U,VT,VU} where VU<:AbstractArray{U,1} where VT<:AbstractArray{Float64,1} where U<:Real(::Histogram{Int64,1,Tuple{UnitRange{Int64}}}) at /home/gipert/.julia/packages/EmpiricalDistributions/oc6hy/src/uv_binned_dist.jl:57
 [17] UvBinnedDist(::Histogram{Int64,1,Tuple{UnitRange{Int64}}}) at /home/gipert/.julia/packages/EmpiricalDistributions/oc6hy/src/uv_binned_dist.jl:68
 [18] top-level scope at REPL[52]:1
 [19] run_repl(::REPL.AbstractREPL, ::Any) at /build/julia/src/julia-1.5.2/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288

I'm reading an histogram from file, that's why I don't use StatsBase.fit...

BoundsError when a pdf ask for a point in the last edge

Hello!

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.

Best,

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

Bounds error getting pdf for last bin

using EmpiricalDistributions: UvBinnedDist
a = [1,2,3]
h = fit(Histogram, a)
uvd = UvBinnedDist(h)
pdf(uvd, 10)

Gives

BoundsError: attempt to access 3-element Array{Float64,1} at index [4]
getindex(::Array{Float64,1}, ::Int64) at array.jl:744
pdf(::UvBinnedDist{Float64}, ::Int64) at uv_binned_dist.jl:89
...

I noticed that length(uvd.edges), length(uvd.volumes) returns 4, 3

I'm on StatsBase v0.32.2

T is undefined in `cdf`

On this line:

p::T = @inbounds sum(d.hist.weights[1:i-1] .* d._volumes[1:i-1])

I just found your package and was playing around, and tried to take the cdf of a UvBinnedDist.

It seems the type parameter was left off of the signature. Relatedly, the where {T, N} annotations on mean/mode etc. are not necessary, I think, since in those functions they aren't being referenced.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.