AI-ML
view release on metacpan or search on metacpan
lib/AI/ML/LogisticRegression.pm view on Meta::CPAN
considerando y [m,1]
=cut
sub train {
my ($self, $x, $y) = @_;
my ($lambda, $thetas, $h, $cost, $reg, $reg_thetas, $grad);
my $iters = $self->{n};
my $alpha = $self->{alpha};
#my $cost_file = exists $opts{cost} ? $opts{cost} : undef;
$x = Math::Lapack::Matrix::concatenate(
M->ones($x->rows,1),
$x
);
my($m, $n) = $x->shape;
$thetas = M->random($n,1);
my @cost_values=();
lib/AI/ML/NeuralNetwork.pm view on Meta::CPAN
{
die "Invalid activation function for layer $i: $href->{func}\n";
}
}
else {
$self->{"l$i"}{func} = "sigmoid";
}
if( exists($href->{units}) && $href->{units} =~ qw. ^\d+$ . ) {
$self->{"l$i"}{units} = $href->{units};
} else{
die "undefined number of units in layer $i\n";
}
}
}
$i++;
}
$self->load_weights_bias();
$self->{n} = exists $opts{n} ? $opts{n} : 100;
$self->{alpha} = exists $opts{alpha} ? $opts{alpha} : 0.1;
$self->{reg} = exists $opts{reg} ? $opts{reg} : undef;
$self->{cost} = exists $opts{cost} ? $opts{cost} : undef;
$self->{plot} = exists $opts{plot} ? $opts{plot} : undef;
return $self;
}
=head2 load_weights_bias
=cut
sub load_weights_bias {
my ($self) = @_;
my $size = keys %$self;
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";
t/00-report-prereqs.t view on Meta::CPAN
# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027
use Test::More tests => 1;
use ExtUtils::MakeMaker;
use File::Spec;
# from $version::LAX
my $lax_version_re =
qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
|
(?:\.[0-9]+) (?:_[0-9]+)?
) | (?:
v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
|
(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
)
)/x;
# hide optional CPAN::Meta modules from prereq scanner
t/00-report-prereqs.t view on Meta::CPAN
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'";
}
}
( run in 1.913 second using v1.01-cache-2.11-cpan-d80b1682f3f )