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

Nilearn sprint example consolidation #2013

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2fc660e
Added packages to requirements-build-docs
illdopejake Apr 15, 2019
949ba85
added reduced confounds to development_fmri
fliem Apr 16, 2019
9348909
Merge branch 'master' of https://github.com/nilearn/nilearn into sele…
fliem Apr 16, 2019
7b96dd3
fix savetxt to work with other versions
fliem Apr 16, 2019
28efb4e
Merge branch 'master' of https://github.com/nilearn/nilearn into sele…
fliem Apr 16, 2019
989ee60
merged CanICA and compare_decomp notebooks
illdopejake Apr 16, 2019
4d63944
removed encoding flag
fliem Apr 16, 2019
73b0d66
a few minor changes
illdopejake Apr 16, 2019
3abe7f8
reduced confounds filename more bidsy
fliem Apr 17, 2019
4dfef55
fixed indent
fliem Apr 17, 2019
6feb546
fixed links and small errors
illdopejake Apr 17, 2019
23440b4
fixed renaming
fliem Apr 17, 2019
cf3f56d
Merge branch 'master' of https://github.com/nilearn/nilearn into sele…
fliem Apr 17, 2019
5a5c79e
merged with nilearn master
illdopejake Apr 17, 2019
b894424
returning conf.py to its defaut state
illdopejake Apr 17, 2019
e6413a3
Merge branch 'master' of https://github.com/nilearn/nilearn into sele…
fliem Apr 17, 2019
3fa63ee
Merge branch 'nimaster' into nilearn-sprint-example-consolidation
illdopejake Apr 17, 2019
af64a6d
fix t_r to 2
fliem Apr 17, 2019
dcc12e5
Renaming stand-alone _unmask function for SpaceNet to _unmask_from_to…
Apr 17, 2019
e6912c8
Incorporated text editing suggestions from PR review
illdopejake Apr 17, 2019
083340a
Update examples/03_connectivity/plot_compare_decomposition.py
GaelVaroquaux Apr 17, 2019
681f9f3
Update examples/03_connectivity/plot_compare_decomposition.py
GaelVaroquaux Apr 17, 2019
e87fb11
got rid of extra show() line
illdopejake Apr 17, 2019
e970f81
Merge branch 'nilearn-sprint-example-consolidation' of https://github…
illdopejake Apr 17, 2019
2a740eb
Remove Python2 testing from appveyor
kchawla-pi Apr 17, 2019
b7fd92c
changed info about rsfmri_dev to a topic
illdopejake Apr 17, 2019
ed08cb9
fixed indent issue with topic
illdopejake Apr 17, 2019
13096c4
Merge pull request #2015 from thomasbazeille/move_rename_space_net_un…
GaelVaroquaux Apr 17, 2019
f861974
Merge pull request #1999 from fliem/selected_confounds
GaelVaroquaux Apr 17, 2019
37a0908
First draft of merge of 8.4.8 and 8.4.11
illdopejake Apr 17, 2019
1a41553
Change n_subjects to 1
illdopejake Apr 17, 2019
c97dee0
Merge pull request #2016 from fliem/dev_tr
GaelVaroquaux Apr 17, 2019
26874ea
small changes
illdopejake Apr 17, 2019
ee0b59d
PR #2017: Remove Python2 testing from appveyor
kchawla-pi Apr 17, 2019
7aac0f5
added blank line after note call to surmount build error
illdopejake Apr 17, 2019
3988130
fixed broken links
illdopejake Apr 17, 2019
a918570
merged with nilearn master
illdopejake Apr 17, 2019
28d8906
Update examples/03_connectivity/plot_compare_decomposition.py
GaelVaroquaux Apr 18, 2019
a583830
Update examples/03_connectivity/plot_compare_decomposition.py
GaelVaroquaux Apr 18, 2019
e70f386
minor html fixes
illdopejake Apr 18, 2019
6fc1a90
fixed bullet indentation and removed extra citation
illdopejake Apr 18, 2019
4f8a147
removed plot_adhd_spheres
illdopejake Apr 18, 2019
0fc899a
removed movie-watching
illdopejake Apr 18, 2019
869a3f8
Update examples/03_connectivity/plot_sphere_based_connectome.py
GaelVaroquaux Apr 18, 2019
fb78da7
Update examples/03_connectivity/plot_sphere_based_connectome.py
GaelVaroquaux Apr 18, 2019
9f65054
Update examples/03_connectivity/plot_sphere_based_connectome.py
GaelVaroquaux Apr 18, 2019
953ad6a
Update examples/03_connectivity/plot_sphere_based_connectome.py
GaelVaroquaux Apr 18, 2019
531220c
fixed tiny note bug
illdopejake Apr 18, 2019
48da288
Merge branch 'nilearn-sprint-example-consolidation_spheres' into nile…
illdopejake Apr 18, 2019
2fa2196
more rst errors
illdopejake Apr 18, 2019
9a49022
hopefully finally fixed html bug
illdopejake Apr 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ environment:
# We run the tests on 2 different target platforms for testing purpose only.
# We use miniconda versions of Python provided by appveyor windows images
matrix:
- PYTHON: "C:\\Miniconda-x64"
PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Miniconda35-x64"
PYTHON_VERSION: "3.5.x"
PYTHON_ARCH: "64"
Expand Down
136 changes: 53 additions & 83 deletions doc/connectivity/resting_state_networks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ Extracting functional brain networks: ICA and related

