-
Notifications
You must be signed in to change notification settings - Fork 421
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
Add SkewNormal distribution #1104
Conversation
Add Skewnormal distribution based on: * [Skew normal distribution on Wikipedia](https://en.wikipedia.org/wiki/Skew_normal_distribution) * [Discourse](https://discourse.julialang.org/t/skew-normal-distribution/21549/7) * [SkewDist.jl](https://github.com/STOR-i/SkewDist.jl)
Codecov Report
@@ Coverage Diff @@
## master #1104 +/- ##
==========================================
- Coverage 79.54% 79.21% -0.33%
==========================================
Files 113 114 +1
Lines 5787 5811 +24
==========================================
Hits 4603 4603
- Misses 1184 1208 +24
Continue to review full report at Codecov.
|
Thanks! This would be a good add. My thoughts:
|
@johnczito thanks for responding. |
Sorry I didn't see your discourse message. I'm very happy that you found my code snippet useful and for some of the code to find its way to |
return d.ξ + d.ω * sign(u0) * u1 | ||
end | ||
|
||
## Fitting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the commented lines should be removed, they seem to come from another file
this looks like a cool addition to Distributions. +1 to add tests |
Codecov Report
@@ Coverage Diff @@
## master #1104 +/- ##
==========================================
+ Coverage 79.54% 79.70% +0.16%
==========================================
Files 113 115 +2
Lines 5787 5958 +171
==========================================
+ Hits 4603 4749 +146
- Misses 1184 1209 +25
Continue to review full report at Codecov.
|
@johnczito @matbesancon @fairbrot @maximerischard |
Looks great! I noticed there weren't any tests for using PyPlot: PyPlot; plt=PyPlot
using Distributions
d1 = SkewNormal(1, 2, 3)
samples = rand(d1, 10^6);
plt.hist(samples; density=true, bins=1000)
let
xx = range(-3.0, stop=8.0, length=1000)
plt.plot(xx, pdf.(d1, xx))
end I then also compared the empirical to the theoretical moments: using Statistics
@show mean(samples), mean(d1)
@show std(samples), std(d1)
@show skewness(samples), skewness(d1)
@show kurtosis(samples), kurtosis(d1)
xx = range(-3.0, stop=8.0, length=100000)
@show xx[argmax(pdf.(d1, xx))], mode(d1)
Again, all looking good except the mode is slightly off since it is an approximation (as is made clear in the comments in the code). |
Yeah, it's a tricky one, as discussed in #143 and #1142. Anything would have some positive failure rate, even if the code is error free. I include some KS testing in the unit tests for the matrix variates, along with crude checks for the sample mean and covariance, but they're really just regression tests. They happen not to fail for this seed. If they start failing, it's just something to look into. |
@johnczito @matbesancon |
Looks good to me. Can you add tests checking that it agrees with |
@johnczito @matbesancon |
Sorry, for the sake of coverage, can you check every method that |
@johnczito done! |
@johnczito please let me know if there is anything else I can do |
Looks good to me. I'm not sure what the path forward is on the cdf. Such as it is, this would be one of only two or three univariates that don't provide it, which means you can't really compute probabilities. I'm not sure how central folks think that functionality is. |
@johnczito thanks for approving!
|
@mschauer thoughts on merging this without a |
@mschauer do you think we can merge this PR? |
var(d::SkewNormal) = abs2(d.ω)*(1-mean_z(d)^2) | ||
std(d::SkewNormal) = √var(d) | ||
skewness(d::SkewNormal) = (4-π)/2 * mean_z(d)^3 / (1-mean_z(d)^2)^(3/2) | ||
kurtosis(d::SkewNormal) = 2*(π-3)*( (delta(d)* sqrt(2/π) )^4 / (1-2*(delta(d)^2)/π)^2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random whitespace
test/skewnormal.jl
Outdated
@test pdf(d3, 3.3) == Distributions.pdf(d4, 3.3) | ||
@test pdf.(d3, 1:3) == Distributions.pdf.(d4, 1:3) | ||
a = mean(d3), var(d3), std(d3) | ||
#b = mean(d4), var(d4), std(d4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#b = mean(d4), var(d4), std(d4) |
test/skewnormal.jl
Outdated
a = mean(d3), var(d3), std(d3) | ||
#b = mean(d4), var(d4), std(d4) | ||
b = Distributions.mean(d4), Distributions.var(d4), Distributions.std(d4) | ||
@test a == b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@test a == b | |
@test a == b |
@mschauer |
@mschauer are we ready to roll? |
seems travis is still failing |
Add SkewNormal distribution based on: