Basic/Correlation.pm

filter: Statementstmt 86.2% 50 / 58 Branchbran 45.8% 11 / 24 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 72.7% 8 / 11 Podpod 100% 6 / 6 totaltotal 71.9% 82 / 114 CC 16 SCAR 19.8
CC
16
Cov
73%
_recalc
11.2
new
9.8
query_mean1
2.0
CRAP 7.3
« Basic/Covariance.pm ↑ Summary Basic/LeastSquareFit.pm »
1  
2 package Statistics::Basic::Correlation;
3  
4 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 33 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 33 ▶use base 'Statistics::Basic::_TwoVectorBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # new {{{
11 10 ▶sub new {
Subroutine new: called CC=9 SCAR=22.8
Pod documented
12 10 my $this = shift;
13 10 ▶ my @var1 = (shift || ());
Condition66%2/3
shift() || ()
l!l&&r!l&&!r
802
MC/DC50%1/2
shift() || ()
shift() ()
Truth table66%2/3
A || B
A= shift()B= ()
ABresult
1X1
011
000
14 10 ▶ my @var2 = (shift || ());
Condition66%2/3
shift() || ()
l!l&&r!l&&!r
802
MC/DC50%1/2
shift() || ()
shift() ()
Truth table66%2/3
A || B
A= shift()B= ()
ABresult
1X1
011
000
15 10 ▶ my $v1 = eval { Statistics::Basic::Vector->new( @var1 ) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
my $v1 = eval { do { "Statistics::Basic::Vector"->new(@var1) } } or croak($@) 10 0 10
16 10 ▶ my $v2 = eval { Statistics::Basic::Vector->new( @var2 ) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
my $v2 = eval { do { "Statistics::Basic::Vector"->new(@var2) } } or croak($@) 10 0 10
17  
18 10 $this = bless {}, $this;
19  
20 10 my $c = $v1->_get_linked_computer( correlation => $v2 );
21 10 ▶ return $c if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 0 10 10
22  
23 10 ▶ $this->{sd1} = eval { Statistics::Basic::StdDev->new($v1) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
$this->{"sd1"} = eval { do { "Statistics::Basic::StdDev"->new($v1) } } or croak($@) 10 0 10
24 10 ▶ $this->{sd2} = eval { Statistics::Basic::StdDev->new($v2) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
$this->{"sd2"} = eval { do { "Statistics::Basic::StdDev"->new($v2) } } or croak($@) 10 0 10
25 10 ▶ $this->{cov} = eval { Statistics::Basic::Covariance->new( $v1, $v2 ) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
$this->{"cov"} = eval { do { "Statistics::Basic::Covariance"->new($v1, $v2) } } or croak($@) 10 0 10
26  
27 10 $this->{_vectors} = [ $v1, $v2 ];
28  
29 10 $v1->_set_linked_computer( correlation => $this, $v2 );
30 10 $v2->_set_linked_computer( correlation => $this, $v1 );
31  
32 10 return $this;
33 }
34 # }}}
35 # _recalc {{{
36 15 ▶sub _recalc {
Subroutine _recalc: called CC=8 SCAR=24.1
37 15 my $this = shift;
38  
39 15 delete $this->{recalc_needed};
40 15 delete $this->{_value};
41  
42 15 ▶ my $c = $this->{cov}->query; return unless defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 15 15
43 15 ▶ my $s1 = $this->{sd1}->query; return unless defined $s1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s1 0 15 15
44 15 ▶ my $s2 = $this->{sd2}->query; return unless defined $s2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s2 0 15 15
45  
46 15 ▶ if( $s1 == 0 or $s2 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s1 == 0 or $s2 == 0) 0 15 15
Condition33%1/3
$s1 == 0 or $s2 == 0
l!l&&r!l&&!r
0015
MC/DC0%0/2
$s1 == 0 or $s2 == 0
$s1 == 0 $s2 == 0
Truth table33%1/3
A or B
A= $s1 == 0B= $s2 == 0
ABresult
1X1
011
000
47 0 ▶ warn "[recalc " . ref($this) . "] Standard deviation of 0. Crazy infinite correlation detected.\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 0 0
48  
49 0 return;
50 }
51  
52 15 $this->{_value} = ( $c / ($s1*$s2) );
53  
54 15 ▶ warn "[recalc " . ref($this) . "] ( $c / ($s1*$s2) ) = $this->{_value}\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 15 15
55  
56 15 return 1;
57 }
58 # }}}
59  
60 # query_vector1 {{{
61 2 ▶sub query_vector1 {
Subroutine query_vector1: called CC=1 SCAR=0.0
Pod documented
62 2 my $this = shift;
63  
64 2 return $this->{cov}->query_vector1;
65 }
66 # }}}
67 # query_vector2 {{{
68 2 ▶sub query_vector2 {
Subroutine query_vector2: called CC=1 SCAR=0.0
Pod documented
69 2 my $this = shift;
70  
71 2 return $this->{cov}->query_vector2;
72 }
73 # }}}
74 # query_mean1 {{{
75 0 ▶sub query_mean1 {
Subroutine query_mean1: not called CC=1 SCAR=6.9
Pod documented
76 0 my $this = shift;
77  
78 0 return $this->{cov}->query_mean1;
79 }
80 # }}}
81 # query_mean2 {{{
82 0 ▶sub query_mean2 {
Subroutine query_mean2: not called CC=1 SCAR=6.9
Pod documented
83 0 my $this = shift;
84  
85 0 return $this->{cov}->query_mean2;
86 }
87 # }}}
88 # query_covariance {{{
89 0 ▶sub query_covariance {
Subroutine query_covariance: not called CC=1 SCAR=6.9
Pod documented
90 0 my $this = shift;
91  
92 0 return $this->{cov};
93 }
94 # }}}
95  
96 33 1;
« Basic/Covariance.pm ↑ Summary Basic/LeastSquareFit.pm »