-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversion Error with Categorical Distribution in ExponentialFamily.jl #202
Comments
Or maybe it's rather because |
Good catch @Nimrais ! To me it seems like Categorical from Distributions.jl cannot be constructed from ArrayPartition, can you try that directly with just Distributions.jl? also I see another bug in your example, the natural parameters are actually not proper (the last parameter must always be zero) |
yeah, sure there more then one bug :) |
The solution would be to write a specialized convert method specifically for Categorical that would call ‘collect’ on the parameters before passing it to the constructor from Distributions.jl |
Yeah seems you are right. julia> Categorical(ArrayPartition([1/3, 1/3], [1/3]))
ERROR: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type ArrayPartition{Float64, Tuple{Vector{Float64}, Vector{Float64}}}
Closest candidates are:
convert(::Type{ArrayPartition{T, S}}, ::ArrayPartition{<:Any, <:Tuple{Vararg{Any, N}}}) where {N, T, S<:Tuple{Vararg{Any, N}}}
@ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/K1bCr/src/array_partition.jl:543
convert(::Type{T}, ::T) where T
@ Base Base.jl:84
convert(::Type{T}, ::T) where T<:AbstractArray
@ Base abstractarray.jl:16
...
Stacktrace:
[1] Categorical{Float64, ArrayPartition{…}}(xs::Base.OneTo{Int64}, ps::ArrayPartition{Float64, Tuple{…}}; check_args::Bool)
@ Distributions ~/.julia/packages/Distributions/ji8PW/src/univariate/discrete/discretenonparametric.jl:34
[2] DiscreteNonParametric
@ ~/.julia/packages/Distributions/ji8PW/src/univariate/discrete/discretenonparametric.jl:24 [inlined]
[3] #_#115
@ ~/.julia/packages/Distributions/ji8PW/src/univariate/discrete/categorical.jl:31 [inlined]
[4] DiscreteNonParametric
@ ~/.julia/packages/Distributions/ji8PW/src/univariate/discrete/categorical.jl:29 [inlined]
[5] (Categorical{P} where P<:Real)(p::ArrayPartition{Float64, Tuple{Vector{Float64}, Vector{Float64}}})
@ Distributions ~/.julia/packages/Distributions/ji8PW/src/univariate/discrete/categorical.jl:34
[6] top-level scope
@ REPL[1]:1
Some type information was truncated. Use `show(err)` to see complete types. |
I think we can also open a bug in |
I have opened an issue there JuliaStats/Distributions.jl#1878 |
Yeah we can do it, and once Distributions.jl will start to support ArrayPartition we would be able to remove it |
When attempting to create and manipulate an ExponentialFamilyDistribution with a Categorical distribution with natural parameters container
ArrayPartition.
The code fails during conversion. I think it's because NaturalToMean, but maybe it's supposed to be so however such behavior is quite inconvenient.Error
The text was updated successfully, but these errors were encountered: