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 ...
Posted on 2004-07-13 03:46:46 by Homer
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:
Posted on 2004-07-13 08:05:53 by roticv
Exp is the inverse of Log

I think there is an example in Raymond Filiatreault's fpu library.
Posted on 2004-07-13 08:18:08 by Siekmanski
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
Posted on 2004-07-13 10:21:26 by Raymond
Thanks :)
Posted on 2004-07-16 13:44:42 by Homer
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
Posted on 2004-07-17 02:25:55 by Homer
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.
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
Posted on 2004-07-17 09:20:31 by Raymond
Posted on 2004-07-18 03:52:59 by Starless
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))
Posted on 2004-07-18 05:54:51 by Eóin