Skip to content

Internal Documentation

Documentation for ScoringRules's internal interface.

Contents

Index

Internal API

ScoringRules._check_multiv Function
julia
_check_multiv(X::AbstractMatrix, y::AbstractVector) -> Any
julia
_check_multiv(X, y)

Verify that X is a d × m matrix and y is a length-d vector.

source
ScoringRules._check_w_vs Function
julia
_check_w_vs(w_vs::AbstractMatrix, d::Integer) -> Any
julia
_check_w_vs(w_vs, d)

Validate a d × d pairwise weight matrix for the variogram score: square of the right size, non-negative and symmetric (the checks R's vs_sample applies to w_vs).

source
ScoringRules._crps_2pexp Function
julia
_crps_2pexp(
    y::Real,
    scale1::Real,
    scale2::Real,
    location::Real
) -> Any
julia
_crps_2pexp(y, scale1, scale2, location)

CRPS of a two-piece-exponential forecast in closed form. Calls _crps_expM (exponential with point mass) for each arm.

source
ScoringRules._crps_2pnorm Function
julia
_crps_2pnorm(
    y::Real,
    scale1::Real,
    scale2::Real,
    location::Real
) -> Any
julia
_crps_2pnorm(y, scale1, scale2, location)

CRPS of a two-piece-normal forecast in closed form. Calls _crps_gtcnorm (generalised truncated/censored normal) for each arm.

source
ScoringRules._crps_beta Function
julia
_crps_beta(
    y::Real,
    shape1::Real,
    shape2::Real,
    lower::Real,
    upper::Real
) -> Any
julia
_crps_beta(y, shape1, shape2, lower, upper)

CRPS of a Beta(shape1, shape2) distribution scaled to [lower, upper], in closed form. For [0, 1] bounds the formula is

julia
c1 + (shape1/(shape1+shape2)) · (c3  c4)

where c1 = y · (2·I_y(shape1, shape2) − 1) c3 = 1 − 2·I_y(shape1+1, shape2) c4 = (2/shape1) · B(2·shape1, 2·shape2) / B(shape1, shape2)²

and I_x(a,b) is the regularised incomplete beta = cdf_ad_safe(Beta(a,b), x), routed through the AD-safe hook becausebeta_incis not Dual-safe in either shape argument (#6). No z==0 guard is needed here (unlike the Student-t CDF):z is a function of the observation alone, so the singular chain-rule composition never arises. A Stirling approximation is substituted for c4 when the beta-function ratio overflows. Non-unit intervals are handled by linear rescaling.

source
ScoringRules._crps_binom Function
julia
_crps_binom(y::Real, size::Integer, prob::Real) -> Any

CRPS of a Binomial(n, p) forecast, via finite sum over the support.

source
ScoringRules._crps_exp Function
julia
_crps_exp(y::Real, rate::Real) -> Any
julia
_crps_exp(y, rate)

CRPS of an Exp(rate) forecast in closed form.

Formula: |y| - (2·F(y) - 0.5) / rate where F is the Exp(rate) CDF.

source
ScoringRules._crps_expM Function
julia
_crps_expM(
    y::Real,
    location::Real,
    scale::Real,
    mass::Real
) -> Any
julia
_crps_expM(y, location, scale, mass)

CRPS of a mixed distribution that places point mass mass at location and distributes the remaining probability (1 - mass) as Exp(1/scale) shifted by location. Internal helper; reused by the two-piece exponential family.

Formula: |y - location| - scale·a·(2·F(y - location, 1/scale) - 0.5·a) where a = 1 - mass and F is the Exp(1/scale) CDF.

source
ScoringRules._crps_gamma Function
julia
_crps_gamma(y::Real, shape::Real, scale::Real) -> Any
julia
_crps_gamma(y, shape, scale)

CRPS of a Gamma(shape, scale) forecast in closed form.

Formula: y·(2·F₁ − 1) − scale·(shape·(2·F₂ − 1) + 1/B(0.5, shape)) where F₁ = CDF of Gamma(shape, scale) at y, F₂ = CDF of Gamma(shape+1, scale) at y, B(a,b) = exp(logbeta(a, b)).

F₁/F₂ go through cdf_ad_safe: the stock cdf(::Gamma) reaches gamma_inc, whose shape-parameter partial is unimplemented, breaking shape differentiation on every AD backend (#11).

source
ScoringRules._crps_gev Function
julia
_crps_gev(y::Real, shape::Real) -> Any
_crps_gev(y::Real, shape::Real, location::Real) -> Any
_crps_gev(
    y::Real,
    shape::Real,
    location::Real,
    scale::Real
) -> Any

CRPS of a GEV(location, scale, shape) forecast at observation y, in closed form (Friederichs & Thorarinsdottir 2012). Shape must be < 1.

The Gumbel limit (|shape| < 1e-12) is handled analytically via the exponential integral Ei.

source
ScoringRules._crps_gpd Function
julia
_crps_gpd(y::Real, shape::Real) -> Any
_crps_gpd(y::Real, shape::Real, location::Real) -> Any
_crps_gpd(
    y::Real,
    shape::Real,
    location::Real,
    scale::Real
) -> Any
_crps_gpd(
    y::Real,
    shape::Real,
    location::Real,
    scale::Real,
    mass::Real
) -> Any

CRPS of a GPD(location, scale, shape) forecast at observation y, in closed form (Friederichs & Thorarinsdottir 2012). Shape must be < 1.

mass is an optional point mass at the location (lower boundary); it is retained for internal use but not exposed through the Distributions dispatch.

source
ScoringRules._crps_hyper Function
julia
_crps_hyper(
    y::Real,
    m::Integer,
    n::Integer,
    k::Integer
) -> Any

CRPS of a Hypergeometric(m, n, k) forecast, via finite sum over the support. Here m = number of white balls, n = number of black balls, k = draws (matching R's phyper / crps_hyper convention).

source
ScoringRules._crps_lapl Function
julia
_crps_lapl(y::Real, location::Real, scale::Real) -> Any
julia
_crps_lapl(y, location, scale)

CRPS of a Laplace(location, scale) forecast in closed form.

Formula (unit-scale, location-shifted): CRPS = scale * (|z| + exp(-|z|) - 3/4) where z = (y - location) / scale.

source
ScoringRules._crps_llapl Function
julia
_crps_llapl(
    y::Real,
    locationlog::Real,
    scalelog::Real
) -> Any
julia
_crps_llapl(y, locationlog, scalelog)

CRPS of a log-Laplace forecast with log-scale parameters locationlog and scalelog (where scalelog ∈ (0,1)), evaluated at observation y.

source
ScoringRules._crps_llogis Function
julia
_crps_llogis(
    y::Real,
    locationlog::Real,
    scalelog::Real
) -> Any
julia
_crps_llogis(y, locationlog, scalelog)

CRPS of a log-logistic forecast with log-scale parameters locationlog and scalelog (where scalelog ∈ (0,1)), evaluated at observation y.

source
ScoringRules._crps_lnorm Function
julia
_crps_lnorm(y::Real, meanlog::Real, sdlog::Real) -> Any
julia
_crps_lnorm(y, meanlog, sdlog)

CRPS of a LogNormal(meanlog, sdlog) forecast in closed form.

Formula: c1 − c2·c3 where c1 = y · (2·Φ_LN(y) − 1) c2 = 2 · exp(meanlog + sdlog²/2) c3 = Φ_LN*(y) + Φ(sdlog/√2) − 1

and Φ_LN is the LogNormal(meanlog, sdlog) CDF, Φ_LN* is the LogNormal(meanlog + sdlog², sdlog) CDF, Φ is the standard-normal CDF.

source
ScoringRules._crps_logis Function
julia
_crps_logis(y::Real, location::Real, scale::Real) -> Any

CRPS of a Logistic(μ, σ) forecast, in closed form.

Unit formula (σ = 1, μ = 0): CRPS = y - 2·log F(y) - 1

source
ScoringRules._crps_mixnorm Function
julia
_crps_mixnorm(
    y::Real,
    means::AbstractVector{<:Real},
    sds::AbstractVector{<:Real},
    weights::AbstractVector{<:Real}
) -> Any

CRPS of a finite Gaussian mixture forecast at observation y.

means and sds are vectors of component means and standard deviations; weights is a vector of non-negative mixture weights (need not sum to 1 — they are normalised internally, matching the R implementation).

source
ScoringRules._crps_nbinom Function
julia
_crps_nbinom(y::Real, size::Real, prob::Real) -> Any

CRPS of a NegativeBinomial(size, prob) forecast, in closed form.

source
ScoringRules._crps_norm Function
julia
_crps_norm(y::Real, μ::Real, σ::Real) -> Any

CRPS of a Normal(μ, σ) forecast, in closed form (Gneiting et al. 2005).

source
ScoringRules._crps_pois Function
julia
_crps_pois(y::Real, lambda::Real) -> Any

CRPS of a Poisson(λ) forecast, in closed form.

The Poisson CDF is F(y) = P(Y ≤ ⌊y⌋) = Q(⌊y⌋+1, λ) = ccdf(Gamma(⌊y⌋+1, 1), λ), and 0 for y < 0 (empty support — matching R's crps_pois). Routed through ccdf_ad_safe so λ stays differentiable: the stock cdf(::Poisson) reaches gamma_inc, which has no method for a Dual shape argument (#11). ccdf_ad_safe returns Q directly rather than 1 - P, keeping the far upper tail accurate.

source
ScoringRules._crps_t Function
julia
_crps_t(
    y::Real,
    df::Real,
    location::Real,
    scale::Real
) -> Any
julia
_crps_t(y, df, location, scale)

CRPS for a location–scale Student-t forecast with df degrees of freedom, location μ, and scale σ > 0. Returns NaN when df ≤ 1.

source
ScoringRules._crps_unif Function
julia
_crps_unif(
    y::Real,
    mn::Real,
    mx::Real,
    lmass::Real,
    umass::Real
) -> Any
julia
_crps_unif(y, min, max, lmass, umass)

CRPS of a generalised uniform distribution on [min, max] with optional point masses lmass at min and umass at max. Setting both masses to zero gives the plain Uniform(min, max) CRPS.

For the unit interval [0, 1] the formula is

julia
|y  z| +·a  z·(1 2·lmass) +/3 + (1 lmass)·umass

where z = clamp(y, 0, 1) and a = 1 − (lmass + umass). Non-unit intervals are handled by linear rescaling.

source
ScoringRules._ints_quantile Function
julia
_ints_quantile(
    y::Real,
    x_lower::Real,
    x_upper::Real,
    target_coverage::Real
) -> Any
julia
_ints_quantile(y, x_lower, x_upper, target_coverage)

Interval score at a single lower/upper quantile pair and nominal coverage target_coverage (e.g. 0.8 for an 80 % prediction interval). Directly mirrors ints_quantiles in scores_quantiles.R:

julia
alpha1 = 0.5 * (1 - target_coverage)
alpha2 = 0.5 * (1 + target_coverage)
score  = (2 / (1 - target_coverage)) * (qs(y, x_lower, alpha1) +
                                         qs(y, x_upper, alpha2))

Expanded this gives: (x_upper - x_lower) + (2/(1-level)) * (x_lower - y) * 1{y < x_lower} + (2/(1-level)) * (y - x_upper) * 1{y > x_upper}

The convention follows nominal coverage (not alpha = 1 - coverage).

source
ScoringRules._member_weights Function
julia
_member_weights(m::Integer, w) -> Any
julia
_member_weights(m, w)

Return a normalised member-weight vector of length m. If w is nothing, uniform weights 1/m are used. Otherwise w is validated (length m, non-negative) and rescaled so that its entries sum to one (analogous to w.helper.multiv in R).

source
ScoringRules._qs_quantile Function
julia
_qs_quantile(y::Real, x::Real, alpha::Real) -> Any
julia
_qs_quantile(y, x, alpha)

Pinball loss at a single quantile level alpha with quantile forecast x and observation y. Directly mirrors qs_quantiles in scores_quantiles.R:

julia
score = ((y < x) - alpha) * (x - y)

Equivalently:

  • if y < x: (1 - alpha) * (x - y) [over-forecast]

  • if y >= x: alpha * (y - x) [under-forecast]

This is the negatively-oriented (lower = better) formulation of the check function / pinball loss.

source
ScoringRules._quantile_hf Function
julia
_quantile_hf(
    x::AbstractVector,
    p::Real,
    qtype::Int64
) -> Any
julia
_quantile_hf(x, p, qtype)

Sample p-quantile of x using the Hyndman & Fan (1996) definition qtype (1–9), matching R's quantile(x, p, type = qtype). Statistics.quantile only implements type 7, so this helper is needed to honour the type keyword of the ensemble-based scores.

source
ScoringRules._rps0 Function
julia
_rps0(p::AbstractVector, y::Integer) -> Any
julia
_rps0(p, y)

Core RPS computation for a single observation y and probability vector p over K categories, where y ∈ {1, …, K}. Mirrors rps0 in rps.R.

The RPS is the sum of squared differences between cumulative forecast probabilities and cumulative empirical (indicator) probabilities:

julia
RPS = Σ_{k=1}^{K} (P_k - 1{y  k})²

where P_k = Σ_{j=1}^{k} p_j is the cumulative forecast probability through category k. This is equivalent to a sum of K Brier scores, one per category boundary.

source
ScoringRules._w_helper Function
julia
_w_helper(X::AbstractMatrix, w) -> Any
julia
_w_helper(X, w)

Normalised member weights for the columns of the d × m ensemble matrix X (see _member_weights).

source