.. topic:: **Page summary**

This page demonstrates the use of multi-subject Independent Component
Analysis (ICA) of movie-watching fMRI data
to extract brain networks in
an data-driven way. Here we use the 'CanICA' approach, that implements
a multivariate random effects model across subjects. A newer technique,
based on dictionary learning, is then described.
This page demonstrates the use of multi-subject decompositions models
to extract brain-networks from fMRI data in a data-driven way.
Specifically, we will apply Independent Component Analysis (ICA), which
implements a multivariate random effects model across subjects. We will
then compare ICA to a newer technique, based on dictionary learning.


.. currentmodule:: nilearn.decomposition
Expand All @@ -25,76 +24,58 @@ Multi-subject ICA: CanICA
fMRI datasets", `NeuroImage Vol 51 (2010)
<http://www.sciencedirect.com/science/article/pii/S1053811910001618>`_, p. 288-299

Data preparation: retrieving example data
-----------------------------------------
Objective
----------
ICA is a useful approach for finding independent sources from fMRI
images. ICA and similar techniques can be therefore used to define
regions or networks that share similar BOLD signal across time. The
CanICA incorporates information both within-subjects and across subjects
to arrive at consensus components.

We will use down-sampled data from the `brain development dataset
<https://osf.io/5hju4/files/>`_ has been
preprocessed using `FMRIPrep and Nilearn <https://osf.io/wjtyq/>`_.
We use nilearn
functions to fetch data from Internet and get the filenames (:ref:`more
on data loading <loading_data>`):
.. topic:: **Nilearn data for examples**

Nilearn provides easy-to-analyze data to explore functional connectivity and resting: the
`brain development dataset <https://osf.io/5hju4/files/>`_, which
has been preprocessed using `FMRIPrep and Nilearn <https://osf.io/wjtyq/>`_
We use nilearn functions to fetch data from Internet and get the
filenames (:ref:`more on data loading <loading_data>`).

.. literalinclude:: ../../examples/03_connectivity/plot_canica_analysis.py
:start-after: # First we load the brain development fmri data
:end-before: ###############################################

Applying CanICA
---------------

Fitting CanICA model with nilearn
---------------------------------
:class:`CanICA` is a ready-to-use object that can be applied to
multi-subject Nifti data, for instance presented as filenames, and will
perform a multi-subject ICA decomposition following the CanICA model.
As with every object in nilearn, we give its parameters at construction,
and then fit it on the data.

