CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/main/seminar5/seminar5.ipynb
Views: 63
Neuro ML 2020
Seminar 5: Functional connectivity
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting nilearn
Downloading nilearn-0.9.2-py3-none-any.whl (9.6 MB)
|████████████████████████████████| 9.6 MB 24.2 MB/s
Requirement already satisfied: requests>=2 in /usr/local/lib/python3.7/dist-packages (from nilearn) (2.23.0)
Requirement already satisfied: scikit-learn>=0.22 in /usr/local/lib/python3.7/dist-packages (from nilearn) (1.0.2)
Requirement already satisfied: pandas>=1.0 in /usr/local/lib/python3.7/dist-packages (from nilearn) (1.3.5)
Requirement already satisfied: lxml in /usr/local/lib/python3.7/dist-packages (from nilearn) (4.9.1)
Requirement already satisfied: joblib>=0.15 in /usr/local/lib/python3.7/dist-packages (from nilearn) (1.1.0)
Requirement already satisfied: nibabel>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from nilearn) (3.0.2)
Requirement already satisfied: scipy>=1.5 in /usr/local/lib/python3.7/dist-packages (from nilearn) (1.7.3)
Requirement already satisfied: numpy>=1.18 in /usr/local/lib/python3.7/dist-packages (from nilearn) (1.21.6)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.0->nilearn) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.0->nilearn) (2022.2.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=1.0->nilearn) (1.15.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2->nilearn) (1.24.3)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2->nilearn) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2->nilearn) (2022.6.15)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2->nilearn) (2.10)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.22->nilearn) (3.1.0)
Installing collected packages: nilearn
Successfully installed nilearn-0.9.2
Data
Get the data. Add a shortcut to your Google Drive
Shared link: https://drive.google.com/file/d/1PCJxMltTSAO-rHXEeUuQ0jqHy1yfmja4/view?usp=sharing
Multivariate time-series
Visualization of time series
Normalization and trend removal
Metrics of functional connectivity
Pearson correlation
Regularization
Condition number - minimum/maximum eigenvalue ratio of a matrix
Tikhonov regularization
Task
Check the minimum eigenvalue of a correlation matrix
Task
Apply Tikhonov regularization and check how it affects the minimum eigenvalue of a correlation matrix
Shrinkage estimators
Ledoit-Wolf
A well conditioned estimator for large dimensional covariance matrices, is predefined according to formula, is inferred from data.
Spearman correlation
Mutual information
Mutual information measures the information that random variables and share, how much knowing one of these variables reduces uncertainty about the other. determined how different to joint distributon is to the production of the marginal distrubutions .
Thresholding
Network visualization
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-62-d5e0630dd648> in <module>
2 fig = plt.figure(figsize=(13,6))
3 edge_options = {"color": "r", "linewidth": 1.5, "alpha": 0.5}
----> 4 plotting.plot_connectome(R_tresholded, coordinates, figure=fig, edge_kwargs=edge_options)
/usr/local/lib/python3.7/dist-packages/nilearn/plotting/img_plotting.py in plot_connectome(adjacency_matrix, node_coords, node_color, node_size, edge_cmap, edge_vmin, edge_vmax, edge_threshold, output_file, display_mode, figure, axes, title, annotate, black_bg, alpha, edge_kwargs, node_kwargs, colorbar)
1164 edge_threshold=edge_threshold,
1165 edge_kwargs=edge_kwargs, node_kwargs=node_kwargs,
-> 1166 colorbar=colorbar)
1167
1168 if output_file is not None:
/usr/local/lib/python3.7/dist-packages/nilearn/plotting/displays/_projectors.py in add_graph(self, adjacency_matrix, node_coords, node_color, node_size, edge_cmap, edge_vmin, edge_vmax, edge_threshold, edge_kwargs, node_kwargs, colorbar)
158 "and 'node_coords'"
159 "'adjacency_matrix' shape is {0}, 'node_coords' shape is {1}"
--> 160 .format(adjacency_matrix_shape, node_coords_shape))
161
162 # If the adjacency matrix is not symmetric, give a warning
ValueError: Shape mismatch between 'adjacency_matrix' and 'node_coords''adjacency_matrix' shape is (117, 117), 'node_coords' shape is (116, 3)
Network analysis
Graph-theoretic
Node degree
Centralities
Clustering coefficient
Efficiency
Spectral graph theory
Eigenvalues of
connectivity matrix
Laplacian matrix
Spectrum
Solve for the eigenvalue problem, where is the connectivity matrix
Laplacian spectrum
Solve for the eigenvalue problem
where is the Laplacian matrix of the graph given by the connectivity matrix
Topological
Loops, Betti numbers, persistent homology
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting ripser
Downloading ripser-0.6.4.tar.gz (74 kB)
|████████████████████████████████| 74 kB 3.8 MB/s
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from ripser) (1.21.6)
Collecting persim
Downloading persim-0.3.1-py3-none-any.whl (47 kB)
|████████████████████████████████| 47 kB 6.2 MB/s
Requirement already satisfied: scikit-learn in /usr/local/lib/python3.7/dist-packages (from ripser) (1.0.2)
Requirement already satisfied: Cython in /usr/local/lib/python3.7/dist-packages (from ripser) (0.29.32)
Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from ripser) (1.7.3)
Collecting hopcroftkarp
Downloading hopcroftkarp-1.2.5.tar.gz (16 kB)
Requirement already satisfied: joblib in /usr/local/lib/python3.7/dist-packages (from persim->ripser) (1.1.0)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from persim->ripser) (3.2.2)
Collecting deprecated
Downloading Deprecated-1.2.13-py2.py3-none-any.whl (9.6 kB)
Requirement already satisfied: wrapt<2,>=1.10 in /usr/local/lib/python3.7/dist-packages (from deprecated->persim->ripser) (1.14.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->persim->ripser) (1.4.4)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->persim->ripser) (2.8.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->persim->ripser) (0.11.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->persim->ripser) (3.0.9)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from kiwisolver>=1.0.1->matplotlib->persim->ripser) (4.1.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib->persim->ripser) (1.15.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->ripser) (3.1.0)
Building wheels for collected packages: ripser, hopcroftkarp
Building wheel for ripser (PEP 517) ... done
Created wheel for ripser: filename=ripser-0.6.4-cp37-cp37m-linux_x86_64.whl size=457764 sha256=dce0a022e661edca0a2b5f47d00e12b6780baa6b3c70645820e377e671611b52
Stored in directory: /root/.cache/pip/wheels/62/fb/5a/a32dc69b86a4548cca943e467cdf256a94e9d9da649583ea78
Building wheel for hopcroftkarp (setup.py) ... done
Created wheel for hopcroftkarp: filename=hopcroftkarp-1.2.5-py2.py3-none-any.whl size=18120 sha256=4c5904db88902ae8317197830445d2f0efdb18d22788d3fc9ca2350f801bf1b4
Stored in directory: /root/.cache/pip/wheels/d2/9f/a8/67f1b86e47cd17338d3d07939f4660378e65b758c4594f96e3
Successfully built ripser hopcroftkarp
Installing collected packages: hopcroftkarp, deprecated, persim, ripser
Successfully installed deprecated-1.2.13 hopcroftkarp-1.2.5 persim-0.3.1 ripser-0.6.4
Machine learning
Use the computed graph, spectral and topological classes features with sklearn classifiers. Try concatenating and/or boosting features of different classes, and stacking/emsembling of classifiers.
0it [00:00, ?it/s]
1it [00:03, 3.94s/it]
2it [00:07, 3.88s/it]
3it [00:11, 4.04s/it]
4it [00:16, 4.04s/it]
5it [00:19, 3.92s/it]
6it [00:24, 4.04s/it]
7it [01:13, 18.92s/it]
8it [01:52, 25.44s/it]
9it [02:31, 29.65s/it]
10it [03:11, 32.71s/it]
11it [03:50, 34.63s/it]
12it [04:30, 36.26s/it]
13it [05:10, 37.42s/it]
14it [05:49, 37.81s/it]
15it [06:29, 38.42s/it]
Topological features
Graph features
Spectral features
Features concatenation
Task
Repeat the feature extraction and machine learning pipeline on mutual information matrices. Note that the estimation of mutual information matrices could be be time-consuming.