seed=: (; ; ,:)~ 0 0
   seed
----------T---┐
│----T---┐│0 0│
││0 0│0 0││0 0│
│L---+----│   │
L---------+----
   
   seeds=: (; ; ,:) 0 0
   seeds
----T---┐
│0 0│0 0│
L---+----
   
   (; 0 0) ; ,: 0 0
----T---┐
│0 0│0 0│
L---+---- 

In seed the reflexive  ~  indicates a dyadic fork.  Without it you have
seeds which is a monadic fork.  Linda



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Adrian May
Sent: Thursday, March 24, 2011 7:03 AM
To: Programming forum
Subject: Re: [Jprogramming] Problem with random numbers

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

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

Reply via email to