On Fri, Mar 25, 2011 at 7:00 AM, Adrian May
<[email protected]> wrote:
> 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?
If you had experimented with goal=. interactively, that definition
would persist.
> 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?
Exactly.
> 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?
(rand 0)&[
> 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?
weightlearn =. learnrate * (ofio */ ifio)@((avgio io)~)
> 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.
Hooks are strange, and Roger Hui has suggested that perhaps they
should not be in the language. But they can be very convenient, and
removing them would break too much code and too many documents.
Anyways, perhaps a bit of explanation can help here:
0 0 (; ,:) 0 0 is the same as 0 0 ; ,: 0 0
More generally, these are equivalent (with nouns m and n, verbs u and v)
m (u v) n
m ([ u v@]) n
m u (v n)
m u v n
> 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:
If I understand correctly, the sum you want is:
(weightlearn y) + (jumblerate@rand w y) + w y
If that is the case, you could use:
(weightlearn + jumblerate@rand@w + w) y
Or some variation on that theme -- for example if you changed the
meaning of jumblerate, you might instead use (jumblerate * rand@w)
for your middle term.
But if by sum you meant +/ I am not sure that this is a good idea. +/
would make sense if you had a reason for these three things to be in a
list already, but since you are computing each value independently,
forming a list form them seems like a meaningless operation.
I hope this helps,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm