{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/8424","repository_url":"https://api.github.com/repos/scipy/scipy","labels_url":"https://api.github.com/repos/scipy/scipy/issues/8424/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/8424/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/8424/events","html_url":"https://github.com/scipy/scipy/issues/8424","id":297452947,"number":8424,"title":"Scipy.stats.poisson underflow/overflow + solution","user":{"login":"labodyn","id":16204193,"avatar_url":"https://avatars3.githubusercontent.com/u/16204193?v=4","gravatar_id":"","url":"https://api.github.com/users/labodyn","html_url":"https://github.com/labodyn","followers_url":"https://api.github.com/users/labodyn/followers","following_url":"https://api.github.com/users/labodyn/following{/other_user}","gists_url":"https://api.github.com/users/labodyn/gists{/gist_id}","starred_url":"https://api.github.com/users/labodyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/labodyn/subscriptions","organizations_url":"https://api.github.com/users/labodyn/orgs","repos_url":"https://api.github.com/users/labodyn/repos","events_url":"https://api.github.com/users/labodyn/events{/privacy}","received_events_url":"https://api.github.com/users/labodyn/received_events","type":"User","site_admin":false},"labels":[{"id":37334597,"url":"https://api.github.com/repos/scipy/scipy/labels/defect","name":"defect","color":"e11d21","default":false},{"id":37340722,"url":"https://api.github.com/repos/scipy/scipy/labels/scipy.stats","name":"scipy.stats","color":"207de5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-15T13:52:01Z","updated_at":"2018-02-24T23:09:22Z","closed_at":null,"author_association":"NONE","body":"poisson.stats.logcdf has underflow and overflow issues. This can be solved using logsumexp on an array of the individual poisson logpmf's.\r\n\r\nNote: neither issue nor solution are exclusive to this scipy function.\r\n\r\n### Reproducing code example:\r\n```\r\n>>> from scipy.stats import poisson\r\n>>> poisson.logcdf(5, 1000)\r\n-inf\r\n>>> poisson.logcdf(500, 10)\r\n0.0\r\n```\r\n\r\n### Possible solution:\r\n (implemented for one pair of argument types only. Might be fully vectorized instead of for loop?)\r\n```\r\nimport numpy as np\r\nfrom scipy.stats import poisson\r\nfrom scipy.misc import logsumexp\r\n\r\ndef poisson_logcdf_stable(k, mu):\r\n    assert isinstance(mu, np.ndarray) and isinstance(k, int), 'Unsupported types, implement yourself.'\r\n    poissons = np.zeros((k + 1, *mu.shape))\r\n    for i in range(k + 1):\r\n        poissons[i, ...] = poisson.logpmf(i, mu)\r\n    return logsumexp(poissons, axis=0)\r\n```\r\n\r\n### Check resolvement of issues\r\n```\r\n>>> mu = np.array([1000, 5])\r\n>>> poisson.logcdf(5, mu)\r\n[       -inf -0.48457219]\r\n>>> poisson_logcdf_stable(5, mu)\r\n[ -9.70243708e+02  -4.84572190e-01] \r\n>>> poisson.logcdf(500, mu)\r\n[-156.76165407    0.        ]\r\n>>> poisson_logcdf_stable(500, mu)\r\n[ -1.56761654e+02  -6.66133815e-16] \r\n```\r\n\r\n### Scipy/Numpy/Python version information:\r\n```\r\n0.19.1 1.13.3 sys.version_info(major=3, minor=6, micro=3, releaselevel='final', serial=0)\r\n```"},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/368267608","html_url":"https://github.com/scipy/scipy/issues/8424#issuecomment-368267608","issue_url":"https://api.github.com/repos/scipy/scipy/issues/8424","id":368267608,"user":{"login":"labodyn","id":16204193,"avatar_url":"https://avatars3.githubusercontent.com/u/16204193?v=4","gravatar_id":"","url":"https://api.github.com/users/labodyn","html_url":"https://github.com/labodyn","followers_url":"https://api.github.com/users/labodyn/followers","following_url":"https://api.github.com/users/labodyn/following{/other_user}","gists_url":"https://api.github.com/users/labodyn/gists{/gist_id}","starred_url":"https://api.github.com/users/labodyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/labodyn/subscriptions","organizations_url":"https://api.github.com/users/labodyn/orgs","repos_url":"https://api.github.com/users/labodyn/repos","events_url":"https://api.github.com/users/labodyn/events{/privacy}","received_events_url":"https://api.github.com/users/labodyn/received_events","type":"User","site_admin":false},"created_at":"2018-02-24T23:09:22Z","updated_at":"2018-02-24T23:09:22Z","author_association":"NONE","body":"Hi, \r\n\r\nThe log cdf can be calculated from the log pmf with full accuracy instead of taking the log of the cdf."}}
{"actor":{"display_login":"labodyn"}}