sub nonlin { my ( $x, $deriv ) = @_; my $f = 1 / ( 1 + exp( -$x ) ); return $f * ( 1 - $f ) if defined $deriv; return $f; }