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

[MRG] Dictionary learning + nilearn.decomposition refactoring #693

Conversation

arthurmensch
Copy link
Contributor

Decomposition estimators (DictLearning / MultiPCA) now inherit a DecompositionEstimator.

Loading of data is made through a PCAMultiNiftiMasker, which loads data from files and compress it.

Potentially, the function check_masker could solve issue #688, as it factorizes the input checking of estimator to which you provide either a masker or parameters for a mask. It is tuned to be able to use PCAMultiNiftiMasker

@arthurmensch arthurmensch force-pushed the l1_dict_learning_composition_mask branch from 1f41aa0 to 40ddf78 Compare July 16, 2015 16:34
@arthurmensch arthurmensch changed the title Refactored nilearn.decomposition Dict learning + nilearn.decomposition refactoring Jul 17, 2015
@arthurmensch arthurmensch changed the title Dict learning + nilearn.decomposition refactoring Dictionary learning + nilearn.decomposition refactoring Jul 17, 2015
n_components = 10

dict_learning = DictLearning(n_components=n_components, smoothing_fwhm=6.,
memory="nilearn_cache", memory_level=5, verbose=2, random_state=0,
Copy link
Member

Choose a reason for hiding this comment

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

memory_level=5, verbose=2, random_state=0 makes it a bit frightening to users. I think that @GaelVaroquaux already raised this issue. Couldn't we rely on defaults ? If not, this couls mean that the defaults are not well chosen...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to put memory_level=2 to have good performance (reuse masking from initialization in dictionary learning). I could make it the default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just did

Copy link
Member

Choose a reason for hiding this comment

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

@arthurmensch arthurmensch changed the title Dictionary learning + nilearn.decomposition refactoring [WIP] Dictionary learning + nilearn.decomposition refactoring Jul 17, 2015
@arthurmensch arthurmensch force-pushed the l1_dict_learning_composition_mask branch from a943057 to 3e0683c Compare July 17, 2015 13:51
@arthurmensch arthurmensch changed the title [WIP] Dictionary learning + nilearn.decomposition refactoring [MRG] Dictionary learning + nilearn.decomposition refactoring Jul 17, 2015
=====================================================

An example applying dictionary learning to resting-state data. This example applies it
to 10 subjects of the ADHD200 datasets.
Copy link
Contributor

Choose a reason for hiding this comment

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

You say 10 and later you fetch 20.

if not hasattr(imgs, '__iter__'):
imgs = [imgs]
imgs = list(_iter_check_niimg(imgs, atleast_4d='True', memory=memory,
memory_level=memory_level))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitely not a good idea. You will waste a lot of memory here if you load everything instead of iterating over it.

Copy link
Member

Choose a reason for hiding this comment

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

This is definitely not a good idea. You will waste a lot of memory here if you
load everything instead of iterating over it.

My PR to this branch solves this problem, to the cost of doing things a
bit more manually. However, I think that we should accept this cost, in
order to merge this PR for the release. We should later inspect our
loading / checking code to see what is the best way to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's as simple as removing list here.

Copy link
Member

Choose a reason for hiding this comment

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

  • imgs = list(_iter_check_niimg(imgs, atleast_4d='True', memory=memory,
  •                         memory_level=memory_level))
    

It's as simple as removing list here.

No, that wasn't enough to limit the memory explosion, it just delayed it.

I suspect that images spanned by the iterator were not properly garbage
collected. But it does require investigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No beacuse we iterate twice. I was stupid to add this list() though. Reviewing Gaël PR now

@arthurmensch
Copy link
Contributor Author

@GaelVaroquaux it should not fail if provided with images with different size isn't it ? n_voxels is based on mask_img size

@GaelVaroquaux
Copy link
Member

GaelVaroquaux commented Dec 3, 2015 via email

@AlexandreAbraham
Copy link
Contributor

Good point, the masker does a lot to make it work.

To answer you about the design flaw, I listed it in my big refactoring issue. I suggest that we merge and take a closer look afterward.

@GaelVaroquaux
Copy link
Member

GaelVaroquaux commented Dec 3, 2015 via email

@@ -70,11 +74,11 @@ Finally, we can plot the map for different ICA components separately:
.. literalinclude:: ../../examples/connectivity/plot_canica_resting_state.py
:start-after: # Finally, we plot the map for each ICA component separately

.. |left_img| image:: ../auto_examples/connectivity/images/sphx_glr_plot_canica_resting_state_003.png
.. |left_img| image:: ../_images/sphx_glr_plot_canica_resting_state_003.png
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably don't want to change this link.

@lesteve
Copy link
Contributor

lesteve commented Dec 4, 2015

Hmmm it looks like this needs a rebase on master. Maybe you'll get a few URL fixes by @mrahim for free.

@arthurmensch arthurmensch force-pushed the l1_dict_learning_composition_mask branch from a2c54da to 7af3a07 Compare December 4, 2015 10:36
@arthurmensch
Copy link
Contributor Author

A rebase never comes for free ;)


.. literalinclude:: ../../examples/connectivity/plot_compare_resting_state_decomposition.py
:start-after: # Dictionary learning
:end-before:# CanICA
Copy link
Contributor

Choose a reason for hiding this comment

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

Genuine error in CircleCI, it looks like you need a space after the :

Try to run the doc generation with make html-strict and you'll be able to reproduce the error and possibly find other problems.

@GaelVaroquaux
Copy link
Member

GaelVaroquaux commented Dec 4, 2015 via email

@@ -70,11 +74,11 @@ Finally, we can plot the map for different ICA components separately:
.. literalinclude:: ../../examples/connectivity/plot_canica_resting_state.py
:start-after: # Finally, we plot the map for each ICA component separately

.. |left_img| image:: ../auto_examples/connectivity/images/sphx_glr_plot_canica_resting_state_003.png
.. |left_img| image:: ../auto_examples/connectivity/plot_canica_resting_state_003.png
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably shouldn't change this link

@AlexandreAbraham
Copy link
Contributor

Merging this one. I opened issues regarding initialization documentation and broken links. Feel free to open issues if problems remain if I missed them.

AlexandreAbraham added a commit that referenced this pull request Dec 8, 2015
…n_mask

[MRG] Dictionary learning + nilearn.decomposition refactoring
@AlexandreAbraham AlexandreAbraham merged commit 340633d into nilearn:master Dec 8, 2015
@GaelVaroquaux
Copy link
Member

Yipi!!!!

Sent from my phone. Please forgive brevity and mis spelling

On Dec 8, 2015, 09:44, at 09:44, Alexandre Abraham notifications@github.com wrote:

Merged #693.


Reply to this email directly or view it on GitHub:
#693 (comment)

@bthirion
Copy link
Member

bthirion commented Dec 8, 2015

Congrats !

@lesteve lesteve mentioned this pull request Dec 14, 2015
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

9 participants