line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::Basic::Variance; |
2
|
|
|
|
|
|
|
|
3
|
33
|
|
|
33
|
|
140
|
use strict; |
|
33
|
|
|
|
|
45
|
|
|
33
|
|
|
|
|
1272
|
|
4
|
33
|
|
|
33
|
|
137
|
use warnings; |
|
33
|
|
|
|
|
41
|
|
|
33
|
|
|
|
|
724
|
|
5
|
33
|
|
|
33
|
|
122
|
use Carp; |
|
33
|
|
|
|
|
38
|
|
|
33
|
|
|
|
|
2435
|
|
6
|
|
|
|
|
|
|
|
7
|
33
|
|
|
33
|
|
168
|
use base 'Statistics::Basic::_OneVectorBase'; |
|
33
|
|
|
|
|
36
|
|
|
33
|
|
|
|
|
11501
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
45
|
|
|
45
|
1
|
1168
|
my $class = shift; |
11
|
|
|
|
|
|
|
|
12
|
45
|
50
|
|
|
|
103
|
warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2; |
13
|
|
|
|
|
|
|
|
14
|
45
|
|
|
|
|
107
|
my $this = bless {}, $class; |
15
|
45
|
50
|
|
|
|
52
|
my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@; |
|
45
|
|
|
|
|
231
|
|
16
|
45
|
100
|
|
|
|
139
|
my $c = $vector->_get_computer("variance"); return $c if defined $c; |
|
45
|
|
|
|
|
169
|
|
17
|
|
|
|
|
|
|
|
18
|
44
|
|
|
|
|
902
|
$this->{v} = $vector; |
19
|
44
|
50
|
|
|
|
71
|
$this->{m} = eval { Statistics::Basic::Mean->new($vector) } or croak $@; |
|
44
|
|
|
|
|
242
|
|
20
|
|
|
|
|
|
|
|
21
|
44
|
|
|
|
|
115
|
$vector->_set_computer( variance => $this ); |
22
|
|
|
|
|
|
|
|
23
|
44
|
|
|
|
|
781
|
return $this; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _recalc { |
27
|
64
|
|
|
64
|
|
76
|
my $this = shift; |
28
|
64
|
|
|
|
|
87
|
my $first = shift; |
29
|
|
|
|
|
|
|
|
30
|
64
|
|
|
|
|
99
|
delete $this->{recalc_needed}; |
31
|
64
|
|
|
|
|
88
|
delete $this->{_value}; |
32
|
|
|
|
|
|
|
|
33
|
64
|
|
|
|
|
188
|
my $mean = $this->{m}->query; |
34
|
64
|
50
|
|
|
|
152
|
return unless defined $mean; |
35
|
|
|
|
|
|
|
|
36
|
64
|
|
|
|
|
97
|
my $v = $this->{v}; |
37
|
64
|
|
|
|
|
162
|
my $cardinality = $v->query_size; |
38
|
64
|
50
|
|
|
|
144
|
$cardinality -- if $Statistics::Basic::UNBIAS; |
39
|
64
|
50
|
|
|
|
141
|
return unless $cardinality > 0; |
40
|
|
|
|
|
|
|
|
41
|
64
|
50
|
|
|
|
126
|
if( $Statistics::Basic::DEBUG >= 2 ) { |
42
|
0
|
|
|
|
|
0
|
warn "[recalc " . ref($this) . "] ( $_ - $mean ) ** 2\n" for $v->query; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
33
|
|
|
33
|
|
259
|
my $sum = 0; { no warnings 'uninitialized'; ## no critic |
|
33
|
|
|
|
|
38
|
|
|
33
|
|
|
|
|
4779
|
|
|
64
|
|
|
|
|
70
|
|
|
64
|
|
|
|
|
115
|
|
46
|
64
|
|
|
|
|
145
|
$sum += ( $_ - $mean ) ** 2 for $v->query; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
64
|
|
|
|
|
23832
|
$this->{_value} = ($sum / $cardinality); |
50
|
|
|
|
|
|
|
|
51
|
64
|
50
|
|
|
|
2112
|
warn "[recalc " . ref($this) . "] ($sum/$cardinality) = $this->{_value}\n" if $Statistics::Basic::DEBUG; |
52
|
|
|
|
|
|
|
|
53
|
64
|
|
|
|
|
134
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
1
|
1
|
4
|
sub query_mean { return $_[0]->{m} } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |