ForwardDiff on CDF for Beta distribution

I am trying to autodiff a function that depends on the CDF for a Beta distribution, but I get an error since this function depends on rmath, which only accepts Float64, not Reals, which I understand is required for Dual numbers to pass through the CDF function. This is all taken from the following open issue (since 2017): Limited Support for ForwardDiff on CDFs · Issue #638 · JuliaStats/Distributions.jl · GitHub.

The CDF of a Beta is the regularized incomplete Beta function, so I really just need autodiff to work on this function. I found an old v0.0.1 package (GitHub - jkovacic/IncGammaBeta.jl: A Julia package that computes incomplete gamma and beta functions and their inverses.) but it downgrades too many packages for me.

Any advice, except implementing the incomplete beta myself? Thanks.

I just added a comment to the issue you linked to Limited Support for ForwardDiff on CDFs · Issue #638 · JuliaStats/Distributions.jl · GitHub. Which derivative are you trying to compute? Wrt to one of the parameters or the “argument”?

1 Like

Thanks for the quick reply! I need the derivative wrt the parameter, not the argument. I interpret the reply of @devmotion to your comment on the github issue that this is now solved in ForwardDiff for the gamma distribution (gamma_inc) but still not for the beta distribution (beta_inc).

The incomplete beta function in the package IncGammaBeta.jl has the same issues:

using IncGammaBeta
using ForwardDiff: Dual
IncGammaBeta.inc_beta_lower_reg(1.2, 2.3, 0.45)
0.6913216388655349 # works with Float64
IncGammaBeta.inc_beta_lower_reg(1.2, 2.3, Dual(0.45,0)) # Errors with Dual numbers
julia> ERROR: MethodError: no method matching incBeta(::Float64, ::Float64, ::Dual{Nothing, Float64, …}, ::Bool, ::Bool)