.. literalinclude:: ../../examples/03_connectivity/plot_canica_analysis.py
:start-after: # Here we apply CanICA on the data
:end-before: ####################################################################

The components estimated are found as the `components_img_` attribute
of the object. A 4D Nifti image.

.. note::
The `components_img_` attribute is implemented from version 0.4.1 which
is easy for visualization without any additional step to unmask to image.
For users who have older versions, components image can be done by
unmasking attribute `components_`. See :ref:`section Inverse transform:
unmasking data <unmasking_step>`.

Visualizing the results
-----------------------
and then fit it on the data. For examples of this process, see
here: :ref:`sphx_glr_auto_examples_03_connectivity_plot_compare_decomposition.py`

We can visualize the components as in the previous examples. The first plot
shows a map generated from all the components. Then we plot an axial cut for
each component separately.
Once an ICA object has been fit to an fMRI dataset, the individual
components can be accessed as a 4D Nifti object using the
``components_img_`` attribute.

.. literalinclude:: ../../examples/03_connectivity/plot_canica_analysis.py
:start-after: # To visualize we plot the outline of all components on one figure
:end-before: ####################################################################
Visualizing results
--------------------
We can visualize each component outlined over the brain:

.. figure:: ../auto_examples/03_connectivity/images/sphx_glr_plot_canica_analysis_001.png
.. figure:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_001.png
:align: center
:target: ../auto_examples/03_connectivity/plot_canica_analysis.html

Finally, we can plot the map for different ICA components separately:
:target: ../auto_examples/03_connectivity/plot_compare_decomposition.html

.. literalinclude:: ../../examples/03_connectivity/plot_canica_analysis.py
:start-after: # Finally, we plot the map for each ICA component separately
We can also plot the map for different components separately:

.. |left_img| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_canica_analysis_003.png
.. |left_img| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_002.png
:width: 23%

.. |right_img| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_canica_analysis_004.png
.. |right_img| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_003.png
:width: 23%

.. centered:: |left_img| |right_img|

.. seealso::

The full code can be found as an example:
:ref:`sphx_glr_auto_examples_03_connectivity_plot_canica_analysis.py`
:ref:`sphx_glr_auto_examples_03_connectivity_plot_compare_decomposition.py`

.. note::

Expand All @@ -103,9 +84,8 @@ Finally, we can plot the map for different ICA components separately:
a fair representation, you should display all components and
investigate which one resemble those displayed above.

Beyond ICA : Dictionary learning
================================

An alternative to ICA: Dictionary learning
===========================================
Recent work has shown that dictionary learning based techniques outperform
ICA in term of stability and constitutes a better first step in a statistical
analysis pipeline.
Expand All @@ -115,53 +95,35 @@ good extracted maps.

.. topic:: **References**

* Arthur Mensch et al. `Compressed online dictionary learning for fast resting-state fMRI decomposition <https://hal.archives-ouvertes.fr/hal-01271033/>`_,
ISBI 2016, Lecture Notes in Computer Science

Applying DictLearning
---------------------
* Arthur Mensch et al. `Compressed online dictionary learning for fast resting-state fMRI decomposition <https://hal.archives-ouvertes.fr/hal-01271033/>`_,
ISBI 2016, Lecture Notes in Computer Science

:class:`DictLearning` is a ready-to-use class with the same interface as CanICA.
Sparsity of output map is controlled by a parameter alpha: using a
larger alpha yields sparser maps.

.. literalinclude:: ../../examples/03_connectivity/plot_compare_decomposition.py
:start-after: # Dictionary learning
:end-before: ###############################################################################
We can fit both estimators to compare them. 4D plotting offers an efficient way
to compare both resulting outputs.

We can fit both estimators to compare them

