Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Basic Neural Network in PDL

by pryrt (Monsignor)
on May 17, 2018 at 22:15 UTC ( #1214803=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214803]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2020-11-26 19:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found