Jump to content

is there a easy way in autoit to do something like a Sigmoid-curve calculation?


FMS
 Share

Recommended Posts

Hello,

is there a easy way in autoit to do something like a Sigmoid-curve calculation?

_sigmoid($some_number  * $some_other_number + $some_number2  * $some_other_number2 + 10 )

What I want to do is have a output between -1 and 1 or in another time between 0 and 1.

Is this posible in autoit?
I couldn't find anything around this subject on the forum.

This is what i got this far but it isn't working guit wright :

Local $in_min = 0
   Local $in_max = 100
   Local $search_num = 10
   Local $out_min = -1
   Local $out_max = 1
   Local $numbers[3] = [Random($in_min , $in_max , 1),Random($in_min , $in_max , 1),Random($in_min , $in_max , 1)]
   Local $numbers2[3] = [Random($in_min , $in_max , 1),Random($in_min , $in_max , 1),Random($in_min , $in_max , 1)]
   Local $temp = 0
   Local $iReturn = 0
   
   _ArrayDisplay($numbers,"$numbers","",32)
   
   For $i = 0 To UBound($numbers,1) - 1
      $temp = $numbers[1] * $numbers2[$i]
      $iReturn = $iReturn + $temp
   Next
   
   $iReturn = $iReturn + 10
      
#Region ### GUI sigmoid function ?
   Local $total = $in_max - $in_min
   Local $dif = $search_num - $in_min
   Local $percent = Round(($dif / $total) * 100 ,3)
   Local $percentage = Round($percent / (100 * $out_max) , 3)

   MsgBox($MB_SYSTEMMODAL, "", "$percentage = " & $percentage)

   If $percentage < $out_min Then
      $percentage = $out_min
   ElseIf $percentage > $out_max Then
      $percentage = $out_max
   EndIf
$iReturn = $percentage
   MsgBox($MB_SYSTEMMODAL, "", "$percentage = " & $percentage)
#EndRegion

 

Edited by FMS

as finishing touch god created the dutch

Link to comment
Share on other sites

You'll need my Eigen4AutoIt matrix environment (link in my sig) and GraphGDIplus for this. The computation itself is trivial (a mere five lines in E4A).:D The plotting bit I adapted from Dannyfirex (with thanks).

#include <GUIConstantsEx.au3>
#include "GraphGDIPlus.au3"

; computational part by RTFC
#include "Eigen4AutoIt.au3"

_Eigen_StartUp()

$rows=101
$matA=_Eigen_CreateMatrix($rows,3)
_Eigen_SetLinSpaced_Col($matA,0,-10,10)
_Eigen_CwiseUnaryOp_ColCol_InPlace($matA,0,1,"exp")
_Eigen_CwiseScalarOp_ColCol_InPlace($matA,1,2,"+",1)
_Eigen_CwiseBinaryOp_ColCol_InPlace($matA,2,1,"/",$matA)
_matrixDisplay($matA)


; plotting part by Dannyfirex, https://www.autoitscript.com/forum/topic/159094-plotting-values-to-a-graph/
HotKeySet("{ESC}", "_terminate")
Opt("GUIOnEventMode", 1)
$GUI = GUICreate("Sigmoid (0-1)",450, 270, Default,Default)

GUISetOnEvent($GUI_EVENT_CLOSE, "_terminate")
GUISetState()

$Graph = _GraphGDIPlus_Create($GUI,50,50,350,120,0xFF000000,0xFF88B3DD)
_GraphGDIPlus_Set_RangeX($Graph,-10,10,21,1); horizontal figures
_GraphGDIPlus_Set_RangeY($Graph,-0.05,1.05,1,1); horizontal figures
_GraphGDIPlus_Set_PenColor($Graph,0xFF325D87)
_GraphGDIPlus_Set_PenSize($Graph,1)

$xvalue = _Eigen_ReadMatrixValue($matA,0,0)
$yvalue = _Eigen_ReadMatrixValue($matA,0,1)
_GraphGDIPlus_Plot_Start($Graph,$xvalue,$yvalue)

for $rc=1 to $rows-1
    $xvalue = _Eigen_ReadMatrixValue($matA,$rc,0)
    $yvalue = _Eigen_ReadMatrixValue($matA,$rc,1)

    _GraphGDIPlus_Plot_Line($Graph,$xvalue,$yvalue)
    _GraphGDIPlus_Refresh($Graph)
Next

While 1
    sleep(1000)
WEnd


Func _terminate()

    _GraphGDIPlus_Delete($GUI,$Graph)
    _Eigen_CleanUp()
    Exit

EndFunc

 

Edited by RTFC
typo
Link to comment
Share on other sites

nice work @RTFC , this i will use in the future for shure.

I was trying to understand what was hapening inside but unfortunaly I couldn't understand what was hapening,
also a little bit complex for mine taste :)

Could you explaine how i only can have the sigmoid value?

_sigmoid($some_number  * $some_other_number + $some_number2  * $some_other_number2 + 10 )

 

as finishing touch god created the dutch

Link to comment
Share on other sites

1 hour ago, FMS said:

Could you explaine how i only can have the sigmoid value?

Sure; I'l try to explain.:) First off, please read the first few paragraphs of this article on sigmoid functions. You'll see that a generic formula for this is: exp(x) / [exp(x)+1] for a range of x from large negative to large positive. (I have no idea where you got that " $some_number  * $some_other_number..." stuff from; I don't think it is at all relevant in this context; please forget it). So what my script does is:

  1. create a matrix with 101 rows and 3 columns (a matrix is like an array, but 16-byte aligned, and contiguous in memory)
  2. fill column 0 with regularly-spaced values between -10 and 10; these are the x-coordinate values to be plugged into the sigmoid function
  3. fill column 1 with exp(x), where x = the value in column 0 for each row in turn
  4. fill column 2 with: 1 + the value in column 1 (filled in the previous step with exp(x)), where x = the value in column 0 for each row in turn
  5. divide column 1's value by column 2's value for each row in turn; now column 1 (our y-coordinate values to plot) contains exp(x) / [exp(x)+1] for the range of x-values in column 0 (our x-values to plot).
  6. Plot x vs y (col 0 vs col 1) for all rows

That's all, folks. The power of matrix arithmetic allows you to perform each operation on a large number of values simultaneously. Please consult E4A's online Help file if you're interested in learning more. But if you just want a single y-value, then plug an input x-value into the sigmoid equation. But in your title and first post you asked for a sigmoid-curve calculation, and a curve consists of many points.

Edited by RTFC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...