AI-ML

 view release on metacpan or  search on metacpan

lib/AI/ML/NeuralNetwork.pm  view on Meta::CPAN

use Math::Lapack::Matrix;
use Math::Lapack::Expr;
use parent 'AI::ML::Expr';

my $functions = {
		sigmoid 	=> \&AI::ML::Expr::sigmoid,
		relu   		=> \&AI::ML::Expr::relu,
		lrelu 		=> \&AI::ML::Expr::lrelu,
		softmax 	=> \&AI::ML::Expr::softmax,
		tanh 		=> \&AI::ML::Expr::tanh,
		dsigmoid    => \&AI::ML::Expr::d_sigmoid,
		drelu   	=> \&AI::ML::Expr::d_relu,
		dlrelu 		=> \&AI::ML::Expr::d_lrelu,
		dtanh  		=> \&AI::ML::Expr::d_tanh
};

=head2 new

=cut
sub new {
	my ($self, $layers, %opts) = @_;
	$self = bless {} => 'AI::ML::NeuralNetwork';

	my $i = 0;
	for my $href ( @$layers ) {
		if( $i == 0 ){
			$self->{"l$i"} = { units => $href };
		}		
		else {
			if( $href =~ qw.^\d+$. ){
				$self->{"l$i"} = { units => $href, func => "sigmoid", dfunc => "dsigmoid" };
			}
			elsif( ref($href) eq "HASH" ) {
				if ( exists $href->{func} ) {
					if ( exists $functions->{$href->{func}} ) 
					{
						$self->{"l$i"}{func}  = $href->{func};
						$self->{"l$i"}{dfunc} = 'd' . $href->{func};
					}
					else
					{



( run in 2.168 seconds using v1.01-cache-2.11-cpan-71847e10f99 )