Skip to content

TDist - cdf and quantile function - Auto-Differentiability #152

Description

@paschermayr

Hi there,

Thank you for all your work! I have seen that recently, pull request #147 was closed in favor of #149.

I believe the former issue tried to make the cdf and quantile function of the TDistribution auto-differentiable, but the latter closed it and did not alleviate this issue. MWE from a fresh project with all up-to-date libraries:

using Distributions, DistributionsAD, StatsBase
using ForwardDiff, ReverseDiff
using StatsFuns

function mytargetfunction(data::AbstractVector)
    function obtaingradient::AbstractVector{R}) where {R<:Real}
        nu = θ[1]
        distr = TDist(nu)
        data_uniform = [cdf(distr, data[iter]) for iter in eachindex(data)]
        data_real = [quantile(distr, data_uniform[iter]) for iter in eachindex(data_uniform)]
        return sum( logpdf(distr, data_real[iter]) for iter in eachindex(data_real) )
    end
end

#working
ν = [3.0]
data = randn(1000)
target = mytargetfunction(data)
target(ν)
#not working
ForwardDiff.gradient(target, ν) #MethodError: no method matching _beta_inc(::ForwardDiff.Dual
ReverseDiff.gradient(target, ν) #MethodError: no method matching _beta_inc(::ReverseDiff.TrackedReal

It seems like the beta_inc function is from the Specialfunctions.jl package and requires Float64 as arguments instead of just reals. Is there a reason for that? I believe I should probably open an issue there as well?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions