Skip to content

Getting started

EpiAwareADTools hosts the EpiAware org's AD-safety machinery in one place. Two families make up the surface: the tape-strip pair primal/primal_distribution, and the AD-safe evaluation hooks cdf_ad_safe and companions. The Charter and status page explains why each entry is here and when it gets deleted; this page is the quickstart.

Installation

The package is not yet registered. Add it by URL:

julia
using Pkg
Pkg.add(url = "https://github.com/EpiAware/EpiAwareADTools.jl")

Load it:

julia
using EpiAwareADTools

AD-safe Gamma evaluation

The hooks evaluate a distribution the way Distributions.jl does, but the Gamma methods stay differentiable in the shape and scale. Load a backend and the matching extension supplies the derivative.

julia
using EpiAwareADTools, Distributions

d = Gamma(2.0, 1.0)
cdf_ad_safe(d, 3.0), logccdf_ad_safe(d, 3.0)
(0.8008517265285442, -1.6137056388801092)

The gradient of a Gamma CDF in its parameters is available on every supported backend:

julia
using ForwardDiff

ForwardDiff.gradient-> cdf_ad_safe(Gamma(θ[1], θ[2]), 3.0), [2.0, 1.0])
2-element Vector{Float64}:
 -0.19742541957920146
 -0.44808361531077556

The stock cdf(::Gamma) has no shape derivative, so this gradient would otherwise error; see AD-safe evaluation hooks.

Stripping an AD wrapper

primal reduces an AD-wrapped scalar to its underlying value, and primal_distribution rebuilds a distribution from primal parameters. Use them to keep a non-differentiable hyperparameter off the AD path.

julia
primal(3.0), primal_distribution(Gamma(2.0, 1.5))
(3.0, Distributions.Gamma{Float64}(α=2.0, θ=1.5))

See Tape-strip: primal for the backend details.

Learning more