.. literalinclude:: ../../examples/03_connectivity/plot_compare_decomposition.py
:start-after: # Fit both estimators
:end-before: ###############################################################################

Visualizing the results
-----------------------

4D plotting offers an efficient way to compare both resulting outputs

.. literalinclude:: ../../examples/03_connectivity/plot_compare_decomposition.py
:start-after: # Visualize the results

.. |left_img_decomp| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_001.png
.. |left_img_decomp| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_022.png
:target: ../auto_examples/03_connectivity/plot_compare_decomposition.html
:width: 50%
.. |right_img_decomp| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_003.png
.. |right_img_decomp| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_023.png
:target: ../auto_examples/03_connectivity/plot_compare_decomposition.html
:width: 50%

.. |left_img_decomp_single| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_002.png
.. |left_img_decomp_single| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_024.png
:target: ../auto_examples/03_connectivity/plot_compare_decomposition.html
:width: 50%
.. |right_img_decomp_single| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_004.png
.. |right_img_decomp_single| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_025.png
:target: ../auto_examples/03_connectivity/plot_compare_decomposition.html
:width: 50%


.. centered:: |left_img_decomp| |right_img_decomp|
.. centered:: |left_img_decomp_single| |right_img_decomp_single|

Maps obtained with dictionary leaning are often easier to exploit as they are
Maps obtained with dictionary learning are often easier to exploit as they are
less noisy than ICA maps, with blobs usually better defined. Typically,
*smoothing can be lower than when doing ICA*.
While dictionary learning computation time is comparable to CanICA, obtained
Expand All @@ -172,3 +134,11 @@ classification tasks.

The full code can be found as an example:
:ref:`sphx_glr_auto_examples_03_connectivity_plot_compare_decomposition.py`

.. seealso::

Learn how to extract fMRI data from regions created with
dictionary learning with this example:
:ref:`sphx_glr_auto_examples_03_connectivity_plot_extract_regions_dictlearning_maps.py`


4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
.. |rest_parcellations| image:: auto_examples/03_connectivity/images/sphx_glr_plot_data_driven_parcellations_001.png
:target: auto_examples/03_connectivity/plot_data_driven_parcellations.html

.. |canica| image:: auto_examples/03_connectivity/images/sphx_glr_plot_canica_analysis_011.png
:target: auto_examples/03_connectivity/plot_canica_analysis.html
.. |canica| image:: auto_examples/03_connectivity/images/sphx_glr_plot_compare_decomposition_011.png
:target: auto_examples/03_connectivity/plot_compare_decomposition.html

.. |tvl1_haxby| image:: auto_examples/02_decoding/images/sphx_glr_plot_haxby_space_net_002.png
:target: auto_examples/02_decoding/plot_haxby_space_net.html
Expand Down
2 changes: 1 addition & 1 deletion doc/manipulating_images/masker_objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,4 @@ seed position is used.

.. topic:: **Examples**

* :ref:`sphx_glr_auto_examples_03_connectivity_plot_adhd_spheres.py`
* :ref:`sphx_glr_auto_examples_03_connectivity_plot_sphere_based_connectome.py`
4 changes: 2 additions & 2 deletions doc/plotting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ different heuristics to find cutting coordinates.
:target: ../auto_examples/01_plotting/plot_demo_glass_brain_extensive.html
:scale: 50

.. |plot_connectome| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_adhd_spheres_003.png
:target: ../auto_examples/03_connectivity/plot_adhd_spheres.html
.. |plot_connectome| image:: ../auto_examples/03_connectivity/images/sphx_glr_plot_sphere_based_connectome_003.png
:target: ../auto_examples/03_connectivity/plot_sphere_based_connectome.html
:scale: 50

.. |plot_anat| image:: ../auto_examples/01_plotting/images/sphx_glr_plot_demo_plotting_003.png
Expand Down
112 changes: 0 additions & 112 deletions examples/03_connectivity/plot_adhd_spheres.py

This file was deleted.