Skip to content

Commit 3bcae79

Browse files
committed
computed dtw signals for matchings and bottleneck
1 parent b8e7330 commit 3bcae79

16 files changed

+5266
-46
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ build/*
1212
# Jupyter notebook files
1313
.ipynb_checkpoints
1414
*.egg-info
15+
# Saved matrices
16+
*.npy
1517
# Output and experiments
1618
*.h5
1719
*.yaml
@@ -20,5 +22,10 @@ build/*
2022
experiments/*
2123
notebooks/experiment_*
2224
notebooks/output
25+
# Strange files
26+
*Zone.Identifier
2327
# Python files
2428
__pycache__
29+
# Other
30+
*/time-warping-corridor/
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "10174b23-25f5-45d2-85a2-43985ce76950",
6+
"metadata": {},
7+
"source": [
8+
"In this notebook, we explore basic analysis of the positions and speeds to detect similarities and differences between behaviouirs.\n",
9+
"\n",
10+
"We start importing some libraries."
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "35f7c19a-b478-4fa9-9451-2722d6275e7c",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"import numpy as np\n",
21+
"import matplotlib.pyplot as plt\n",
22+
"import matplotlib as mpl\n",
23+
"import os\n",
24+
"\n",
25+
"import perdiver.perdiver as perdiver\n",
26+
"\n",
27+
"from navground import core, sim\n",
28+
"\n",
29+
"plots_dir = os.path.join(\"plots\", \"visualisation\")\n",
30+
"experiment_dir = \"experiments\"\n",
31+
"os.makedirs(plots_dir, exist_ok=True)\n",
32+
"os.makedirs(\"experiments\", exist_ok=True)"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "f88c00d1-7647-4543-8357-965de185f7ec",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"# Small Corridor\n",
43+
"length = 8\n",
44+
"width=1.0\n",
45+
"# Large Corridor\n",
46+
"# width=1.5\n",
47+
"# length = 15.0\n",
48+
"num_steps = 400\n",
49+
"\n",
50+
"num_agents = 11 # 31\n",
51+
"num_runs = 1\n",
52+
"behaviour_list = [\"ORCA\", \"HL\", \"HRVO\", \"Dummy\"]\n",
53+
"marker_behaviour = {\"ORCA\": \"o\", \"HL\": \"X\", \"HRVO\": \"+\", \"Dummy\": \"*\"}\n",
54+
"color_behaviour = {}\n",
55+
"for i, behaviour in enumerate(behaviour_list):\n",
56+
" color_behaviour[behaviour] = mpl.colormaps[\"Set1\"](i / (len(behaviour_list) +1))\n",
57+
"for behaviour in behaviour_list:\n",
58+
" path = os.path.join(experiment_dir, f\"visualisation_{behaviour}.h5\")\n",
59+
" yaml = f\"\"\"\n",
60+
" steps: {num_steps}\n",
61+
" time_step: 0.1\n",
62+
" record_pose: true\n",
63+
" record_twist: true\n",
64+
" runs: {num_runs}\n",
65+
" record_collisions: true\n",
66+
" record_deadlocks: true\n",
67+
" record_safety_violation: true\n",
68+
" record_efficacy: true\n",
69+
" terminated_when_idle_or_stuck: false\n",
70+
" scenario:\n",
71+
" type: Corridor\n",
72+
" length: {length}\n",
73+
" width: {width} \n",
74+
" groups:\n",
75+
" -\n",
76+
" type: thymio\n",
77+
" number: {num_agents}\n",
78+
" radius: 0.08\n",
79+
" control_period: 0.1\n",
80+
" speed_tolerance: 0.02\n",
81+
" kinematics:\n",
82+
" type: 2WDiff\n",
83+
" wheel_axis: 0.094\n",
84+
" max_speed: 0.166\n",
85+
" behavior:\n",
86+
" type: {behaviour}\n",
87+
" optimal_speed: \n",
88+
" sampler: normal\n",
89+
" mean: 0.2\n",
90+
" std_dev: 0.05\n",
91+
" horizon: 5.0\n",
92+
" safety_margin: \n",
93+
" sampler: normal\n",
94+
" mean: 0.2\n",
95+
" std_dev: 0.05\n",
96+
" state_estimation:\n",
97+
" type: Bounded\n",
98+
" range: 5.0\n",
99+
" \"\"\"\n",
100+
" experiment = sim.load_experiment(yaml)\n",
101+
" experiment.run(keep=False, data_path=path)\n",
102+
" del experiment"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"id": "d84b1524-0407-4828-b2ab-8b8485e41a97",
109+
"metadata": {},
110+
"outputs": [],
111+
"source": [
112+
"runs = {}\n",
113+
"# Reload simulations\n",
114+
"for behaviour in behaviour_list:\n",
115+
" path = os.path.join(experiment_dir, f\"visualisation_{behaviour}.h5\")\n",
116+
" recorded_experiment = sim.RecordedExperiment(path)\n",
117+
" runs[behaviour] = recorded_experiment.runs"
118+
]
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"id": "ec5913e6-73bc-4a7e-b5c0-1a0fe3f11ee4",
123+
"metadata": {},
124+
"source": [
125+
"Now, we illustrate movements for each behaviour in a single image."
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": null,
131+
"id": "73b1f80f-61aa-4a96-b574-c4d361661a5a",
132+
"metadata": {},
133+
"outputs": [],
134+
"source": [
135+
"fig, ax = plt.subplots(nrows=len(behaviour_list), figsize=(10, 1.5*len(behaviour_list)))\n",
136+
"timestep_list = list(range(0,100,10))\n",
137+
"for i, behaviour in enumerate(behaviour_list):\n",
138+
" run = runs[behaviour][0]\n",
139+
" perdiver.plot_timesteps_corridor(run, timestep_list, length, width, ax[i])\n",
140+
" ax[i].set_title(behaviour, fontsize=20)\n",
141+
"plt.tight_layout()\n",
142+
"plt.savefig(os.path.join(plots_dir, \"behaviours_simulations.png\"))"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": null,
148+
"id": "6ed906db-afe1-4713-adb4-cff59c65d427",
149+
"metadata": {},
150+
"outputs": [],
151+
"source": []
152+
}
153+
],
154+
"metadata": {
155+
"kernelspec": {
156+
"display_name": "Python 3 (ipykernel)",
157+
"language": "python",
158+
"name": "python3"
159+
},
160+
"language_info": {
161+
"codemirror_mode": {
162+
"name": "ipython",
163+
"version": 3
164+
},
165+
"file_extension": ".py",
166+
"mimetype": "text/x-python",
167+
"name": "python",
168+
"nbconvert_exporter": "python",
169+
"pygments_lexer": "ipython3",
170+
"version": "3.10.12"
171+
}
172+
},
173+
"nbformat": 4,
174+
"nbformat_minor": 5
175+
}

