Algorithm-AdaGrad
view release on metacpan or search on metacpan
lib/Algorithm/AdaGrad.pm view on Meta::CPAN
package Algorithm::AdaGrad;
use 5.012;
use strict;
use warnings;
use XSLoader;
BEGIN{
our $VERSION = "0.03";
XSLoader::load __PACKAGE__, $VERSION;
}
1;
__END__
=encoding utf-8
=head1 NAME
Algorithm::AdaGrad - AdaGrad learning algorithm.
=head1 SYNOPSIS
use Algorithm::AdaGrad;
my $ag = Algorithm::AdaGrad->new(0.1);
$ag->update([
{ "label" => 1, "features" => { "R" => 1.0, "G" => 0.0, "B" => 0.0 } },
]);
$ag->update([
{ "label" => -1, "features" => { "R" => 0.0, "G" => 1.0, "B" => 0.0 } },
{ "label" => -1, "features" => { "R" => 0, "G" => 0, "B" => 1 } },
{ "label" => -1, "features" => { "R" => 0.0, "G" => 1.0, "B" => 1.0 } },
{ "label" => 1, "features" => { "R" => 1.0, "G" => 0.0, "B" => 1.0 } },
{ "label" => 1, "features" => { "R" => 1.0, "G" => 1.0, "B" => 0.0 } }
]);
my $result = $ag->classify({ "R" => 1.0, "G" => 1.0, "B" => 0.0 });
=head1 DESCRIPTION
Algorithm::AdaGrad is implementation of AdaGrad(Adaptive Gradient) online learning algorithm.
This module can be use for binary classification.
=head1 METHODS
=head2 new($eta)
Constructor.
C<$eta> is learning ratio.
=head2 update($learning_data)
Executes learning.
C<$learning_data> is ArrayRef like bellow.
$ag->update([
{ "label" => -1, "features" => { "R" => 0.0, "G" => 1.0, "B" => 0.0 } },
{ "label" => -1, "features" => { "R" => 0, "G" => 0, "B" => 1 } },
{ "label" => -1, "features" => { "R" => 0.0, "G" => 1.0, "B" => 1.0 } },
{ "label" => 1, "features" => { "R" => 1.0, "G" => 0.0, "B" => 1.0 } },
{ "label" => 1, "features" => { "R" => 1.0, "G" => 1.0, "B" => 0.0 } }
]);
C<features> is set of feature-string and value(real number) pair.
C<label> is a expected output label (+1 or -1).
=head2 classify($features)
Executes binary classification.
Returns 1 or -1.
C<$features> is HashRef like bellow.
( run in 0.735 second using v1.01-cache-2.11-cpan-172d661cebc )