You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JuliaStats/Distributions.jl#1978 will add logupdf and logulikelihood functions to the API: logupdf includes all terms in logpdf that depend on the argument (parameter-only terms are excluded), while logulikelihood includes all terms in logpdf that depend on the parameters (argument-only terms are excluded). This more efficient function evaluations and is especially useful when the omitted constants are expensive.
I propose StatsFuns gets a matching function like logupdf. e.g. if a function <distr>logpdf is implemented, so is a function <distr>logupdf. In some cases <distr>logpdf could just call the logupdf version and add a normalization factor.
Here are a few example implementations:
functiongammalogupdf(k::T, θ::T, x::T) where {T <:Real}
# we ensure that `log(x)` does not error if `x < 0`
xθ =max(x, 0) / θ
val =-xθ
# xlogy(k - 1, xθ) - xθ -> -∞ for xθ -> ∞ so we only add the first term# when it's safeifisfinite(xθ)
val +=xlogy(k -1, xθ)
endreturn x <0?oftype(val, -Inf) : val
endfunctionbetalogupdf(α::T, β::T, x::T) where {T <:Real}
# we ensure that `log(x)` and `log1p(-x)` do not error
y =clamp(x, 0, 1)
val =xlogy(α -1, y) +xlog1py(β -1, -y)
return x <0|| x >1?oftype(val, -Inf) : val
endnormlogupdf(z::Number) =abs2(z) /-2functionnormlogupdf(μ::Real, σ::Real, x::Number)
ifiszero(σ) && x == μ
z =zval(μ, one(σ), x)
else
z =zval(μ, σ, x)
endreturnnormlogupdf(z)
endfunctionpoislogupdf(λ::T, x::T) where {T <:Real}
val =xlogy(x, λ) -loggamma(x +1)
return x >=0&&isinteger(x) ? val :oftype(val, -Inf)
endfunctiontdistlogupdf(ν::T, x::T) where {T <:Real}
isinf(ν) &&returnnormlogupdf(x)
νp12 = (ν +1) /2return-νp12 *log1p(x^2/ ν)
end
The text was updated successfully, but these errors were encountered:
JuliaStats/Distributions.jl#1978 will add
logupdf
andlogulikelihood
functions to the API:logupdf
includes all terms inlogpdf
that depend on the argument (parameter-only terms are excluded), whilelogulikelihood
includes all terms inlogpdf
that depend on the parameters (argument-only terms are excluded). This more efficient function evaluations and is especially useful when the omitted constants are expensive.I propose StatsFuns gets a matching function like
logupdf
. e.g. if a function<distr>logpdf
is implemented, so is a function<distr>logupdf
. In some cases<distr>logpdf
could just call thelogupdf
version and add a normalization factor.Here are a few example implementations:
The text was updated successfully, but these errors were encountered: