Created
May 24, 2017 20:04
-
-
Save mathurinm/417e77b941e8fe6005d0b19607625678 to your computer and use it in GitHub Desktop.
issue on mixed_norm_solver() MNE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import join as pjoin | |
import numpy as np | |
from numpy.linalg import norm | |
import time | |
import mne | |
from mne.datasets import sample | |
from mne.inverse_sparse.mxne_inverse import (_to_fixed_ori, _prepare_gain) | |
from mne.inverse_sparse.mxne_optim import mixed_norm_solver, norm_l2inf, norm_l21 | |
# from mne.inverse_sparse.mxne_optim import _mixed_norm_solver_cd | |
data_path = sample.data_path() | |
fwd_fname = pjoin(data_path, "MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif") | |
ave_fname = data_path + '/MEG/sample/sample_audvis-ave.fif' | |
cov_fname = data_path + '/MEG/sample/sample_audvis-shrunk-cov.fif' | |
condition = 'Left Auditory' | |
fwd = mne.read_forward_solution(fwd_fname, surf_ori=True) | |
fwd = _to_fixed_ori(fwd) | |
noise_cov = mne.read_cov(cov_fname) | |
evoked = mne.read_evokeds(ave_fname, condition=condition, baseline=(None, 0)) | |
evoked.crop(tmin=0.04, tmax=0.18) | |
evoked = evoked.pick_types(eeg=True, meg=True) | |
loose, depth = 0, 0.8 | |
# apply solver on whitened data | |
gain, gain_info, whitener, source_weighting, mask = _prepare_gain( | |
fwd, evoked.info, noise_cov, pca=False, depth=depth, | |
loose=loose, weights=None, weights_min=None) | |
sel = [evoked.ch_names.index(name) for name in gain_info['ch_names']] | |
M = evoked.data[sel] | |
M = np.dot(whitener, M) | |
alpha_max = norm_l2inf(np.dot(gain.T, M), n_orient=1) | |
alpha = alpha_max / 2. | |
n_alphas = 5 | |
times = np.zeros(n_alphas) | |
tol = 1e-6 | |
for i, alpha_div in enumerate(np.logspace(0.69, 1, n_alphas)): | |
alpha = alpha_max / alpha_div | |
t0 = time.time() | |
X, active_set, E = mixed_norm_solver(M, gain, alpha, | |
solver='cd', | |
debias=False, tol=tol) | |
times[i] = time.time() - t0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment