line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::Basic::Variance; |
2
|
|
|
|
|
|
|
|
3
|
33
|
|
|
33
|
|
137
|
use strict; |
|
33
|
|
|
|
|
40
|
|
|
33
|
|
|
|
|
1040
|
|
4
|
33
|
|
|
33
|
|
125
|
use warnings; |
|
33
|
|
|
|
|
38
|
|
|
33
|
|
|
|
|
681
|
|
5
|
33
|
|
|
33
|
|
133
|
use Carp; |
|
33
|
|
|
|
|
33
|
|
|
33
|
|
|
|
|
2141
|
|
6
|
|
|
|
|
|
|
|
7
|
33
|
|
|
33
|
|
153
|
use base 'Statistics::Basic::_OneVectorBase'; |
|
33
|
|
|
|
|
40
|
|
|
33
|
|
|
|
|
10318
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
45
|
|
|
45
|
1
|
1245
|
my $class = shift; |
11
|
|
|
|
|
|
|
|
12
|
45
|
50
|
|
|
|
106
|
warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2; |
13
|
|
|
|
|
|
|
|
14
|
45
|
|
|
|
|
92
|
my $this = bless {}, $class; |
15
|
45
|
50
|
|
|
|
62
|
my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@; |
|
45
|
|
|
|
|
233
|
|
16
|
45
|
100
|
|
|
|
128
|
my $c = $vector->_get_computer("variance"); return $c if defined $c; |
|
45
|
|
|
|
|
158
|
|
17
|
|
|
|
|
|
|
|
18
|
44
|
|
|
|
|
928
|
$this->{v} = $vector; |
19
|
44
|
50
|
|
|
|
44
|
$this->{m} = eval { Statistics::Basic::Mean->new($vector) } or croak $@; |
|
44
|
|
|
|
|
163
|
|
20
|
|
|
|
|
|
|
|
21
|
44
|
|
|
|
|
101
|
$vector->_set_computer( variance => $this ); |
22
|
|
|
|
|
|
|
|
23
|
44
|
|
|
|
|
797
|
return $this; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _recalc { |
27
|
64
|
|
|
64
|
|
67
|
my $this = shift; |
28
|
64
|
|
|
|
|
62
|
my $first = shift; |
29
|
|
|
|
|
|
|
|
30
|
64
|
|
|
|
|
94
|
delete $this->{recalc_needed}; |
31
|
64
|
|
|
|
|
78
|
delete $this->{_value}; |
32
|
|
|
|
|
|
|
|
33
|
64
|
|
|
|
|
184
|
my $mean = $this->{m}->query; |
34
|
64
|
50
|
|
|
|
126
|
return unless defined $mean; |
35
|
|
|
|
|
|
|
|
36
|
64
|
|
|
|
|
87
|
my $v = $this->{v}; |
37
|
64
|
|
|
|
|
141
|
my $cardinality = $v->query_size; |
38
|
64
|
50
|
|
|
|
130
|
$cardinality -- if $Statistics::Basic::UNBIAS; |
39
|
64
|
50
|
|
|
|
129
|
return unless $cardinality > 0; |
40
|
|
|
|
|
|
|
|
41
|
64
|
50
|
|
|
|
118
|
if( $Statistics::Basic::DEBUG >= 2 ) { |
42
|
0
|
|
|
|
|
0
|
warn "[recalc " . ref($this) . "] ( $_ - $mean ) ** 2\n" for $v->query; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
33
|
|
|
33
|
|
164
|
my $sum = 0; { no warnings 'uninitialized'; ## no critic |
|
33
|
|
|
|
|
37
|
|
|
33
|
|
|
|
|
4108
|
|
|
64
|
|
|
|
|
72
|
|
|
64
|
|
|
|
|
55
|
|
46
|
64
|
|
|
|
|
134
|
$sum += ( $_ - $mean ) ** 2 for $v->query; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
64
|
|
|
|
|
23149
|
$this->{_value} = ($sum / $cardinality); |
50
|
|
|
|
|
|
|
|
51
|
64
|
50
|
|
|
|
1958
|
warn "[recalc " . ref($this) . "] ($sum/$cardinality) = $this->{_value}\n" if $Statistics::Basic::DEBUG; |
52
|
|
|
|
|
|
|
|
53
|
64
|
|
|
|
|
140
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
1
|
1
|
4
|
sub query_mean { return $_[0]->{m} } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |