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

Implement gammalogccdf for ForwardDiff #666

Open
mashu opened this issue Sep 20, 2023 · 1 comment
Open

Implement gammalogccdf for ForwardDiff #666

mashu opened this issue Sep 20, 2023 · 1 comment

Comments

@mashu
Copy link

mashu commented Sep 20, 2023

I am modeling in Turing.jl some process in which I use Gamma prior to parametrize Truncated Poisson and I use NUTs sampler.

However, my model has nested dependence and I cannot fully vectorize the loop, so Zygote would be slow. The default ForwardDiff throws at me an error

ERROR: MethodError: no method matching _gammalogccdf(::ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}, ::ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}, ::ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8})
Stacktrace:
  [1] gammalogccdf(k::Int64, θ::Int64, x::ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8})
    @ StatsFuns ~/.julia/packages/StatsFuns/atA5S/src/distrs/gamma.jl:71
  [2] poislogcdf(λ::ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}, x::Int64)
    @ StatsFuns ~/.julia/packages/StatsFuns/atA5S/src/distrs/pois.jl:30
  [3] logcdf(d::Poisson{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}}, x::Int64)
    @ Distributions ~/.julia/packages/Distributions/Ufrz2/src/univariates.jl:638
  [4] _logcdf_noninclusive(d::Poisson{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}}, x::Int64)
    @ Distributions ~/.julia/packages/Distributions/Ufrz2/src/censored.jl:441
  [5] truncated(d::Poisson{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}}, l::Int64, u::Int64)
    @ Distributions ~/.julia/packages/Distributions/Ufrz2/src/truncate.jl:67
  [6] Truncated(d::Poisson{ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 8}}, l::Int64, u::Int64)
    @ Distributions ./deprecated.jl:105
  [7] macro expansion

To my understanding this error suggests that the model is encountering issues with automatic differentiation, specifically when evaluating the complementary cumulative distribution function (CCDF) of the Gamma distribution. Seems like the error might be related to the Truncated Poisson distribution, as the truncation operation might involve the CCDF of the underlying distribution.

Can that be solved in ForwardDiff AD ?

@devmotion
Copy link
Member

I think this issue should be filed with StatsFuns. The missing part is support of ForwardDiff for StatsFuns.gammalogccdf and/or StatsFuns.poislogcdf. These functions do not support ForwardDiff.Dual yet. The problem is similar to JuliaStats/StatsFuns.jl#152.

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