http://qs321.pair.com?node_id=1214803


in reply to Basic Neural Network in PDL

++Very nice. I had been thinking about brushing up on my neural net skills (they're 20years rusty), and I've bookmarked this this will be a good starting point for using PDL to do so.

My one minor nitpick: the sigmoid function you chose, the "logistic function", has a derivative that's f(x) * (1-f(x)), not x * (1-x), so you should replace your nonlin() sub with

sub nonlin { my ( $x, $deriv ) = @_; my $f = 1 / ( 1 + exp( -$x ) ); return $f * ( 1 - $f ) if defined $deriv; return $f; }
... It still trains with your slope, but with my slope, it gets there faster, so 10k training loops gives better results:
Output After Training: [ [ 0.0007225057] [0.00048051061] [ 0.999593] [ 0.999388] ]