dcsimg
Results 1 to 2 of 2

Thread: Overflow Error using EXP()

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2016
    Posts
    86

    Overflow Error using EXP()

    Hello All,

    I developed a feedfoward neural network in Excel VBA. It works as expected, except for the occasional overflow error. Which I expected at some point to be honest. I know VBA is not the best language for scientific calculations, but its all I have at the moment at my workplace.

    Anyway...The overflow error occurs during a sigmoid activation function:

    Code:
    1/(1 + exp(-x))
    Here is the actual line of code:

    Code:
       
                    Dim X As Double 
                    X = CDbl(Round(Trim(SubString2(E)), 3))
                    Sum(ii) = Round(1# / (1# + Exp(-X)), 3) 'Error occurs on this line
    I used this code to help with matrix manipulation in VBA: https://codereview.stackexchange.com...edirect=1&lq=1

    SubString2(E) is an array containing the numeric value as a string. This was part of how I chose to manipulate matrixes in VBA. Also you can see I took every step I could to ensure the values were doubles. This was before I discovered the limits of the EXP() function noted below.

    I did some research on the matter and discovered here: https://docs.microsoft.com/en-us/off...p/exp-function

    That the EXP() function cannot handle numbers that exceed 709.782712893.

    So my question is, how else can I write the sigmoid activation function so it doesn't overflow?

  2. #2
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,331

    Re: Overflow Error using EXP()

    Maybe something like this:

    Code:
    If Abs(X) < 709 Then
        Sum(ii) = Round(1# / (1# + Exp(-X)), 3)
    Else
        ' Do whatever you want to handle the error here.
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width