0

In a machine learning algorithm that I'm using, I need to get the exponential values of something in one of the steps.

This is the step that I'm dealing with right now: enter image description here

I've already have all the 1+g_j(X_i) etc etc calculated, there's no problem in that. Let's call it calculated_value. There's no issue there. The problem is, when I use math.exp(calculated_value), I get an overflow. I then decided to use np.exp(calculated_value). I still got an overflow. Other times, apart from get oveflows, I sometimes get infinities.

An example is: I have the following number that needs to be raised to the power of e, which is a Decimal:

dot1 = 3.55114473577e+256
np.exp(dot1) #  <-- this is where I get the error below:
decimal.Overflow: above Emax

What's the solution for this? If there isn't any direct python solution to this, then what would the logarithmic version of the same function, that I could use in place of the function below?

β is going to be used as a coefficient to some variables.

user961627
  • 12,379
  • 42
  • 136
  • 210
  • Can you add some runnable code that demonstrates the problem? – YXD May 07 '14 at 14:49
  • It's not the same question... I've asked for the logarithmic alternative as well... – user961627 May 07 '14 at 15:00
  • Are you absolutely sure you want values this large? Provided they are correct, is it impossible to rescale your problem? – eickenberg May 07 '14 at 15:00
  • I agree with MrE, the underlaying problem is the same as the post he pointed out, you are overflowing the Decimal limits, you'll have to re-scale the values or use another data type. That post recommends using bigfloat, it even mention how to handle logarithmic function too. – KurzedMetal May 07 '14 at 15:07
  • 1
    @eickenberg No it would be great to rescale it! I'm getting these results out of `statsmodels`' `Weighted Least Squares`... I get them by using `sm.WLS(y, X, w).fit().params`, where `X` and `y` are vector with pretty small integer values, actually... like `0` and `1` and in fact, a maximum of `6`. I'm not really experienced at the rescaling bit... what would be a reasonable rescale? – user961627 May 07 '14 at 15:08
  • 2
    It is impossible to represent np.exp(3.55114473577e+256) in floating point, as the representation as IEEE float would require more memory than there are atoms in the universe. Obviously this is a number not often met. – Antti Haapala -- Слава Україні May 07 '14 at 15:47
  • 1
    This question appears to be off-topic because it is about math and it would be much better suited for http://math.stackexchange.com/ –  May 07 '14 at 16:53

0 Answers0