Internal Documentation
Documentation for ConvolvedDistributions's internal interface.
Contents
Index
Distributions.cdfDistributions.componentsDistributions.logcdfDistributions.logpdfDistributions.pdfStatistics.meanStatistics.stdStatistics.var
Internal API
Distributions.cdf Function
cdf(d::UnivariateDistribution, x::Real)Evaluate the cumulative probability at x.
See also ccdf, logcdf, and logccdf.
cdf(d::ConvolvedDistributions.Convolved, x::Real) -> AnyCompute the cumulative distribution function.
Uses an analytical convolution when Distributions.convolve applies to all component pairs, otherwise AD-safe numeric quadrature.
See also: logcdf
cdf(
d::ConvolvedDistributions.Convolved,
x::AbstractVector{<:Real}
) -> AnyCompute the CDF for a vector of evaluation points in one batched composite-quadrature pass.
Each point is integrated over the same window the scalar path picks, on a shared panel grid whose nodes and integration-component density are evaluated once and reused across points, plus small per-point end-correction integrals. Batched and scalar results therefore agree to well within ~1e-8 (typically near machine precision) for batches spanning up to ~40x point ranges; extreme spans (100x and beyond) stay within ~1e-6. See the FAQ.
See also: cdf
cdf(d::Difference, z::Real) -> AnyCompute the cumulative distribution function.
Uses the analytic Normal-Normal difference where it applies, otherwise AD-safe numeric quadrature of
See also: logcdf
cdf(d::ConvolvedDistributions.Product, z::Real) -> AnyCompute the cumulative distribution function.
Uses the analytic LogNormal-LogNormal product where it applies, otherwise AD-safe numeric quadrature of Y's density diverges at zero (shape below one).
See also: logcdf
Distributions.components Function
components(d::AbstractMixtureModel)Get a list of components of the mixture model d.
components(d::ConvolvedDistributions.Convolved) -> Tuplecomponents(d::Convolved)The independent delay distributions whose sum d represents, returned as the component tuple. The public accessor for peeling a Convolved apart without reaching into its fields — a downstream lower bridge, for one, folds them into a series phase-type chain. Extends Distributions.components (the standard composite-distribution accessor), so it composes with using Distributions rather than clashing with it.
Distributions.logcdf Function
logcdf(d::UnivariateDistribution, x::Real)The logarithm of the cumulative function value(s) evaluated at x, i.e. log(cdf(x)).
logcdf(d::ConvolvedDistributions.Convolved, x::Real) -> AnyCompute the log cumulative distribution function.
See also: cdf
logcdf(d::Difference, z::Real) -> AnyCompute the log cumulative distribution function.
See also: cdf
logcdf(d::ConvolvedDistributions.Product, z::Real) -> AnyCompute the log cumulative distribution function.
See also: cdf
Distributions.logpdf Function
logpdf(d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,N}) where {N}Evaluate the logarithm of the probability density function of d at x.
This function checks if the size of x is compatible with distribution d. This check can be disabled by using @inbounds.
Implementation
Instead of logpdf one should implement _logpdf(d, x) which does not have to check the size of x.
See also: pdf, gradlogpdf.
logpdf(d::Distribution{ArrayLikeVariate{N}}, x) where {N}Evaluate the logarithm of the probability density function of d at every element in a collection x.
This function checks for every element of x if its size is compatible with distribution d. This check can be disabled by using @inbounds.
Here, x can be
an array of dimension
> Nwithsize(x)[1:N] == size(d), oran array of arrays
xiof dimensionNwithsize(xi) == size(d).
logpdf(d::UnivariateDistribution, x::Real)Evaluate the logarithm of probability density (mass) at x.
See also: pdf.
logpdf(d::Union{UnivariateMixture, MultivariateMixture}, x)Evaluate the logarithm of the (mixed) probability density function over x. Here, x can be a single sample or an array of multiple samples.
logpdf(d::ConvolvedDistributions.Convolved, x::Real) -> AnyCompute the log probability density function.
sourcelogpdf(
d::ConvolvedDistributions.Convolved,
x::AbstractVector{<:Real}
) -> AnyCompute log densities for a vector of points, reusing the batched PDF solve for the numeric path.
Each point is integrated over the same window the scalar path picks (shared composite panels plus per-point end corrections), so batched and scalar log densities agree to well within ~1e-8 even for wide batches (typically near machine precision; extreme 100x-plus point spans stay within ~1e-6).
sourcelogpdf(d::Difference, z::Real) -> AnyCompute the log probability density function.
sourcelogpdf(d::ConvolvedDistributions.Product, z::Real) -> AnyCompute the log probability density function.
sourceStatistics.mean Function
mean(d::UnivariateDistribution)Compute the expectation.
sourcemean(d::MultivariateDistribution)Compute the mean vector of distribution d.
mean(d::MatrixDistribution)Return the mean matrix of d.
mean(d::Union{UnivariateMixture, MultivariateMixture})Compute the overall mean (expectation).
sourcemean(d::ConvolvedDistributions.Convolved) -> AnyMean of the convolution: the exact sum of the component means.
A Convolved is a sum of independent components, so the mean is mean; a component without one errors (there is no numeric fallback).
mean(d::Difference) -> AnyMean of the difference: the difference of the component means,
mean(d::ConvolvedDistributions.Product) -> AnyMean of the product: the product of the component means,
mean(itr)Compute the mean of all elements in a collection.
Note
If itr contains NaN or missing values, the result is also NaN or missing (missing takes precedence if array contains both). Use the skipmissing function to omit missing entries and compute the mean of non-missing values.
Examples
julia> using Statistics
julia> mean(1:20)
10.5
julia> mean([1, missing, 3])
missing
julia> mean(skipmissing([1, missing, 3]))
2.0mean(f, itr)Apply the function f to each element of collection itr and take the mean.
julia> using Statistics
julia> mean(√, [1, 2, 3])
1.3820881233139908
julia> mean([√1, √2, √3])
1.3820881233139908mean(f, A::AbstractArray; dims)Apply the function f to each element of array A and take the mean over dimensions dims.
Julia 1.3
This method requires at least Julia 1.3.
julia> using Statistics
julia> mean(√, [1, 2, 3])
1.3820881233139908
julia> mean([√1, √2, √3])
1.3820881233139908
julia> mean(√, [1 2 3; 4 5 6], dims=2)
2×1 Matrix{Float64}:
1.3820881233139908
2.2285192400943226mean(A::AbstractArray; dims)Compute the mean of an array over the given dimensions.
Julia 1.1
mean for empty arrays requires at least Julia 1.1.
Examples
julia> using Statistics
julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
1 2
3 4
julia> mean(A, dims=1)
1×2 Matrix{Float64}:
2.0 3.0
julia> mean(A, dims=2)
2×1 Matrix{Float64}:
1.5
3.5Distributions.pdf Function
pdf(d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,N}) where {N}Evaluate the probability density function of d at x.
This function checks if the size of x is compatible with distribution d. This check can be disabled by using @inbounds.
Implementation
Instead of pdf one should implement _pdf(d, x) which does not have to check the size of x. However, since the default definition of pdf(d, x) falls back to logpdf(d, x) usually it is sufficient to implement logpdf.
See also: logpdf.
pdf(d::Distribution{ArrayLikeVariate{N}}, x) where {N}Evaluate the probability density function of d at every element in a collection x.
This function checks for every element of x if its size is compatible with distribution d. This check can be disabled by using @inbounds.
Here, x can be
an array of dimension
> Nwithsize(x)[1:N] == size(d), oran array of arrays
xiof dimensionNwithsize(xi) == size(d).
pdf(d::UnivariateDistribution, x::Real)Evaluate the probability density (mass) at x.
See also: logpdf.
pdf(d::Union{UnivariateMixture, MultivariateMixture}, x)Evaluate the (mixed) probability density function over x. Here, x can be a single sample or an array of multiple samples.
pdf(d::ConvolvedDistributions.Convolved, x::Real) -> AnyCompute 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
pdf(
d::ConvolvedDistributions.Convolved,
x::AbstractVector{<:Real}
) -> AnyCompute densities for a vector of points in one batched composite-quadrature pass (see the batched cdf method).
See also: pdf
pdf(d::Difference, z::Real) -> AnyCompute the probability density function.
Uses the exact analytic Normal-Normal density where it applies, otherwise the AD-safe numeric cross-correlation
See also: logpdf
pdf(d::ConvolvedDistributions.Product, z::Real) -> AnyCompute the probability density function.
Uses the exact analytic LogNormal-LogNormal density where it applies, otherwise the AD-safe numeric Mellin convolution
See also: logpdf
pdf(
pmf::ConvolvedDistributions.DelayPMF,
lag::Integer
) -> AnyRead the precomputed DelayPMF masses at integer lags.
pdf(pmf, lag) returns the discretised interval mass at lag (an integer, or a vector of integers for a batched read), reusing the build-once masses instead of re-evaluating CDF differences per lag. A lag outside 0..maxlag returns a zero of the PMF's element type (no mass is carried there). lag counts grid steps, not time units: for a PMF built with interval != 1, pdf(pmf, k) is the mass on [k * interval, (k + 1) * interval).
Arguments
pmf: a precomputedDelayPMF.lag: an integer lag, or a vector of integer lags.
Examples
using ConvolvedDistributions, Distributions
pmf = discretise_pmf(Gamma(2.0, 1.0), 10)
pdf(pmf, 3)
pdf(pmf, 0:5)See also
discretise_pmf: build the PMF once
Statistics.std Function
std(d::UnivariateDistribution)Return the standard deviation of distribution d, i.e. sqrt(var(d)).
std(d::MultivariateDistribution)Compute the vector of element-wise standard deviations for distribution d.
std(d::ConvolvedDistributions.Convolved) -> AnyStandard deviation of the convolution,
std(d::Difference) -> AnyStandard deviation of the difference,
std(d::ConvolvedDistributions.Product) -> AnyStandard deviation of the product,
std(itr; corrected::Bool=true, mean=nothing[, dims])Compute the sample standard deviation of collection itr.
The algorithm returns an estimator of the generative distribution's standard deviation under the assumption that each entry of itr is a sample drawn from the same unknown distribution, with the samples uncorrelated. For arrays, this computation is equivalent to calculating sqrt(sum((itr .- mean(itr)).^2) / (length(itr) - 1)). If corrected is true, then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false with n the number of elements in itr.
If itr is an AbstractArray, dims can be provided to compute the standard deviation over dimensions.
A pre-computed mean may be provided. When dims is specified, mean must be an array with the same shape as mean(itr, dims=dims) (additional trailing singleton dimensions are allowed).
Note
If array contains NaN or missing values, the result is also NaN or missing (missing takes precedence if array contains both). Use the skipmissing function to omit missing entries and compute the standard deviation of non-missing values.
Statistics.var Function
var(d::UnivariateDistribution)Compute the variance. (A generic std is provided as std(d) = sqrt(var(d)))
var(d::MultivariateDistribution)Compute the vector of element-wise variances for distribution d.
var(d::MatrixDistribution)Compute the matrix of element-wise variances for distribution d.
var(d::UnivariateMixture)Compute the overall variance (only for UnivariateMixture).
var(d::ConvolvedDistributions.Convolved) -> AnyVariance of the convolution: the exact sum of the component variances.
Independence makes the variance additive, mean, each component must provide an analytic var or the call errors.
var(d::Difference) -> AnyVariance of the difference: the sum of the component variances,
var(d::ConvolvedDistributions.Product) -> AnyVariance of the product:
var(itr; corrected::Bool=true, mean=nothing[, dims])Compute the sample variance of collection itr.
The algorithm returns an estimator of the generative distribution's variance under the assumption that each entry of itr is a sample drawn from the same unknown distribution, with the samples uncorrelated. For arrays, this computation is equivalent to calculating sum((itr .- mean(itr)).^2) / (length(itr) - 1). If corrected is true, then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n is the number of elements in itr.
If itr is an AbstractArray, dims can be provided to compute the variance over dimensions.
A pre-computed mean may be provided. When dims is specified, mean must be an array with the same shape as mean(itr, dims=dims) (additional trailing singleton dimensions are allowed).
Note
If array contains NaN or missing values, the result is also NaN or missing (missing takes precedence if array contains both). Use the skipmissing function to omit missing entries and compute the variance of non-missing values.