{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/587","repository_url":"https://api.github.com/repos/JuliaStats/Distributions.jl","labels_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/587/labels{/name}","comments_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/587/comments","events_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/587/events","html_url":"https://github.com/JuliaStats/Distributions.jl/pull/587","id":218622447,"node_id":"MDExOlB1bGxSZXF1ZXN0MTEzNzM2Nzc3","number":587,"title":"WIP: GeneralizedInverseGaussian","user":{"login":"nsgrantham","id":4433521,"node_id":"MDQ6VXNlcjQ0MzM1MjE=","avatar_url":"https://avatars1.githubusercontent.com/u/4433521?v=4","gravatar_id":"","url":"https://api.github.com/users/nsgrantham","html_url":"https://github.com/nsgrantham","followers_url":"https://api.github.com/users/nsgrantham/followers","following_url":"https://api.github.com/users/nsgrantham/following{/other_user}","gists_url":"https://api.github.com/users/nsgrantham/gists{/gist_id}","starred_url":"https://api.github.com/users/nsgrantham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsgrantham/subscriptions","organizations_url":"https://api.github.com/users/nsgrantham/orgs","repos_url":"https://api.github.com/users/nsgrantham/repos","events_url":"https://api.github.com/users/nsgrantham/events{/privacy}","received_events_url":"https://api.github.com/users/nsgrantham/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-03-31T21:31:39Z","updated_at":"2018-12-06T17:36:01Z","closed_at":"2018-11-04T16:10:28Z","author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/JuliaStats/Distributions.jl/pulls/587","html_url":"https://github.com/JuliaStats/Distributions.jl/pull/587","diff_url":"https://github.com/JuliaStats/Distributions.jl/pull/587.diff","patch_url":"https://github.com/JuliaStats/Distributions.jl/pull/587.patch"},"body":"With respect to #554, an initial implementation of the [generalized inverse Gaussian distribution](https://en.wikipedia.org/wiki/Generalized_inverse_Gaussian_distribution). The areas that require particular attention are:\r\n\r\n1. Sampling methods from [Hormann and Leydold, (2014)](http://link.springer.com/article/10.1007/s11222-013-9387-3) in `rand`, and\r\n2. Estimation of the CDF [eq (5) from Lemonte and Cordeiro (2011)](https://www.ime.usp.br/~abe/lista/pdfeX5DRCVM26.pdf) in `cdf`.\r\n\r\nThe CDF algorithm requires some extra care, it is unstable for very small and large values of `x`, when the function should simply return `0.0` and `1.0` respectively, but the overflow makes these situations a bit difficult to capture.\r\n\r\nIt should also be noted that the sampling algorithms are designed for quick \"one-off\" sampling, as one might do in Gibbs sampling, rather than bulk sampling. Perhaps another algorithm should be included for bulk sampling."},"comment":{"url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/comments/444960340","html_url":"https://github.com/JuliaStats/Distributions.jl/pull/587#issuecomment-444960340","issue_url":"https://api.github.com/repos/JuliaStats/Distributions.jl/issues/587","id":444960340,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDk2MDM0MA==","user":{"login":"dylanfesta","id":5700344,"node_id":"MDQ6VXNlcjU3MDAzNDQ=","avatar_url":"https://avatars3.githubusercontent.com/u/5700344?v=4","gravatar_id":"","url":"https://api.github.com/users/dylanfesta","html_url":"https://github.com/dylanfesta","followers_url":"https://api.github.com/users/dylanfesta/followers","following_url":"https://api.github.com/users/dylanfesta/following{/other_user}","gists_url":"https://api.github.com/users/dylanfesta/gists{/gist_id}","starred_url":"https://api.github.com/users/dylanfesta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylanfesta/subscriptions","organizations_url":"https://api.github.com/users/dylanfesta/orgs","repos_url":"https://api.github.com/users/dylanfesta/repos","events_url":"https://api.github.com/users/dylanfesta/events{/privacy}","received_events_url":"https://api.github.com/users/dylanfesta/received_events","type":"User","site_admin":false},"created_at":"2018-12-06T17:36:01Z","updated_at":"2018-12-06T17:36:01Z","author_association":"NONE","body":"The problem here is that the CDF is not in closed form. It only appears in  [equation (5) in the following paper](https://www.ime.usp.br/~abe/lista/pdfeX5DRCVM26.pdf) however it is not numerically stable even for perfectly legitimate parameters.\r\n\r\nIn other words, the following happens:\r\n```julia-repl\r\njulia> d = GeneralizedInverseGaussian(1., 1., 1.)\r\nGeneralizedInverseGaussian{Float64}(a=1.0, b=1.0, p=1.0)\r\njulia> cdf(d,1.0)\r\nERROR: DomainError with -1.0:\r\nNaN result for non-NaN input.\r\nStacktrace:\r\n [1] nan_dom_err at ./math.jl:339 [inlined]\r\n [2] gamma at /home/dfesta/.julia/packages/SpecialFunctions/fvheQ/src/gamma.jl:558 [inlined]\r\n [3] cdf(::GeneralizedInverseGaussian{Float64}, ::Float64) at /home/dfesta/Repositories/Distributions/src/univariate/continuous/generalizedinversegaussian.jl:118\r\n [4] top-level scope at none:0\r\n```\r\nThis is *not a bug*, just the result of a discontinuity in the Gamma functions of equation (5) in the reference linked above . Writing a CDF requires much more work than just using that formula, which is certainly mathematically correct, but unfit for numerical computation.  \r\n\r\nAnd of course the (1 , 1...) parameters work correctly for the sampler, the pdf, etc...  \r\n\r\n![testexample](https://user-images.githubusercontent.com/5700344/49601226-3fa24100-f953-11e8-84b6-c0e777a4f055.png)\r\n\r\n"}}
{"actor":{"display_login":"dylanfesta"}}