pymc-devs / pymc-experimental

https://pymc-experimental.readthedocs.io
Other
77 stars 49 forks source link

Log Cdf of GenExtreme outputs negative infinity instead of zero at extreme right #349

Open souvikpaul33 opened 3 months ago

souvikpaul33 commented 3 months ago

Adding a change to gev logcdf

souvikpaul33 commented 3 months ago

pull req first time

ricardoV94 commented 3 months ago

Did you close by accident @souvikpaul33 ?

souvikpaul33 commented 3 months ago

@ricardoV94 I think yes. Sorry for that. I'm reopening it.

ricardoV94 commented 3 months ago

CC @ccaprani if you want to review

ricardoV94 commented 3 months ago

@souvikpaul33 can you rename the PR title to be more informative (we use it for the release notes). And can you add a test that covers the previously broken functionality?

souvikpaul33 commented 2 months ago

@souvikpaul33 can you rename the PR title to be more informative (we use it for the release notes). And can you add a test that covers the previously broken functionality?

@ricardoV94 Thanks! Renamed the title.

This is the example test case where it was broken before

import numpy as np import pymc as pm import pymc_experimental.distributions as pmx

rv = pmx.GenExtreme.dist(mu=0, sigma=1, xi=-0.5) # range of x: (-inf, 2) x = np.array([-100,-50,-40, -30, -10,-5,-2,-1,0,1,1.5,1.7,1.9,1.99,2,3,4,5]) # check last four values : extreme right lcdf_gev = pm.logcdf(rv, x) print(x) # check last four values : extreme right [-100. -50. -40. -30. -10. -5. -2. -1. 0. 1.5 1.7 1.9 1.99 2. 3. 4. 5. ] print(lcdf_gev.eval()) # check last four values : extreme right [-2.601e+03 -6.760e+02 -4.410e+02 -2.560e+02 -3.600e+01 -1.225e+01 -4.000e+00 -2.250e+00 -1.000e+00 -2.500e-01 -6.250e-02 -2.250e-02 -2.500e-03 -2.500e-05 -inf -inf -inf -inf]

print(np.exp(lcdf_gev.eval())) # check last four values : extreme right [0.00000000e+000 2.61174176e-294 2.99318445e-192 6.61626106e-112 2.31952283e-016 4.78511739e-006 1.83156389e-002 1.05399225e-001 3.67879441e-001 7.78800783e-001 9.39413063e-001 9.77751237e-001 9.97503122e-001 9.99975000e-001 0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000]

Screenshot 2024-06-06 115109

ricardoV94 commented 2 months ago

It should be enough to test one of the last values that was giving -inf. You'll have to add the check as a test in the codebase