Giter Club home page Giter Club logo

Comments (15)

dmbates avatar dmbates commented on May 22, 2024

I meant using erfinv for the quantile function and erf for the cdf, of course.

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

One quick check of their disagreement gives this:

julia> using Distributions

julia> phi(x) = 0.5 + 0.5 * erf(x / sqrt(2))
# methods for generic function phi
phi(x) at none:1

julia> max(map(x -> abs(cdf(Normal(), x) - phi(x)), -5.0:0.1:5.0))
1.1102230246251565e-16

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

This seems like it's on the order of round-off error, but it would be good to hear from others before making the change.

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

And here's the other direction:

julia> invphi(p) = sqrt(2) * erfinv(2 * p - 1.0)
# methods for generic function invphi
invphi(p) at none:1

julia> max(map(p -> abs(quantile(Normal(), p) - invphi(p)), 0.0:0.01:1.0))
5.329070518200751e-15

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

One advantage of using erf is that it is defined for the BigFloat type. I haven't checked to see whether this should provide more accuracy than the converting the Float64 result to BigFloat.

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

The BigFloat point is definitely worth keeping in mind.

Do you have a sense of how we should go about deciding whether the function definition I proposed is (1) sufficiently accurate and (2) sufficiently fast?

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

For the cdf we could use the BigFloat evaluation and compare the results of the Rmath call and the erf-based Float64 version. I assume that the authors of the GNU MPFR library can be counted upon to get the "correct" Float64 value after converting their BigFloat result.

As for sufficiently fast we could time the two methods but both are going to be so fast that it will be difficult to disitnguish.

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

In commit 6008e71 on the db/Normal branch I wrote just the pdf and logpdf in Julia simply to test them out. One thing that can be done in pure Julia code is to create templated types allowing for BigFloat distributions, should anyone want them. For this purpose I added math_const values of some values like log2pi.

I also switched the names of the fields in the type to the unicode characters for mu and sigma. What do others think? Is this too cute or would it ultimately be helpful for those trying to related parameters to a text-book representation?

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

I really like the unicode characters, but am hesitant to use them when the end-user might need to access the variables. So I'm not sure we should use unicode for the fields of Distributions, even though it does look really nice.

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

There's always cut-and-paste :-)

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

Also, in this case mean(d) and std(d) provide easy extractors.

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

That's very true. I'm happy with requiring people to use mean(d) and std(d) since I'd like our implementation details not to bleed into the end-user API.

For me, the main reason that the Greek characters are so usable is that I can set my OS X keyboard to map to Greek, which puts the characters were I expect them: p is pi, s is sigma, etc.

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

So was the decision to allow Greek characters for the parameters of a distribution as long as there are convenient extractor functions that can be typed on a conventional keyboard?

from distributions.jl.

johnmyleswhite avatar johnmyleswhite commented on May 22, 2024

I think the decision was that we'll only use Greek letters as local variables, but I'm not totally sure.

from distributions.jl.

dmbates avatar dmbates commented on May 22, 2024

Closed via 4cdc884

from distributions.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.