Compute sparse inverse solution with mixed norm: MxNE and irMxNE

Runs (ir)MxNE (L1/L2 [1] or L0.5/L2 [2] mixed norm) inverse solver. L0.5/L2 is done with irMxNE which allows for sparser source estimates with less amplitude bias due to the non-convexity of the L0.5/L2 mixed norm penalty.

References

[1]Gramfort A., Kowalski M. and Hamalainen, M. “Mixed-norm estimates for the M/EEG inverse problem using accelerated gradient methods”, Physics in Medicine and Biology, 2012. https://doi.org/10.1088/0031-9155/57/7/1937.
[2]Strohmeier D., Haueisen J., and Gramfort A. “Improved MEG/EEG source localization with reweighted mixed-norms”, 4th International Workshop on Pattern Recognition in Neuroimaging, Tuebingen, 2014. 10.1109/PRNI.2014.6858545
# Author: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
#
# License: BSD (3-clause)

import mne
from mne.datasets import sample
from mne.inverse_sparse import mixed_norm
from mne.minimum_norm import make_inverse_operator, apply_inverse
from mne.viz import plot_sparse_source_estimates

print(__doc__)

data_path = sample.data_path()
fwd_fname = 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'
subjects_dir = data_path + '/subjects'

# Read noise covariance matrix
cov = mne.read_cov(cov_fname)
# Handling average file
condition = 'Left Auditory'
evoked = mne.read_evokeds(ave_fname, condition=condition, baseline=(None, 0))
evoked.crop(tmin=0, tmax=0.3)
# Handling forward solution
forward = mne.read_forward_solution(fwd_fname, surf_ori=True)

ylim = dict(eeg=[-10, 10], grad=[-400, 400], mag=[-600, 600])
evoked.plot(ylim=ylim, proj=True)
../../_images/sphx_glr_plot_mixed_norm_inverse_001.png

Out:

365 x 365 full covariance (kind = 1) found.
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 59) active
Reading /home/ubuntu/mne_data/MNE-sample-data/MEG/sample/sample_audvis-ave.fif ...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Found the data of interest:
        t =    -199.80 ...     499.49 ms (Left Auditory)
        0 CTF compensation matrices available
        nave = 55 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
Applying baseline correction (mode: mean)
Reading forward solution from /home/ubuntu/mne_data/MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif...
    Reading a source space...
    Computing patch statistics...
    Patch information added...
    Distance information added...
    [done]
    Reading a source space...
    Computing patch statistics...
    Patch information added...
    Distance information added...
    [done]
    2 source spaces read
    Desired named matrix (kind = 3523) not available
    Read MEG forward solution (7498 sources, 306 channels, free orientations)
    Desired named matrix (kind = 3523) not available
    Read EEG forward solution (7498 sources, 60 channels, free orientations)
    MEG and EEG forward solutions combined
    Source spaces transformed to the forward solution coordinate frame
    Converting to surface-based source orientations...
    Average patch normals will be employed in the rotation to the local surface coordinates....
[done]

Run solver

alpha = 50  # regularization parameter between 0 and 100 (100 is high)
loose, depth = 0.2, 0.9  # loose orientation & depth weighting
n_mxne_iter = 10  # if > 1 use L0.5/L2 reweighted mixed norm solver
# if n_mxne_iter > 1 dSPM weighting can be avoided.

# Compute dSPM solution to be used as weights in MxNE
inverse_operator = make_inverse_operator(evoked.info, forward, cov,
                                         loose=None, depth=depth, fixed=True)
stc_dspm = apply_inverse(evoked, inverse_operator, lambda2=1. / 9.,
                         method='dSPM')

# Compute (ir)MxNE inverse solution
stc, residual = mixed_norm(
    evoked, forward, cov, alpha, loose=loose, depth=depth, maxit=3000,
    tol=1e-4, active_set_size=10, debias=True, weights=stc_dspm,
    weights_min=8., n_mxne_iter=n_mxne_iter, return_residual=True)
residual.plot(ylim=ylim, proj=True)
../../_images/sphx_glr_plot_mixed_norm_inverse_002.png

Out:

info["bads"] and noise_cov["bads"] do not match, excluding bad channels from both
Computing inverse operator with 364 channels.
    Created an SSP operator (subspace dimension = 4)
