def transform(self, X): """Apply transform to covariances Parameters ---------- covs: list of array list of covariance matrices, shape (n_rois, n_rois) Returns ------- list of array, transformed covariance matrices, shape (n_rois * (n_rois+1)/2,) """ covs = [self.cov_estimator_.fit(x).covariance_ for x in X] covs = spd_mfd.my_stack(covs) if self.kind == 'tangent': covs = [spd_mfd.logm(self.whitening_.dot(c).dot(self.whitening_)) for c in covs] elif self.kind == 'precision': covs = [spd_mfd.inv(g) for g in covs] elif self.kind == 'partial correlation': covs = [prec_to_partial(spd_mfd.inv(g)) for g in covs] elif self.kind == 'correlation': covs = [cov_to_corr(g) for g in covs] else: raise ValueError("Unknown connectivity measure.") return np.array([sym_to_vec(c) for c in covs])
def test_inv(): """Testing inv function""" m = my_mfd.random_spd(41) m_inv = my_mfd.inv(m) assert_array_almost_equal(m.dot(m_inv), np.eye(41))