Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add patch info to source space #1118

Merged
merged 2 commits into from
Feb 5, 2014
Merged

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented Feb 4, 2014

Should be ready for review.

@@ -1622,6 +1640,16 @@ def add_source_space_distances(src, dist_limit=np.inf, n_jobs=1, verbose=None):
shape=(s['np'], s['np']), dtype=np.float32)
s['dist'] = d
s['dist_limit'] = np.array([dist_limit], np.float32)

# Let's see if our distance was sufficient to allow for patch info
if not any(np.any(np.isinf(md)) for md in min_dists):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that using generators with any / all can produce weird bugs. Better use a list comprehension here.

@larsoner
Copy link
Member Author

larsoner commented Feb 4, 2014

Minor comment addressed, and rebased to deal with whats_new change conflict.

@dengemann
Copy link
Member

@Eric89GXL out of curiosity, I've never used the patch feature on purpose. Do you see any differences in your results with patch information?

@larsoner
Copy link
Member Author

larsoner commented Feb 4, 2014

Nope, but Matti spent some effort adding the patch information in inverse calculation (and so did we), so I figured I might as well add it here since I assume it's better. @agramfort or @mluessi do you have opinions?

@dengemann
Copy link
Member

@Eric89GXL this was more some sort of poll because I really don't have any idea about the consequences of adding patch information. I'm absolutely +1 for adding this. Would be great to hear some thoughts from someone who has experience with it.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.65%) when pulling 7b0d10b on Eric89GXL:patch-stats into 6a0b5c9 on mne-tools:master.

@@ -16,14 +17,15 @@
requires_freesurfer, run_subprocess,
requires_mne, requires_scipy_version)
from mne.surface import _accumulate_normals, _triangle_neighbors

from scipy.spatial.distance import cdist
from mne.externals.six.moves import zip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric89GXL out of curiosity, why do you need a py2/3 safe zip here? It seems you only loop over it, which means the zip will be unpacked in python 3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just always default to using the one from externals, I didn't realize there were situations where you could still use the built-in one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good to know I did not miss anything. The point is that zip in python 3k doesn't return a collection, but a generator. If you loop over a zip expression you're good. But things like numbers = zip(*[(1, 'a'), (2, 'b')])[0] would fail and require explicit unpacking or an additional list call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, comment updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a failing test on my box:

======================================================================
FAIL: Test adding distances to source space
----------------------------------------------------------------------
Traceback (most recent call last):
  File
"/Users/alex/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nose/case.py",
line 197, in runTest
    self.test(*self.arg)
  File
"/Users/alex/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/testing/decorators.py",
line 146, in skipper_func
    return f(*args, **kwargs)
  File
"/Users/alex/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/testing/decorators.py",
line 146, in skipper_func
    return f(*args, **kwargs)
  File "/Users/alex/work/src/mne-python/mne/tests/test_source_space.py",
line 125, in test_add_source_space_distances
    assert_array_equal(so['dist_limit'], np.array([-0.007], np.float32))
  File
"/Users/alex/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/testing/utils.py",
line 718, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File
"/Users/alex/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/testing/utils.py",
line 644, in assert_array_compare
    raise AssertionError(msg)
AssertionError:
Arrays are not equal

(mismatch 100.0%)
 x: array(None, dtype=object)
 y: array([-0.007], dtype=float32)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't touch that line... do you have this failure on master, and is your sample dataset updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups ... yes I have this error on master too due to a change in my sample
data :-/

sorry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cool, I run into this issue occasionally somehow, too.

@agramfort
Copy link
Member

LGTM

shall I merge? are you done here?

@larsoner
Copy link
Member Author

larsoner commented Feb 5, 2014

Yep, good to go. In the future we might want to replace that dummy source space I made with one where the C code can calculate distances (it currently segfaults!). It would allow us to increase our test coverage on Travis. It might even be possible to have a mini set of data -- using a small source space and decimated head surfaces could actually make it fairly small in my estimation. But that would be for a future PR when someone is really bored...

agramfort added a commit that referenced this pull request Feb 5, 2014
ENH: Add patch info to source space
@agramfort agramfort merged commit a830613 into mne-tools:master Feb 5, 2014
@agramfort
Copy link
Member

thanks !

@larsoner
Copy link
Member Author

larsoner commented Feb 5, 2014

BTW @agramfort do you have an opinion on how much the patch statistics help the inverse? I'm planning on adding them now because it's pretty easy to do so, but I'm just curious what you think.

@agramfort
Copy link
Member

I never compared. So let me know :)

@larsoner larsoner deleted the patch-stats branch March 11, 2014 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants