Skip to content

Conversation

@pdeffebach
Copy link
Contributor

Closes #1497

test/chi.jl Outdated
@test isfinite(mean(Chi(1000)))

# see #1497
@test pdf(Chi(3), -.5) == 0.0

Choose a reason for hiding this comment

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

Suggested change
@test pdf(Chi(3), -.5) == 0.0
@test pdf(Chi(3), -0.5) == 0.0


logpdf(d::Chi, x::Real) == d.ν;
function logpdf(d::Chi, x::Real)
x < 0 && return 0.0
Copy link
Member

Choose a reason for hiding this comment

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

This is type unstable, better to compute the result as much as possible (as done for other distributions).

Suggested change
x < 0 && return 0.0

Copy link
Member

Choose a reason for hiding this comment

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

BTW one should also not return 0 but -Inf (of the correct type).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, was thinking of pdf.

Copy link

@rikhuijzer rikhuijzer left a comment

Choose a reason for hiding this comment

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

Also much better to use multi line function here indeed instead of the one-liner with bracket

Note that I don't have merge rights here, but more eyes is more better I guess

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
@pdeffebach
Copy link
Contributor Author

Thanks for the detailed in-line changes. I merged them and confirmed they work locally.

I think this can be merged!

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2022

Codecov Report

Merging #1498 (e909006) into master (8aea3cc) will decrease coverage by 0.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1498      +/-   ##
==========================================
- Coverage   84.46%   84.26%   -0.20%     
==========================================
  Files         124      124              
  Lines        7520     7514       -6     
==========================================
- Hits         6352     6332      -20     
- Misses       1168     1182      +14     
Impacted Files Coverage Δ
src/univariate/continuous/chi.jl 95.12% <100.00%> (+0.25%) ⬆️
src/utils.jl 64.40% <0.00%> (-35.60%) ⬇️
...rc/univariate/continuous/skewedexponentialpower.jl 72.91% <0.00%> (-1.60%) ⬇️
src/univariate/discrete/hypergeometric.jl 80.00% <0.00%> (-1.49%) ⬇️
src/univariate/discrete/negativebinomial.jl 91.11% <0.00%> (-0.38%) ⬇️
...rc/univariate/discrete/noncentralhypergeometric.jl 91.39% <0.00%> (-0.33%) ⬇️
src/univariate/discrete/binomial.jl 93.40% <0.00%> (-0.15%) ⬇️
src/matrix/lkj.jl 99.17% <0.00%> (-0.03%) ⬇️
src/univariate/discrete/discretenonparametric.jl 98.83% <0.00%> (-0.02%) ⬇️
... and 8 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 8aea3cc...e909006. Read the comment docs.

@devmotion
Copy link
Member

Unfortunately, it seems to break downstream tests of Tracker in DistributionsAD: e.g., https://github.com/JuliaStats/Distributions.jl/runs/5009289497?check_suite_focus=true#step:6:322 We have to check if this is a downstream problem or an actual issue with this PR.

@devmotion
Copy link
Member

Apart from that the PR looks good 🙂

@devmotion
Copy link
Member

Seems to be an issue in Tracker since it does not define derivatives for LogExpFunctions yet. It's an easy fix, I'll open a PR. Let's hold back with merging this PR to avoid breaking downstream packages and rerun tests (and merge if they pass) once a new version of Tracker is released.

@devmotion
Copy link
Member

FluxML/Tracker.jl#124

@devmotion
Copy link
Member

The downstream issues are fixed 🙂

Thanks a lot for the PR @pdeffebach!

@devmotion devmotion merged commit f41e44c into JuliaStats:master Feb 9, 2022
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.

No bounds checking in Chi distribution

4 participants