Raul,

Thanks, that's exactly what I needed. I was trying to figure out what
syn0 = 2*np.random.random((3,1)) - 1
did. Now I know.

Running the network 10000 times:

Raul:

   tiny_toy_network1 ''

0.00966589

0.00786586

0.993588

0.992118


Article:

Output After Training:
[[ 0.00966449]
 [ 0.00786506]
 [ 0.99358898]
 [ 0.99211957]]

​So the outpots look very similar. There are slight differences, but that's
because the weights are assigned randomly each time.​

This gives me a big start on building neural networks in J.

Skip


Skip Cave
Cave Consulting LLC

On Sat, Nov 18, 2017 at 1:14 AM, Raul Miller <[email protected]> wrote:

> The 11 line fragment at the top is probably something like
>
> tiny_toy_network=:3 :0
>   X=: #: 1 3 5 7
>   Y=: ,. 0 1 1 0
>   syn0=: (2*?3 4$0)-1
>   syn1=: (2*?4 1$0)-1
>   for_j. i.60000 do.
>     l1=: %1+^-X +/ .* syn0
>     l2=: %1+^-l1 +/ .* syn1
>     l2_delta=: (Y - l2)*(l2*(1-l2))
>     l1_delta=: (l2_delta +/ .* |:syn1) * l1 * 1-l1
>     syn1=: syn1+ (|:l1)+/ .* l2_delta
>     syn0=: syn0+ (|:X)+/ .* l1_delta
>   end.
>   l2
> )
>
> I think it's just for show, however, because it doesn't actually
> identify a result, and I just arbitrarily picked l2 as the result
> because that's the sort of result the next bit of code prints.
>
> I've made all the variables be global, though, so you can inspect any
> of them. (Also, you could make this an actual function by editing X
> and Y to be x and y and eliminating those first two lines.)
>
> Anyways, the next bit of code has basically the same math structure
> but rephrased a bit, and with different "argument" values (neither
> routine's values, by the way, exactly match table 1 in that article).
> It also does not spin as long:
>
> nonlin=:3 :0
>   %1+^-y
> :
>   y*1-y
> )
>
> tiny_toy_network1=:3 :0
>    X=: #:1 3 5 7
>    Y=: ,.0 0 1 1
>    syn0=: (2*?3 1$0)-1
>    for. i.10000 do.
>      l0=: X
>      l1=: nonlin l0 +/ .* syn0
>      l1_error=: Y - l1
>      l1_delta=: l1_error * 1 nonlin l1
>      syn0=: syn0+(|:l0)+/ .*l1_delta
>    end.
>    l1
> )
>
> Is this enough to get you started? (do you feel that, using this as a
> template, you can translate the next code example yourself?)
>
> Thanks,
>
> --
> Raul
>
>
>
> On Sat, Nov 18, 2017 at 1:30 AM, 'Skip Cave' via Programming
> <[email protected]> wrote:
> > All,
> >
> > I found this article on building a Neural Network in 11 lines of Python.
> >
> > Does anyone know enough Python to translate this into J?
> >
> > http://iamtrask.github.io/2015/07/12/basic-python-network/
> >
> > Skip
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> 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