At the risk of doing the whole assignment:

The way you've written "calcNetError" it's not a function, it's data.

Things start to look wonky about here (but it's still not clear what you're
attempting to do):

 Input=: |: (0 1 { |: > Data)
Input
0 1
1 0
0 0
1 1
NB. A noun - is this supposed to be a verb that takes "Data" as an argument?

  ]desOutputs=: |: ( 2 { |: > Data)
1 1 0 0
NB. Another noun...

  ]Output=: Input propagate Weights
0.88079705
0.88008779
0.73105858
0.88079708
NB. Another noun

  ]Error=: +/ *: Output-desOutputs
1.3388384
NB. Another noun

  ]calcNetError=: Input,desOutputs, Output, Error
0 1 0 0
1 0 0 0
0 0 0 0
1 1 0 0
1 1 0 0
0.88079705 0 0 0
0.88008779 0 0 0
0.73105858 0 0 0
0.88079708 0 0 0
1.3388384 0 0 0
NB. Yet another noun formed from the nouns defined before.

If you expect "calcNetError" to be a function, do you think that its
components
"Input,desOutputs, Output, Error" consist of one or more functions?

For instance, do you intend "Input" to be a function that works on the
global
variable "Data"? If so, you need to define it explicitly:

Input=: 3 : '|: (0 1 { |: > Data)'

but this looks peculiar, not the least because of the seemingly unnecessary
parens and ">".

I notice that maybe you have adopted a naming convention whereby you
capitalize nouns (variables) but name verbs (functions) with an initial
lowercase?

Also, why all the magic numbers in the definitions of "getIHW" and "getHOW"?

It looks like you're expecting a very static argument since you're selecting
using fixed indexes.

Oh, I see: you're just selecting the 1st 4 elements of Weights and making
them into a 2x2, then you're selecting the last 2 elements of Weights and
making them into a 2x1. So, in fact the 1st magic 2 is really NIn and the
second magic 2 is NHid?

OK - I'm starting to figure this out.

Everything here is unnecessarily complicated because some things which look
like functions, like "getHIW", "Input", "desOutputs", "getHOW" are really
just getting static data.

A good idea is to begin with the data, so let's look at the highest-level
parameters:
  Weights =:                  10 5   15 30   1 1
  NIn=: 2     NB. refers to |   | ?
  NHid=:2    NB. refers to           | | ?
  Nout=:1
  Data=:0 1 1, 1 0 1, 0 0 0,: 1 1 0

The way "Weights" is used, it should really be defined:

  ]Weights=: (10 5,:15 30);1 1 NB. (Input and Hidden), Output layers
+-----+---+
|10 5|1 1|
|15 30| |
+-----+---+

and transpose the data to more natural form:

  Data=: |:Data
or
  Data=: 0 1 0 1,1 0 0 1,:1 1 0 0

