
Simple Neural Network in 22 lines J lang without library - ghosthamlet
https://github.com/ghosthamlet/ann.apl/blob/master/ann.ijs
======
ghosthamlet
The original Python implemation found at:
[http://iamtrask.github.io/2015/07/12/basic-python-
network/](http://iamtrask.github.io/2015/07/12/basic-python-network/)

X =: 4 3 $ 0 0 1 0 1 1 1 0 1 1 1 1

Y =: 4 1 $ 0 0 1 1

w =: 3 1 $ 0.5069797399 0.5703818579 0.9265880619

e =: 2.718281828459045

iter =: ^:

dot =: +/ . *

T =: |:

output =: verb define

1 % 1 + e ^ 0 - X dot y

)

train =: verb define

l1 =: output y

l1_err =: Y - l1

l1_delta =: l1_err * l1 * 1 - l1

y + (T X) dot l1_delta

)

w =: (train iter 1000) w

l1 =: output w

l1

~~~
libx
I compared the time it takes to run both scripts, with 10000000 iteration.
1m32s for the Python version and only 29s for the J's.

If an algorithm is parallelizable, does J use all cores of a CPU?

~~~
ghosthamlet
it run fast may be as the optimized j interpreter:
[http://code.jsoftware.com/wiki/Guides/AVX](http://code.jsoftware.com/wiki/Guides/AVX),
and indeed J may use all cores of CPU in some situations, you can see:
[http://code.jsoftware.com/wiki/User:Devon_McCormick](http://code.jsoftware.com/wiki/User:Devon_McCormick),
[http://code.jsoftware.com/wiki/NYCJUG/2010-03-09#Parallel-
Pr...](http://code.jsoftware.com/wiki/NYCJUG/2010-03-09#Parallel-
Programming_Projects_on_the_J_Wiki)
[http://code.jsoftware.com/wiki/NYCJUG/2010-04-14/ExampleConv...](http://code.jsoftware.com/wiki/NYCJUG/2010-04-14/ExampleConvertingJCodetoUseMultipleCores)

