AI-Nerl
view release on metacpan or search on metacpan
examples/digits/idx_to_fits.pl view on Meta::CPAN
use File::Slurp;
use PDL::IO::FITS;
use FindBin qw($Bin);
chdir $Bin;
die 'filename' unless $ARGV[0];
my $img_filename = $ARGV[0];
my $img_data = read_file( $img_filename, binmode => ':raw' ) ;
my @header = map {ord} split ('', substr ($img_data, 0, 4, ''));
my $numdims = $header[3];
my @dims = map {ord} split ('',substr($img_data, 0, 4*$numdims, ''));
#'IDX' format described here: http://yann.lecun.com/exdb/mnist/
for (0..$numdims-1){
$dims[$_] = 256*$dims[4*$_+2] + $dims[4*$_+3];
}
@dims=@dims[0..$numdims-1];
#die join ' ',@dims;
#my @img_data = map{ord}split('',$img_data);
my $img_pdl = pdl(unpack('C*',$img_data));
use PDL::Graphics2D;
if(!defined($dims[1])){
$img_pdl = $img_pdl->squeeze;
}
elsif ($dims[1]==28){ #images
@dims = (28**2,$dims[0]);
$img_pdl = $img_pdl->reshape(@dims)->transpose();
train_y => $AND,
);
$AND_nerl->build_network;
my $AND_output = $AND_nerl->run($x);
}
#task: mod 3
#in: 8 bits from (n=0..255);
#out: 1 output: (n%3 != 0)
my $x = map{split '',sprintf("%b",$_)} 0..255;
$x = pdl($x)->transpose;
my $y = pdl map{$_%3 ? 1 : 0} 0..255;
$y = identity(3)->range($y->transpose);
my $nerl = AI::Nerl->new(
train_x => $x,
train_y => $y,
l2 => 4,
);
#$nerl->init_network();
$nerl->build_network();
t/nerl_network.t view on Meta::CPAN
#build a few really simple nets.
#in: x1,x2
#out: x1 AND|OR|XOR x2
{
my $id2 = identity(2);
my $x = pdl([0,0,1,1],[0,1,0,1]);
my $AND = $id2->range(pdl(0,0,0,1)->transpose);
my $OR = $id2->range(pdl(0,1,1,1)->transpose);
my $XOR = $id2->range(pdl(0,1,1,0)->transpose);
my ($AND_nn,$OR_nn,$XOR_nn) = map {
AI::Nerl::Network->new(
l1=>2,
l2=>4,
l3=>2,
alpha=>.5,
lambda=>0,
);
} 1..3;
isa_ok($XOR_nn, 'AI::Nerl::Network');
is($XOR_nn->theta1->dim(0), 2, 'theta1 dim1 == 2');
( run in 0.525 second using v1.01-cache-2.11-cpan-49f99fa48dc )