mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 11:54:10 +01:00
Update Python version and refine Jupyter Notebook formatting
- Bump Python version from 3.11 to 3.13 in .python-version file. - Reset execution counts to null in Jupyter Notebook for reproducibility. - Improve code readability by adjusting comments and formatting in the notebook. - Change the policy definition to use numpy.ndarray for better clarity. - Modify pyproject.toml to enable E501 rule for line length management.
This commit is contained in:
@@ -1 +1 @@
|
|||||||
3.11
|
3.13
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 73,
|
"execution_count": null,
|
||||||
"id": "100d1e0d",
|
"id": "100d1e0d",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -42,7 +42,9 @@
|
|||||||
"np.set_printoptions(\n",
|
"np.set_printoptions(\n",
|
||||||
" precision=3,\n",
|
" precision=3,\n",
|
||||||
" suppress=True,\n",
|
" suppress=True,\n",
|
||||||
") # (not mandatory) This line is for limiting floats to 3 decimal places, avoiding scientific notation (like 1.23e-04) for small numbers.\n",
|
")\n",
|
||||||
|
"# (not mandatory) This line is for limiting floats to 3 decimal places,\n",
|
||||||
|
"# avoiding scientific notation (like 1.23e-04) for small numbers.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# For reproducibility\n",
|
"# For reproducibility\n",
|
||||||
"rng = np.random.default_rng(seed=42) # This line creates a random number generator."
|
"rng = np.random.default_rng(seed=42) # This line creates a random number generator."
|
||||||
@@ -229,7 +231,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 78,
|
"execution_count": null,
|
||||||
"id": "a1258de4",
|
"id": "a1258de4",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -249,18 +251,17 @@
|
|||||||
"pos_to_state = {} # (i,j) -> s\n",
|
"pos_to_state = {} # (i,j) -> s\n",
|
||||||
"\n",
|
"\n",
|
||||||
"start_state = None # will store the state index of start state\n",
|
"start_state = None # will store the state index of start state\n",
|
||||||
"goal_states = [] # will store the state index of goal state # We use a list in case there are multiple goals\n",
|
"goal_states = [] # will store the state index of goal state\n",
|
||||||
"trap_states = [] # will store the state index of trap state # We use a list in case there are multiple traps\n",
|
"trap_states = [] # will store the state index of trap state\n",
|
||||||
"\n",
|
"\n",
|
||||||
"s = 0\n",
|
"s = 0\n",
|
||||||
"for i in range(n_rows): # i = row index\n",
|
"for i in range(n_rows): # i = row index\n",
|
||||||
" for j in range(n_cols): # j = column index\n",
|
" for j in range(n_cols): # j = column index\n",
|
||||||
" cell = maze_str[i][j] # cell = the character at that position (S, ., #, etc.)\n",
|
" cell = maze_str[i][j] # cell = the character at that position (S, ., #, etc.)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" if (\n",
|
" if cell in FREE:\n",
|
||||||
" cell in FREE\n",
|
" # FREE contains: free cells \".\", start cell \"S\", goal cell \"G\" and trap cell \"X\"\n",
|
||||||
" ): # FREE contains: free cells \".\", start cell \"S\", goal cell \"G\" and trap cell \"X\"\n",
|
" # Walls # are ignored, they are not MDP states.\n",
|
||||||
" # Walls # are ignored, they are not MDP states.\n",
|
|
||||||
" state_to_pos[s] = (i, j)\n",
|
" state_to_pos[s] = (i, j)\n",
|
||||||
" pos_to_state[(i, j)] = s\n",
|
" pos_to_state[(i, j)] = s\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -365,7 +366,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 80,
|
"execution_count": null,
|
||||||
"id": "fc61ceef-217c-47f4-8eba-0353369210db",
|
"id": "fc61ceef-217c-47f4-8eba-0353369210db",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -398,7 +399,7 @@
|
|||||||
" for (\n",
|
" for (\n",
|
||||||
" s,\n",
|
" s,\n",
|
||||||
" (i, j),\n",
|
" (i, j),\n",
|
||||||
" ) in state_to_pos.items(): # Calling .items() returns a list-like sequence of (key, value) pairs in the dictionary.\n",
|
" ) in state_to_pos.items():\n",
|
||||||
" cell = maze_str[i][j]\n",
|
" cell = maze_str[i][j]\n",
|
||||||
"\n",
|
"\n",
|
||||||
" if cell == \"S\":\n",
|
" if cell == \"S\":\n",
|
||||||
@@ -517,7 +518,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 83,
|
"execution_count": null,
|
||||||
"id": "4b06da5e-bc63-48e5-a336-37bce952443d",
|
"id": "4b06da5e-bc63-48e5-a336-37bce952443d",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -967,7 +968,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 91,
|
"execution_count": null,
|
||||||
"id": "2fffe0b7",
|
"id": "2fffe0b7",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -1109,7 +1110,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 94,
|
"execution_count": null,
|
||||||
"id": "4c428327",
|
"id": "4c428327",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -1125,7 +1126,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"def plot_values(V: np.ndarray, title=\"Value function\") -> None:\n",
|
"def plot_values(V: np.ndarray, title: str = \"Value function\") -> None:\n",
|
||||||
" \"\"\"Plot the value function V on the maze as a heatmap.\"\"\"\n",
|
" \"\"\"Plot the value function V on the maze as a heatmap.\"\"\"\n",
|
||||||
" grid_values = np.full(\n",
|
" grid_values = np.full(\n",
|
||||||
" (n_rows, n_cols),\n",
|
" (n_rows, n_cols),\n",
|
||||||
@@ -1149,7 +1150,7 @@
|
|||||||
" # For each state:\n",
|
" # For each state:\n",
|
||||||
" # Place the text label at (column j, row i).\n",
|
" # Place the text label at (column j, row i).\n",
|
||||||
" # Display value to two decimals.\n",
|
" # Display value to two decimals.\n",
|
||||||
" # Use white text so it’s visible on the heatmap.\n",
|
" # Use white text so it's visible on the heatmap.\n",
|
||||||
" # Center the text inside each cell.\n",
|
" # Center the text inside each cell.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" for s, (i, j) in state_to_pos.items():\n",
|
" for s, (i, j) in state_to_pos.items():\n",
|
||||||
@@ -1183,12 +1184,12 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 95,
|
"execution_count": null,
|
||||||
"id": "c1ab67f0-bd5e-4ffe-b655-aec030401b78",
|
"id": "c1ab67f0-bd5e-4ffe-b655-aec030401b78",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def plot_policy(policy: np.ndarray, title=\"Policy\") -> None:\n",
|
"def plot_policy(policy: np.ndarray, title: str =\"Policy\") -> None:\n",
|
||||||
" \"\"\"Plot the given policy on the maze.\"\"\"\n",
|
" \"\"\"Plot the given policy on the maze.\"\"\"\n",
|
||||||
" _fig, ax = plt.subplots()\n",
|
" _fig, ax = plt.subplots()\n",
|
||||||
" # draw walls as dark cells\n",
|
" # draw walls as dark cells\n",
|
||||||
@@ -1253,7 +1254,7 @@
|
|||||||
" ax.set_yticks(np.arange(-0.5, n_rows, 1))\n",
|
" ax.set_yticks(np.arange(-0.5, n_rows, 1))\n",
|
||||||
" ax.set_xticklabels([])\n",
|
" ax.set_xticklabels([])\n",
|
||||||
" ax.set_yticklabels([])\n",
|
" ax.set_yticklabels([])\n",
|
||||||
" ax.grid(True)\n",
|
" ax.grid(visible=True)\n",
|
||||||
" ax.set_title(title)\n",
|
" ax.set_title(title)\n",
|
||||||
" plt.show()"
|
" plt.show()"
|
||||||
]
|
]
|
||||||
@@ -1297,7 +1298,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 97,
|
"execution_count": null,
|
||||||
"id": "929707e6-3022-4d86-96cc-12f251f890a9",
|
"id": "929707e6-3022-4d86-96cc-12f251f890a9",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -1323,35 +1324,37 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"my_policy = [\n",
|
"my_policy = np.ndarray(\n",
|
||||||
" A_RIGHT,\n",
|
" [\n",
|
||||||
" A_RIGHT,\n",
|
" A_RIGHT,\n",
|
||||||
" A_RIGHT,\n",
|
" A_RIGHT,\n",
|
||||||
" A_DOWN,\n",
|
" A_RIGHT,\n",
|
||||||
" A_DOWN, # First row\n",
|
" A_DOWN,\n",
|
||||||
" A_UP,\n",
|
" A_DOWN, # First row\n",
|
||||||
" A_DOWN,\n",
|
" A_UP,\n",
|
||||||
" A_DOWN,\n",
|
" A_DOWN,\n",
|
||||||
" A_LEFT, # Second row\n",
|
" A_DOWN,\n",
|
||||||
" A_UP,\n",
|
" A_LEFT, # Second row\n",
|
||||||
" A_RIGHT,\n",
|
" A_UP,\n",
|
||||||
" A_DOWN, # Third row\n",
|
" A_RIGHT,\n",
|
||||||
" A_UP,\n",
|
" A_DOWN, # Third row\n",
|
||||||
" A_LEFT,\n",
|
" A_UP,\n",
|
||||||
" A_RIGHT,\n",
|
" A_LEFT,\n",
|
||||||
" A_RIGHT,\n",
|
" A_RIGHT,\n",
|
||||||
" A_RIGHT, # Fourth row\n",
|
" A_RIGHT,\n",
|
||||||
" A_UP,\n",
|
" A_RIGHT, # Fourth row\n",
|
||||||
" A_LEFT,\n",
|
" A_UP,\n",
|
||||||
" A_DOWN,\n",
|
" A_LEFT,\n",
|
||||||
" A_RIGHT,\n",
|
" A_DOWN,\n",
|
||||||
" A_UP, # Fifth row\n",
|
" A_RIGHT,\n",
|
||||||
"]\n",
|
" A_UP, # Fifth row\n",
|
||||||
|
" ],\n",
|
||||||
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"V_my_policy = policy_evaluation(policy=my_policy, P=P, R=R, gamma=gamma)\n",
|
"V_my_policy = policy_evaluation(policy=my_policy, P=P, R=R, gamma=gamma)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plot_values(V=V_my_policy, title=\"Value function: my policy\")\n",
|
"plot_values(V=V_my_policy, title=\"Value function: my policy\")\n",
|
||||||
"plot_policy(policy=my_policy, title=\"My policy\")"
|
"plot_policy(policy=my_policy, title=\"My policy\")\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1400,7 +1403,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.13.9"
|
"version": "3.11.12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ select = ["ALL"]
|
|||||||
|
|
||||||
# Désactiver certaines règles
|
# Désactiver certaines règles
|
||||||
ignore = [
|
ignore = [
|
||||||
# "E501", # line too long, géré par le formatter
|
"E501", # line too long, géré par le formatter
|
||||||
"E402", # Imports in top of file
|
"E402", # Imports in top of file
|
||||||
"T201", # Print
|
"T201", # Print
|
||||||
"N806",
|
"N806",
|
||||||
|
|||||||
Reference in New Issue
Block a user