AI-ML
view release on metacpan or search on metacpan
lib/AI/ML/Expr.pm view on Meta::CPAN
=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";
}
=head2 d_sigmoid
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";
}
=head2 sigmoid_cost
Allows get the value of the cost of sigmoid function.
put examples
=cut
sub sigmoid_cost {
my ($x, $y, $weights) = @_;
return _sigmoid_cost($x->matrix_id, $y->matrix_id, $weights->matrix_id);
}
=head2 mini-batch
=cut
sub mini_batch {
my ($self, $start, $size, $axis) = @_;
$axis = 0 unless defined $axis; #default
return _bless _mini_batch($self->matrix_id, $start, $size, $axis);
}
=head2 prediction
=cut
sub prediction {
my ($self, %opts) = @_;
my $t = exists $opts{threshold} ? $opts{threshold} : 0.50;
return _bless _predict_binary_classification($self->matrix_id, $t);
}
=head2 precision
=cut
sub precision {
my ($y, $yatt) = @_;
return _precision($y->matrix_id, $yatt->matrix_id);
}
=head2 accuracy
=cut
sub accuracy {
my ($y, $yatt) = @_;
return _accuracy($y->matrix_id, $yatt->matrix_id);
}
=head2 recall
=cut
sub recall {
my ($y, $yatt) = @_;
return _recall($y->matrix_id, $yatt->matrix_id);
}
=head2 f1
=cut
sub f1 {
my ($y, $yatt) = @_;
return _f1($y->matrix_id, $yatt->matrix_id);
}
=head2 plot
=cut
sub plot {
my ($x, $y, $theta, $file) = @_;
my @xdata = $x->vector_to_list();
my @ydata = $y->vector_to_list();
my @thetas = $theta->vector_to_list();
my $f = $thetas[0] . "+" . $thetas[1] . "*x";
( run in 0.464 second using v1.01-cache-2.11-cpan-39bf76dae61 )