|
2005 | 2005 | "cell_type": "markdown", |
2006 | 2006 | "metadata": {}, |
2007 | 2007 | "source": [ |
2008 | | - "Here, we are only interested in the voxels with good generalization\n", |
2009 | | - "performances. We select an arbitrary threshold of 0.05 (R^2 score).\n", |
| 2008 | + "Because the ridge model allows a different regularization per voxel, the\n", |
| 2009 | + "regression coefficients may have very different scales. In turn, these\n", |
| 2010 | + "different scales can introduce a bias in the interpretation, focusing the\n", |
| 2011 | + "attention disproportionately on voxels fitted with the lowest alpha. To\n", |
| 2012 | + "address this issue, we rescale the regression coefficient to have a norm\n", |
| 2013 | + "equal to the square-root of the $R^2$ scores. We found empirically that\n", |
| 2014 | + "this rescaling best matches results obtained with a regularization shared\n", |
| 2015 | + "accross voxels. This rescaling also removes the need to select only best\n", |
| 2016 | + "performing voxels, because voxels with low prediction accuracies are rescaled\n", |
| 2017 | + "to have a low norm.\n", |
2010 | 2018 | "\n" |
2011 | 2019 | ] |
2012 | 2020 | }, |
|
2018 | 2026 | }, |
2019 | 2027 | "outputs": [], |
2020 | 2028 | "source": [ |
2021 | | - "primal_coef_selection = primal_coef[:, scores > 0.05]" |
| 2029 | + "primal_coef /= np.linalg.norm(primal_coef, axis=0)[None]\n", |
| 2030 | + "primal_coef *= np.sqrt(np.maximum(0, scores))[None]" |
2022 | 2031 | ] |
2023 | 2032 | }, |
2024 | 2033 | { |
|
2039 | 2048 | "source": [ |
2040 | 2049 | "# split the ridge coefficients per delays\n", |
2041 | 2050 | "delayer = pipeline.named_steps['delayer']\n", |
2042 | | - "primal_coef_per_delay = delayer.reshape_by_delays(primal_coef_selection,\n", |
2043 | | - " axis=0)\n", |
| 2051 | + "primal_coef_per_delay = delayer.reshape_by_delays(primal_coef, axis=0)\n", |
2044 | 2052 | "print(\"(n_delays, n_features, n_voxels) =\", primal_coef_per_delay.shape)\n", |
| 2053 | + "del primal_coef\n", |
2045 | 2054 | "\n", |
2046 | 2055 | "# average over delays\n", |
2047 | 2056 | "average_coef = np.mean(primal_coef_per_delay, axis=0)\n", |
2048 | | - "print(\"(n_features, n_voxels) =\", average_coef.shape)" |
| 2057 | + "print(\"(n_features, n_voxels) =\", average_coef.shape)\n", |
| 2058 | + "del primal_coef_per_delay" |
2049 | 2059 | ] |
2050 | 2060 | }, |
2051 | 2061 | { |
|
2166 | 2176 | "objects like `sky` and `city`)\".\n", |
2167 | 2177 | "\n", |
2168 | 2178 | "In this example, because we use only a single subject and we perform a\n", |
2169 | | - "different voxel selection, our result is slightly different than in [1]_. We\n", |
2170 | | - "also use a different regularization parameter in each voxel, while in [1]_\n", |
2171 | | - "all voxels had the same regularization parameter. We do not aim at\n", |
2172 | | - "reproducing exactly the results in [1]_, but we rather describe the general\n", |
2173 | | - "approach.\n", |
| 2179 | + "different voxel selection, our result is slightly different than in the\n", |
| 2180 | + "original publication. We also use a different regularization parameter in\n", |
| 2181 | + "each voxel, while in [1]_ all voxels had the same regularization parameter.\n", |
| 2182 | + "However, we do not aim at reproducing exactly the results of the original\n", |
| 2183 | + "publication, but we rather describe the general approach.\n", |
2174 | 2184 | "\n" |
2175 | 2185 | ] |
2176 | 2186 | }, |
|
2191 | 2201 | }, |
2192 | 2202 | "outputs": [], |
2193 | 2203 | "source": [ |
2194 | | - "# split the ridge coefficients per delays\n", |
2195 | | - "primal_coef_per_delay = delayer.reshape_by_delays(primal_coef, axis=0)\n", |
2196 | | - "print(\"(n_delays, n_features, n_voxels) =\", primal_coef_per_delay.shape)\n", |
2197 | | - "del primal_coef\n", |
2198 | | - "\n", |
2199 | | - "# average over delays\n", |
2200 | | - "average_coef = np.mean(primal_coef_per_delay, axis=0)\n", |
2201 | | - "print(\"(n_features, n_voxels) =\", average_coef.shape)\n", |
2202 | | - "del primal_coef_per_delay\n", |
2203 | | - "\n", |
2204 | 2204 | "# transform with the fitted PCA\n", |
2205 | 2205 | "average_coef_transformed = pca.transform(average_coef.T).T\n", |
2206 | 2206 | "print(\"(n_components, n_voxels) =\", average_coef_transformed.shape)\n", |
|
0 commit comments