https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1
To easily test the Python code: (replace xrange with range and use parentesis in print call)
https://www.onlinegdb.com/online_python_debugger
Lets try to port those 9 lines of Python into Harbour:
- Code: Select all Expand view
- function Main()
local aInputs := { { 0, 0, 1 }, { 1, 1, 1 }, { 1, 0, 1 }, { 0, 1, 1 } }
local aOutputs := { { 0 }, { 1 }, { 1 }, { 0 } }
local aWeights := Array( Len( aInputs ) )
AEval( aWeights, { | n, i | aWeights[ i ] := { hb_Random() } } )
? AOutput( MatrixMult( aInputs, aWeights ) )
return nil
function MatrixMult( aMatrix1, aMatrix2 )
local aRowMatrix1, nSum, nCols := Len( aMatrix2[ 1 ] )
local aResult := Array( Len( aMatrix1 ), nCols )
for each aRowMatrix1 in aMatrix1
for nCol := 1 to nCols
nSum = 0
AEval( aRowMatrix1, { |n,i| nSum += n * aMatrix2[ i, nCol ] } )
aResult[ aRowMatrix1:__enumIndex, nCol ] = nSum
next
next
return aResult
function AOutput( aValues )
return AEval( aValues, { |n,i| aValues[ i ] := If( ValType( aValues[ i ] ) == "N", 1 / ( 1 + exp( n ) ), AOutput( aValues[ i ] ) ) } )