def log_lik(subject_cov, group_cov, sigma, whiten=True): if whiten: whitening = spd_manifold.inv_sqrtm(group_cov) subject_cov = np.dot(np.dot(whitening, subject_cov), whitening) group_cov = np.eye(n_rois) return (-n_rois**2 * np.log(sigma) - 1 / (2 * sigma**2) * (np.sum((group_cov - subject_cov)**2) + np.sum(np.diag(group_cov - subject_cov)**2)))
def log_lik(subject_cov, group_cov, sigma, whiten=True): if whiten: whitening = spd_manifold.inv_sqrtm(group_cov) subject_cov = np.dot(np.dot(whitening, subject_cov), whitening) group_cov = np.eye(n_rois) return ( -n_rois**2*np.log(sigma) - 1/(2*sigma**2) * ( np.sum((group_cov - subject_cov)**2) + np.sum(np.diag(group_cov - subject_cov)**2) ))
def fit(self, group_covs): if self.whiten: self.mean_cov = mean_cov = spd_manifold.log_mean(group_covs) whitening = spd_manifold.inv_sqrtm(mean_cov) group_covs = [ np.dot(np.dot(whitening, g), whitening) for g in group_covs ] mean_cov = np.eye(n_rois) else: self.mean_cov = mean_cov = np.mean(group_covs, axis=0) self.sigma = 1. / n_rois * np.sqrt(1. / len(group_covs) * np.sum( np.sum((mean_cov - g)**2) + np.sum(np.diag(mean_cov - g)**2) for g in group_covs)) return self
def fit(self, group_covs): if self.whiten: self.mean_cov = mean_cov = spd_manifold.log_mean(group_covs) whitening = spd_manifold.inv_sqrtm(mean_cov) group_covs = [np.dot(np.dot(whitening, g), whitening) for g in group_covs] mean_cov = np.eye(n_rois) else: self.mean_cov = mean_cov = np.mean(group_covs, axis=0) self.sigma = 1./n_rois* np.sqrt(1./len(group_covs)* np.sum( np.sum((mean_cov - g)**2) + np.sum(np.diag(mean_cov - g)**2) for g in group_covs )) return self