| Server IP : 118.27.122.120 / Your IP : 216.73.216.136 Web Server : Apache System : Linux web0216.sh.tyo1 4.18.0-553.141.2.lve.el7h.x86_64 #1 SMP Wed Jul 8 17:20:31 UTC 2026 x86_64 User : r4834334 ( 11094) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/proc/thread-self/root/usr/share/perl5/Statistics/Basic/ |
Upload File : |
package Statistics::Basic::Variance;
use strict;
use warnings;
use Carp;
use base 'Statistics::Basic::_OneVectorBase';
sub new {
my $class = shift;
warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2;
my $this = bless {}, $class;
my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@;
my $c = $vector->_get_computer("variance"); return $c if defined $c;
$this->{v} = $vector;
$this->{m} = eval { Statistics::Basic::Mean->new($vector) } or croak $@;
$vector->_set_computer( variance => $this );
return $this;
}
sub _recalc {
my $this = shift;
my $first = shift;
delete $this->{recalc_needed};
delete $this->{_value};
my $mean = $this->{m}->query;
return unless defined $mean;
my $v = $this->{v};
my $cardinality = $v->query_size;
$cardinality -- if $Statistics::Basic::UNBIAS;
return unless $cardinality > 0;
if( $Statistics::Basic::DEBUG >= 2 ) {
warn "[recalc " . ref($this) . "] ( $_ - $mean ) ** 2\n" for $v->query;
}
my $sum = 0; { no warnings 'uninitialized'; ## no critic
$sum += ( $_ - $mean ) ** 2 for $v->query;
}
$this->{_value} = ($sum / $cardinality);
warn "[recalc " . ref($this) . "] ($sum/$cardinality) = $this->{_value}\n" if $Statistics::Basic::DEBUG;
return;
}
sub query_mean { return $_[0]->{m} }
1;