I would work backwards, to get a 3x4 random
_1 1 1 1 1 0 0 0
1 1 1 _1 = 1 - 2 * 0 0 0 1
1 1 1 1 0 0 0 0
so it reduce to find the random of a 3x4 matrix
2 2 2 2
1 - 2 * ? 2 2 2 2
2 2 2 2
or
1 - 2 * ? (3 4)$2
so it need to know the shape of the arguement which is the monad $
say the arugment is i. 3 4
1 - 2 * ? ($ $ 2:) i. 3 4
or equivalently by swapping the order
1 - 2 * ? (2 $~ $) i. 3 4
1 - 2 * ? (2 $~ $) i. 3 4
_1 1 1 1
1 1 1 _1
1 1 _1 1
1 - 2 * ? (2 $~ $) i. 3 4
1 _1 1 1
_1 _1 _1 _1
1 1 1 1
or you may prefer +: instead of 2 * or write it in tacit form.
Чтв, 24 Мар 2011, Adrian May писал(а):
> Thanks everybody,
>
> You made quite an accurate job of disassembling my program. I can't read it
> at all and I wrote it. Here's what I wrote (plus your corrections) before I
> squashed it all together to make it look scary and see if I could:
>
> 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)) NB. looks nicer now
>
> env =. (rand&[)`(reward&[) @. (-:&goal)
> decide =. _1 1 {~ >:&0
> think =. w (] ; decide@matmul) env@o
>
> weightlearn =. learnrate@(ofio */ ifio)@((avgio io)~)
> weightjumble =. (+ jumblerate@rand)
> weightnew =. (weightlearn + (weightjumble@forgetrate@w@[))
>
> cycle =. ((] ; weightnew) think)
>
> cycle@show ^:30 ((0 0;0 0); 2 2 $ 0)
>
> goal =. _1 1
> reward =. _1 _1
> learnrate =. 0.5&*
> forgetrate =. 0.5&*
> jumblerate =. 0.2&*
>
>
> I'm still, still confused about how env's rand knows to make two numbers. In
> 1-~2*?@:(2"0), the 2"0 means I want 1s and 0s. It doesn't say anything about
> how many numbers I want. I know that the vector gets presented to (rand&[)
> but I don't see how or why it makes it down to rand. In (2&*) 3 you don't
> present the 3 to the 2.
>
> But look what I get in the terminal:
>
> rand
> 1 -~ 2 * ?@:(2"0)
> | (rand&[) (2 2$0)
> 1 1
> 1 1
> | (rand&[) (2 2$0)
> 1 1
> 1 1
> | (rand&[) (2 2$0)
> 1 1
> 1 1
> | (rand&[) (2 2$0)
> 1 1
> 1 1
> | (rand&[) (2 2$0)
> 1 1
> 1 1
> | rand (2 2$0)
> 1 1
> 1 1
> | rand (2 2$0)
> 1 1
> 1 1
> | rand (2 2$0)
> 1 1
> 1 1
> | rand (2 2$0)
> 1 1
> 1 1
> | rand (2 2$0)
> 1 1
> 1 1
> rand 2 2
> _1 _1
> rand 2 2
> 1 1
> rand 2 2
> _1 1
> rand(2 2)
> 1 _1
> rand(2 2)
> _1 _1
> rand(2 2)
> 1 _1
> ?2"0 (2 2$0)
> 1 0
> 0 0
> ?2"0 (2 2$0)
> 0 1
> 0 0
>
> What on earth is going on there? I have a hunch that my program isn't giving
> random numbers everywhere. I can recognise the symptoms: it takes longer to
> learn and sometimes doesn't at all.
>
> I now do the vector comparison with -: but why can't I just use = ?
>
> That combiningFn didn't do quite what I wanted. It's supposed to do a matrix
> multiply (nothing's in boxes at that point) then replace everything in the
> answer by its sign. That overall sentence afterwards confused me a bit.
>
> I can't seem to make constants work your way. It barfs when I substitute it
> in. What would I write in weightlearn if learnrate was 0.5&[ ?
>
> > addrandom =: 13 : 'y + ?x#~#y'
>
> I'm confused. #y counts the elements in y. y+ adds, ?x rolls. But what's #~
> A lot of these things don't seem to be in the vocabulary. {~ wasn't either.
>
> The incredible thing about this language is that I never needed to call
> anything twice (except accessors). Those forks and hooks did everything I
> could have asked for in a single sentence. And it's eminently readable too.
>
> Adrian.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm