Skip to content

Commit 92171e6

Browse files
committed
added a few example files
1 parent 1684849 commit 92171e6

File tree

9 files changed

+932
-186
lines changed

9 files changed

+932
-186
lines changed

notebooks/dtw-matchings/TorusCross-matchings.ipynb

+8-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"metadata": {},
5656
"outputs": [],
5757
"source": [
58-
"from perdiver.navground_parser import parser\n",
58+
"from perdiver.navground_io import parser\n",
5959
"\n",
6060
"args = parser.parse_args([\n",
6161
" '--side', '6.5',\n",
@@ -64,7 +64,8 @@
6464
" '--time_step', '0.1',\n",
6565
" '--num_agents', '10',\n",
6666
" '--max_speed', '1.66',\n",
67-
" '--optimal_speed', '1.2',\n",
67+
" '--optimal_speed_min', '1.1',\n",
68+
" '--optimal_speed_min', '1.5',\n",
6869
" '--radius', '0.4',\n",
6970
" '--safety_margin', '0.1',\n",
7071
" '--behavior', 'HL',\n",
@@ -362,6 +363,7 @@
362363
"metadata": {},
363364
"outputs": [],
364365
"source": [
366+
"args.optimal_speed=1.2\n",
365367
"yaml = f\"\"\"\n",
366368
"runs: {args.num_runs}\n",
367369
"steps: {args.num_steps}\n",
@@ -387,7 +389,10 @@
387389
" max_speed: {args.max_speed}\n",
388390
" behavior:\n",
389391
" type: {args.behavior}\n",
390-
" optimal_speed: {args.optimal_speed}\n",
392+
" optimal_speed:\n",
393+
" sampler: uniform\n",
394+
" from: {args.optimal_speed_min}\n",
395+
" to: {args.optimal_speed_max}\n",
391396
" horizon: 5.0\n",
392397
" safety_margin: {args.safety_margin}\n",
393398
" state_estimation:\n",

notebooks/examples/Stability.ipynb

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "814e6431-c5d6-42e7-8fbc-1430425b9d10",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import numpy as np\n",
11+
"import matplotlib.pyplot as plt\n",
12+
"import matplotlib as mpl\n",
13+
"\n",
14+
"import os\n",
15+
"\n",
16+
"from navground import core, sim\n",
17+
"from navground.sim.ui.video import display_video_from_run\n",
18+
"\n",
19+
"import perdiver.perdiver as perdiver\n",
20+
"from perdiver.navground_io import parser, run_navground\n",
21+
"from perdiver.distances import *\n",
22+
"\n",
23+
"plots_dir = os.path.join(\"plots\", \"stability\")\n",
24+
"os.makedirs(plots_dir, exist_ok=True)"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "09fd3f0a-7243-41ff-b239-9f0d9518cfa6",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"args = parser.parse_args([\n",
35+
" '--scenario', 'Cross',\n",
36+
" '--side', '10',\n",
37+
" '--num_steps', '500',\n",
38+
" '--time_step', '0.1',\n",
39+
" '--num_agents', '12',\n",
40+
" '--max_speed', '1.66',\n",
41+
" '--optimal_speed_min', '0.1',\n",
42+
" '--optimal_speed_min', '0.15',\n",
43+
" '--radius', '0.4',\n",
44+
" '--safety_margin', '0.1',\n",
45+
" '--epsilon', '30',\n",
46+
" '--time_delay', '5',\n",
47+
"])\n",
48+
"behavior_list = [\"ORCA\"]\n",
49+
"runs = {}\n",
50+
"for behavior in behavior_list:\n",
51+
" args.behavior = behavior\n",
52+
" runs[behavior] = run_navground(args)"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"id": "578d1674-1e5f-4914-b174-47555adaaeb5",
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"from perdiver.perdiver import get_matching_diagram, plot_matching_diagram, plot_timesteps_cross\n",
63+
"\n",
64+
"args.weight = 1\n",
65+
"\n",
66+
"run = runs[\"ORCA\"][0]\n",
67+
"ps = np.array(run.poses)\n",
68+
"twists = np.array(run.twists)\n",
69+
"\n",
70+
"fig, ax = plt.subplots(figsize=(15,5), ncols=3)\n",
71+
"match_diagram_list = []\n",
72+
"for i, initial_step in enumerate([150, 153]):\n",
73+
" args.start_step = initial_step\n",
74+
" X = ps[args.start_step]\n",
75+
" Y = ps[args.start_step + args.epsilon]\n",
76+
" vel_X = twists[args.start_step]\n",
77+
" vel_Y = twists[args.start_step + args.epsilon]\n",
78+
" X_len = X.shape[0]-1\n",
79+
" # Plot two timesteps\n",
80+
" plot_timesteps_cross(run, [args.start_step, args.start_step + args.epsilon], args.side, ax[i]) \n",
81+
" # Save figure\n",
82+
" ax[i].set_xticks([])\n",
83+
" ax[i].set_yticks([])\n",
84+
" ax[i].set_title(f\"Start timestep:{initial_step}\", fontsize=20)\n",
85+
" # Plot matching diagram\n",
86+
" Dist_X = distances_2Dtorus_weighted_velocities(X, vel_X, args.weight, args.side)\n",
87+
" Dist_Y = distances_2Dtorus_weighted_velocities(Y, vel_Y, args.weight, args.side)\n",
88+
" match_diagram_list.append(get_matching_diagram(Dist_X, Dist_Y))\n",
89+
"# end for \n",
90+
"plot_matching_diagram(match_diagram_list[0], ax[2], color=\"blue\")\n",
91+
"match_diagram = match_diagram_list[1]\n",
92+
"ax[2].scatter(match_diagram[:,0], match_diagram[:,1], color=\"red\", marker=\"X\")\n",
93+
"ax[2].set_title(\"Matching diagrams\", fontsize=20)\n",
94+
"# Save figure\n",
95+
"plt.savefig(os.path.join(plots_dir, \"stability.png\"))"
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": null,
101+
"id": "41c8a7d1-ee7c-4e05-9842-00c6d2953890",
102+
"metadata": {},
103+
"outputs": [],
104+
"source": []
105+
}
106+
],
107+
"metadata": {
108+
"kernelspec": {
109+
"display_name": "Python 3 (ipykernel)",
110+
"language": "python",
111+
"name": "python3"
112+
},
113+
"language_info": {
114+
"codemirror_mode": {
115+
"name": "ipython",
116+
"version": 3
117+
},
118+
"file_extension": ".py",
119+
"mimetype": "text/x-python",
120+
"name": "python",
121+
"nbconvert_exporter": "python",
122+
"pygments_lexer": "ipython3",
123+
"version": "3.10.12"
124+
}
125+
},
126+
"nbformat": 4,
127+
"nbformat_minor": 5
128+
}

notebooks/examples/stability-illustration.ipynb

-118
This file was deleted.

0 commit comments

Comments
 (0)