"print('shape of data frame for time series:', X_ts.shape)\n",
"print('shape of data frame for time series:', df_ts.shape)\n",
"print('shape of numpy array for FC:', FC.shape)\n",
"print('shape of labels:', y.shape)"
"print('shape of labels:', y_task.shape, y_sub.shape)"
]
},
{
"cell_type": "markdown",
"id": "8d3fda37-8191-4bec-af12-76a1df6db301",
"metadata": {},
"source": [
"Be careful of the types of the elements of the dataframe: here for time series they correspond to `pandas.Series`. We can plot the time series for a given sample and a few inputs."
]
},
{
...
...
@@ -59,7 +67,10 @@
},
"outputs": [],
"source": [
"type(X['dim_0'][0])"
"print(type(df_ts))\n",
"print(df_ts.shape)\n",
"print(type(df_ts.iloc[0,0]))\n",
"print(df_ts.iloc[0,0].shape)"
]
},
{
...
...
@@ -73,7 +84,7 @@
"source": [
"plt.figure()\n",
"for i in range(6):\n",
" plt.plot(X_ts.iloc[0,i])\n",
" plt.plot(df_ts.iloc[0,i])\n",
"plt.xlabel('time')\n",
"plt.ylabel('a.u.')\n",
"plt.title('example trace')\n",
...
...
@@ -81,6 +92,55 @@
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "f5188adb-adec-4f79-ac36-a8b4df2c0f48",
"metadata": {},
"source": [
"To calculate the mean, we can apply the `numpy.mean` fonction to all `Series` elements of the dataframe."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b819b32-7847-4cb2-b98d-faf27988dd32",
"metadata": {},
"outputs": [],
"source": [
"df_ts.map(np.mean)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d7e9d49c-27af-4faa-8f8a-81486590a4d9",
"metadata": {},
"outputs": [],
"source": [
"train_ind = [0,1,3,5]\n",
"df_ts.iloc[train_ind]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55367ad3-b7c6-4e17-8f8c-275b51b0ed66",
"metadata": {},
"outputs": [],
"source": [
"X = np.array(df_ts.map(np.mean))\n",
"print(X.shape)\n",
"print(X.dtype)"
]
},
{
"cell_type": "markdown",
"id": "88f56f3a-7fab-4b8a-87b6-bb92b929ed4d",
"metadata": {},
"source": [
"The `FC` array contains the functional connectivity matrices. We can recompute them from the time series."
]
},
{
"cell_type": "code",
"execution_count": null,
...
...
@@ -97,6 +157,31 @@
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de2c9861-3296-4015-be79-d813042f4167",
"metadata": {},
"outputs": [],
"source": [
"# get times series for sample 0 and all inputs\n",
"T = df_ts.iloc[0,0].size # number of time points\n",
"ts_tmp = np.zeros([T,N])\n",
"for i in range(N):\n",
" ts_tmp[:,i] = df_ts.iloc[0,i]\n",
"\n",
"# calculate correlation across all pairs of regions\n",
Be careful of the types of the elements of the dataframe: here for time series they correspond to `pandas.Series`. We can plot the time series for a given sample and a few inputs.