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

Reply via email to