From 8f0d685f15dd2e57ad341ae6717726116cdac70a Mon Sep 17 00:00:00 2001 From: natalieklein Date: Thu, 24 Mar 2016 10:46:33 -0400 Subject: [PATCH 1/2] take row of V.H not column in SVD --- mne/label.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mne/label.py b/mne/label.py index eb9b37604a2..fe98a28af18 100644 --- a/mne/label.py +++ b/mne/label.py @@ -1081,7 +1081,8 @@ def label_sign_flip(label, src): _, _, Vh = linalg.svd(ori, full_matrices=False) # Comparing to the direction of the first right singular vector - flip = np.sign(np.dot(ori, Vh[:, 0] if len(vertno_sel) > 3 else Vh[0])) + # (Note: linalg.svd -> U D V' and returns V' not V, so take first row of Vh) + flip = np.sign(np.dot(ori, Vh[0,:])) return flip From a1d4c24948a537d3bf7933220059b4f6617cb355 Mon Sep 17 00:00:00 2001 From: natalieklein Date: Thu, 24 Mar 2016 11:15:15 -0400 Subject: [PATCH 2/2] started test for label_sign_flip, not finished --- mne/tests/test_label.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mne/tests/test_label.py b/mne/tests/test_label.py index 99a5c7446e3..5885c582843 100644 --- a/mne/tests/test_label.py +++ b/mne/tests/test_label.py @@ -745,5 +745,18 @@ def test_grow_labels(): l1 = l11 + l12 assert_array_equal(l1.vertices, l0.vertices) +@testing.requires_testing_data +def test_label_sign_flip(): + src = mne.read_source_spaces(src_fname) + lh_vertno = src[0]['vertno'] + label = mne.Label(vertices=lh_vertno[0:5],hemi='lh') + src[0]['nn'][lh_vertno[0:5]] = np.array([[1., 0., 0.], + [0., 1., 0.], + [0., 0., 1.], + [np.sqrt(2), np.sqrt(2), 0.], + [np.sqrt(2), np.sqrt(2), 0.]]) + flip = mne.label_sign_flip(label, src) + # Don't understand the last part of the test + #assert_allclose(np.abs(np.dot(flip, [np.sqrt(2), np.sqrt(2), 0])), 1.) run_tests_if_main()