oalg

Collection of online algorithms. Most of them are online versions of their offline counterparts in numpy, but because of their online nature, they are formulated as classes instead of functions.

For further information about online algorithms, please check Wikipedia: http://en.wikipedia.org/wiki/Online_algorithm

Usage is as follows:

  1. In front of an (probably infinite) loop, instantiate the class.
  2. Then, within each iteration, add some data to the class using the method add().
  3. The result of the calculation can be obtained at any point (after the loop has been exited, but also within the loop) by calling the instance as a function.

Most classes accept scalar values as well as n-dimensional arrays, as well as many different data types. Check the documentation of the respective class for further details.

Classes

class oalg.Mean(shape=None, dtype=None, init_value=None, init_var=None, init_count=None)[source]

Online algorithm to compute the sample arithmetic mean (average), plus the corresponding sample variance.

To be specific, the algorithm calculates an estimator for the sample average and an estimator for the sample variance.

After creating an instance of this class, add values to it using the method add. After at least one value has been added, the result can be obtained by calling the instance or the method mean. Sample variance, sample standard deviation and sample standard error can be obtained by calling the methods var, std and stderr.

Working principle:

Besides the sample count N, the class only has to remember two other values (scalar or nd-array):

  1. The sum of all added values, sigma.
  2. The sum of all squared values, sigma2.

With this information, it is easy to calculate the arithmetic mean and the sample variance:

mean = sigma/N

var = 1/(N-1)*sigma2-sigma**2/(N*(N-1))

class oalg.gMean(shape=None, dtype=None, init_value=None, init_var=None, init_count=None)[source]

Online algorithm to compute the sample geometric mean, plus the corresponding variance.

To be specific, the algorithm calculates an estimator for the sample geometric mean and an estimator for the corresponding sample variance.

After creating an instance of this class, add values to it using the method add(). After at least one value has been added, the result can be obtained by calling the instance or the method gmean(). Sample variance, sample standard deviation and sample standard error can be obtained by calling the methods var(), std() and stderr().

Working principle:

Besides the sample count N, the class only has to remember two other values (scalar or nd-array):

  1. The sum of the logarithm of all added values, gamma.
  2. The sum of the squared logarithms of all added values, gamma2.

With this information, the sample geometric mean and the sample variance can be calculated as follows:

mean = exp(gamma/N)

var = exp(2*gamma/N)*(1/(N-1)*gamma2-gamma**2/(N*(N-1)))

Indices and tables

Table Of Contents

This Page