Jump to content

noellarkin
 Share

Recommended Posts

I'm going to grok matrix operations over the next few months, and I wanted to use AutoIt, because I'm sick of all ML examples I come across being in Python :)
I'll post example scripts here, starting from the most basic operations (addition, subtraction, multiplication etc). This is primarily so that people checking out basic ML applications of AutoIt have some resources to work with. My own use cases are to do with natural language processing and vector embeddings, so I'll eventually throw in domain-specific examples.

I'm going to use the excellent Eigen4AutoIt UDF by @RTFC - - it's a monster of a UDF, and I hope to scratch its surface, example by example...wish me luck :)

NOTE: When using the Eigen4AutoIt library, remember to set the value of $EIGEN_DLLPATH - - read the Eigen4AutoIt QuickStart Manual (page 2) for details.
Link to comment
Share on other sites

 EXAMPLE #1 - MATRIX MULTIPLICATION FOR 2 MATRICES

Make sure that your matrices are the right size before multiplying (The number of columns in the first matrix must match the number of rows in the second).

#include <Eigen4AutoIt.au3>

_Eigen_Startup()
Local $MatrixA = _Eigen_CreateMatrix(2,4)
Local $MatrixB = _Eigen_CreateMatrix(4,2)

; Matrix A
_Eigen_WriteMatrixValue($MatrixA, 0, 0, 34)
_Eigen_WriteMatrixValue($MatrixA, 0, 1, 254)
_Eigen_WriteMatrixValue($MatrixA, 0, 2, 9)
_Eigen_WriteMatrixValue($MatrixA, 0, 3, 94)

_Eigen_WriteMatrixValue($MatrixA, 1, 0, 23)
_Eigen_WriteMatrixValue($MatrixA, 1, 1, 98)
_Eigen_WriteMatrixValue($MatrixA, 1, 2, 10)
_Eigen_WriteMatrixValue($MatrixA, 1, 3, 120)

_MatrixDisplay($MatrixA)

; Matrix B
_Eigen_WriteMatrixValue($MatrixB, 0, 0, 13)
_Eigen_WriteMatrixValue($MatrixB, 0, 1, 45)

_Eigen_WriteMatrixValue($MatrixB, 1, 0, 75)
_Eigen_WriteMatrixValue($MatrixB, 1, 1, 30)

_Eigen_WriteMatrixValue($MatrixB, 2, 0, 239)
_Eigen_WriteMatrixValue($MatrixB, 2, 1, 876)

_Eigen_WriteMatrixValue($MatrixB, 3, 0, 54)
_Eigen_WriteMatrixValue($MatrixB, 3, 1, 32)

_MatrixDisplay($MatrixB)

Local $MatMul = _Eigen_Multiply_AB($MatrixA, $MatrixB, 0)
_MatrixDisplay($MatMul)

_Eigen_ReleaseMatrix($MatrixA)
_Eigen_ReleaseMatrix($MatrixB)

_Eigen_CleanUp()

 

Link to comment
Share on other sites

EXAMPLE #2 - SETTING ZERO VALUES FOR ALL COLUMNS AND ROWS

#include <Eigen4AutoIt.au3>

_Eigen_Startup()

Local $Matrix = _Eigen_CreateMatrix(2,6)

_Eigen_WriteMatrixValue($Matrix, 0, 0, 34)
_Eigen_WriteMatrixValue($Matrix, 0, 1, 254)
_Eigen_WriteMatrixValue($Matrix, 0, 2, 9)
_Eigen_WriteMatrixValue($Matrix, 0, 3, 94)
_Eigen_WriteMatrixValue($Matrix, 0, 4, 2)
_Eigen_WriteMatrixValue($Matrix, 0, 5, 7)
_Eigen_WriteMatrixValue($Matrix, 1, 0, 23)
_Eigen_WriteMatrixValue($Matrix, 1, 1, 98)
_Eigen_WriteMatrixValue($Matrix, 1, 2, 10)
_Eigen_WriteMatrixValue($Matrix, 1, 3, 120)
_Eigen_WriteMatrixValue($Matrix, 1, 4, 8)
_Eigen_WriteMatrixValue($Matrix, 1, 5, 5)

_MatrixDisplay($Matrix)
_MatrixDisplay(_Eigen_SetZero($Matrix))
_Eigen_ReleaseMatrix($Matrix)

_Eigen_CleanUp()

 

Link to comment
Share on other sites

EXAMPLE #3 - TRANSPOSING A MATRIX

#include <Eigen4AutoIt.au3>

_Eigen_Startup()

Local $Matrix = _Eigen_CreateMatrix(12, 15)
_Eigen_SetRandom($Matrix)

_MatrixDisplay($Matrix)

Local $TransposedMatrix = _Eigen_Transpose($Matrix)
_MatrixDisplay($TransposedMatrix)

_Eigen_ReleaseMatrix($Matrix)
_Eigen_ReleaseMatrix($TransposedMatrix)

_Eigen_CleanUp()

 

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

×
×
  • Create New...