File Coverage

blib/lib/Statistics/Descriptive/Smoother/Exponential.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition 1 2 50.0
subroutine 5 5 100.0
pod 1 1 100.0
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Statistics::Descriptive::Smoother::Exponential;
2 3     3   22 use strict;
  3         7  
  3         98  
3 3     3   16 use warnings;
  3         6  
  3         97  
4              
5 3     3   17 use base 'Statistics::Descriptive::Smoother';
  3         6  
  3         859  
6              
7             our $VERSION = '3.0702';
8              
9             sub _new {
10 7     7   21 my ($class, $args) = @_;
11              
12 7   50     38 return bless $args || {}, $class;
13             }
14              
15             # The name of the variables used in the code refers to the explanation in the pod
16             sub get_smoothed_data {
17 4     4 1 33 my ($self) = @_;
18              
19 4         8 my @smoothed_values;
20 4         7 push @smoothed_values, @{$self->{data}}[0];
  4         19  
21 4         19 my $C = $self->get_smoothing_coeff();
22              
23 4         16 foreach my $sample_idx (1 .. $self->{count} -1) {
24 36         72 my $smoothed_value = $C * ($smoothed_values[-1]) + (1 - $C) * $self->{data}->[$sample_idx];
25 36         63 push @smoothed_values, $smoothed_value;
26             }
27 4         17 return @smoothed_values;
28             }
29              
30             1;
31              
32             __END__