|
3 | 3 | Compute the explainable variance |
4 | 4 | ================================ |
5 | 5 |
|
| 6 | +Before fitting voxelwise models to the fMRI responses, we can compute the |
| 7 | +explainable variance on the test set repeats. |
| 8 | +
|
| 9 | +The explainable variance is the part of the fMRI responses that can be |
| 10 | +explained by voxelwise modeling. It is thus the upper bound of voxelwise |
| 11 | +modeling performances. |
| 12 | +
|
| 13 | +Indeed, we can decompose the signal into a sum of two components, one |
| 14 | +component that is repeated if we repeat the same experiment, and one component |
| 15 | +that changes for each repeat. Because voxelwise modeling would use the same |
| 16 | +features for each repeat, it can only model the component that is common to |
| 17 | +all repeats. This shared component can be estimated by taking the mean over |
| 18 | +repeats of the same experiment. |
6 | 19 | """ |
7 | 20 |
|
8 | 21 | ############################################################################### |
|
14 | 27 | subject = "S01" |
15 | 28 |
|
16 | 29 | ############################################################################### |
| 30 | +# Compute the explainable variance |
| 31 | +# -------------------------------- |
17 | 32 | import os |
18 | 33 | import numpy as np |
19 | 34 |
|
20 | 35 | from voxelwise.io import load_hdf5_array |
21 | 36 |
|
22 | | -# Load fMRI responses on the test set |
| 37 | +############################################################################### |
| 38 | +# First, we load the fMRI responses on the test set, which contains 10 repeats. |
23 | 39 | file_name = os.path.join(directory, 'responses', f'{subject}_responses.hdf') |
24 | 40 | Y_test = load_hdf5_array(file_name, "Y_test") |
25 | 41 |
|
26 | | -# compute the explainable variance per voxel, based on the test set repeats |
| 42 | +############################################################################### |
| 43 | +# Then, we compute the explainable variance per voxel. |
| 44 | +# The variance of the signal is estimated by taking the average variance over |
| 45 | +# repeats (``mean_var``). The variance of the component shared across repeats |
| 46 | +# is estimated by taking the variance of the average response (``var_mean``). |
| 47 | +# Then, we can compute the explainable variance by dividing the two quantities. |
| 48 | + |
27 | 49 | mean_var = np.mean(np.var(Y_test, axis=1), axis=0) |
28 | 50 | var_mean = np.var(np.mean(Y_test, axis=0), axis=0) |
29 | 51 | explainable_variance = var_mean / mean_var |
30 | 52 |
|
31 | 53 | ############################################################################### |
32 | 54 | # Map to subject flatmap |
| 55 | +# ---------------------- |
33 | 56 | import matplotlib.pyplot as plt |
34 | 57 | from voxelwise.viz import plot_flatmap_from_mapper |
35 | 58 |
|
36 | 59 | mapper_file = os.path.join(directory, 'mappers', f'{subject}_mappers.hdf') |
37 | 60 | plot_flatmap_from_mapper(explainable_variance, mapper_file, vmin=0, vmax=0.7) |
38 | 61 | plt.show() |
| 62 | + |
| 63 | +############################################################################### |
| 64 | +# We can see that the explainable variance is mainly located in the visual |
| 65 | +# cortex, which was expected since this is a purely visual experiment. |
0 commit comments