[med-svn] [python-mne] 162/376: mne WIP
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:22:26 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.1
in repository python-mne.
commit d1c4e60967452a9a86e39d230c0a6f9cc28d78b2
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Mon Mar 28 10:25:42 2011 -0400
mne WIP
---
examples/plot_compute_mne_inverse.py | 2 +-
mne/__init__.py | 2 +-
mne/inverse.py | 70 +++++++++++++++++++-----------------
mne/tests/test_inverse.py | 2 +-
4 files changed, 41 insertions(+), 35 deletions(-)
diff --git a/examples/plot_compute_mne_inverse.py b/examples/plot_compute_mne_inverse.py
index 76f9115..431f06e 100644
--- a/examples/plot_compute_mne_inverse.py
+++ b/examples/plot_compute_mne_inverse.py
@@ -34,7 +34,7 @@ evoked = Evoked(fname_evoked, setno=setno, baseline=(None, 0))
inverse_operator = mne.read_inverse_operator(fname_inv)
# Compute inverse solution
-res = mne.compute_inverse(evoked, inverse_operator, lambda2, dSPM)
+res = mne.apply_inverse(evoked, inverse_operator, lambda2, dSPM)
# Save result in stc files
lh_vertices = res['inv']['src'][0]['vertno']
diff --git a/mne/__init__.py b/mne/__init__.py
index c78f117..124f0d8 100644
--- a/mne/__init__.py
+++ b/mne/__init__.py
@@ -6,7 +6,7 @@ from .forward import read_forward_solution
from .stc import read_stc, write_stc
from .bem_surfaces import read_bem_surfaces
from .source_space import read_source_spaces
-from .inverse import read_inverse_operator, compute_inverse, minimum_norm
+from .inverse import read_inverse_operator, apply_inverse, minimum_norm
from .epochs import Epochs
from .label import label_time_courses, read_label
import fiff
diff --git a/mne/inverse.py b/mne/inverse.py
index a6681d6..02e017f 100644
--- a/mne/inverse.py
+++ b/mne/inverse.py
@@ -230,10 +230,10 @@ def read_inverse_operator(fname):
# Some empty fields to be filled in later
#
inv['proj'] = [] # This is the projector to apply to the data
- inv['whitener'] = [] # This whitens the data
- inv['reginv'] = [] # This the diagonal matrix implementing
- # regularization and the inverse
- inv['noisenorm'] = [] # These are the noise-normalization factors
+ inv['whitener'] = [] # This whitens the data
+ inv['reginv'] = [] # This the diagonal matrix implementing
+ # regularization and the inverse
+ inv['noisenorm'] = [] # These are the noise-normalization factors
#
nuse = 0
for k in range(len(inv['src'])):
@@ -259,38 +259,42 @@ def read_inverse_operator(fname):
# Compute inverse solution
def combine_xyz(vec):
- """
- %
- % function [comb] = mne_combine_xyz(vec)
- %
- % Compute the three Cartesian components of a vector together
- %
- %
- % vec - Input row or column vector [ x1 y1 z1 ... x_n y_n z_n ]
- % comb - Output vector [x1^2+y1^2+z1^2 ... x_n^2+y_n^2+z_n^2 ]
- %
+ """Compute the three Cartesian components of a vector together
+
+ Parameters
+ ----------
+ vec : array
+ Input row or column vector [ x1 y1 z1 ... x_n y_n z_n ]
+
+ Returns
+ -------
+ comb : array
+ Output vector [x1^2+y1^2+z1^2 ... x_n^2+y_n^2+z_n^2]
"""
if vec.ndim != 1 or (vec.size % 3) != 0:
raise ValueError, ('Input must be a 1D vector with '
'3N entries')
-
- s = _block_diag(vec[None, :], 3)
- comb = (s * s.T).diagonal()
- return comb
+ return np.sqrt((noise_norm.ravel()**2).reshape(-1, 3).sum(axis=1))
def prepare_inverse_operator(orig, nave, lambda2, dSPM):
- """
- %
- % [inv] = mne_prepare_inverse_operator(orig,nave,lambda2,dSPM)
- %
- % Prepare for actually computing the inverse
- %
- % orig - The inverse operator structure read from a file
- % nave - Number of averages (scales the noise covariance)
- % lambda2 - The regularization factor
- % dSPM - Compute the noise-normalization factors for dSPM?
- %
+ """Prepare an inverse operator for actually computing the inverse
+
+ Parameters
+ ----------
+ orig : dict
+ The inverse operator structure read from a file
+ nave : int
+ Number of averages (scales the noise covariance)
+ lambda2 : float
+ The regularization factor. Recommended to be 1 / SNR**2
+ dSPM : bool
+ If True, compute the noise-normalization factors for dSPM.
+
+ Returns
+ -------
+ inv : dict
+ Prepared inverse operator
"""
if nave <= 0:
@@ -380,13 +384,15 @@ def prepare_inverse_operator(orig, nave, lambda2, dSPM):
if inv['source_ori'] == FIFF.FIFFV_MNE_FREE_ORI:
#
# The three-component case is a little bit more involved
- # The variances at three consequtive entries must be squeared and
+ # The variances at three consequtive entries must be squared and
# added together
#
# Even in this case return only one noise-normalization factor
# per source location
#
+ 1/0
noise_norm = np.sqrt(combine_xyz(noise_norm))
+
#
# This would replicate the same value on three consequtive
# entries
@@ -401,8 +407,8 @@ def prepare_inverse_operator(orig, nave, lambda2, dSPM):
return inv
-def compute_inverse(evoked, inverse_operator, lambda2, dSPM=True):
- """Compute inverse solution
+def apply_inverse(evoked, inverse_operator, lambda2, dSPM=True):
+ """Apply inverse operator to evoked data
Computes a L2-norm inverse solution
Actual code using these principles might be different because
diff --git a/mne/tests/test_inverse.py b/mne/tests/test_inverse.py
index a4a8325..8589fde 100644
--- a/mne/tests/test_inverse.py
+++ b/mne/tests/test_inverse.py
@@ -26,7 +26,7 @@ def test_compute_mne_inverse():
evoked = mne.fiff.Evoked(fname_data, setno=setno, baseline=(None, 0))
inverse_operator = mne.read_inverse_operator(fname_inv)
- res = mne.compute_inverse(evoked, inverse_operator, lambda2, dSPM)
+ res = mne.apply_inverse(evoked, inverse_operator, lambda2, dSPM)
assert np.all(res['sol'] > 0)
assert np.all(res['sol'] < 35)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git
More information about the debian-med-commit
mailing list