Skip to content

Commit a3ee9c3

Browse files
committed
Update NB 7.0 with f-strings
1 parent b01bccd commit a3ee9c3

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

notebooks/7.0-The-error-matrix.ipynb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"\\chi^2(m,c;\\{x_k\\},\\{y_k\\},\\{\\alpha_k\\}) = \\sum_{k=1}^N\\frac{[y_k - (mx_k + c)]^2}{\\alpha_k^2} \\label{eq:lsq}\\tag{1}\n",
6969
"$$\n",
7070
"\n",
71-
"with respect to the parameters $m$ and $c$. We use a semicolon to emphasize the distinction between the *model parameters*, $m$ and $c$, and the *measurements*, $\\{x_k\\},\\{y_k\\}$, and $\\{\\alpha_k\\}$. Typically we are interested only in the functional dependence of $\\chi^2$ on the model parameters, holding the measurement variables fixed."
71+
"with respect to the parameters $m$ and $c$. We use a semicolon to emphasize the distinction between the *model parameters*, $m$ and $c$, and the *measurements*, $\\{x_k\\},\\{y_k\\}$, and $\\{\\alpha_k\\}$. Typically, we are interested only in the functional dependence of $\\chi^2$ on the model parameters, holding the measurement variables fixed."
7272
]
7373
},
7474
{
@@ -119,8 +119,8 @@
119119
"cAlpha = np.sqrt(pCov[1, 1])\n",
120120
"\n",
121121
"# Display formatted results\n",
122-
"print(\"Model slope (mV/Hz): {0:.2f} ± {1:.2f}\".format(mHat, mAlpha))\n",
123-
"print(\"Model intercept (mV): {0:.0f} ± {1:.0f}\".format(cHat, cAlpha))\n",
122+
"print(f\"Model slope (mV/Hz): {mHat:.2f} ± {mAlpha:.2f}\")\n",
123+
"print(f\"Model intercept (mV): {cHat:.0f} ± {cAlpha:.0f}\")\n",
124124
"print()\n",
125125
"\n",
126126
"# Evaluate the chi-squared function at the minimum and define contour levels\n",
@@ -231,7 +231,7 @@
231231
"print(\"Covariance matrix:\")\n",
232232
"print(np.array_str(pCov, precision=4, suppress_small=True))\n",
233233
"print()\n",
234-
"print(\"Correlation coefficient: {0:.3f}\".format(rho_mc))\n",
234+
"print(f\"Correlation coefficient: {rho_mc:.3f}\")\n",
235235
"print()"
236236
]
237237
},
@@ -251,14 +251,14 @@
251251
"outputs": [],
252252
"source": [
253253
"trial = np.arange(1,77)\n",
254-
"noiseScale = 0.1;\n",
254+
"noiseScale = 0.1\n",
255255
"\n",
256-
"mRange = [0.925, 1.075];\n",
257-
"cRange = [-0.35, 0.35];\n",
258-
"m = np.linspace(mRange[0], mRange[1], Nm);\n",
259-
"c = np.linspace(cRange[0], cRange[1], Nc);\n",
256+
"mRange = [0.925, 1.075]\n",
257+
"cRange = [-0.35, 0.35]\n",
258+
"m = np.linspace(mRange[0], mRange[1], Nm)\n",
259+
"c = np.linspace(cRange[0], cRange[1], Nc)\n",
260260
"\n",
261-
"chi2grid_trial = np.zeros([Nc, Nm]);\n",
261+
"chi2grid_trial = np.zeros([Nc, Nm])\n",
262262
"\n",
263263
"fig, ax = plt.subplots(5, 5, sharex=True, sharey=True, figsize=[12.8, 9.6])\n",
264264
"\n",
@@ -293,7 +293,7 @@
293293
" linewidths=1, linestyles='dotted')\n",
294294
" ax[i][j].vlines(mHat_trial + mAlpha_trial*np.array([-1, 1]), c[0], c[-1], \n",
295295
" linewidths=1, linestyles='dotted')\n",
296-
" ax[i][j].text(1.05, 0.25, \"({0:d})\".format(5*i+j+1))\n",
296+
" ax[i][j].text(1.05, 0.25, f\"({5*i+j+1:d})\")\n",
297297
"\n",
298298
"fig.text(0.5, 0.04, 'Gradient (trial/mean)', ha='center')\n",
299299
"fig.text(0.04, 0.5, 'Intercept (trial)', va='center', rotation='vertical')\n",
@@ -351,7 +351,7 @@
351351
"source": [
352352
"N_sim = 500\n",
353353
"trial = np.arange(1,77)\n",
354-
"noiseScale = 0.1;\n",
354+
"noiseScale = 0.1\n",
355355
"\n",
356356
"mHat_sim = np.zeros(N_sim)\n",
357357
"cHat_sim = np.zeros(N_sim)\n",
@@ -367,17 +367,17 @@
367367
"Nm = 50\n",
368368
"Nc = 50\n",
369369
"\n",
370-
"mRange = [0.95, 1.06];\n",
371-
"cRange = [-0.35, 0.35];\n",
372-
"m = np.linspace(mRange[0], mRange[1], Nm);\n",
373-
"c = np.linspace(cRange[0], cRange[1], Nc);\n",
370+
"mRange = [0.95, 1.06]\n",
371+
"cRange = [-0.35, 0.35]\n",
372+
"m = np.linspace(mRange[0], mRange[1], Nm)\n",
373+
"c = np.linspace(cRange[0], cRange[1], Nc)\n",
374374
"\n",
375375
"# Define the chi-squared function for m and c, given the data\n",
376376
"def chi2fun(m, c):\n",
377377
" normres = (meanVal - (m*trial + c))/(noiseScale*trial)\n",
378378
" return np.sum(normres**2)\n",
379379
"\n",
380-
"chi2grid_sim = np.zeros([Nc, Nm]);\n",
380+
"chi2grid_sim = np.zeros([Nc, Nm])\n",
381381
"for i in range(Nc):\n",
382382
" for j in range(Nm):\n",
383383
" chi2grid_sim[i, j] = chi2fun(m[j], c[i])\n",

0 commit comments

Comments
 (0)