Public Documentation
Documentation for EpiAwareADTools's public interface.
Contents
Index
EpiAwareADTools.ccdf_ad_safeEpiAwareADTools.cdf_ad_safeEpiAwareADTools.logccdf_ad_safeEpiAwareADTools.logcdf_ad_safeEpiAwareADTools.pdf_ad_safeEpiAwareADTools.primalEpiAwareADTools.primal_distribution
Public API
EpiAwareADTools.ccdf_ad_safe Function
ccdf_ad_safe(
dist::Distributions.UnivariateDistribution,
u::Real
) -> AnyAD-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
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
using EpiAwareADTools, Distributions
ccdf_ad_safe(Gamma(2.0, 1.0), 3.0)EpiAwareADTools.cdf_ad_safe Function
cdf_ad_safe(
dist::Distributions.UnivariateDistribution,
u::Real
) -> AnyAD-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
using EpiAwareADTools, Distributions
cdf_ad_safe(Gamma(2.0, 1.0), 3.0)EpiAwareADTools.logccdf_ad_safe Function
logccdf_ad_safe(
dist::Distributions.UnivariateDistribution,
u::Real
) -> AnyAD-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 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
using EpiAwareADTools, Distributions
logccdf_ad_safe(Gamma(2.0, 1.0), 3.0)EpiAwareADTools.logcdf_ad_safe Function
logcdf_ad_safe(
dist::Distributions.UnivariateDistribution,
u::Real
) -> AnyAD-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
using EpiAwareADTools, Distributions
logcdf_ad_safe(Gamma(2.0, 1.0), 3.0)EpiAwareADTools.pdf_ad_safe Function
pdf_ad_safe(
dist::Distributions.UnivariateDistribution,
t::Real
) -> AnyAD-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
using EpiAwareADTools, Distributions
pdf_ad_safe(Gamma(2.0, 1.0), 3.0)EpiAwareADTools.primal Function
primal(x::Real) -> AnyStrip 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
using EpiAwareADTools
primal(3.0), primal(((1.0, 2.0), 3.0))EpiAwareADTools.primal_distribution Function
primal_distribution(
d::Distributions.UnivariateDistribution
) -> AnyRebuild 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
using EpiAwareADTools, Distributions
primal_distribution(Gamma(2.0, 1.0))