notebooks/Corridor/Corridor-matchings-PCA.ipynb

+14-16
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@
4646
{
4747
"cell_type": "code",
4848
"execution_count": null,
49-
"id": "786083bb-b76e-4198-9ff8-e2045b119dbc",
49+
"id": "e39169b8-b6e2-45f7-930c-3743eab4d13a",
5050
"metadata": {},
5151
"outputs": [],
5252
"source": [
5353
"# Small Corridor\n",
5454
"# length = 8\n",
5555
"# width=1.0\n",
5656
"# Large Corridor\n",
57-
"width=1.5\n",
57+
"width=2\n",
5858
"length = 15.0\n",
59-
"num_steps = 300\n",
59+
"num_steps = 400\n",
6060
"\n",
61-
"num_agents = 20 # 31\n",
62-
"num_runs = 20\n",
63-
"behaviour_list = [\"ORCA\", \"HL\", \"HRVO\", \"Dummy\"]\n",
61+
"num_agents = 12 # 31\n",
62+
"num_runs = 15\n",
63+
"behaviour_list = [\"ORCA\", \"HL\", \"HRVO\", \"Dummy\", \"SocialForce\"]\n",
64+
"marker_behaviour = {\"ORCA\": \"o\", \"HL\": \"X\", \"HRVO\": \"+\", \"Dummy\": \"*\", \"SocialForce\": \"x\"}\n",
6465
"color_behaviour = {}\n",
6566
"for i, behaviour in enumerate(behaviour_list):\n",
6667
" color_behaviour[behaviour] = mpl.colormaps[\"Set1\"](i / (len(behaviour_list) +1))\n",
@@ -85,24 +86,21 @@
8586
" -\n",
8687
" type: thymio\n",
8788
" number: {num_agents}\n",
88-
" radius: 0.08\n",
89+
" radius: 0.35\n",
8990
" control_period: 0.1\n",
9091
" speed_tolerance: 0.02\n",
9192
" kinematics:\n",
9293
" type: 2WDiff\n",
9394
" wheel_axis: 0.094\n",
94-
" max_speed: 0.166\n",
95+
" max_speed: 0.2\n",
9596
" behavior:\n",
9697
" type: {behaviour}\n",
9798
" optimal_speed: \n",
9899
" sampler: normal\n",
99-
" mean: 0.2\n",
100-
" std_dev: 0.05\n",
100+
" mean: 0.16\n",
101+
" std_dev: 0.04\n",
101102
" horizon: 5.0\n",
102-
" safety_margin: \n",
103-
" sampler: normal\n",
104-
" mean: 0.2\n",
105-
" std_dev: 0.05\n",
103+
" safety_margin: 0.1\n",
106104
" state_estimation:\n",
107105
" type: Bounded\n",
108106
" range: 5.0\n",
@@ -275,7 +273,7 @@
275273
"metadata": {},
276274
"outputs": [],
277275
"source": [
278-
"fig, ax = plt.subplots(ncols=4, figsize=(20,5))\n",
276+
"fig, ax = plt.subplots(ncols=len(behaviour_list), figsize=(20,5))\n",
279277
"for i, behaviour in enumerate(behaviour_list):\n",
280278
" image = perim_arr_dict[behaviour][1].reshape((npixels,npixels))\n",
281279
" image = image * np.array(list(range(npixels)))\n",
@@ -304,7 +302,7 @@
304302
"pca = PCA(n_components=2)\n",
305303
"# scaled_all_perim = minmax_scale(all_perim_transformed)\n",
306304
"# Y = pca.fit_transform(scaled_all_perim)\n",
307-
"Y = pca.fit_transform(all_perim_transformed)\n",
305+
"Y = pca.fit_transform(all_perim_transformed[:-num_runs])\n",
308306
"\n",
309307
"Y_dict = {}\n",
310308
"for i, behaviour in enumerate(behaviour_list):\n",

notebooks/Corridor/Corridor-matchings-old.ipynb

+7-5
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,12 @@
269269
"gs_kw = dict(width_ratios=[5, 2, 2], height_ratios=[1,1])\n",
270270
"fig, axd = plt.subplot_mosaic([['points_HL', 'Diag_HL', 'Diag_ORCA'],\n",
271271
" ['points_ORCA', 'Diag_HL', 'Diag_ORCA']],\n",
272-
" gridspec_kw=gs_kw, figsize=(16, 4),\n",
272+
" gridspec_kw=gs_kw, figsize=(14, 4),\n",
273273
" layout=\"constrained\")\n",
274274
"for behaviour in [\"HL\", \"ORCA\"]:\n",
275-
" ps = np.array(runs[behaviour][0].poses)[:,:]\n",
276-
" twists = np.array(runs[behaviour][0].twists)[:,:]\n",
275+
" run = runs[behaviour][0]\n",
276+
" ps = np.array(run.poses)[:,:]\n",
277+
" twists = np.array(run.twists)[:,:]\n",
277278
" X = ps[start_step]\n",
278279
" Y = ps[start_step + shift_time]\n",
279280
" vel_X = twists[start_step]\n",
@@ -282,7 +283,8 @@
282283
" # Plot two timesteps\n",
283284
" # fig, ax = plt.subplots(figsize=(8, 1))\n",
284285
" ax = axd[f\"points_{behaviour}\"]\n",
285-
" perdiver.plot_two_timesteps_with_velocities(X[:,:2], Y[:,:2], vel_X[:,:2], vel_Y[:,:2], ax, arrow_width=0.03)\n",
286+
" # perdiver.plot_two_timesteps_with_velocities(X[:,:2], Y[:,:2], vel_X[:,:2], vel_Y[:,:2], ax, arrow_width=0.03)\n",
287+
" perdiver.plot_timesteps_corridor(run, [start_step, start_step + shift_time], length, width, ax) \n",
286288
" ax.set_title(f\"points_{behaviour}\", fontsize=20)\n",
287289
" # Plot matching diagram\n",
288290
" ax = axd[f\"Diag_{behaviour}\"]\n",
@@ -291,7 +293,7 @@
291293
" perdiver.plot_matching_diagram(match_diagram, ax, color=\"blue\")\n",
292294
" ax.set_title(behaviour, fontsize=20)\n",
293295
"\n",
294-
"perdiver.same_diagram_scale(axd[\"Diag_HL\"], axd[\"Diag_ORCA\"])\n",
296+
"perdiver.same_diagram_scale([axd[\"Diag_HL\"], axd[\"Diag_ORCA\"]])\n",
295297
"plt.savefig(os.path.join(plots_dir, f\"two_timesteps_points_matching_diags_ORCA_HL.png\"))"
296298
]
297299
},

0 commit comments

Comments
 (0)