line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Statistics::Basic::Correlation; |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
138
|
use strict; |
|
33
|
|
|
|
|
42
|
|
|
33
|
|
|
|
|
1075
|
|
5
|
33
|
|
|
33
|
|
139
|
use warnings; |
|
33
|
|
|
|
|
42
|
|
|
33
|
|
|
|
|
817
|
|
6
|
33
|
|
|
33
|
|
145
|
use Carp; |
|
33
|
|
|
|
|
142
|
|
|
33
|
|
|
|
|
2078
|
|
7
|
|
|
|
|
|
|
|
8
|
33
|
|
|
33
|
|
229
|
use base 'Statistics::Basic::_TwoVectorBase'; |
|
33
|
|
|
|
|
52
|
|
|
33
|
|
|
|
|
17964
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# new {{{ |
11
|
|
|
|
|
|
|
sub new { |
12
|
10
|
|
|
10
|
1
|
73097
|
my $this = shift; |
13
|
10
|
|
66
|
|
|
52
|
my @var1 = (shift || ()); |
14
|
10
|
|
66
|
|
|
30
|
my @var2 = (shift || ()); |
15
|
10
|
50
|
|
|
|
18
|
my $v1 = eval { Statistics::Basic::Vector->new( @var1 ) } or croak $@; |
|
10
|
|
|
|
|
47
|
|
16
|
10
|
50
|
|
|
|
19
|
my $v2 = eval { Statistics::Basic::Vector->new( @var2 ) } or croak $@; |
|
10
|
|
|
|
|
31
|
|
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
|
|
35
|
$this = bless {}, $this; |
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
|
|
41
|
my $c = $v1->_get_linked_computer( correlation => $v2 ); |
21
|
10
|
50
|
|
|
|
27
|
return $c if $c; |
22
|
|
|
|
|
|
|
|
23
|
10
|
50
|
|
|
|
14
|
$this->{sd1} = eval { Statistics::Basic::StdDev->new($v1) } or croak $@; |
|
10
|
|
|
|
|
56
|
|
24
|
10
|
50
|
|
|
|
17
|
$this->{sd2} = eval { Statistics::Basic::StdDev->new($v2) } or croak $@; |
|
10
|
|
|
|
|
31
|
|
25
|
10
|
50
|
|
|
|
13
|
$this->{cov} = eval { Statistics::Basic::Covariance->new( $v1, $v2 ) } or croak $@; |
|
10
|
|
|
|
|
58
|
|
26
|
|
|
|
|
|
|
|
27
|
10
|
|
|
|
|
27
|
$this->{_vectors} = [ $v1, $v2 ]; |
28
|
|
|
|
|
|
|
|
29
|
10
|
|
|
|
|
30
|
$v1->_set_linked_computer( correlation => $this, $v2 ); |
30
|
10
|
|
|
|
|
28
|
$v2->_set_linked_computer( correlation => $this, $v1 ); |
31
|
|
|
|
|
|
|
|
32
|
10
|
|
|
|
|
39
|
return $this; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
# }}} |
35
|
|
|
|
|
|
|
# _recalc {{{ |
36
|
|
|
|
|
|
|
sub _recalc { |
37
|
15
|
|
|
15
|
|
27
|
my $this = shift; |
38
|
|
|
|
|
|
|
|
39
|
15
|
|
|
|
|
32
|
delete $this->{recalc_needed}; |
40
|
15
|
|
|
|
|
24
|
delete $this->{_value}; |
41
|
|
|
|
|
|
|
|
42
|
15
|
50
|
|
|
|
67
|
my $c = $this->{cov}->query; return unless defined $c; |
|
15
|
|
|
|
|
30
|
|
43
|
15
|
50
|
|
|
|
63
|
my $s1 = $this->{sd1}->query; return unless defined $s1; |
|
15
|
|
|
|
|
35
|
|
44
|
15
|
50
|
|
|
|
48
|
my $s2 = $this->{sd2}->query; return unless defined $s2; |
|
15
|
|
|
|
|
34
|
|
45
|
|
|
|
|
|
|
|
46
|
15
|
50
|
33
|
|
|
81
|
if( $s1 == 0 or $s2 == 0 ) { |
47
|
0
|
0
|
|
|
|
0
|
warn "[recalc " . ref($this) . "] Standard deviation of 0. Crazy infinite correlation detected.\n" if $Statistics::Basic::DEBUG; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
15
|
|
|
|
|
518
|
$this->{_value} = ( $c / ($s1*$s2) ); |
53
|
|
|
|
|
|
|
|
54
|
15
|
50
|
|
|
|
1662
|
warn "[recalc " . ref($this) . "] ( $c / ($s1*$s2) ) = $this->{_value}\n" if $Statistics::Basic::DEBUG; |
55
|
|
|
|
|
|
|
|
56
|
15
|
|
|
|
|
82
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
# }}} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# query_vector1 {{{ |
61
|
|
|
|
|
|
|
sub query_vector1 { |
62
|
2
|
|
|
2
|
1
|
193
|
my $this = shift; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
12
|
return $this->{cov}->query_vector1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
# }}} |
67
|
|
|
|
|
|
|
# query_vector2 {{{ |
68
|
|
|
|
|
|
|
sub query_vector2 { |
69
|
2
|
|
|
2
|
1
|
7
|
my $this = shift; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
10
|
return $this->{cov}->query_vector2; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
# }}} |
74
|
|
|
|
|
|
|
# query_mean1 {{{ |
75
|
|
|
|
|
|
|
sub query_mean1 { |
76
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $this->{cov}->query_mean1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
# }}} |
81
|
|
|
|
|
|
|
# query_mean2 {{{ |
82
|
|
|
|
|
|
|
sub query_mean2 { |
83
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $this->{cov}->query_mean2; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
# }}} |
88
|
|
|
|
|
|
|
# query_covariance {{{ |
89
|
|
|
|
|
|
|
sub query_covariance { |
90
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $this->{cov}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
# }}} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |