lib/Peta/NN/Layer/Activation.pm

filter: Statementstmt 100% 17 / 17 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 8 / 8 totaltotal 94.7% 36 / 38 CC 3 SCAR 3.2
CC
3
Cov
90%
new
2.1
init
2.0
BEGIN
1.0
CRAP 1.4
« lib/Peta/NN/Backend/PDL.pm ↑ Summary lib/Peta/NN/Layer/Dense.pm »
1 package Peta::NN::Layer::Activation;
2 # ABSTRACT: relu, tanh and sigmoid
3  
4 # Element-wise non-linearities. Each derivative is taken in terms of the
5 # OUTPUT, so the layer keeps only what it returned.
6  
7 27 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 27 our $VERSION = '0.2610090';
10  
11 27 my %KIND = map { $_ => 1 } qw(relu tanh sigmoid);
12  
13 27 ▶sub kinds { return sort keys %KIND }
Subroutine kinds: called CC=1 SCAR=0.0
Pod documented
14  
15 152 ▶sub new ($class, %arg) {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
16 152 ▶ die "unknown activation '$arg{kind}'\n" if !$KIND{ $arg{kind} };
Branch: 1 branch
BranchTrueFalseTotal
unless $KIND{$arg{"kind"}} 0 152 152
17 152 return bless { kind => $arg{kind} }, $class;
18 }
19  
20 1584 ▶sub type ($self) { return $self->{kind} }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
21  
22 152 ▶sub init ($self, $n_in, $rng, $backend) {
Subroutine init: called CC=2 SCAR=7.1
Pod documented
23 152 ▶ die "$self->{kind} cannot follow a token input directly\n" if ref $n_in;
Branch: 1 branch
BranchTrueFalseTotal
if ref $n_in 0 152 152
24 152 $self->{backend} = $backend;
25 152 return $n_in;
26 }
27  
28 17806 ▶sub param_names ($self) { return }
Subroutine param_names: called CC=1 SCAR=0.0
Pod documented
29  
30 95909 ▶sub forward ($self, $X) {
Subroutine forward: called CC=1 SCAR=0.0
Pod documented
31 95909 return $self->{Y} = $self->{backend}->activate($self->{kind}, $X);
32 }
33  
34 93142 ▶sub backward ($self, $dY) {
Subroutine backward: called CC=1 SCAR=0.0
Pod documented
35 93142 return $self->{backend}->activate_grad($self->{kind}, $self->{Y}, $dY);
36 }
37  
38 33 ▶sub spec ($self) { return $self->{kind} }
Subroutine spec: called CC=1 SCAR=0.0
Pod documented
39  
40 27 1;
41  
42 __END__
« lib/Peta/NN/Backend/PDL.pm ↑ Summary lib/Peta/NN/Layer/Dense.pm »