Skip to content

Internal Documentation

Documentation for CensoredDistributions.jl's internal interface.

Contents

Index

Internal API

Base.rand Method
julia
rand(
    rng::Random.AbstractRNG,
    d::CensoredDistributions.IntervalCensored
) -> Any

Generate a random sample by discretising a sample from the underlying distribution.

See also: quantile

source
Base.rand Method
julia
rand(
    rng::Random.AbstractRNG,
    d::CensoredDistributions.PrimaryCensored
) -> Any

Generate a random sample by summing samples from delay and primary event distributions.

See also: quantile

source
Base.rand Method
julia
rand(
    rng::Random.AbstractRNG,
    d::CensoredDistributions.Weighted
) -> Any

Generate a random sample (delegates to underlying distribution).

See also: quantile

source
Base.rand Method
julia
rand(rng::Random.AbstractRNG, d::ExponentiallyTilted) -> Any

Generate a random sample using inverse transform sampling.

See also: quantile

source
CensoredDistributions._collect_unique_boundaries Method
julia
_collect_unique_boundaries(
    d::CensoredDistributions.IntervalCensored,
    x::AbstractVector{<:Real}
) -> Any
julia
_collect_unique_boundaries(d::IntervalCensored, x::AbstractVector)

Collect all unique interval boundaries needed for vectorised PDF computation.

Returns a sorted vector of unique boundaries with appropriate type promotion. The boundaries are functions of the (constant) lags and the interval spec, not the distribution's AD parameters, so AD rules mark this non-differentiable (the unique/sort internals are never traced); see the AD extensions (#699, #701).

source
CensoredDistributions._compute_boundary_cdfs Method
julia
_compute_boundary_cdfs(
    d::CensoredDistributions.IntervalCensored,
    boundaries::AbstractVector
) -> Any
julia
_compute_boundary_cdfs(d::IntervalCensored, boundaries)

