Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing docstring for loglikelihood #1845

Open
cgarling opened this issue Apr 1, 2024 · 3 comments
Open

Missing docstring for loglikelihood #1845

cgarling opened this issue Apr 1, 2024 · 3 comments

Comments

@cgarling
Copy link

cgarling commented Apr 1, 2024

On the latest version of the documentation, the following docstring is missing as there is no method with this signature defined. It looks like this should be loglikelihood(::UnivariateDistribution, ::Real) instead.

loglikelihood(::UnivariateDistribution, ::AbstractArray)

@mschauer
Copy link
Member

mschauer commented Apr 1, 2024

The vectorised version left us with d6985ad#diff-c185a88dade2ce18f68ff0130b5626734ed3cdb341bf5765dbb008fd8a6d91a0

loglikelihood(::UnivariateDistribution, ::Real) should have a docstring though, did it get lost there?

@cgarling
Copy link
Author

cgarling commented Apr 2, 2024

I am unfortunately not a git wizard but it looks to me like the relevant method definition is

# loglikelihood for `Real`
Base.@propagate_inbounds loglikelihood(d::UnivariateDistribution, x::Real) = logpdf(d, x)

for which I do not see a docstring.

@cgarling
Copy link
Author

cgarling commented Apr 2, 2024

P.S. It looks like pdf(::MultivariateDistribution, ::AbstractArray) and logpdf(::MultivariateDistribution, ::AbstractArray) are also included in the documentation but do not exist. I don't use the multivariate models much so I'm not sure what changed, but if I had to guess maybe these are the correct methods now?

"""
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`](@ref).
"""
@inline function pdf(
d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,M}
) where {N,M}
if M == N
@boundscheck begin
size(x) == size(d) ||
throw(DimensionMismatch("inconsistent array dimensions"))
end
return _pdf(d, x)
else
@boundscheck begin
M > N ||
throw(DimensionMismatch(
"number of dimensions of the variates ($M) must be greater than or equal to the dimension of the distribution ($N)"
))
ntuple(i -> size(x, i), Val(N)) == size(d) ||
throw(DimensionMismatch("inconsistent array dimensions"))
end
return @inbounds map(Base.Fix1(pdf, d), eachvariate(x, variate_form(typeof(d))))
end
end

"""
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`](@ref).
"""
@inline function logpdf(
d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,M}
) where {N,M}
if M == N
@boundscheck begin
size(x) == size(d) ||
throw(DimensionMismatch("inconsistent array dimensions"))
end
return _logpdf(d, x)
else
@boundscheck begin
M > N ||
throw(DimensionMismatch(
"number of dimensions of the variates ($M) must be greater than or equal to the dimension of the distribution ($N)"
))
ntuple(i -> size(x, i), Val(N)) == size(d) ||
throw(DimensionMismatch("inconsistent array dimensions"))
end
return @inbounds map(Base.Fix1(logpdf, d), eachvariate(x, variate_form(typeof(d))))
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants