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.oracle.com/cd/E19957-01/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'. 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.
 
_init_internals(self, x)
Init the internal structures.
 
fix(self, center=True)
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.

Inherited from unreachable.newobject: __long__, __native__, __nonzero__, __unicode__, next

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

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)

 
Init the internal 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, center=True)

 

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

If center is false, the returned matrix is the matrix of the second moments, i.e. the covariance matrix of the data without subtracting the mean.

update(self, x)

 

Update internal structures.

Note that no consistency checks are performed on the data (this is typically done in the enclosing node).