pyGAM icon indicating copy to clipboard operation
pyGAM copied to clipboard

Overflow RuntimeWarning

Open ouslan opened this issue 1 year ago • 2 comments

There seems to be some overflow in line 197 in pygam/links.py. This is mostly cause by exceeding the float value. The easiest fix would be to clip the function with np.clip to a smaller value like 700 to prevent this overflow. I manage to fix it but will open the PR after #366 has been merge to main.

ouslan avatar Dec 08 '24 23:12 ouslan

I got something similar at a different spot:

  File "/root/axiom/predict/clinical/dili_risk/models/gam_simple.py", line 105, in train
    self.model.fit(X, y, weights=sample_weight)
  File "/usr/local/lib/python3.11/site-packages/pygam/pygam.py", line 912, in fit
    self._pirls(X, y, weights)
  File "/usr/local/lib/python3.11/site-packages/pygam/pygam.py", line 769, in _pirls
    W = self._W(mu, weights, y)  # create pirls weight matrix
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pygam/pygam.py", line 630, in _W
    self.link.gradient(mu, self.distribution) ** 2
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^~~
FloatingPointError: overflow encountered in square

cabreraalex avatar Aug 07 '25 21:08 cabreraalex

OK this is a good idea. i think we may want to add a tiny value to the denominators, and clip values before exponentiation (on values greater than 1)?

dswah avatar Nov 20 '25 15:11 dswah