Refactor error messages and function signatures across multiple notebooks for clarity and consistency

- Updated error messages in Gauss method and numerical methods to use variables for better readability.
- Added return type hints to function signatures in various notebooks to improve code documentation.
- Corrected minor grammatical issues in docstrings for better clarity.
- Adjusted print statements and list concatenations for improved output formatting.
- Enhanced plotting functions to ensure consistent figure handling.
This commit is contained in:
2025-12-24 22:26:59 +01:00
parent 1141382c81
commit bcac5764f6
19 changed files with 60 additions and 58 deletions

View File

@@ -295,7 +295,7 @@
],
"source": [
"def get_model() -> keras.Model:\n",
" model = keras.Sequential(\n",
" return keras.Sequential(\n",
" [\n",
" keras.layers.InputLayer(shape=(32, 32, 3)),\n",
" keras.layers.Conv2D(\n",
@@ -330,7 +330,6 @@
" ],\n",
" )\n",
"\n",
" return model\n",
"\n",
"\n",
"model = get_model()\n",
@@ -371,14 +370,12 @@
" metrics=[\"accuracy\"],\n",
" )\n",
"\n",
" history = model.fit(\n",
" return model.fit(\n",
" X_train,\n",
" y_train,\n",
" validation_data=(X_valid, y_valid),\n",
" **kwargs,\n",
" )\n",
"\n",
" return history"
" )\n"
]
},
{

View File

@@ -177,7 +177,7 @@
"import _pickle as pickle\n",
"\n",
"train_size = 0.8\n",
"train_index = int(round(len(sequences) * train_size))\n",
"train_index = round(len(sequences) * train_size)\n",
"X_train = X[:train_index, :, :]\n",
"y_train = y[:train_index, :]\n",
"\n",
@@ -471,7 +471,7 @@
},
"outputs": [],
"source": [
"def save_model(model, name):\n",
"def save_model(model, name) -> None:\n",
" \"\"\"Save a Keras model to JSON and H5 files.\"\"\"\n",
" model_json = model.to_json()\n",
" with open(name + \".json\", \"w\") as json_file:\n",

View File

@@ -226,7 +226,7 @@
"source": [
"print(range(4, 10))\n",
"print(range(5, 50, 3))\n",
"print([3, 1, 4] + [1, 5, 9])\n",
"print([3, 1, 4, 1, 5, 9])\n",
"print(len(range(4, 10)))"
]
},
@@ -282,7 +282,7 @@
"\n",
"print(num in [1, 2, 3] and num > 0)\n",
"\n",
"print(not 5 == 3)"
"print(5 != 3)"
]
},
{

View File

@@ -381,7 +381,7 @@
}
],
"source": [
"def plot_maze_with_states():\n",
"def plot_maze_with_states() -> None:\n",
" \"\"\"Plot the maze with state indices.\"\"\"\n",
" grid = np.ones(\n",
" (n_rows, n_cols),\n",
@@ -391,7 +391,7 @@
" if maze_str[i][j] == \"#\":\n",
" grid[i, j] = 0 # We replace walls (#) with 0\n",
"\n",
" fig, ax = plt.subplots()\n",
" _fig, ax = plt.subplots()\n",
" ax.imshow(grid, cmap=\"gray\", alpha=0.7)\n",
"\n",
" # Plot state indices\n",
@@ -1142,7 +1142,7 @@
" ] # For each reachable cell, we write the value V[s] in the grid.\n",
" # Walls # never get values, and they stay as NaN.\n",
"\n",
" fig, ax = plt.subplots()\n",
" _fig, ax = plt.subplots()\n",
" im = ax.imshow(grid_values, cmap=\"magma\")\n",
" plt.colorbar(im, ax=ax)\n",
"\n",

View File

@@ -186,7 +186,7 @@
}
],
"source": [
"def plot_maze_with_states():\n",
"def plot_maze_with_states() -> None:\n",
" \"\"\"Plot the maze with state indices.\"\"\"\n",
" grid = np.ones(\n",
" (n_rows, n_cols),\n",
@@ -196,7 +196,7 @@
" if maze_str[i][j] == \"#\":\n",
" grid[i, j] = 0 # We replace walls (#) with 0\n",
"\n",
" fig, ax = plt.subplots(figsize=figsize)\n",
" _fig, ax = plt.subplots(figsize=figsize)\n",
" ax.imshow(grid, cmap=\"gray\", alpha=0.7)\n",
"\n",
" # Plot state indices\n",
@@ -565,7 +565,7 @@
" ] # For each reachable cell, we write the value V[s] in the grid.\n",
" # Walls # never get values, and they stay as NaN.\n",
"\n",
" fig, ax = plt.subplots(figsize=figsize)\n",
" _fig, ax = plt.subplots(figsize=figsize)\n",
" im = ax.imshow(grid_values, cmap=\"magma\")\n",
" plt.colorbar(im, ax=ax)\n",
"\n",