AI-ML

 view release on metacpan or  search on metacpan

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

    return bless { package => __PACKAGE__, type => 'softmax', args => [$self] } => __PACKAGE__; 
}

sub eval_softmax {
    my $tree = shift;
    if (ref($tree) eq "Math::Lapack::Matrix") {
        my $s = $tree->max();
        my $e_x = exp( $tree - $s );
        my $div = sum( $e_x, 1 );
        return $e_x / $div;
        #use Data::Dumper;
        #print STDERR Dumper $matrix;
#        return _bless _softmax($tree->matrix_id);
    }
    die "softmax for non matrix";
}

=head2 d_softmax
Allows apply the function d_softmax to every element of the matrix.

    $m = d_softmax($m);

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


package AI::ML::LinearRegression;
use strict;
use warnings;

use Scalar::Util 'blessed';
use aliased 'Math::Lapack::Matrix' => 'M';
use Math::Lapack::Expr;
use parent 'AI::ML::Expr';

use Data::Dumper;

=head2 new

=cut
sub new {
	my ($self, %opts) = @_;
	$self = bless {} => 'AI::ML::LinearRegression';
		
	$self->{grad} 	= $opts{gradient} if exists $opts{gradient}; 
	$self->{reg} 	= $opts{lambda}   if exists $opts{lambda};

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


package AI::ML::LogisticRegression;
use strict;
use warnings;

use Scalar::Util 'blessed';
use aliased 'Math::Lapack::Matrix' => 'M';
use Math::Lapack::Expr;
use AI::ML::Expr;
use parent 'AI::ML::Expr';
use Data::Dumper;


=head2 new

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

	$self->{reg} 	= $opts{reg} 			if exists $opts{reg};

scripts/mnist.pl  view on Meta::CPAN

#!/usr/bin/env perl

use warnings;
use strict;

use HTTP::Tiny;
use Data::Dumper;
use File::Fetch;

use Math::Lapack;
use Math::Lapack::Matrix;

use AI::ML;
use AI::ML::NeuralNetwork;
    
my %opt = (
        "train-images" => "train-images-idx3-ubyte",

t/01-activation-funcs.t  view on Meta::CPAN

#!perl

use Test2::V0 qw'is float done_testing';
use Math::Lapack::Matrix;
use Math::Lapack::Expr;
use AI::ML::Expr;

use Data::Dumper;


my $m = Math::Lapack::Matrix->new(
				[ 
					[0, 0.002, 3, 4, 7.333, -.00008, -2.03456, 9, 100.3456, -300] 
				]
);

is($m->rows, 1, "Right number of rows");
is($m->columns, 10, "Right number of columns");

t/07-neural-network.t  view on Meta::CPAN

#!perl

use Test2::V0 qw'is float done_testing';
use Math::Lapack::Matrix;
use AI::ML::NeuralNetwork;
use Math::Lapack;
use Data::Dumper;


Math::Lapack->seed_rng(0);

my $x = Math::Lapack::Matrix::read_csv("t/x.csv");
my $y = Math::Lapack::Matrix::read_csv("t/y.csv");

my $NN = AI::ML::NeuralNetwork->new(
				[
								2,

t/08-gradient-checking.t_  view on Meta::CPAN

#!perl

use Test2::V0 qw'is float done_testing';
use Math::Lapack::Matrix;
use AI::ML::NeuralNetwork;
use Math::Lapack;
use Data::Dumper;


Math::Lapack->seed_rng(0);

#my $x = Math::Lapack::Matrix::read_csv("t/logistic.csv", col_range =>[0,2]);
#my $y = Math::Lapack::Matrix::read_csv("t/logistic.csv", col => 3);


my $x = Math::Lapack::Matrix::read_csv("t/x_grad_check.csv");
my $y = Math::Lapack::Matrix::read_csv("t/y_grad_check.csv");



( run in 0.291 second using v1.01-cache-2.11-cpan-a5abf4f5562 )