Basic/Variance.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 55.5% 10 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 88.0% 66 / 75 CC 12 SCAR 16.5
CC
12
Cov
86%
_recalc
8.5
new
5.1
BEGIN
1.0
CRAP 5.2
« Basic/LeastSquareFit.pm ↑ Summary Basic/Vector.pm »
1 package Statistics::Basic::Variance;
2  
3 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 33 ▶use base 'Statistics::Basic::_OneVectorBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 45 ▶sub new {
Subroutine new: called CC=5 SCAR=16.3
Pod documented
10 45 my $class = shift;
11  
12 45 ▶ warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG >= 2 0 45 45
13  
14 45 my $this = bless {}, $class;
15 45 ▶ my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
my $vector = eval { do { "Statistics::Basic::Vector"->new(@_) } } or croak($@) 45 0 45
16 45 ▶ my $c = $vector->_get_computer("variance"); return $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 1 44 45
17  
18 44 $this->{v} = $vector;
19 44 ▶ $this->{m} = eval { Statistics::Basic::Mean->new($vector) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
$this->{"m"} = eval { do { "Statistics::Basic::Mean"->new($vector) } } or croak($@) 44 0 44
20  
21 44 $vector->_set_computer( variance => $this );
22  
23 44 return $this;
24 }
25  
26 64 ▶sub _recalc {
Subroutine _recalc: called CC=8 SCAR=21.4
27 64 my $this = shift;
28 64 my $first = shift;
29  
30 64 delete $this->{recalc_needed};
31 64 delete $this->{_value};
32  
33 64 my $mean = $this->{m}->query;
34 64 ▶ return unless defined $mean;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mean 0 64 64
35  
36 64 my $v = $this->{v};
37 64 my $cardinality = $v->query_size;
38 64 ▶ $cardinality -- if $Statistics::Basic::UNBIAS;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::UNBIAS 0 64 64
39 64 ▶ return unless $cardinality > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $cardinality > 0 0 64 64
40  
41 64 ▶ if( $Statistics::Basic::DEBUG >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Statistics::Basic::DEBUG >= 2) 0 64 64
42 0 warn "[recalc " . ref($this) . "] ( $_ - $mean ) ** 2\n" for $v->query;
43 }
44  
45 33 ▶ my $sum = 0; { no warnings 'uninitialized'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
46 64 $sum += ( $_ - $mean ) ** 2 for $v->query;
47 }
48  
49 64 $this->{_value} = ($sum / $cardinality);
50  
51 64 ▶ warn "[recalc " . ref($this) . "] ($sum/$cardinality) = $this->{_value}\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 64 64
52  
53 64 return;
54 }
55  
56 1 ▶sub query_mean { return $_[0]->{m} }
Subroutine query_mean: called CC=1 SCAR=0.0
Pod documented
57  
58 33 1;
« Basic/LeastSquareFit.pm ↑ Summary Basic/Vector.pm »