View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jarkko Hietaniemi > Statistics-DEA-0.04 > Statistics::DEA



Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  


Statistics::DEA - Discontiguous Exponential Averaging


    use Statistics::DEA;

    my $dea = Statistics::DEA->new($alpha, $max_gap);

    while (($data, $time) = some_data_source(...)) {
      $dea->update($data, $time);
      print $dea->average(), "\n";
      print $dea->standard_deviation(), "\n";
      print $dea->completeness($time), "\n";


The Statistics::DEA module can be used to compute exponentially decaying averages and standard deviations even when the data has gaps. The algorithm also avoids initial value bias and postgap bias.


    my $dea = Statistics::DEA->new($alpha, $max_gap);

Creates a new (potentially discontiguous) exponential average object.

The $alpha is the exponential decay of data: from zero (inclusive) to one (exclusive): the lower values cause the effect of data to decay more quickly, the higher values cause the effect of data to decay more slowly . Specifically, weights on older data decay exponentially with a characteristic time of -1/log(alpha) (log being the natural logarithm).

The $max_gap is the maximum time gap after which the data is considered lost. If the time interval between updates is dt, using a $max_gap of N*dt will cause each update to fill in up to N-1 of any preceeding skipped updates with the current data value. Use a $max_gap of dt to prevent such filling.


    $dea->update($data, $time);

Update the average with new data at a particular point in time.

The time parameter is how you can indicate gaps in the data; if you don't have gaps in your data, just monotonously increase it, for example $time++.


    my $avg = $dea->average();

Return the current average.

Functionally equivalent alias avg() is also available.


    my $std_dev = $dea->standard_deviation();

Return the current standard deviation.

Functionally equivalent alias std_dev() is also available.


    my $completeness = $dea->completeness($time);

Return the current completeness: how well based the current average and standard deviation are on actual data. Any time intervals between updates greater than $max_gap reduce this value. A series of updates at time intervals of less than $max_gap will gradually increase this value from its initial, minimum, value of 0 to its maximum value of 1.

The $time should represent the current time. It must be >= the time of the last update.


    my $alpha = $dea->alpha();

Return the current exponential decay of data.


Set the exponential decay of data.


    my $alpha = $dea->max_gap();

Return the current maximum time gap.


Set the maximum time gap.


Jarkko Hietaniemi <>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


The idea and the code are from the September 1998 Doctor Dobb's Journal Algorithm Alley article "Discontiguous Exponential Averaging" by John C. Gunther, used with permission. JCG also provided valuable feedback for the documentation -- and even fixed a bug in the code without knowing Perl as such. This is just a Perlification of the pseudocode in the article, all errors in transcription are solely mine.

syntax highlighting: