|
| 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 | +} |
0 commit comments