note
pryrt
<p>++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.</p>
<p>My one minor nitpick: the sigmoid function you chose, [https://en.wikipedia.org/wiki/Logistic_function|the "logistic function"], has a [https://en.wikipedia.org/wiki/Logistic_function#Derivative|derivative] that's <c>f(x) * (1-f(x))</c>, not <c>x * (1-x)</c>, so you should replace your <c>nonlin()</c> sub with <code>
sub nonlin {
my ( $x, $deriv ) = @_;
my $f = 1 / ( 1 + exp( -$x ) );
return $f * ( 1 - $f ) if defined $deriv;
return $f;
}
</code>... It still trains with your slope, but with my slope, it gets there faster, so 10k training loops gives better results: <code>
Output After Training:
[
[ 0.0007225057]
[0.00048051061]
[ 0.999593]
[ 0.999388]
]
</code></p>
1214548
1214548