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

broadcast doesn't work for pdf calculation #63

Open
afniedermayer opened this issue Oct 26, 2018 · 1 comment
Open

broadcast doesn't work for pdf calculation #63

afniedermayer opened this issue Oct 26, 2018 · 1 comment

Comments

@afniedermayer
Copy link

broadcast doesn't work for pdf calculation, see e.g.

julia> using KernelDensity

julia> y=kde(randn(1000));

julia> pdf.(y, [.5,.6])
ERROR: MethodError: no method matching length(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}})
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:582
  length(::Base.MethodList) at reflection.jl:728
  length(::Core.MethodTable) at reflection.jl:802
  ...
Stacktrace:
 [1] _similar_for(::UnitRange{Int64}, ::Type, ::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Base.HasLength) at .\array.jl:532
 [2] _collect(::UnitRange{Int64}, ::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Base.HasEltype, ::Base.HasLength) at .\array.jl:563
 [3] collect(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at .\array.jl:557
 [4] broadcastable(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at .\broadcast.jl:609
 [5] broadcasted(::Function, ::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Array{Float64,1}) at .\broadcast.jl:1163
 [6] top-level scope at none:0

This is in contrast to other calculations of pdfs, e.g.

julia> using Distributions

julia> N=Normal()
Normal{Float64}=0.0, σ=1.0)

julia> pdf.(N, [.5,.6])
2-element Array{Float64,1}:
 0.3520653267642995
 0.33322460289179967

The non-broadcasting version does work for KernelDensity (pdf(y,[.5,.6])), however, for this kind of usage seems to be not recommended and deprecated, see e.g.

julia> pdf(N, [.5,.6])
┌ Warning: `pdf(d::UnivariateDistribution, X::AbstractArray)` is deprecated, use `pdf.(d, X)` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
2-element Array{Float64,1}:
 0.3520653267642995
 0.33322460289179967
@simonbyrne
Copy link
Member

Good point. You can use pdf.(Ref(y), [.5,.6]) until this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants