line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Statistics::Basic::Correlation; |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
148
|
use strict; |
|
33
|
|
|
|
|
55
|
|
|
33
|
|
|
|
|
1256
|
|
5
|
33
|
|
|
33
|
|
142
|
use warnings; |
|
33
|
|
|
|
|
43
|
|
|
33
|
|
|
|
|
755
|
|
6
|
33
|
|
|
33
|
|
151
|
use Carp; |
|
33
|
|
|
|
|
367
|
|
|
33
|
|
|
|
|
2321
|
|
7
|
|
|
|
|
|
|
|
8
|
33
|
|
|
33
|
|
238
|
use base 'Statistics::Basic::_TwoVectorBase'; |
|
33
|
|
|
|
|
61
|
|
|
33
|
|
|
|
|
22520
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# new {{{ |
11
|
|
|
|
|
|
|
sub new { |
12
|
10
|
|
|
10
|
1
|
48174
|
my $this = shift; |
13
|
10
|
|
66
|
|
|
54
|
my @var1 = (shift || ()); |
14
|
10
|
|
66
|
|
|
33
|
my @var2 = (shift || ()); |
15
|
10
|
50
|
|
|
|
19
|
my $v1 = eval { Statistics::Basic::Vector->new( @var1 ) } or croak $@; |
|
10
|
|
|
|
|
49
|
|
16
|
10
|
50
|
|
|
|
17
|
my $v2 = eval { Statistics::Basic::Vector->new( @var2 ) } or croak $@; |
|
10
|
|
|
|
|
36
|
|
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
|
|
30
|
$this = bless {}, $this; |
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
|
|
42
|
my $c = $v1->_get_linked_computer( correlation => $v2 ); |
21
|
10
|
50
|
|
|
|
32
|
return $c if $c; |
22
|
|
|
|
|
|
|
|
23
|
10
|
50
|
|
|
|
9
|
$this->{sd1} = eval { Statistics::Basic::StdDev->new($v1) } or croak $@; |
|
10
|
|
|
|
|
59
|
|
24
|
10
|
50
|
|
|
|
24
|
$this->{sd2} = eval { Statistics::Basic::StdDev->new($v2) } or croak $@; |
|
10
|
|
|
|
|
42
|
|
25
|
10
|
50
|
|
|
|
18
|
$this->{cov} = eval { Statistics::Basic::Covariance->new( $v1, $v2 ) } or croak $@; |
|
10
|
|
|
|
|
122
|
|
26
|
|
|
|
|
|
|
|
27
|
10
|
|
|
|
|
29
|
$this->{_vectors} = [ $v1, $v2 ]; |
28
|
|
|
|
|
|
|
|
29
|
10
|
|
|
|
|
31
|
$v1->_set_linked_computer( correlation => $this, $v2 ); |
30
|
10
|
|
|
|
|
35
|
$v2->_set_linked_computer( correlation => $this, $v1 ); |
31
|
|
|
|
|
|
|
|
32
|
10
|
|
|
|
|
42
|
return $this; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
# }}} |
35
|
|
|
|
|
|
|
# _recalc {{{ |
36
|
|
|
|
|
|
|
sub _recalc { |
37
|
15
|
|
|
15
|
|
20
|
my $this = shift; |
38
|
|
|
|
|
|
|
|
39
|
15
|
|
|
|
|
34
|
delete $this->{recalc_needed}; |
40
|
15
|
|
|
|
|
23
|
delete $this->{_value}; |
41
|
|
|
|
|
|
|
|
42
|
15
|
50
|
|
|
|
68
|
my $c = $this->{cov}->query; return unless defined $c; |
|
15
|
|
|
|
|
35
|
|
43
|
15
|
50
|
|
|
|
76
|
my $s1 = $this->{sd1}->query; return unless defined $s1; |
|
15
|
|
|
|
|
37
|
|
44
|
15
|
50
|
|
|
|
45
|
my $s2 = $this->{sd2}->query; return unless defined $s2; |
|
15
|
|
|
|
|
47
|
|
45
|
|
|
|
|
|
|
|
46
|
15
|
50
|
33
|
|
|
85
|
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
|
|
|
|
|
550
|
$this->{_value} = ( $c / ($s1*$s2) ); |
53
|
|
|
|
|
|
|
|
54
|
15
|
50
|
|
|
|
1705
|
warn "[recalc " . ref($this) . "] ( $c / ($s1*$s2) ) = $this->{_value}\n" if $Statistics::Basic::DEBUG; |
55
|
|
|
|
|
|
|
|
56
|
15
|
|
|
|
|
32
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
# }}} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# query_vector1 {{{ |
61
|
|
|
|
|
|
|
sub query_vector1 { |
62
|
2
|
|
|
2
|
1
|
39
|
my $this = shift; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
10
|
return $this->{cov}->query_vector1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
# }}} |
67
|
|
|
|
|
|
|
# query_vector2 {{{ |
68
|
|
|
|
|
|
|
sub query_vector2 { |
69
|
2
|
|
|
2
|
1
|
8
|
my $this = shift; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
9
|
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; |