view release on metacpan or search on metacpan
#include "C/config.h"
typedef struct s_matrix{
int columns;
int rows;
REAL *values;
}Matrix;
typedef enum _axis{
HORIZONTAL = 0,
VERTICAL = 1
} Axis;
Matrix *sub_matrices(Matrix *A, Matrix *B);
Matrix *mul_matrices(Matrix *A, Matrix *B);
Matrix *div_matrices(Matrix *A, Matrix *B);
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
}
},
"name" : "ModuleBuild",
"version" : "6.010"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
"config" : {
"Dist::Zilla::Plugin::Prereqs" : {
"phase" : "test",
"type" : "requires"
}
},
"name" : "TestRequires",
"version" : "6.010"
},
{
"class" : "Dist::Zilla::Plugin::Git::GatherDir",
"config" : {
"Dist::Zilla::Plugin::GatherDir" : {
"exclude_filename" : [],
config:
Dist::Zilla::Role::TestRunner:
default_jobs: 1
name: ModuleBuild
version: '6.010'
-
class: Dist::Zilla::Plugin::Prereqs
config:
Dist::Zilla::Plugin::Prereqs:
phase: test
type: requires
name: TestRequires
version: '6.010'
-
class: Dist::Zilla::Plugin::Git::GatherDir
config:
Dist::Zilla::Plugin::GatherDir:
exclude_filename: []
exclude_match: []
follow_symlinks: 0
include_dotfiles: 0
inc/MyBuilder.pm view on Meta::CPAN
my $archdir = path($self->blib, "arch", "auto", "AI", "ML");
$archdir->mkpath unless -d $archdir;
my $xs = path("XS", "ML.xs");
my $xs_c = path("XS", "ML.c");
if (!$self->up_to_date($xs, $xs_c)) {
ExtUtils::ParseXS::process_file(
filename => $xs->stringify,
prototypes => 0,
output => $xs_c->stringify
);
}
my $xs_o = path("XS", "ML.o");
if (!$self->up_to_date($xs_c, $xs_o)) {
$cbuilder->compile(
source => $xs_c,
extra_compiler_flags => $EXTRA_O_FLAGS,
include_dirs => ["."],
lib/AI/ML/Expr.pm view on Meta::CPAN
use aliased 'Math::Lapack::Matrix' => 'M';
use parent 'Exporter';
use parent 'Math::Lapack::Expr';
our @EXPORT = qw(mini_batch tanh sigmoid relu lrelu d_sigmoid d_relu d_lrelu d_tanh softmax sigmoid_cost plot plot_cost);
use Math::Lapack::Expr;
sub _bless {
my $matrix = shift;
return bless { _matrix => $matrix, type => 'matrix' } => "Math::Lapack::Matrix";
}
=head2 sigmoid
Allow apply the function sigmoid to every element of the matrix.
$m = $m->sigmoid();
$m = sigmoid($m);
=cut
sub sigmoid {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'sigmoid', args => [$self] } => __PACKAGE__
}
sub eval_sigmoid {
my $tree = shift;
if (blessed($tree) && $tree->isa("Math::Lapack::Matrix")) {
return _bless _sigmoid($tree->matrix_id);
}
die "Sigmoid for non matrix: " . ref($tree);
}
lib/AI/ML/Expr.pm view on Meta::CPAN
Allows apply the function relu to every element of the matrix.
$m = $m->relu();
$m = relu($m);
=cut
sub relu {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'relu', args => [$self] } => __PACKAGE__;
}
sub eval_relu {
my $tree = shift;
if (ref($tree) eq "Math::Lapack::Matrix") {
return _bless _relu($tree->matrix_id);
}
die "ReLU for non matrix";
}
lib/AI/ML/Expr.pm view on Meta::CPAN
Allows apply the function d_relu to every element of the matrix.
$m = $m->d_relu();
$m = d_relu($m);
=cut
sub d_relu {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'd_relu', args => [$self] } => __PACKAGE__;
}
sub eval_d_relu {
my $tree = shift;
if (ref($tree) eq "Math::Lapack::Matrix") {
return _bless _d_relu($tree->matrix_id);
}
die "ReLU for non matrix";
}
lib/AI/ML/Expr.pm view on Meta::CPAN
Allows apply the function lrelu to every element of the matrix.
$th::Lapack::Matrixref(1)m = lrelu($m, 0.0001);
$m = m->lrelu(0.1);
=cut
sub lrelu {
my ($self, $v) = @_;
return bless { package => __PACKAGE__, type => 'lrelu', args => [$self, $v] } => __PACKAGE__;
}
sub eval_lrelu {
my ($tree, $v) = @_;
if (ref($tree) eq "Math::Lapack::Matrix") {
return _bless _lrelu($tree->matrix_id, $v);
}
die "lReLU for non matrix";
}
lib/AI/ML/Expr.pm view on Meta::CPAN
Allows apply the function d_lrelu to every element of the matrix.
$th::Lapack::Matrixref(1)m = lrelu($m, 0.0001);
$m = m->lrelu(0.1);
=cut
sub d_lrelu {
my ($self, $v) = @_;
return bless { package => __PACKAGE__, type => 'd_lrelu', args => [$self, $v] } => __PACKAGE__;
}
sub eval_d_lrelu {
my ($tree, $v) = @_;
if (ref($tree) eq "Math::Lapack::Matrix") {
return _bless _d_lrelu($tree->matrix_id, $v);
}
die "lReLU for non matrix";
}
=head2 softmax
Allows apply the function softmax to every element of the matrix.
$m = softmax($m);
$m = $m->softmax();
=cut
sub softmax {
my ($self) = @_;
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;
lib/AI/ML/Expr.pm view on Meta::CPAN
=head2 d_softmax
Allows apply the function d_softmax to every element of the matrix.
$m = d_softmax($m);
$m = $m->d_softmax();
=cut
sub d_softmax {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'd_softmax', args => [$self] } => __PACKAGE__;
}
sub eval_d_softmax {
my $tree = shift;
if (ref($tree) eq "Math::Lapack::Matrix") {
return _bless _d_softmax($tree->matrix_id);
}
die "d_softmax for non matrix";
}
=head2 tanh
Allows apply the function tanh to every element of the matrix.
$m = tanh($m);
$m = $m->tanh();
=cut
sub tanh {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'tanh', args => [$self] } => __PACKAGE__;
}
sub eval_tanh {
my $tree = shift;
if( ref($tree) eq "Math::Lapack::Matrix"){
return _bless _tanh($tree->matrix_id);
}
die "tanh for non matrix";
}
=head2 d_tanh
Allows apply the function d_tanh to every element of the matrix.
$m = d_tanh($m);
$m = $m->d_tanh();
=cut
sub d_tanh {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'd_tanh', args => [$self] } => __PACKAGE__;
}
sub eval_d_tanh {
my $tree = shift;
if( ref($tree) eq "Math::Lapack::Matrix"){
return _bless _d_tanh($tree->matrix_id);
}
die "d_tanh for non matrix";
}
lib/AI/ML/Expr.pm view on Meta::CPAN
Allow apply the derivate of function sigmoid to every element of the matrix.
$m = $m->d_sigmoid();
$m = d_sigmoid($m);
=cut
sub d_sigmoid {
my ($self) = @_;
return bless { package => __PACKAGE__, type => 'd_sigmoid', args => [$self] } => __PACKAGE__;
}
sub eval_d_sigmoid {
my $tree = shift;
if( ref($tree) eq "Math::Lapack::Matrix"){
return _bless _d_sigmoid($tree->matrix_id);
}
return "d_sigmoid for non matrix";
}
scripts/load_data.c view on Meta::CPAN
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
//https://gist.github.com/spaghetti-source/5620288
typedef struct s_matrix {
int columns;
int rows;
double *values;
} Matrix;
#define NEW_MATRIX(m,r,c) m=(Matrix*)malloc(sizeof(Matrix));\
m->rows = r; m->columns = c;\
m->values = (double*) malloc (r * c * sizeof(double));
scripts/load_data.c view on Meta::CPAN
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
fprintf(stderr, "%f\t", m->values[i * cols + j]);
}
fprintf(stderr, "\n");
}
}
int main(int argc, char *argv[]){
if (argc != 4) {
fprintf(stderr, "Usage: load <type> input-ubyte output-txt\n");
fprintf(stderr, "\ttype can be:\n");
fprintf(stderr, "\t\timages\n");
fprintf(stderr, "\t\tlabels\n");
exit(1);
}
char *path = argv[2];
Matrix *m;
if (strcmp(argv[1], "images") == 0) {
m = read_csv(path);
} else if (strcmp(argv[1], "labels") == 0) {
m = read_label_csv(path);
} else {
fprintf(stderr, "Unknown file type: %s\n", argv[1]);
}
save(m, argv[3]);
destroy(m);
return 0;
}
scripts/mnist.pl view on Meta::CPAN
sub _load_data {
_download_data();
# compile c file
system("gcc load_data.c -o load");
my @matrices;
for my $key ( keys %opt ) {
my (undef, $type) = split /-/, $key;
system("gunzip $opt{$key}.gz");
system("./load $type $opt{$key} $key.csv");
}
}
sub _download_data{
my $http = HTTP::Tiny->new();
my $url = "http://yann.lecun.com/exdb/mnist";
my $res;
for my $key ( keys %opt ) {
t/00-report-prereqs.t view on Meta::CPAN
# CPAN::Meta::Prereqs object
if (ref $collector eq $cpan_meta_pre) {
return $collector->with_merged_prereqs(
CPAN::Meta::Prereqs->new( $prereqs )
);
}
# Raw hashrefs
for my $phase ( keys %$prereqs ) {
for my $type ( keys %{ $prereqs->{$phase} } ) {
for my $module ( keys %{ $prereqs->{$phase}{$type} } ) {
$collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module};
}
}
}
return $collector;
}
my @include = qw(
);
t/00-report-prereqs.t view on Meta::CPAN
# Add static includes into a fake section
for my $mod (@include) {
$req_hash->{other}{modules}{$mod} = 0;
}
for my $phase ( qw(configure build test runtime develop other) ) {
next unless $req_hash->{$phase};
next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});
for my $type ( qw(requires recommends suggests conflicts modules) ) {
next unless $req_hash->{$phase}{$type};
my $title = ucfirst($phase).' '.ucfirst($type);
my @reports = [qw/Module Want Have/];
for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
next if $mod eq 'perl';
next if grep { $_ eq $mod } @exclude;
my $file = $mod;
$file =~ s{::}{/}g;
$file .= ".pm";
my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
my $want = $req_hash->{$phase}{$type}{$mod};
$want = "undef" unless defined $want;
$want = "any" if !$want && $want == 0;
my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
if ($prefix) {
my $have = MM->parse_version( File::Spec->catfile($prefix, $file) );
$have = "undef" unless defined $have;
push @reports, [$mod, $want, $have];
if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
if ( $have !~ /\A$lax_version_re\z/ ) {
push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
}
elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
push @dep_errors, "$mod version '$have' is not in required range '$want'";
}
}
}
else {
push @reports, [$mod, $want, "missing"];
if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
push @dep_errors, "$mod is not installed ($req_string)";
}
}
}
if ( @reports ) {
push @full_reports, "=== $title ===\n\n";
my $ml = _max( map { length $_->[0] } @reports );
my $wl = _max( map { length $_->[1] } @reports );
my $hl = _max( map { length $_->[2] } @reports );
if ($type eq 'modules') {
splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
}
else {
splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
}
push @full_reports, "\n";
}