<jupyter_start><jupyter_text>FGL-3SR for analysis of connectomes==================================================================This example uses FGL-3SR in order to learn functional connectivity betweenregions of interest. Load ADHD dataset and MSDL atlas--------------------------------<jupyter_code>from nilearn import datasets
adhd_data = datasets.fetch_adhd(n_subjects=1)<jupyter_output>/home/ph/.local/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
/usr/local/lib/python3.5/dist-packages/nilearn/datasets/func.py:503: VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default.
  dtype=None)<jupyter_text>We use probabilistic regions of interest (ROIs) from the MSDL atlas.<jupyter_code>msdl_data = datasets.fetch_atlas_msdl()
msdl_coords = msdl_data.region_coords
n_regions = len(msdl_coords)
print('MSDL has {0} ROIs, part of the following networks :\n{1}.'.format(
    n_regions, msdl_data.networks))
from nilearn import input_data

masker = input_data.NiftiMapsMasker(
    msdl_data.maps, resampling_target="data", t_r=2.5, detrend=True,
    low_pass=.1, high_pass=.01, memory='nilearn_cache', memory_level=1)<jupyter_output><empty_output><jupyter_text>Region signals extraction-------------------------We extract regions time series.<jupyter_code>subjects_timeseries = []
adhd_labels = []
for func_file, confound_file, phenotypic in zip(
        adhd_data.func, adhd_data.confounds, adhd_data.phenotypic):
    time_series = masker.fit_transform(func_file, confounds=confound_file)
    is_adhd = phenotypic['adhd']
    subjects_timeseries.append(time_series)
    adhd_labels.append(is_adhd)<jupyter_output>/usr/local/lib/python3.5/dist-packages/scipy/signal/_arraytools.py:45: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  b = a[a_slice]<jupyter_text>FGL-3SR-------------------------We learn functional connectivity between regions of interest with FGL-3SR.<jupyter_code>import GL_3SR

beta = 1500.
alpha = .0001

Y = subjects_timeseries[0].T
N = Y.shape[0]
gl3sr = GL_3SR.FGL_3SR(trace=N, beta=beta, alpha=alpha, maxit=100, verbose=True, cv_crit=10e-12)
gl3sr.fit(Y)
import numpy as np

X, H, lbd, err = gl3sr.get_coeffs()
Lpred = X.dot(np.diag(lbd)).dot(X.T)
Wpred = np.diag(np.diag(Lpred)) - Lpred
Wpred = (Wpred + Wpred.T)/2
Wpred *= (Wpred>np.mean(Wpred))<jupyter_output><empty_output><jupyter_text>Estimate weight matrix<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt

plt.imshow(Wpred)
from nilearn import plotting

plotting.plot_connectome(Wpred, msdl_coords, colorbar=True, edge_cmap='Greys',
                         edge_vmin=.02, edge_vmax=.08, title='')
%matplotlib inline
import matplotlib as mlp
import matplotlib.pyplot as plt
mlp.rcParams["figure.figsize"] = (15, 5)

plt.subplot(131)
plt.plot(err[1:])
plt.grid(alpha=.3)
plt.title("Error convergence")

plt.subplot(132)
plt.title('$k = $' + str(np.sum(np.sum(abs(H), 1)>0)))
plt.imshow(abs(H[1:, :40]))

plt.subplot(133)
plt.plot(Y[0], label="true")
plt.plot(X.dot(H)[0], label='by FGL-3SR')
plt.grid(alpha=.3)
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.157923799006074, 'fraction_numerical': 0.022087244616234125, 'mean_word_length': 5.214408233276158, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '42020', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1264, 'n_words': 279, 'path': 'FGL_3SR_demo.ipynb', 'repo_name': 'pierreHmbt/GL-3SR', 'size': '3622'}