FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index Utilities / Utilidades function SoftMax()
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
function SoftMax()
Posted: Tue May 14, 2024 07:02 PM
la función SoftMax() hace que la suma de todos los valores sea 1

Esto se conoce como "normalización" o "estandarización" de los valores
Code (fw): Select all Collapse
function Main()

   local aValues := { 1, 2, 3 }

   ? SoftMax( aValues )
   
   ? aValues[ 1 ] + aValues[ 2 ] + aValues[ 3 ]   // { 0.09, 0.24, 0.67 } --> 1

return nil

FUNCTION Softmax( aValues )

   LOCAL n, nSum := 0

   FOR n := 1 TO Len( aValues )
      nSum += Exp( aValues[ n ] )
   NEXT

   FOR n := 1 TO Len( aValues )
      aValues[ n ] := Exp( aValues[ n ] ) / nSum
   NEXT

RETURN aValues
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion