Skip to content

Public Documentation

Documentation for EpiAwareADTools's public interface.

Contents

Index

Public API

EpiAwareADTools.ccdf_ad_safe Function
julia
ccdf_ad_safe(
    dist::Distributions.UnivariateDistribution,
    u::Real
) -> Any

AD-safe ccdf(dist, u): the survival  .

ccdf_ad_safe is the survival companion to cdf_ad_safe. Generic dispatch falls through to Distributions.ccdf; the Gamma method routes through the AD-safe so the survival differentiates w.r.t. the Gamma shape/scale.

An extension point: a downstream package adds methods for its own component types, the same pattern as pdf_ad_safe.

Arguments

  • dist: the distribution whose survival is evaluated.

  • u: the evaluation point.

Examples

julia
using EpiAwareADTools, Distributions

ccdf_ad_safe(Gamma(2.0, 1.0), 3.0)
source
EpiAwareADTools.cdf_ad_safe Function
julia
cdf_ad_safe(
    dist::Distributions.UnivariateDistribution,
    u::Real
) -> Any

AD-safe cdf(dist, u) companion to logcdf_ad_safe.

Same dispatch idea: route Gamma through _gamma_cdf so a CDF evaluation remains differentiable under reverse-mode AD in its shape/scale. A downstream numeric kernel that evaluates components through this hook can add a method for a component type with a non-AD-safe cdf.

An extension point: a wrapper package adds methods the same way as pdf_ad_safe.

Arguments

  • dist: the distribution whose CDF is evaluated.

  • u: the evaluation point.

Examples

julia
using EpiAwareADTools, Distributions

cdf_ad_safe(Gamma(2.0, 1.0), 3.0)
source
EpiAwareADTools.logccdf_ad_safe Function
julia
logccdf_ad_safe(
    dist::Distributions.UnivariateDistribution,
    u::Real
) -> Any

AD-safe logccdf(dist, u): the log survival  .

logccdf_ad_safe is the log-survival companion to logcdf_ad_safe. Generic dispatch falls through to Distributions.logccdf; the Gamma method routes through the AD-safe so a survival term differentiates w.r.t. the Gamma shape/scale (the stock logccdf(::Gamma) calls _gammalogccdf, which has no ForwardDiff.Dual shape method and errors).

An extension point: a downstream package adds methods for its own component types, the same pattern as pdf_ad_safe.

Arguments

  • dist: the distribution whose log survival is evaluated.

  • u: the evaluation point.

Examples

julia
using EpiAwareADTools, Distributions

logccdf_ad_safe(Gamma(2.0, 1.0), 3.0)
source
EpiAwareADTools.logcdf_ad_safe Function
julia
logcdf_ad_safe(
    dist::Distributions.UnivariateDistribution,
    u::Real
) -> Any

AD-safe logcdf(dist, u) for use inside differentiable integrands.

logcdf_ad_safe is the log-CDF member of the AD-safe hook family. Generic dispatch falls through to Distributions.logcdf. The Gamma method routes through _gamma_cdf so its ChainRulesCore.rrule is picked up by reverse-mode AD; without this, the integrand calls gamma_inc and breaks under every supported AD backend.

An extension point: a downstream package adds methods for component types whose stock logcdf is not AD-safe, the same pattern as pdf_ad_safe.

Arguments

  • dist: the distribution whose log CDF is evaluated.

  • u: the evaluation point.

Examples

julia
using EpiAwareADTools, Distributions

logcdf_ad_safe(Gamma(2.0, 1.0), 3.0)
source
EpiAwareADTools.pdf_ad_safe Function
julia
pdf_ad_safe(
    dist::Distributions.UnivariateDistribution,
    t::Real
) -> Any

AD-safe pdf(dist, t) for a component density inside a differentiable quadrature.

pdf_ad_safe is the density companion to cdf_ad_safe. Generic dispatch falls through to Distributions.pdf, and a downstream extension adds a method for a component whose stock pdf routes through functions that are not differentiable under the supported AD backends.

An extension point: a wrapper package hooks it so its modified components stay differentiable inside the quadrature, the same pattern as ccdf_ad_safe.

Arguments

  • dist: the component distribution whose density is evaluated.

  • t: the evaluation point.

Examples

julia
using EpiAwareADTools, Distributions

pdf_ad_safe(Gamma(2.0, 1.0), 3.0)
source
EpiAwareADTools.primal Function
julia
primal(x::Real) -> Any

Strip any AD wrapper (ForwardDiff Dual, ReverseDiff TrackedReal, Enzyme/Mooncake duals) from a scalar, returning its underlying primal value.

The generic method is the identity on a plain real, so a non-AD call keeps the value's own float type (e.g. Float32). The per-backend extensions add the unwrapping methods: EpiAwareADToolsForwardDiffExt and EpiAwareADToolsReverseDiffExt supply value-reading methods, while EpiAwareADToolsChainRulesCoreExt marks primal @non_differentiable, EpiAwareADToolsEnzymeExt marks it EnzymeRules.inactive, and EpiAwareADToolsMooncakeExt gives it a @zero_derivative rule. Together these keep a non-differentiable hyperparameter — for example a quadrature window endpoint, which is just where to integrate — off the AD path on every backend.

A composite distribution returns nested per-component parameter tuples from params, so the Tuple method strips elementwise (recursing into nested tuples). This is what lets primal_distribution, and any caller mapping primal over params(d), handle a component whose parameter is itself a tuple.

This is the sanctioned replacement for the underscore-prefixed _primal that ConvolvedDistributions.jl and CensoredDistributions.jl each carry internally; it stays hosted here until those packages depend on it directly.

Arguments

  • x: the value to strip; a plain real is returned unchanged, a tuple is stripped elementwise.

Examples

julia
using EpiAwareADTools

primal(3.0), primal(((1.0, 2.0), 3.0))
source
EpiAwareADTools.primal_distribution Function
julia
primal_distribution(
    d::Distributions.UnivariateDistribution
) -> Any

Rebuild a distribution with its parameters stripped to their primal values via the type's positional constructor.

params(d) round-trips through the constructor for the Distributions.jl families used here, so mapping primal over the parameters and calling the wrapper constructor reconstructs the distribution with plain (AD-stripped) parameters. The check_args = false keyword is intentionally not passed: the original distribution already validated its parameters and the primal copy uses the identical values. Reconstructing from primal parameters is what lets a downstream package evaluate a non-differentiable quantity (such as a quadrature-window quantile) on an integration component without live Dual or TrackedReal parameters flowing into it.

Arguments

  • d: the univariate distribution to rebuild from primal parameters.

Examples

julia
using EpiAwareADTools, Distributions

primal_distribution(Gamma(2.0, 1.0))
source