File Coverage

blib/lib/Lingua/Identifier/ForwardProp.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 27 29 93.1


line stmt bran cond sub pod time code
1             package Lingua::Identifier::ForwardProp;
2             $Lingua::Identifier::ForwardProp::VERSION = '0.01';
3 2     2   34 use 5.006;
  2         7  
  2         81  
4 2     2   14 use strict;
  2         4  
  2         75  
5              
6 2     2   12 use Math::Matrix::MaybeGSL;
  2         3  
  2         461  
7              
8             sub sigmoid {
9 2     2 0 8 my $matrix = shift;
10 2     1182   30 return $matrix->each( sub { 1 / ( 1 + exp( - shift)) } );
  1182         14225  
11             }
12              
13             sub forward_prop {
14 1     1 0 2 my ($x, $Thetas) = @_;
15              
16 1         4 my $a = [];
17 1         3 $a->[0] = $x;
18              
19 1         7 for my $i (1 .. scalar(@$Thetas)) {
20 2         133 my $m = Matrix->new(1,1);
21 2         119 $m->assign(1,1,1);
22 2         63 my $z = $Thetas->[$i-1] * $m->vconcat($a->[$i-1]);
23 2         2550232 $a->[$i] = sigmoid($z);
24             }
25              
26 1         213 return $a->[-1];
27             }
28              
29              
30             =for Pod::Coverage sigmoid forward_prop
31              
32             =cut
33              
34             1;
35              
36