Evaluate the boundary CDF once per unique boundary, returning a vector parallel to the sorted unique boundaries. cdf_ad_safe keeps the Gamma path differentiable (see #257). CDF values keep their natural type so the AD tangent is not stripped. Boundaries at or below minimum(dist) / at or above maximum(dist) get the literal 0 / 1 (typed via partype) instead of an evaluation, mirroring the scalar pdf guard; evaluating cdf_ad_safe at a degenerate boundary (e.g. LogNormal at 0) would poison the reverse sweep with a -Inf/NaN adjoint (#699).

source
CensoredDistributions._compute_pdfs_with_cache Method
julia
_compute_pdfs_with_cache(
    d::CensoredDistributions.IntervalCensored,
    x::AbstractVector{<:Real},
    boundaries::AbstractVector,
    cdf_values::AbstractVector
) -> Any
julia
_compute_pdfs_with_cache(d, x, boundaries, cdf_values)

Compute PDFs efficiently using the cached boundary CDFs held in the parallel arrays boundaries (sorted, unique) and cdf_values.

Uses the same boundary case handling as the scalar method.

source
CensoredDistributions._lookup_boundary_cdf Method
julia
_lookup_boundary_cdf(
    boundaries::AbstractVector,
    cdf_values::AbstractVector,
    b
) -> Any
julia
_lookup_boundary_cdf(boundaries, cdf_values, b)

Look up the cached CDF for boundary b in the sorted, unique boundaries vector via searchsortedfirst, returning the matching cdf_values entry. The concretely-typed parallel arrays plus an index lookup keep the boundary CDF cache type-stable so the AD tangent is tracked through it (#699).

source
CensoredDistributions._make_weibull_g Method
julia
_make_weibull_g(
    k::Real,
    λ::Real
) -> CensoredDistributions.var"#weibull_g_specialized#_make_weibull_g##0"{<:Real, <:Real}

Function factory for optimized Weibull g function.

Creates a specialized function with pre-computed constants for g(t; k, λ) = γ(1 + 1/k, (t/λ)^k) where γ is the lower incomplete gamma function.

Pre-computes inv_k = 1/k and a = 1 + inv_k to avoid repeated computation in the returned specialized function.

Arguments

  • k::Real: Weibull shape parameter

  • λ::Real: Weibull scale parameter

Returns

A specialized function weibull_g_specialized(t::Real) that efficiently computes the Weibull g function using pre-computed constants.

Examples

julia
weibull_g_func = _make_weibull_g(2.0, 1.5)
g_val = weibull_g_func(3.0)
source
CensoredDistributions._quantile_optimization Method
julia
_quantile_optimization(
    d,
    p::Real;
    initial_guess_fn,
    result_postprocess_fn,
    check_nan
) -> Any

Internal function for quantile optimization using numerical methods.

Solves the equation cdf(d, q) - p = 0 using the Nelder-Mead algorithm. This is shared logic used by both PrimaryCensored and IntervalCensored quantile functions.

Arguments

  • d: The distribution for which to compute the quantile

  • p: The probability value in [0, 1]

Keyword Arguments

  • initial_guess_fn: Function that takes (d, p) and returns initial guess vector. If nothing, uses quantile(get_dist(d), p) as scalar initial guess.

  • result_postprocess_fn: Function to post-process the optimization result. Defaults to identity (no post-processing).

  • check_nan: If true, explicitly check for NaN input values.

Returns

The quantile value after optimization and post-processing.

Implementation Details

  • Validates that p ∈ [0, 1] (with optional NaN checking)

  • Handles boundary cases p=0 (minimum) and p=1 (maximum) analytically

  • Creates objective function (cdf(d, q) - p)^2 with support checking

  • Uses heavy penalty for values outside distribution support

  • Solves with Nelder-Mead algorithm with tight tolerances

  • Checks convergence and applies post-processing to result

Type Stability

This function is designed to maintain type stability when the initial guess function and post-processing function are type-stable.

source
CensoredDistributions.combine_weights Method
julia
combine_weights(_::Missing, _::Missing) -> Missing

Combine constructor weight with observation weight using dispatch-based rules.

Weight combination rules:

  • missing, missing → missing (both missing means no weight)

  • w1, missing → w1 (use constructor weight)

  • missing, w2 → w2 (use observation weight)

  • w1, w2 → w1 * w2 (multiply weights)

Vector Extensions

For Product distributions, additional methods handle vectorised weight combinations:

  • Vector, Vector → combine_weights.(vector1, vector2) (element-wise combination)

  • Vector, missing → Vector (keep constructor weights)

  • Vector, scalar → [combine_weights(w, scalar) for w in Vector] (broadcast scalar)

source
Distributions.ccdf Method
julia
ccdf(d::CensoredDistributions.Weighted, x::Real) -> Any

Compute the complementary cumulative distribution function (delegates to underlying distribution).

See also: cdf

source
Distributions.cdf Method
julia
cdf(
    d::CensoredDistributions.Convolved,
    x::AbstractVector{<:Real}
) -> Any

Compute the CDF for a vector of evaluation points using a single quadrature solve (the integrand returns a vector).

See also: cdf

source
Distributions.cdf Method
julia
cdf(d::CensoredDistributions.Convolved, x::Real) -> Any

Compute the cumulative distribution function.

Uses an analytical convolution when Distributions.convolve applies to all component pairs, otherwise AD-safe numeric quadrature.

See also: logcdf

source
Distributions.cdf Method
julia
cdf(
    d::CensoredDistributions.IntervalCensored,
    x::Real
) -> Any

Compute the cumulative distribution function.

See also: logcdf

source
Distributions.cdf Method
julia
cdf(
    d::CensoredDistributions.PrimaryCensored,
    x::Real
) -> Any

Compute the cumulative distribution function.

See also: logcdf

source
Distributions.cdf Method
julia
cdf(d::CensoredDistributions.Weighted, x::Real) -> Any

Compute the cumulative distribution function (delegates to underlying distribution).

See also: logcdf

source
Distributions.cdf Method
julia
cdf(d::ExponentiallyTilted, x::Real) -> Any

Compute the cumulative distribution function.

See also: logcdf, quantile

source
Distributions.logccdf Method
julia
logccdf(d::CensoredDistributions.Weighted, x::Real) -> Any

Compute the log complementary cumulative distribution function (delegates to underlying distribution).

See also: logcdf

source
Distributions.logcdf Method
julia
logcdf(d::CensoredDistributions.Convolved, x::Real) -> Any

Compute the log cumulative distribution function.

See also: cdf

source
Distributions.logcdf Method
julia
logcdf(
    d::CensoredDistributions.IntervalCensored,
    x::Real
) -> Any

Compute the log cumulative distribution function.

See also: cdf

source
Distributions.logcdf Method
julia
logcdf(
    d::CensoredDistributions.PrimaryCensored,
    x::Real
) -> Any

Compute the log cumulative distribution function.

See also: cdf

source
Distributions.logcdf Method
julia
logcdf(d::CensoredDistributions.Weighted, x::Real) -> Any

Compute the log cumulative distribution function (delegates to underlying distribution).

See also: cdf

source
Distributions.logcdf Method
julia
logcdf(d::ExponentiallyTilted, x::Real) -> Any

Compute the log cumulative distribution function.

See also: cdf

source
Distributions.logpdf Method
julia
logpdf(
    d::CensoredDistributions.Convolved,
    x::AbstractVector{<:Real}
) -> Any

Compute log densities for a vector of points, reusing the batched PDF solve for the numeric path.

See also: logpdf, pdf

source
Distributions.logpdf Method
julia
logpdf(d::CensoredDistributions.Convolved, x::Real) -> Any

Compute the log probability density function.

See also: pdf, logcdf

source
Distributions.logpdf Method
julia
logpdf(
    d::CensoredDistributions.IntervalCensored,
    x::AbstractVector{<:Real}
) -> Any

Compute log probability masses for an array of values using optimised PDF computation.

See also: pdf, logpdf

source
Distributions.logpdf Method
julia
logpdf(
    d::CensoredDistributions.IntervalCensored,
    x::Real
) -> Any

Compute the log probability mass for the interval containing x.

See also: pdf, logcdf

source
Distributions.logpdf Method
julia
logpdf(
    d::CensoredDistributions.PrimaryCensored,
    x::Real
) -> Any

Compute the log probability density function using numerical differentiation of the log CDF.

See also: pdf, logcdf

source
Distributions.logpdf Method
julia
logpdf(
    d::CensoredDistributions.Weighted,
    obs::NamedTuple{(:value, :weight)}
) -> Any

Return the weighted log-probability for joint observations as NamedTuple.

Combines constructor weight with observation weight via multiplication. Expected format: (value = x, weight = w).

See also: pdf

source
Distributions.logpdf Method
julia
logpdf(d::CensoredDistributions.Weighted, x::Real) -> Any

Return the weighted log-probability for scalar observations.

See also: pdf

source
Distributions.logpdf Method
julia
logpdf(
    d::Distributions.Product{<:Distributions.ValueSupport, <:CensoredDistributions.Weighted, <:AbstractVector{<:CensoredDistributions.Weighted}},
    x::AbstractVector{<:Real}
) -> Any

Efficient vectorised log-probability computation for Product{<:ValueSupport, <:Weighted} with vector observations.

See also: logpdf

source
Distributions.logpdf Method
julia
logpdf(
    d::Distributions.Product{<:Distributions.ValueSupport, <:CensoredDistributions.Weighted, <:AbstractVector{<:CensoredDistributions.Weighted}},
    obs::NamedTuple{(:values, :weights)}
) -> Any

Efficient vectorised log-probability computation for Product{<:ValueSupport, <:Weighted} with joint observations.

Handles joint observations and weight stacking. Expected format: (values = [...], weights = [...]).

See also: logpdf

source
Distributions.logpdf Method
julia
logpdf(d::ExponentiallyTilted, x::Real) -> Any

Compute the log probability density function.

See also: pdf, cdf

source
Distributions.pdf Method
julia
pdf(
    d::CensoredDistributions.Convolved,
    x::AbstractVector{<:Real}
) -> Any

Compute densities for a vector of points using a single quadrature solve (the integrand returns a vector).

See also: pdf

source
Distributions.pdf Method
julia
pdf(d::CensoredDistributions.Convolved, x::Real) -> Any

Compute the probability density function.

Uses the exact analytical convolved density where Distributions.convolve applies to all component pairs, otherwise the AD-safe numeric density convolution    .

See also: logpdf

source
Distributions.pdf Method
julia
pdf(
    d::CensoredDistributions.IntervalCensored,
    x::AbstractVector{<:Real}
) -> Any

Compute probability masses for an array of values using optimised vectorisation.

This method collects unique interval boundaries, computes CDFs once, then uses cached values for efficient PDF computation across the array.

See also: pdf, logpdf

source
Distributions.pdf Method
julia
pdf(
    d::CensoredDistributions.IntervalCensored,
    x::Real
) -> Any

Compute the probability mass for the interval containing x.

See also: logpdf, cdf

source
Distributions.pdf Method
julia
pdf(
    d::CensoredDistributions.PrimaryCensored,
    x::Real
) -> Any

Compute the probability density function using numerical differentiation.

See also: logpdf

source
Distributions.pdf Method
julia
pdf(d::CensoredDistributions.Weighted, x::Real) -> Any

Return the probability density from the underlying distribution (unweighted).

See also: logpdf

source
Distributions.pdf Method
julia
pdf(d::ExponentiallyTilted, x::Real) -> Any

Compute the probability density function.

See also: logpdf

source
Distributions.sampler Method
julia
sampler(d::CensoredDistributions.Weighted) -> Any

Create a sampler for efficient sampling (delegates to underlying distribution).

See also: rand

source
Statistics.mean Method
julia
mean(d::ExponentiallyTilted) -> Any

Compute the mean of the distribution.

See also: var, std

source
Statistics.median Method
julia
median(d::ExponentiallyTilted) -> Any

Compute the median of the distribution.

See also: quantile, mean

source
Statistics.quantile Method
julia
quantile(
    d::CensoredDistributions.IntervalCensored,
    p::Real
) -> Any

Compute the quantile using numerical optimization.

The returned quantile respects the interval structure:

  • For regular intervals: quantiles are multiples of the interval width

  • For arbitrary intervals: quantiles correspond to interval boundary values

See also: cdf

source
Statistics.quantile Method
julia
quantile(
    d::CensoredDistributions.PrimaryCensored,
    p::Real
) -> Any

Compute the quantile (inverse CDF) using numerical optimization.

See also: cdf

source
Statistics.quantile Method
julia
quantile(d::CensoredDistributions.Weighted, p::Real) -> Any

Compute the quantile function (delegates to underlying distribution).

See also: cdf

source
Statistics.quantile Method
julia
quantile(d::ExponentiallyTilted, p::Real) -> Any

Compute the quantile function (inverse CDF) using analytical formula.

See also: cdf

source
Statistics.std Method
julia
std(d::ExponentiallyTilted) -> Any

Compute the standard deviation of the distribution.

See also: mean, var

source
Statistics.var Method
julia
var(d::ExponentiallyTilted) -> Any

Compute the variance of the distribution.

See also: mean, std

source
StatsAPI.loglikelihood Method
julia
loglikelihood(
    d::CensoredDistributions.Weighted,
    obs::NamedTuple{(:value, :weight)}
) -> Any

Compute log-likelihood for single Weighted distribution with joint observations.

Handles joint observations as NamedTuple: (value = x, weight = w).

See also: logpdf

source
StatsAPI.loglikelihood Method
julia
loglikelihood(
    d::CensoredDistributions.Weighted,
    obs::NamedTuple{(:values, :weights)}
) -> Any

Compute log-likelihood for single Weighted distribution with vectorized joint observations.

Handles joint observations as NamedTuple: (values = [...], weights = [...]). This is useful when a single weighted distribution is used with multiple observations.

See also: logpdf

source
StatsAPI.loglikelihood Method
julia
loglikelihood(
    d::Distributions.Product{<:Distributions.ValueSupport, <:CensoredDistributions.Weighted, <:AbstractVector{<:CensoredDistributions.Weighted}},
    obs::NamedTuple{(:values, :weights)}
) -> Any

Compute log-likelihood for Product{<:ValueSupport, <:Weighted} with joint observations.

Handles joint observations as NamedTuple: (values = [...], weights = [...]).

See also: logpdf

source