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

Class VartimeCovarianceMatrix


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.

As compared to the CovarianceMatrix class, this class accepts sampled input in conjunction with a non-constant time increment between samples. The covariance matrix is then computed as a (centered) scalar product between functions, that is sampled unevenly, using the trapezoid rule.

The mean is computed using the trapezoid rule as well.

Note that the internal sum is a standard __add__ operation.

Instance Methods [hide private]
 
__init__(self, dtype=None)
Initialize a VartimeCovarianceMatrix.
 
fix(self, center=True)
Returns a triple containing the generalized covariance matrix, the average and length of the sequence (in time/summed increments).
 
update(self, x, dt=None, time_dep=True)
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__

    Inherited from CovarianceMatrix
 
_init_internals(self, x)
Init the internal structures.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, dtype=None)
(Constructor)

 
Initialize a VartimeCovarianceMatrix.
Parameters:
  • dtype (numpy.dtype or str) - Datatype of the input. Default is None. If dtype is not defined, it will be inherited from the first data bunch received by 'update'.
Overrides: object.__init__

fix(self, center=True)

 

Returns a triple containing the generalized covariance matrix, the average and length of the sequence (in time/summed increments).

The covariance matrix is then reset to a zero-state.

of sequence (in time/summed increments). :rtype: Tuple[np.ndarray, np.ndarray, np.ndarray]

Parameters:
  • center (bool) - 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.
Returns:
Generalized covariance matrix, average and length
Overrides: CovarianceMatrix.fix

update(self, x, dt=None, time_dep=True)

 

Update internal structures.

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

Parameters:
  • x (numpy.ndarray) - Timed sequence of vectors, with samples along the rows and random variables along the columns.
  • dt (numpy.ndarray or numeric) - Sequence of time increments between vectors.

    Usage with only single chunk of data:
    dt should be of length x.shape[0]-1 or a constant. When constant, the time increments are assumed to be constant. If dt is not supplied, a constant time increment of one is assumed. If a time sequence of length x.shape[0] is supplied the first element is disregarded and a warning is presented.
    Usage with multiple chunks of data with intended time dependence:
    dt should have length x.shape[0]-1 in the first call and be of length x.shape[0] starting with the second call. Starting with the second call, the first element in each chunk will be considered the time difference between the last element of x in the previous chunk and the first element of x of the current chunk. The time_dep argument being True indicates this mode.
    Usage with multiple chunks without time dependence:
    The moments are computed as a weighted average of the moments of separate chunks, if dt continues to have length x.shape[0]-1 after the first call. Time dependence between chunks is thus omitted and all algorithmic components regard only the time structure within chunks. The time_dep argument being False indicates this mode. As in the single chunk case it is possible to set dt to be a constant or omit it completely for constant or unit time increments within chunks respectively.
  • time_dep (bool) - Indicates whether time dependence between chunks can be considered. The argument is only relevant if multiple chunks of data are used. Time dependence between chunks is disregarded when data collection has been done time-independently and thus no reasonable time increment between the end of a chunk and beginning of the next can be specified.
Overrides: CovarianceMatrix.update