Math E and function Sigmoid()

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Math E and function Sigmoid()

Post by Antonio Linares »

https://www.lemoda.net/c/maths-constants/

Code: Select all

#include "FiveWin.ch"

function Main()

   MsgInfo( Math_E() )

return nil

#pragma BEGINDUMP

#include <hbapi.h>
#include <math.h>

HB_FUNC( MATH_E )
{
   hb_retnd( M_E );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Math E and function Sigmoid()

Post by Antonio Linares »

function Sigmoid( nValue )

return 1 / ( 1 + Math_E() ^ ( -nValue / 1 ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Math E and function Sigmoid()

Post by Antonio Linares »

Sigmoid demo:

sigmoid.prg

Code: Select all

#include "FiveWin.ch"

function Main()

   local n

   for n = 1 to 20
      MsgInfo( Sigmoid( If( n % 2 == 0, -1, 1 ) * nRandom() / nRandom() ) )
   next   
 
return nil

function Sigmoid( nValue )

return 1 / ( 1 + Math_E() ^ ( -nValue / 1 ) )

#pragma BEGINDUMP

#include <hbapi.h>
#include <math.h>

HB_FUNC( MATH_E )
{
   hb_retnd( M_E );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Math E and function Sigmoid()

Post by Antonio Linares »

https://en.wikipedia.org/wiki/Sigmoid_function
A wide variety of sigmoid functions have been used as the activation function of artificial neurons
Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Math E and function Sigmoid()

Post by Enrico Maria Giordano »

Antonio Linares wrote:function Sigmoid( nValue )

return 1 / ( 1 + Math_E() ^ ( -nValue / 1 ) )
Simplified:

Code: Select all

return 1 / ( 1 + Math_E()  ^ -nValue )
EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Math E and function Sigmoid()

Post by Antonio Linares »

thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Math E and function Sigmoid()

Post by Antonio Linares »

function dSigmoid( n ) --> returns the derivative of the sigmoid function

Code: Select all

function dSigmoid( nValue )

   local n := Sigmoid( nValue )

return n * ( 1 - n )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Math E and function Sigmoid()

Post by Antonio Linares »

Example

Code: Select all

function Main()

   local n

   SET DECIMALS TO 10

   for n = 1 to 10
      ? Sigmoid( n ), dSigmoid( n )
   next

return nil

function Sigmoid( nValue )

return 1 / ( 1 + Math_E()  ^ -nValue )

function dSigmoid( nValue ) // returns the derivative of the sigmoid function

   local n := Sigmoid( nValue )

return n * ( 1 - n )
 
0.7310585786 0.19661193324148180000
0.8807970780 0.10499358540350660000
0.9525741268 0.04517665973091220000
0.9820137900 0.01766270621329111000
0.9933071491 0.00664805667079003200
0.9975273768 0.00246650929135993100
0.9990889488 0.00091022118012178410
0.9996646499 0.00033523767075636810
0.9998766054 0.00012337934976493020
0.9999546021 0.00004539580773590766
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply