Yippee! I got my first J program working. Here it is:

((];(0.5*((<1)&{::*/(<0)&{::)@(((%&2@:+&.>)(<0)&{::)~)(+)((+
1-~2*?@:(2"0))@(*&0.5)@((<1)&{::)@[)))((><1)&{::(];((_1&[)`(1&[)@.(>:&0))"0@(+/
.*))((1-~2*?@:(2"0))&[)`((_1 _1)&[)@.((*/ .=)&(_1
1))@((0;1)&{::)))@([(1!:2&2)@(8!:0)@((0;0)&{::,(0;1)&{::))^:40((0 0;0 0);2
2$0) NB. starting with blank inputs, outputs and weights, do 30 iterations
of printing and the main algorithm which presents the reward input if the
output is the desired one otherwise a random input, matrix multiplies the
input through the weights and digitises to +/-1 and updates the weights with
decay and random drift and iff both ends of a weight are unchanged for two
consecutive cycles also the input-output correlation.

That was FUN! I love this language. I once ended up inventing something like
fork and hook in haskell (or was it python) but it was a pig to use. So when
I heard about that in J my heart sank. But in practice they turned out to be
exactly what I wanted whenever I wanted something like that. This seems like
quite an active community as well: 3 answers in about an hour.

I'm a bit confused about this bit:

((1-~2*?@:(2"0))&[)`((_1 _1)&[)@.((*/ .=)&(_1 1))

because

1-~2*?@:(2"0) is magically producing a length 2 list like I want it to. How?
Is it getting a list fed to it as a parameter? I know that would do the
trick, but how's it getting in? I know the parameter gets fed to (rand&[),
but why would it go deeper?

Adrian.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to