From 0593ca4c5a34084340ef8ce8b0537cdaa94e0040 Mon Sep 17 00:00:00 2001 From: Sam Nastase Date: Fri, 31 Jul 2020 13:44:34 -0400 Subject: [PATCH 1/2] Fix pairwise bootstrap to tolerate NaNs --- brainiak/isc.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/brainiak/isc.py b/brainiak/isc.py index 27d14a223..4e6b48f76 100644 --- a/brainiak/isc.py +++ b/brainiak/isc.py @@ -19,7 +19,7 @@ as statistical tests designed specifically for ISC analyses. The implementation is based on the work in [Hasson2004]_, [Kauppi2014]_, -[Simony2016]_, and [Chen2016]_. +[Simony2016]_, [Chen2016]_, and [Nastase2019]_. .. [Chen2016] "Untangling the relatedness among correlations, part I: nonparametric approaches to inter-subject correlation analysis at the @@ -41,6 +41,11 @@ during narrative comprehension.", E. Simony, C. J. Honey, J. Chen, O. Lositsky, Y. Yeshurun, A. Wiesel, U. Hasson, 2016, Nature Communications, 7, 12141. https://doi.org/10.1038/ncomms12141 + +.. [Nastase2019] "Measuring shared responses across subjects using + intersubject correlation." S. A. Nastase, V. Gazzola, U. Hasson, + C. Keysers, 2019, Social Cognitive and Affective Neuroscience, 14, + 667-685. https://doi.org/10.1093/scan/nsz037 """ # Authors: Sam Nastase, Christopher Baldassano, Qihong Lu, @@ -405,7 +410,7 @@ def _check_isc_input(iscs, pairwise=False): # Check if incoming pairwise matrix is vectorized triangle if pairwise: try: - test_square = squareform(iscs[:, 0]) + test_square = squareform(iscs[:, 0], force='tomatrix') n_subjects = test_square.shape[0] except ValueError: raise ValueError("For pairwise input, ISCs must be the " @@ -744,13 +749,13 @@ def bootstrap_isc(iscs, pairwise=False, summary_statistic='median', for voxel_iscs in iscs.T: # Square the triangle and fill diagonal - voxel_iscs = squareform(voxel_iscs) + try: + voxel_iscs = squareform(voxel_iscs, force='tomatrix') + except ValueError as e: + raise Exception("Pairwise ISC input must be " + "distance-vector format") from e np.fill_diagonal(voxel_iscs, 1) - # Check that pairwise ISC matrix is square and symmetric - assert voxel_iscs.shape[0] == voxel_iscs.shape[1] - assert np.allclose(voxel_iscs, voxel_iscs.T) - # Shuffle square correlation matrix and get triangle voxel_sample = voxel_iscs[subject_sample, :][:, subject_sample] voxel_sample = squareform(voxel_sample, checks=False) From a721dde7a836e39be7774e2735e3e56b96ff8e99 Mon Sep 17 00:00:00 2001 From: Sam Nastase Date: Fri, 31 Jul 2020 14:19:19 -0400 Subject: [PATCH 2/2] Remove extraneous try/except error message (oops) --- brainiak/isc.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/brainiak/isc.py b/brainiak/isc.py index 4e6b48f76..5250b7505 100644 --- a/brainiak/isc.py +++ b/brainiak/isc.py @@ -749,11 +749,7 @@ def bootstrap_isc(iscs, pairwise=False, summary_statistic='median', for voxel_iscs in iscs.T: # Square the triangle and fill diagonal - try: - voxel_iscs = squareform(voxel_iscs, force='tomatrix') - except ValueError as e: - raise Exception("Pairwise ISC input must be " - "distance-vector format") from e + voxel_iscs = squareform(voxel_iscs, force='tomatrix') np.fill_diagonal(voxel_iscs, 1) # Shuffle square correlation matrix and get triangle