Oh blimey! So it was just that vertical bar from the terminal. Sorry I was
groggy this morning and didn't read your post properly.

You say goal wasn't defined as a noun because it was at the bottom and it
only worked for me cos it was defined from an earlier attempt. But I use =.
everywhere so shouldn't it be a blank slate every time anyway?

I understand that rand =. _1 1 {~ ?@:(2"0) returns a block of 1s and _1s the
same shape as its parameter. What I don't understand is how the parameter
gets though (rand&[) to rand. Roger Stokes says:

            (f @: g) y  =  f (g y)
            (f & g)  y  =  (f @: g) " G  y

where G is the monadic rank of g , which is infinite in my case. But JfC
says f&g y = f g y. I'm not sure why that's not a contradiction, but I'm
using it in the latter sense so (rand&[) y = rand [ y = rand. When did y hit
rand? Oh I get it. rand is not a constant so it'll use the former case, then
[ ends up being used monadically which is the identity function. So I get
rand y. Correct? Well that was a lucky accident. Why don't I just write
rand? Aha. That works too. But how I make something that's undeniably
constant and would invoke the [ I (wrongly) wanted in the first place?
Speaking of which...

> in. What would I write in weightlearn if learnrate was 0.5&[ ?
Can you expand on these issues a bit?  I am confused myself.

In C I'd just write:
learnrate = 0.5;
... learnrate*blahblahblah;

So the * is in the formula, not in the constant. That seems more intuitive
to me. How do I do that?


   0 0 ( ; ,: ) 0 0
┌───┬───┐
│0 0│0 0│
└───┴───┘
  (0 0 ; (0 0 ,: 0 0) )
┌───┬───┐
│0 0│0 0│
│   │0 0│
└───┴───┘
That was strange. I thought those two should be the same cos it's a dyadic
hook.

Here's the latest then:

goal =: _1 1
reward =: _1 _1
learnrate =: 0.5&*
forgetrate =: 0.5&*
jumblerate =: 0.2&*

rand =: _1 1 {~ ?@:(2"0)
matmul =: +/ .*
avg =: %&2@:+
avgio =: avg &.>

w =: 1&{::
io =: 0&{::
ifio =: 0&{::
ofio =: 1&{::
i =: ifio@io
o =: ofio@io
show =: ([(1!:2&2)@('-+'{~>:&0)@(i,o))

env =: (rand)`(reward&[) @. (-:&goal)
decide =: _1 1 {~ >:&0
think =: w (] ; decide@matmul) env@o

weightlearn =: learnrate@*/~&>/@((avgio io)~)
weightjumble =: (+ jumblerate@rand)
weightnew =:  (weightlearn + (weightjumble@forgetrate@w@[))

cycle =: ((] ; weightnew) think)

cycle@show ^:40 (; ; ,:)~ 0 0



Now I'm trying to tidy up that weights business. The new weights matrix is a
sum of three matrices all based on the old weights and the new io, so it
should be written as a sum. I got this working:

   r
*&10000 100 1
   a
+/@r@(+ , - , *)
   10 a 2
120820

   a
1 2
3 4
   b
5 6
7 8
   g
+/@(+ , - , *)"0
   a g b
 7 16
27 40

   a    +/@((3 2 1)&*)"2@(+,-,*)"0 b
15 28
43 60

which is correct. So I'm trying to write:

rates = ((0.5 0.2 0.5)&*)"2 NB. remember, jumble, learn
weightnew =: +/@rates@( w@[ , rand@w@[ , (ofio */ ifio)@((avgio io)~ )

Or ( w&[ , w&[ , w&[ ). Doesnt work either way and I'm stumped.

A huge thank you to everyone who's putting so much time into helping me!

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

Reply via email to