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

Von mises range fix #1280

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Astro-mh
Copy link

This pull request reverts part of #965 which added bound checking to the pdf of several distributions.
This shouldn't be done for the von Mises distribution as it is designed to be periodic, repeating every 2π, so values for the pdf beyond the support of the distribution are entirely valid.

To enable the univariate_bounds tests to continue working with as few changes as possible, this also adds an isperiodic() method which is set to false in univariates.jl and then set to true in vonmises.jl

@codecov-io
Copy link

Codecov Report

Merging #1280 (e492112) into master (0b1ecad) will decrease coverage by 1.96%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1280      +/-   ##
==========================================
- Coverage   81.34%   79.38%   -1.97%     
==========================================
  Files         117      117              
  Lines        6563     5977     -586     
==========================================
- Hits         5339     4745     -594     
- Misses       1224     1232       +8     
Impacted Files Coverage Δ
src/Distributions.jl 100.00% <ø> (ø)
src/univariate/continuous/vonmises.jl 84.37% <100.00%> (-3.51%) ⬇️
src/univariates.jl 65.97% <100.00%> (-0.70%) ⬇️
src/univariate/discrete/hypergeometric.jl 56.75% <0.00%> (-6.66%) ⬇️
src/univariate/discrete/skellam.jl 75.00% <0.00%> (-6.25%) ⬇️
src/univariate/continuous/normalinversegaussian.jl 79.16% <0.00%> (-6.02%) ⬇️
src/univariate/continuous/skewnormal.jl 61.29% <0.00%> (-4.34%) ⬇️
src/univariate/continuous/biweight.jl 56.66% <0.00%> (-3.94%) ⬇️
src/matrix/wishart.jl 84.04% <0.00%> (-3.81%) ⬇️
... and 94 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b1ecad...e492112. Read the comment docs.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments regarding the implementation.

However, more generally I am not sure if the pdf and logpdf should be changed in this way. The convention is that the pdf is zero outside of the support of the distribution, so the definition of support and pdf/logpdf should be consistent. Also it seems inconsistent if the pdf does not imtegrate up to 1 anymore. Additionally, it would be inconsistent with cdf etc.

@@ -193,6 +193,7 @@ export
isplatykurtic, # Is excess kurtosis > 0.0?
isleptokurtic, # Is excess kurtosis < 0.0?
ismesokurtic, # Is excess kurtosis = 0.0?
isperiodic, # Has a periodic pdf?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a very special case, so currently I think it should not be part of the API. And hence also not exported.

@@ -58,6 +58,7 @@ get_subtypes(x::Type) = _subtypes_in(Base.loaded_modules_array(), x)
dists = get_subtypes(UnivariateDistribution)
filter!(x -> hasmethod(x, ()), dists)
filter!(x -> isbounded(x()), dists)
filter!(x -> !isperiodic(x()), dists)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just filter VonMises here if necessary?

Comment on lines +70 to +71
pdf(d::VonMises{T}, x::Real) where T<:Real = exp(d.κ * (cos(x - d.μ) - 1)) / (twoπ * d.I0κx)
logpdf(d::VonMises{T}, x::Real) where T<:Real = d.κ * (cos(x - d.μ) - 1) - log(d.I0κx) - log2π
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pdf(d::VonMises{T}, x::Real) where T<:Real = exp(d.κ * (cos(x - d.μ) - 1)) / (twoπ * d.I0κx)
logpdf(d::VonMises{T}, x::Real) where T<:Real = d.κ * (cos(x - d.μ) - 1) - log(d.I0κx) - log2π
pdf(d::VonMises, x::Real) = exp(d.κ * (cos(x - d.μ) - 1)) / (twoπ * d.I0κx)
logpdf(d::VonMises, x::Real) = d.κ * (cos(x - d.μ) - 1) - log(d.I0κx) - log2π

@jerlich
Copy link

jerlich commented Sep 16, 2022

It is frustrating that this PR (and other PR) related to VonMises are not resolved and merged. The current implementation gives unexpected results.

It seems that the simplest solution to these issues is to define support on [-pi , pi] and then wrap input (to pdf or cdf) to this range and likewise, always give samples in this range.

@devmotion
Copy link
Member

I reviewed the PR and it seems the PR is clearly not in a mergeable state. The comments have to be addressed first but apparently this has not been done.

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

Successfully merging this pull request may close these issues.

4 participants