0

I tried various solutions for below, but I still get the errors as described:

log1p(1 + math.exp(comp * -1))

Error: OverflowError: math range error

So I changed it to: log1p(1 + np.exp(comp * -1)) Now I get error : RuntimeWarning: overflow encountered in exp

So again based on some suggestion on previous questions asked I changed it to: log1p(1 + np.exp((comp * -1), dtype=np.float256))

Now my error is : module 'numpy' has no attribute 'float256'

Any other suggestions? Please help thanks!

EDIT: X -> Input feature array of 'N' rows and 'm' features. w -> weight vector of size 'm'

    for rowIndex in range(len(X)):
        val1 = np.sum(np.dot(X[rowIndex], w))
        val2 = y[rowIndex]
        comp = np.dot(val2, val1)
        loss = loss + log1p(1 + np.exp((comp * -1)))
5
  • 1
    What is the value of comp? Also, what you are attempting to compute is ln(2 + exp(-comp)). Is this really what you want? Commented Mar 27, 2018 at 18:25
  • 'comp' is just some value which could go upto 6000 in some cases... 'log1p(1 + math.exp(comp * -1))' is what I want to do... Commented Mar 27, 2018 at 18:30
  • 2
    Do you realise that log1p(x) = log(x + 1)? Also, log1p(1 + math.exp(comp * -1)) works fine for various values of comp, including 6000. Please provide a complete example demonstrating the problem. Commented Mar 27, 2018 at 18:33
  • I note that already for comp = 40, the exp part can be treated as zero: log1p(1+exp(-40))-log(2) is zero. Commented Mar 27, 2018 at 18:34
  • Can comp be negative? What you describe doesn't seem possible otherwise. And if comp is large and negative, then the 1 + ... will be insignificant, so your expression log1p(1 + math.exp(comp * -1)) will be simply -comp, to within numerical error. (Also: what @jmd_dk said: are you sure you want log(1 + 1 + math.exp(...))? Commented Mar 27, 2018 at 19:23

1 Answer 1

0

I replaced the code as below:

loss = loss - log1p(expit(val))

Basically I rearranged my code to be able to use the expit function...

Sign up to request clarification or add additional context in comments.

1 Comment

That doesn't look like the same thing at all. Note that it's not true that log1p(thing) = -log1p(1/thing). Are you sure you mean log1p and not log?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.