mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 18:59:59 +01:00
Refactor code for improved readability and consistency across notebooks
- Standardized spacing around operators and function arguments in TP7_Kmeans.ipynb and neural_network.ipynb. - Enhanced the formatting of model building and training code in neural_network.ipynb for better clarity. - Updated the pyproject.toml to remove a specific TensorFlow version and added linting configuration for Ruff. - Improved comments and organization in the code to facilitate easier understanding and maintenance.
This commit is contained in:
@@ -122,7 +122,7 @@
|
||||
" y = np.zeros(N + 1)\n",
|
||||
" y[0] = y0\n",
|
||||
" for n in range(N):\n",
|
||||
" y[n + 1] = np.power(h + np.sqrt(h ** 2 + y[n]), 2)\n",
|
||||
" y[n + 1] = np.power(h + np.sqrt(h**2 + y[n]), 2)\n",
|
||||
" return t, y"
|
||||
]
|
||||
},
|
||||
@@ -158,7 +158,7 @@
|
||||
"\n",
|
||||
"plt.scatter(t, sol_appr, label=\"Approximation with EI\")\n",
|
||||
"plt.plot(x, f_exact(x, T), label=\"Exact solution\", color=\"red\")\n",
|
||||
"plt.plot(x, x ** 2, label=\"Square function\", color=\"green\")\n",
|
||||
"plt.plot(x, x**2, label=\"Square function\", color=\"green\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
@@ -297,9 +297,9 @@
|
||||
"\n",
|
||||
"sol = odeint(F, y0, t, args=(a, r))\n",
|
||||
"\n",
|
||||
"plt.plot(t, sol[:, 0], label='S(t)')\n",
|
||||
"plt.plot(t, sol[:, 1], label='I(t)')\n",
|
||||
"plt.plot(t, sol[:, 2], label='R(t)')\n",
|
||||
"plt.plot(t, sol[:, 0], label=\"S(t)\")\n",
|
||||
"plt.plot(t, sol[:, 1], label=\"I(t)\")\n",
|
||||
"plt.plot(t, sol[:, 2], label=\"R(t)\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
@@ -336,7 +336,9 @@
|
||||
"\n",
|
||||
"def calculate_errors(sol_exact, sol_appr):\n",
|
||||
" return np.max(\n",
|
||||
" np.power(np.abs(sol_appr - sol_exact), 2)[np.isfinite(np.power(np.abs(sol_appr - sol_exact), 2))]\n",
|
||||
" np.power(np.abs(sol_appr - sol_exact), 2)[\n",
|
||||
" np.isfinite(np.power(np.abs(sol_appr - sol_exact), 2))\n",
|
||||
" ]\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -356,8 +358,8 @@
|
||||
"plt.plot(errors_EE, label=\"Euler Explicit\")\n",
|
||||
"plt.plot(errors_H, label=\"Heun\")\n",
|
||||
"plt.plot(errors_RK4, label=\"Runge Kutta order 4\")\n",
|
||||
"plt.yscale('log')\n",
|
||||
"plt.xscale('log')\n",
|
||||
"plt.yscale(\"log\")\n",
|
||||
"plt.xscale(\"log\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
@@ -431,23 +433,23 @@
|
||||
"# Plot the real parts\n",
|
||||
"plt.figure(figsize=(12, 6))\n",
|
||||
"plt.subplot(1, 2, 1)\n",
|
||||
"plt.plot(t, np.real(x_appr_EI), label='Numerical Solution by EI')\n",
|
||||
"plt.plot(t, np.real(x_appr_EE), label='Numerical Solution by EE')\n",
|
||||
"plt.plot(t, np.real(x_exact), label='Exact Solution', linestyle='--')\n",
|
||||
"plt.xlabel('Time')\n",
|
||||
"plt.ylabel('Real Part')\n",
|
||||
"plt.plot(t, np.real(x_appr_EI), label=\"Numerical Solution by EI\")\n",
|
||||
"plt.plot(t, np.real(x_appr_EE), label=\"Numerical Solution by EE\")\n",
|
||||
"plt.plot(t, np.real(x_exact), label=\"Exact Solution\", linestyle=\"--\")\n",
|
||||
"plt.xlabel(\"Time\")\n",
|
||||
"plt.ylabel(\"Real Part\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.title('Real Part of the Solution')\n",
|
||||
"plt.title(\"Real Part of the Solution\")\n",
|
||||
"\n",
|
||||
"# Plot the imaginary parts\n",
|
||||
"plt.subplot(1, 2, 2)\n",
|
||||
"plt.plot(t, np.imag(x_appr_EI), label='Numerical Solution by EI')\n",
|
||||
"plt.plot(t, np.imag(x_appr_EE), label='Numerical Solution by EE')\n",
|
||||
"plt.plot(t, np.imag(x_exact), label='Exact Solution', linestyle='--')\n",
|
||||
"plt.xlabel('Time')\n",
|
||||
"plt.ylabel('Imaginary Part')\n",
|
||||
"plt.plot(t, np.imag(x_appr_EI), label=\"Numerical Solution by EI\")\n",
|
||||
"plt.plot(t, np.imag(x_appr_EE), label=\"Numerical Solution by EE\")\n",
|
||||
"plt.plot(t, np.imag(x_exact), label=\"Exact Solution\", linestyle=\"--\")\n",
|
||||
"plt.xlabel(\"Time\")\n",
|
||||
"plt.ylabel(\"Imaginary Part\")\n",
|
||||
"plt.legend()\n",
|
||||
"plt.title('Imaginary Part of the Solution')\n",
|
||||
"plt.title(\"Imaginary Part of the Solution\")\n",
|
||||
"\n",
|
||||
"plt.show()"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user