mne-tools/mne-python — pull request #168 by dengemann (2012-10-30 16:56:50+00:00)
Title: ENH: refactoring ICA

Hi folks,

I significantly refactored the ICA code and the underlying machinery and option-landscape to allow for neater and more (num)pythonic ICA handling.
Also the changes imply gains in stability. As is now the ICA procedures provided are less error-prone. I also think the code is much better readable now. Let me summarize whats's new:

- No magic in the core methods, nothing gets sorted. All indices refer to the original indices as returned from the decomposition. However, now, the user has the option to do some well controlled and transparent sorting by passing sorting indices on invoking plot_sources methods.
- As a consequence, sort_sources has died, also ica.sorted_by and ica._sort_idx. Of course, I updated the __repr__ method. The terminal output now is less cluttered.
- I removed superfluous private functions.
- The find_sources methods are now simpler and smarter at the same time. Depending on whether the target arg refers to some data or is None, either X, Y args functions or X args functions are processed. However, to underline the 'nothing sorted philosophy', I dropped default score functions.
- To make working with score funcs more fun I included and index attribute that is just np.arange(self.n_components). For example, to get some thresholds, you now you can write ica.index[scores < .4] which I find quite nice.
- To access some common score_funcs, I took the dict sublclass Bunch from fiff.constants and intialized an instance that distributes the score funcs in a modified fashion to serve the needs of our ICA source-finding-routines. Those routines know about this Bunch and can look up the functions there (original string names preserved). As the bunch is public, users can browse in it from IPy, especially as names and docs are preserved.
The selection is achieved via the inspect module, I allowed everything from scipy.spatial.distance and scipy.stats that has the X, Y input structure. The tests did not complain so far (each of those gets invoked). Anyways, passing the score_funcs directly is possible at any point. I made this score_func bunch visible in the mne.artifacts namespace.
- I updated the examples and demonstrated some of the new sort_func raw power.
- I updated the tests.
- I included the find events from ICA functions in the mne.artifacts name space, I created examples and tests.
- I tried to include all the tiny details from our last discussion. Hope I did not forget anything.

Feedback is welcome,

D