How would this expression translate into masm format?

return ( 1 / ( 1 + exp(-input / response)))

(where input and response are REAL8)

I'm just unsure what exp means ...

return ( 1 / ( 1 + exp(-input / response)))

(where input and response are REAL8)

I'm just unsure what exp means ...

I guess it is Euler's constant.

Checking www.cplusplus.com ,

double exp ( double x );

Calculate exponential.

Returns the exponential value of parameter x.

I leave the conversion to floating point to you. :grin:

Checking www.cplusplus.com ,

double exp ( double x );

Calculate exponential.

Returns the exponential value of parameter x.

I leave the conversion to floating point to you. :grin:

Exp is the inverse of Log

I think there is an example in Raymond Filiatreault's fpu library.

I think there is an example in Raymond Filiatreault's fpu library.

**exp(n)**is the usual shorthand for

**e^n**where

**e**is the Napierian constant 2.71828...

If you want to code the expression yourself after computing the (-input / response) portion, have a look at the FpuEexpX function of the FPULIB.

Raymond

Thanks :)

I've been working with REAL8s - Raymond, your fpu stuff uses TBYTEs, with this in mind, does this look ok, and is the fpu conversion step really required?

CNeuralNet_Sigmoid proc netinput:REAL8, response:REAL8

local fptemp:tbyte

; return ( 1 / ( 1 + exp(-netinput / response)))

;exp(n) is the usual shorthand for e^n where e is the Napierian constant 2.71828...

fld fp1

fld netinput

fchs

fdiv response

fstp fptemp ;exp() function requires float in tbyte form

invoke FpuEexpX , addr fptemp, NULL, SRC1_REAL or DEST_FPU ;leave result on fpu

fadd fp1

fdiv

ret ;Again, leave result on fpu

CNeuralNet_Sigmoid

CNeuralNet_Sigmoid proc netinput:REAL8, response:REAL8

local fptemp:tbyte

; return ( 1 / ( 1 + exp(-netinput / response)))

;exp(n) is the usual shorthand for e^n where e is the Napierian constant 2.71828...

fld fp1

fld netinput

fchs

fdiv response

fstp fptemp ;exp() function requires float in tbyte form

invoke FpuEexpX , addr fptemp, NULL, SRC1_REAL or DEST_FPU ;leave result on fpu

fadd fp1

fdiv

ret ;Again, leave result on fpu

CNeuralNet_Sigmoid

Whatever is already in FPU registers is always in tbyte format. It would not change by storing it and reloading it. Here's your algo with some minor corrections and simplifications.

When your program gets to the final stage and you would really need that it runs faster, you should then replace the invoke with actual code to get rid of the function's overhead.

Meanwhile, make sure you keep a clean FPU by removing returned values or re-initializing it as required.

Raymond

```
CNeuralNet_Sigmoid proc netinput:REAL8, response:REAL8
```

; return ( 1 / ( 1 + exp(-netinput / response)))

;exp(n) is the usual shorthand for e^n where e is the Napierian constant 2.71828...

fld netinput

fchs

fdiv response

invoke FpuEexpX , 0, 0, SRC1_FPU or DEST_FPU ;leave result on fpu

fld1

fadd st(1),st ;leaves the 1 in st(0)

fdivr ;reverse division with st(1) and pops the 1

ret ;Again, leave result on fpu

CNeuralNet_Sigmoid endp

I have been assuming that you are using MASM syntax.
When your program gets to the final stage and you would really need that it runs faster, you should then replace the invoke with actual code to get rid of the function's overhead.

Meanwhile, make sure you keep a clean FPU by removing returned values or re-initializing it as required.

Raymond

Or, you might want this:

http://www.asmcommunity.net/board/showthread.php?threadid=2979&highlight=exp

http://www.asmcommunity.net/board/showthread.php?threadid=2979&highlight=exp

Here is the code I used, it uses bitRAKE exp code, it doesn't do the division by response though

```
; In: x in st0, Out 1/(1+exp(-x)) in st0
```

fchs ; -x

sub esp,16

fldl2e

fmul

fist dword ptr [esp+12]

fld1

fstp tbyte ptr [esp]

fisub dword ptr [esp+12]

mov eax,[esp+12]

add [esp+8],eax

f2xm1

fld1

fadd

fld tbyte ptr [esp]

fmul

add esp,16 ;exp(-x)

fadd One ;1+exp(-x)

fdivr One ;1/(1+exp(-x))