Statistics-Welford-0.02/0000755000175000001440000000000011333021302014153 5ustar kaareusersStatistics-Welford-0.02/META.yml0000444000175000001440000000073611333021302015430 0ustar kaareusers--- abstract: "Standard statistics using Welford's algorithm" author: - 'Kaare Rasmussen .' configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3603' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Statistics-Welford provides: Statistics::Welford: file: lib/Statistics/Welford.pm version: 0.02 resources: license: http://dev.perl.org/licenses/ version: 0.02 Statistics-Welford-0.02/lib/0000755000175000001440000000000011333021302014721 5ustar kaareusersStatistics-Welford-0.02/lib/Statistics/0000755000175000001440000000000011333021302017053 5ustar kaareusersStatistics-Welford-0.02/lib/Statistics/Welford.pm0000444000175000001440000000431211333021302021011 0ustar kaareuserspackage Statistics::Welford; =pod =head1 NAME Statistics::Welford - Standard statistics using Welford's algorithm =head1 SYNOPSIS my $stat = Statistics::Welford->new; while (1) { $stat->add(rand); ... } print $stat->mean; =head1 DESCRIPTION Standard statistics using Welford's algorithm =head1 METHODS =cut use strict; use warnings; our $VERSION = '0.02'; =pod =head2 new my $stat = Statistics::Welford->new; The C constructor lets you create a new B object. =cut sub new { my $class = shift; my $self = bless { @_ }, $class; $self->{n} = 0; return $self; } =pod =head2 add Add an entry to the statistics base =cut sub add { my ($self, $x) = @_; $self->{n}++; if ($self->{n} == 1) { $self->{old_m} = $x; $self->{new_m} = $x; $self->{min} = $x; $self->{max} = $x; $self->{old_s} = 0.0; return $self; } $self->{new_m} = $self->{old_m} + ($x - $self->{old_m})/$self->{n}; $self->{new_s} = $self->{old_s} + ($x - $self->{old_m})*($x - $self->{new_m}); $self->{min} = $x if $x < $self->{min}; $self->{max} = $x if $x > $self->{max}; # set up for next iteration $self->{old_m} = $self->{new_m}; $self->{old_s} = $self->{new_s}; return $self; } =head2 n Returns the number of entries to the statistics base =cut sub n { my $self = shift; return $self->{n}; } =head2 min Returns the minimum number in the statistics base =cut sub min { my $self = shift; return $self->{min}; } =head2 max Returns the maximum number in the statistics base =cut sub max { my $self = shift; return $self->{max}; } =head2 mean Returns the mean value =cut sub mean { my $self = shift; return $self->{n} > 0 ? $self->{new_m} : 0.0; } =head2 variance Returns the variance value =cut sub variance { my $self = shift; return $self->{n} > 1 ? $self->{new_s}/($self->{n} - 1) : 0.0; } =head2 standard_deviation Returns the standard deviation value =cut sub standard_deviation { my $self = shift; return sqrt( $self->variance ); } 1; =pod =head1 AUTHOR Kaare Rasmussen . =head1 COPYRIGHT Copyright (C) 2010, Kaare Rasmussen This module is free software; you can redistribute it or modify it under the same terms as Perl itself. =cut Statistics-Welford-0.02/Changes0000444000175000001440000000012611333021302015443 0ustar kaareusers0.02 2010-02-05 - Make tests work with 5.10.1 0.01 2010-01-06 - original version Statistics-Welford-0.02/Makefile.PL0000444000175000001440000000053611333021302016127 0ustar kaareusers# Note: this file was auto-generated by Module::Build::Compat version 0.3603 use ExtUtils::MakeMaker; WriteMakefile ( 'PL_FILES' => {}, 'INSTALLDIRS' => 'site', 'NAME' => 'Statistics::Welford', 'EXE_FILES' => [], 'VERSION_FROM' => 'lib/Statistics/Welford.pm', 'PREREQ_PM' => {} ) ; Statistics-Welford-0.02/MANIFEST0000444000175000001440000000020511333021302015277 0ustar kaareusersBuild.PL Changes lib/Statistics/Welford.pm MANIFEST This list of files t/functions.t t/pod.t t/pod_coverage.t Makefile.PL META.yml Statistics-Welford-0.02/t/0000755000175000001440000000000011333021302014416 5ustar kaareusersStatistics-Welford-0.02/t/pod.t0000444000175000001440000000025011333021302015360 0ustar kaareusers#!perl -T use strict; use warnings; use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Statistics-Welford-0.02/t/pod_coverage.t0000444000175000001440000000036211333021302017237 0ustar kaareusers#!perl -T use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok( { also_private => [ qw/id subscribe/ ], } ); Statistics-Welford-0.02/t/functions.t0000444000175000001440000000107511333021302016614 0ustar kaareusersuse strict; use warnings; use Test::More tests => 18; use_ok 'Statistics::Welford'; ok( my $stat = Statistics::Welford->new, 'New object' ); ok( $stat->add($_), 'Add data' ) for (1..10); is( $stat->n, 10, 'Check if n is correct' ); is( $stat->min, 1, 'Check if min is correct' ); is( $stat->max, 10, 'Check if max is correct' ); is( $stat->mean, 5.5, 'Check if mean is correct' ); is( substr($stat->variance,0,15), 9.1666666666666, 'Check if variance is correct' ); is( substr($stat->standard_deviation,0,15), 3.0276503540974, 'Check if standard_deviation is correct' ); Statistics-Welford-0.02/Build.PL0000444000175000001440000000040011333021302015437 0ustar kaareusers#!perl use Module::Build; my $build = Module::Build->new( dist_version_from => 'lib/Statistics/Welford.pm', module_name => 'Statistics::Welford', license => 'perl', create_makefile_pl => 'traditional', ); $build->create_build_script;