|
41 | 41 |
|
42 | 42 | ############################################################################### |
43 | 43 | # Then, we compute the explainable variance per voxel. |
44 | | -# The variance of the signal is estimated by taking the variance over |
45 | | -# time (``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. |
| 44 | +# The variance of the signal is estimated by taking the average variance over |
| 45 | +# repeats. The variance of the component shared across repeats is estimated by |
| 46 | +# taking the variance of the average response. Then, we compute the |
| 47 | +# explainable variance by dividing these two quantities. |
| 48 | +# Finally, an correction can be applied to account for small numbers of repeat. |
48 | 49 |
|
49 | | -var = np.var(Y_test.reshape(-1, Y_test.shape[-1]), axis=0) |
50 | | -var_mean = np.var(np.mean(Y_test, axis=0), axis=0) |
51 | | -explainable_variance = var_mean / var |
| 50 | +from voxelwise.utils import explainable_variance |
| 51 | + |
| 52 | +ev = explainable_variance(Y_test, bias_correction=False) |
52 | 53 |
|
53 | 54 | ############################################################################### |
54 | 55 | # Plot the distribution of explainable variance over voxels. |
55 | 56 | import matplotlib.pyplot as plt |
56 | 57 |
|
57 | | -plt.hist(explainable_variance, bins=np.linspace(0, 1, 100), log=True, |
| 58 | +plt.hist(ev, bins=np.linspace(0, 1, 100), log=True, |
58 | 59 | histtype='step') |
59 | 60 | plt.xlabel("Explainable variance") |
60 | 61 | plt.ylabel("Number of voxels") |
|
68 | 69 | from voxelwise.viz import plot_flatmap_from_mapper |
69 | 70 |
|
70 | 71 | mapper_file = os.path.join(directory, 'mappers', f'{subject}_mappers.hdf') |
71 | | -plot_flatmap_from_mapper(explainable_variance, mapper_file, vmin=0, vmax=0.7) |
| 72 | +plot_flatmap_from_mapper(ev, mapper_file, vmin=0, vmax=0.7) |
72 | 73 | plt.show() |
73 | 74 |
|
74 | 75 | ############################################################################### |
|
0 commit comments