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] ]

Replies are listed 'Best First'.
Re^2: Basic Neural Network in PDL
by mxb (Pilgrim) on May 18, 2018 at 07:57 UTC

    Thanks for the kind words, I'm glad this post may assist.

    Interesting point about the Sigmoid derivative. Both PDL and neural networks are still new to me, so I wouldn't have caught it. I'm glad someone with more experience has had a glance over the code. I wasn't aware that it was incorrect as it's a direct port of the code from the original blog post. I just checked and that code has the same error.

    Thanks for the fix.