pyntbci.utilities.covariance

pyntbci.utilities.covariance(X: ndarray[Any, dtype[_ScalarType_co]], n_old: int = 0, avg_old: ndarray[Any, dtype[_ScalarType_co]] | None = None, cov_old: ndarray[Any, dtype[_ScalarType_co]] | None = None, estimator: BaseEstimator | None = None, running: bool = False) tuple[int, ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]]][source]

Compute the covariance matrix.

Parameters:
  • X (NDArray) – Data matrix of shape (n_samples, n_features).

  • n_old (int (default: 0)) – Number of already observed samples.

  • avg_old (NDArray (default: None)) – Already observed average of shape (n_features).

  • cov_old (NDArray (default: None)) – Already observed covariance of shape (n_features, n_features).

  • estimator (BaseEstimator (default: None)) – An object that estimates a covariance matrix using a fit method. If None, a custom implementation of the empirical covariance is used.

  • running (bool (default: False)) – Whether to use a running covariance. If False, the covariance matrix is computed instantaneously using only X, such that n_old, avg_old, and cov_old are not used.

Returns:

  • n_new (int) – Number of samples.

  • avg_new (NDArray) – The average of shape (1, n_features).

  • cov_new (NDArray) – The covariance of shape (n_features, n_features).