estimated rank (mag + grad): 302
Setting small MEG eigenvalues to zero.
Not doing PCA for MEG.
estimated rank (eeg): 58
Setting small EEG eigenvalues to zero.
Not doing PCA for EEG.
Total rank is 360
Creating the depth weighting matrix...
    203 planar channels
    limit = 7262/7498 = 10.020865
    scale = 2.58122e-08 exp = 0.9
    Picked elements from a free-orientation depth-weighting prior into the fixed-orientation one
    Changing to fixed-orientation forward solution with surface-based source orientations...
    [done]
Computing inverse operator with 364 channels.
Creating the source covariance matrix
Whitening the forward solution.
Adjusting source covariance matrix.
Computing SVD of whitened and weighted lead field matrix.
    largest singular value = 6.01803
    scaling factor to adjust the trace = 6.9571e+18
Preparing the inverse operator for use...
    Scaled noise and source covariance from nave = 1 to nave = 55
    Created the regularized inverter
    Created an SSP operator (subspace dimension = 4)
    Created the whitener using a full noise covariance matrix (4 small eigenvalues omitted)
    Computing noise-normalization factors (dSPM)...
[done]
Picked 364 channels from the data
Computing inverse...
(eigenleads need to be weighted)...
(dSPM)...
[done]
info["bads"] and noise_cov["bads"] do not match, excluding bad channels from both
Computing inverse operator with 364 channels.
    Created an SSP operator (subspace dimension = 4)
estimated rank (mag + grad): 302
Setting small MEG eigenvalues to zero.
Not doing PCA for MEG.
estimated rank (eeg): 58
Setting small EEG eigenvalues to zero.
Not doing PCA for EEG.
Reducing data rank to 360
Total rank is 360
Whitening lead field matrix.
Applying loose dipole orientations. Loose value of 0.2.
Reducing source space to 551 sources
Whitening data matrix.
-- ALPHA MAX : 100.0
Using block coordinate descent
Iteration 1 :: pobj 1915.138768 :: dgap 0.000092 ::n_active_start 10 :: n_active_end 3
Convergence reached ! (gap: 9.23375971524e-05 < 0.0001)
Final active set size: 3
active set size 3
-- ALPHA MAX : 255.133190485
Using block coordinate descent
Final active set size: 3
active set size 3
-- ALPHA MAX : 382.101398865
Using block coordinate descent
Final active set size: 3
active set size 3
-- ALPHA MAX : 408.517323975
Using block coordinate descent
Final active set size: 2
active set size 2
-- ALPHA MAX : 412.903113891
Using block coordinate descent
Final active set size: 2
active set size 2
-- ALPHA MAX : 413.780470677
Using block coordinate descent
Final active set size: 2
active set size 2
-- ALPHA MAX : 413.912974792
Using block coordinate descent
Final active set size: 2
active set size 2
-- ALPHA MAX : 413.930992334
Using block coordinate descent
Final active set size: 2
active set size 2
Convergence reached after 7 reweightings!
Debiasing converged after 72 iterations max(|D - D0| = 3.142884e-07 < 1.000000e-06)
combining the current components...
4 projection items deactivated
Created an SSP operator (subspace dimension = 4)
4 projection items activated
SSP projectors applied...
0 projection items deactivated
[done]

View in 2D and 3D (“glass” brain like 3D plot)

plot_sparse_source_estimates(forward['src'], stc, bgcolor=(1, 1, 1),
                             fig_name="MxNE (cond %s)" % condition,
                             opacity=0.1)

# and on the fsaverage brain after morphing
stc_fsaverage = stc.morph(subject_from='sample', subject_to='fsaverage',
                          grade=None, sparse=True, subjects_dir=subjects_dir)
src_fsaverage_fname = subjects_dir + '/fsaverage/bem/fsaverage-ico-5-src.fif'
src_fsaverage = mne.read_source_spaces(src_fsaverage_fname)

plot_sparse_source_estimates(src_fsaverage, stc_fsaverage, bgcolor=(1, 1, 1),
                             opacity=0.1)
  • ../../_images/sphx_glr_plot_mixed_norm_inverse_003.png
  • ../../_images/sphx_glr_plot_mixed_norm_inverse_004.png
  • ../../_images/sphx_glr_plot_mixed_norm_inverse_005.png
  • ../../_images/sphx_glr_plot_mixed_norm_inverse_006.png

Out:

Total number of active sources: 2
    Left-hemisphere map read.
    Right-hemisphere map read.
    Reading a source space...
    [done]
    Reading a source space...
    [done]
    2 source spaces read
Total number of active sources: 2

Total running time of the script: ( 0 minutes 11.332 seconds)

Generated by Sphinx-Gallery