NB. Study the problem in steps, using J's interactivity along the way...

  (>0{Weights) +/ .* 2{.Data NB. Apply (Input, Hidden) weights to data
5 10 0 15
30 15 0 45

  (>1{Weights)+/ . * sig (>0{Weights) +/ .* 2{.Data NB. output weights
1.9933071 1.9999543 1 1.9999997
  sig (>1{Weights)+/ . * sig (>0{Weights) +/ .* 2{.Data NB. Apply sigmoid
0.88009258 0.88079228 0.73105858 0.88079705
NB. Same as before but simple vector instead of 1-col table.
  Output
0.88079705
0.88008779
0.73105858
0.88079708

  propagate
[: sig calcHiddenOut inProd getHOW

  propagate=: 13 : 'sig (>1{y)+/ . * sig (>0{y) +/ .* 2{.x'
  Data propagate Weights
0.88009258 0.88079228 0.73105858 0.88079705

NB. OK but break into pieces like example...
  calcHidden=: 13 : 'sig (>0{y) +/ .* 2{.x'
  propagate=: 13 : 'sig (>1{y)+/ . * x calcHidden y'
  Data propagate Weights
0.88009258 0.88079228 0.73105858 0.88079705

NB. Generalize to eliminate magic numbers: assume data has desired
NB. output as last row.
  calcHidden=: 13 : 'sig (>0{y) +/ .* _1}.x'
  Data propagate Weights
0.88009258 0.88079228 0.73105858 0.88079705
  calcErr=: 13 : '+/*: (_1{x)-x propagate y'
  Data calcErr Weights
1.3388384
  ,.Weights;Data;(Data propagate Weights);Data calcErr Weights  NB. ,. for
better display
+-------------------------------------------+
|+-----+---+ |
||10 5|1 1| |
||15 30| | |
|+-----+---+ |
+-------------------------------------------+
|0 1 0 1 |
|1 0 0 1 |
|1 1 0 0 |
+-------------------------------------------+
|0.88009258 0.88079228 0.73105858 0.88079705|
+-------------------------------------------+
|1.3388384 |
+-------------------------------------------+
  propagate
[: sig ([: > 1 { ]) +/ .* calcHidden
  calcHidden
[: sig ([: > 0 { ]) +/ .* _1 }. [
  sig
[: %@:>: [: ^@:- ]
  NB. sig could be more simply written:
  sig=: 13 : '%>:^-y'
  sig
[: % [: >: [: ^ -





On 4/28/07, R.A. MacDonald <[EMAIL PROTECTED]> wrote:

Hello Alan;

I can see some misunderstandings of J that might not get fixed in a
single email. I have only a 50% confidence that I can even see what you
are trying to do. I'll ask some questions, phrased so that each question
is answerable with Yes:

0. Is it true that you see the following sentence as your 'main' sentence:

    NetParams calcNetError Weights

1. do you see that the following sentence does the same thing?

   (NIn; NHid; Nout; Data) calcNetError Weights

2. Do you see that your sentence:

calcNetError=: Input,desOutputs, Output, Error

defines 'calcNetError' as a noun?

3. Are you thinking that J works like FORTRAN, in that when you assign
an expression to a function name, you are setting the return value of
the function?

3a. Do you know that the return value of an explicitly defined J verb is
the value of last expression executed?

4. Do you see that, the way you have defined Data,  it is the same as
>Data

5. Do you see that 2{|:>Data is the same as 2({"1)Data?  This gives you
the 2 column without having to do a transpose?

6. Does something like this work:

calcNetError=: 3 : 0
    'NIn NHid Nout Data' =. x NB. The left argument is x; Do you
understand what is going on here with 'name name' =. expression?
    Weights =. y NB. The right argument is y
    Input =. 0 1 {"1 Data
    desOutputs =. 2{"1 Data
    Output =. Input  propagate Weights NB. There may be some problems
here, as 'propogate' uses global names. That may need to wait for
another message.
    Error =. +/ *: Output-desOutputs
    Input;desOutputs;Output;Error    NB. last expression, therefore the
return value. I changed the , to a ;
)

(NIn; NHid; Nout; Data)  calcNetError Weights

(there will be those who complain that I'm doing someones homework I say
7 lines of  J won't spoil him.)

7. Does this get you started?

Alan Mac Hugh wrote:
> Hi I'm working on a assignment for college, I would e-mail my lecture,
> but
> the  assignment due in on Monday at 12noon and I'm not sure if he
> checks his
> e-mail  over the weekend. I have got the program working, but the
> output is
> not right.
>
> When I type in
>
> NetParams calcNetError Weights
>
> I should just get the answer.
>
> I know the answer there as when I type calcNetError, the answer is
> the last
> thing displayed.The propagate function is my lectures solution to a
> previous
> assignment all the rest is my own code.
>
> Below is the code:
>
> [code]
>
> nProd =:  +/ . *     NB. dyad: returns inner product of x and y
>
> sig =:  [: %@:>: [: ^@:- ]   NB. monad: returns sigmoid function of y
>
> getIHW =:   (2 2) $ (i. 4) { ]    NB. monad: returns the input->hidden
> weight matrix from y
>
> getHOW =:   (2 1) $ (4 + i. 2) { ]   NB. monad: returns the
> hidden->output
> weight matrix from y
>
> calcHiddenOut =:[: sig [ inProd getIHW   NB. dyad: returns the hidden
> unit
> activations
>
>      NB. from input x to network with y weights
>
> propagate =:  [: sig calcHiddenOut inProd getHOW NB. dyad: returns the
> output from the output unit
>
>      NB. from input x to a network with y weights
>
>
>
>
>
> ] Weights =: 10 5 15 30 1 1
>
> 10 5 15 30 1 1
>
>
>
>  NIn=: 2
>
>  NHid=:2
>
>  Nout=:1
>
>  Data=:0 1 1, 1 0 1, 0 0 0,: 1 1 0
>
>
>
> NetParams=:NIn; NHid; Nout; Data
>
> Input=: |: (0 1 { |: > Data)
>
> desOutputs=:|: ( 2 { |: > Data)
>
> Output=:Input  propagate Weights
>
> Error=:+/ *: Output-desOutputs
>
> calcNetError=: Input,desOutputs, Output, Error
>
> NetParams calcNetError Weights
>
>
> [/code]
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to