Descriptive/Smoother/Weightedexponential.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 96.9% 63 / 65 CC 4 SCAR 5.1
CC
4
Cov
98%
_new
3.0
get_smoothed_data
2.0
BEGIN
1.0
CRAP 1.7
« Descriptive/Smoother.pm ↑ Summary Descriptive/Smoother/Exponential.pm »
1 package Statistics::Descriptive::Smoother::Weightedexponential;
2 3 $Statistics::Descriptive::Smoother::Weightedexponential::VERSION = '3.0801';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp qw/ carp /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use parent 'Statistics::Descriptive::Smoother';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub _new
10 5 ▶{
Subroutine _new: called CC=3 SCAR=11.0
11 5 my ( $class, $args ) = @_;
12  
13 5 ▶ if ( scalar @{ $args->{data} } != scalar @{ $args->{samples} } )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$args->{"data"};} != scalar @{$args->{"samples"};}) 1 4 5
14 {
15 1 carp("Number of data values and samples need to be the same\n");
16 1 return;
17 }
18  
19 4 ▶ return bless $args || {}, $class;
Condition50%1/2
$args || {}
l!l
40
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
20 }
21  
22 # The name of the variables used in the code refers to the explanation in the pod
23 sub get_smoothed_data
24 3 ▶{
Subroutine get_smoothed_data: called CC=2 SCAR=6.9
Pod documented
25 3 my ($self) = @_;
26  
27 3 my ( @smoothed_values, @Wts );
28  
29 # W(0) = N(0)
30 3 push @Wts, @{ $self->{samples} }[0];
31  
32 # S(0) = X(0)
33 3 push @smoothed_values, @{ $self->{data} }[0];
34 3 my $C = $self->get_smoothing_coeff();
35  
36 3 foreach my $idx ( 1 .. ( $self->{count} - 1 ) )
37 {
38 27 my $Xt = $self->{data}->[$idx];
39 27 my $Nt = $self->{samples}->[$idx];
40 27 my $St_1 = $smoothed_values[-1];
41 27 my $Wt_1 = $Wts[-1];
42  
43 27 push @Wts, $self->_get_Wt( $Wt_1, $Nt );
44  
45 27 my $coeff_a = $self->_get_coeff_A( $Wt_1, $Nt );
46 27 my $coeff_b = $self->_get_coeff_B( $Wt_1, $Nt );
47  
48 27 my $smoothed_value =
49 ( $St_1 * $coeff_a + $Xt * $coeff_b ) / ( $coeff_a + $coeff_b );
50 27 push @smoothed_values, $smoothed_value;
51 }
52 3 return @smoothed_values;
53 }
54  
55 sub _get_Wt
56 27 ▶{
Subroutine _get_Wt: called CC=1 SCAR=0.0
57 27 my ( $self, $Wt_1, $Nt ) = @_;
58  
59 27 my $C = $self->get_smoothing_coeff();
60 27 my $coeff_a = $self->_get_coeff_A( $Wt_1, $Nt );
61 27 my $coeff_b = $self->_get_coeff_B( $Wt_1, $Nt );
62  
63 27 return ( ( $Wt_1 * $coeff_a + $Nt * $coeff_b ) / ( $coeff_a + $coeff_b ) );
64 }
65  
66 sub _get_coeff_A
67 54 ▶{
Subroutine _get_coeff_A: called CC=1 SCAR=0.0
68 54 my ( $self, $Wt_1, $Nt ) = @_;
69  
70 54 my $C = $self->get_smoothing_coeff();
71 54 return $C * ( $Wt_1 / ( $Wt_1 + $Nt ) );
72 }
73  
74 sub _get_coeff_B
75 54 ▶{
Subroutine _get_coeff_B: called CC=1 SCAR=0.0
76 54 my ( $self, $Wt_1, $Nt ) = @_;
77  
78 54 my $C = $self->get_smoothing_coeff();
79 54 return ( 1 - $C ) * ( $Nt / ( $Nt + $Wt_1 ) );
80 }
81  
82 3 1;
83  
84 __END__
« Descriptive/Smoother.pm ↑ Summary Descriptive/Smoother/Exponential.pm »