Package mdp :: Package utils :: Class CovarianceMatrix
[hide private]
[frames] | no frames]

Class CovarianceMatrix


This class stores an empirical covariance matrix that can be updated
incrementally. A call to the 'fix' method returns the current state of
the covariance matrix, the average and the number of observations, and
resets the internal data.

Note that the internal sum is a standard __add__ operation. We are not
using any of the fancy sum algorithms to avoid round off errors when
adding many numbers. If you want to contribute a CovarianceMatrix class
that uses such algorithms we would be happy to include it in MDP.
For a start see the Python recipe by Raymond Hettinger at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090
For a review about floating point arithmetic and its pitfalls see
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Instance Methods [hide private]
 
__init__(self, dtype=None, bias=False)
If dtype is not defined, it will be inherited from the first data bunch received by 'update'.
 
_init_internals(self, x)
Inits some internals structures.
 
fix(self)
Returns a triple containing the covariance matrix, the average and the number of observations.
 
update(self, x)
Update internal structures.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, dtype=None, bias=False)
(Constructor)

 
If dtype is not defined, it will be inherited from the first
data bunch received by 'update'.
All the matrices in this class are set up with the given dtype and
no upcast is possible.
If bias is True, the covariance matrix is normalized by dividing
by T instead of the usual T-1.

Overrides: object.__init__

_init_internals(self, x)

 
Inits some internals structures. The reason this is not done in
the constructor is that we want to be able to derive the input
dimension and the dtype directly from the data this class receives.

fix(self)

 
Returns a triple containing the covariance matrix, the average and
the number of observations. The covariance matrix is then reset to
a zero-state.

update(self, x)

 
Update internal structures.