#NEWLINE# def csp_base( C_a , C_b ) : #NEWLINE# #INDENT# "\n  Calculate the full common spatial patterns (CSP) transform. \n\n  The CSP transform finds spatial filters that maximize the variance\n  in one condition, and minimize the signal's variance in the other.\n  See [1]. Usually, only a subset of the spatial filters is used.\n\n  Parameters\n  ----------\n  C_a : array-like of shape (n, n)\n    Sensor covariance in condition 1.\n  C_b : array-like of shape (n, n)\n    Sensor covariance in condition 2.\n\n  Returns\n  -------\n  W : array of shape (m, n)\n    A matrix with m spatial filters with decreasing variance in the\n    first condition. The rank of (C_a + C_b) determines the number\n    of filters m.\n\n  See also\n  --------\n  csp : common spatial patterns algorithm.\n  outer_n : pick indices from both sides.\n\n  References\n  ----------\n  [1] Zoltan J. Koles. The quantitative extraction and topographic\n  mapping of the abnormal components in the clinical EEG.\n  Electroencephalography and Clinical Neurophysiology,\n  79(6):440--447, December 1991.\n\n\n  Examples:\n  ---------\n  In condition 1 the signals are positively correlated, in condition 2\n  they are negatively correlated. Their variance stays the same:\n  >>> C_1 = np.ones((2, 2))\n  >>> C_1\n  array([[ 1.,  1.],\n         [ 1.,  1.]])\n\n  >>> C_2 = 2 * np.eye(2) - np.ones((2, 2))\n  >>> C_2\n  array([[ 1., -1.],\n         [-1.,  1.]])\n\n  The most differentiating projection is found with the CSP transform:\n  >>> csp_base(C_1, C_2).round(2)\n  array([[-0.5,  0.5],\n         [ 0.5,  0.5]])\n  " #NEWLINE# P = whitener ( ( C_a + C_b ) ) #NEWLINE# P_C_b = reduce ( np . dot , [ P , C_b , P . T ] ) #NEWLINE# ( _ , _ , B ) = np . linalg . svd ( P_C_b ) #NEWLINE# return np . dot ( B , P . T )