| 1 | |||||||||||
| 2 | package Statistics::Basic::Mean; | ||||||||||
| 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::_OneVectorBase'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 115 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 11 | 115 | my $class = shift; | |||||||||
| 12 | |||||||||||
| 13 | 115 | ▶ | warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | |||||||||||
| 15 | 115 | my $this = bless {}, $class; | |||||||||
| 16 | 115 | ▶ | my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 115 | ▶ | my $c = $vector->_get_computer("mean"); return $c if defined $c; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 76 | $this->{v} = $vector; | |||||||||
| 20 | |||||||||||
| 21 | 76 | $vector->_set_computer( mean => $this ); | |||||||||
| 22 | |||||||||||
| 23 | 76 | return $this; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 107 | ▶ | sub _recalc { | ||||||||
|
Subroutine
_recalc: called CC=5 SCAR=16.1
| |||||||||||
| 27 | 107 | my $this = shift; | |||||||||
| 28 | 107 | my $sum = 0; | |||||||||
| 29 | 107 | my $v = $this->{v}; | |||||||||
| 30 | 107 | my $cardinality = $v->query_size; | |||||||||
| 31 | |||||||||||
| 32 | 107 | delete $this->{recalc_needed}; | |||||||||
| 33 | 107 | delete $this->{_value}; | |||||||||
| 34 | |||||||||||
| 35 | 107 | ▶ | return unless $cardinality > 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 106 | ▶ | return unless $v->query_filled; # only applicable in certain circumstances | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 33 | ▶ | { no warnings 'uninitialized'; ## no critic | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 104 | $sum += $_ for $v->query; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 104 | $this->{_value} = ($sum / $cardinality); | |||||||||
| 43 | |||||||||||
| 44 | 104 | ▶ | warn "[recalc " . ref($this) . "] ($sum/$cardinality) = $this->{_value}\n" if $Statistics::Basic::DEBUG; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 104 | return; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 33 | 1; | |||||||||