-
Notifications
You must be signed in to change notification settings - Fork 415
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
Fix #894 Normal distribution and its type parameter #896
Fix #894 Normal distribution and its type parameter #896
Conversation
@@ -87,7 +89,7 @@ cf(d::Normal, t::Real) = exp(im * t * d.μ - d.σ^2/2 * t^2) | |||
|
|||
#### Sampling | |||
|
|||
rand(rng::AbstractRNG, d::Normal) = d.μ + d.σ * randn(rng) | |||
rand(rng::AbstractRNG, d::Normal{T}) where {T} = d.μ + d.σ * randn(rng, T) |
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.
Not sure if we shouldn't watch out here, since randn
does not support all types
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.
Precisely the concern I mentioned above; although on balance, I think this is an improvement. The prior behavior wasn't technically correct, either due to the wrong output type, or the right output type but the code not actually doing what one would expect (as shown in the examples I gave above).
@halleysfifthinc thanks a lot for that. Could you add a simple test with for example the eltype, for instance with a Dual from ForwardDiff or Float32 |
Yeah I can add some tests. Where would be appropriate? I didn't see any for the Normal distribution. I'm also not familiar with Dual/ForwardDiff, but I can definitely add some for Float32/Float64. |
If you don't see any testset / test file where it fits you can just create one |
ping @halleysfifthinc |
Codecov Report
@@ Coverage Diff @@
## master #896 +/- ##
==========================================
+ Coverage 73.78% 73.79% +<.01%
==========================================
Files 107 107
Lines 5200 5201 +1
==========================================
+ Hits 3837 3838 +1
Misses 1363 1363
Continue to review full report at Codecov.
|
Could you merge master into your branch? This should put cover back
…On Fri, May 24, 2019 at 7:45 PM Codecov ***@***.***> wrote:
Codecov
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896?src=pr&el=h1>
Report
❗️ No coverage uploaded for pull request base ***@***.***). Click
here to learn what that means
<https://docs.codecov.io/docs/error-reference#section-missing-base-commit>
.
The diff coverage is 100%.
[image: Impacted file tree graph]
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896?src=pr&el=tree>
@@ Coverage Diff @@
## master #896 +/- ##
=========================================
Coverage ? 73.79%
=========================================
Files ? 107
Lines ? 5201
Branches ? 0
=========================================
Hits ? 3838
Misses ? 1363
Partials ? 0
Impacted Files
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896?src=pr&el=tree> Coverage
Δ
src/univariate/continuous/normal.jl
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896/diff?src=pr&el=tree#diff-c3JjL3VuaXZhcmlhdGUvY29udGludW91cy9ub3JtYWwuamw=> 94.38%
<100%> (ø)
------------------------------
Continue to review full report at Codecov
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896?src=pr&el=continue>
.
*Legend* - Click here to learn more
<https://docs.codecov.io/docs/codecov-delta>
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896?src=pr&el=footer>.
Last update db09a0a...273960a
<https://codecov.io/gh/JuliaStats/Distributions.jl/pull/896?src=pr&el=lastupdated>.
Read the comment docs <https://docs.codecov.io/docs/pull-request-comments>
.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#896?email_source=notifications&email_token=AB2FDMRNAKG72GKGZVBJPBTPXASTXA5CNFSM4HM2FW6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGDHTA#issuecomment-495727564>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2FDMUOCTSZTF4OU7X22NLPXASTXANCNFSM4HM2FW6A>
.
--
Mathieu Besançon
|
thanks @halleysfifthinc ! |
I didn't see any similar tests so I'm not sure if this needs any tests. I don't imagine that fixing the
eltype
would be particularly breaking (although it is changing the output type ofrand(n::Normal, dims)
).However, the fix for the single
rand
return type could change an incorrect return type into an error, if theeltype
of the Normal dist. doesn't supportrandn
. I noticed this when using DoubleFloats (prior to v0.8.1 of DoubleFloats.jl).So the previous behavior was both inconsistent, and not accurate in the case of the DoubleFloats. The return type was correct due to the type promotion, but the random number wasn't being generated with the precision of the DoubleFloat.
randn
support for DoubleFloats was added in v0.8.1.