pm21-dragon/exercises/release/exercise-08/2__Optimization_first_steps.ipynb

543 lines
58 KiB
Plaintext
Raw Normal View History

2024-11-29 03:11:15 -05:00
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "29874499fd2a20779e162626f76f6776",
"grade": false,
"grade_id": "cell-e894ec2378fa46eb",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# You must run this cell, but you can ignore its contents.\n",
"\n",
"import hashlib\n",
"\n",
"def ads_hash(ty):\n",
" \"\"\"Return a unique string for input\"\"\"\n",
" ty_str = str(ty).encode()\n",
" m = hashlib.sha256()\n",
" m.update(ty_str)\n",
" return m.hexdigest()[:10]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "6f1fee68b047ccaf945f9998a29d8651",
"grade": false,
"grade_id": "cell-ada87b3b188b2d39",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# You must also run this cell.\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "bd84ae4c048d756b33d0fd85d55f1aec",
"grade": false,
"grade_id": "cell-d7462f8b0f718bef",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"# Exercise - Optimization first steps\n",
"\n",
"We are going to take our first steps towards optimization by returning to a bumblebee example.\n",
"\n",
"We are going to define the positions of a flower and the flight path of a bumblebee."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "13882d6eb738408b7520368a4b5e8ff5",
"grade": false,
"grade_id": "cell-78cb75cddd4fc5ef",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"flower = np.array([7.5, 10.3])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "5f73a413f4a03726e882c755a3430c17",
"grade": false,
"grade_id": "cell-ab9736432799913b",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"def make_bee_track(t):\n",
" pos0 = (-10,3)\n",
" velocity = (4.0, 0.2)\n",
" pos_x = pos0[0] + t*velocity[0]\n",
" pos_y = pos0[1] + t*velocity[1]\n",
" return np.array([pos_x,pos_y])\n",
"\n",
"t = np.linspace(0,15,20)\n",
"bee_track = make_bee_track(t)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "6aa761a551cb0142afbfe7e7d81947ed",
"grade": false,
"grade_id": "cell-08928dcd585933a7",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"Here we plot these positions."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c8e52b43cbe861d8eddacccc87aeb1e2",
"grade": false,
"grade_id": "cell-4b58d56276437c3a",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(nrows=1, ncols=1)\n",
"ax.plot( [flower[0]], [flower[1]], 'or', label='flower' )\n",
"ax.plot( bee_track[0], bee_track[1], '.-k', label='bee')\n",
"ax.axis('equal')\n",
"ax.legend();"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "0f3a53f8323083b2effbac78689c09d7",
"grade": false,
"grade_id": "cell-701acd6a5b4a9581",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"## Q1 Draw a figure as above with, additionally, a blue line between each point on `bee_track` and `flower`.\n",
"\n",
"When complete, your figure should look like this:\n",
"\n",
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAisAAAGdCAYAAADT1TPdAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAABcgElEQVR4nO3dd3hUZfo+8Hsy6Z2SSkIPSpWiYlAkKuBaUcAVdRUrIKIiuiKLruhPwL7iUhSwrgrsShER9ysiTSnSoggsBggkgcRQQhqpM+/vj8eTMz0zIeVE7s91zaWZTDlzMsy553mf9z0mpZQCERERkUH5NfUGEBEREXnCsEJERESGxrBCREREhsawQkRERIbGsEJERESGxrBCREREhsawQkRERIbGsEJERESG5t/UG3CurFYrjh8/joiICJhMpqbeHCIiIvKCUgrFxcVITEyEn5/n2kmzDyvHjx9HcnJyU28GERER1UF2djaSkpI83qbZh5WIiAgA8mIjIyObeGuIiIjIG0VFRUhOTq45jnvS7MOKNvQTGRnJsEJERNTMeNPCwQZbIiIiMjSGFSIiIjK0Bg0r8+bNQ69evWqGaFJTU/H111/X/F4phWnTpiExMREhISFIS0vD3r17G3KTiIiIqJlp0J6VpKQkvPzyy+jcuTMA4KOPPsKwYcOwe/dudO/eHa+++irefPNNfPjhh+jSpQteeuklDBkyBAcOHPCq4YaIiMhXSilUV1fDYrE09ab8oZnNZvj7+9fLsiImpZSqh23yWsuWLfHaa6/h/vvvR2JiIiZOnIjJkycDACoqKhAXF4dXXnkFY8eO9erxioqKEBUVhcLCQjbYEhGRR5WVlcjNzcXZs2ebelPOC6GhoUhISEBgYKDT73w5fjfabCCLxYL//Oc/KC0tRWpqKjIzM5GXl4ehQ4fW3CYoKAiDBg3C5s2b3YaViooKVFRU1PxcVFTU4NtORETNn9VqRWZmJsxmMxITExEYGMjFRBuIUgqVlZU4ceIEMjMzkZKSUuvCb540eFjZs2cPUlNTUV5ejvDwcCxfvhzdunXD5s2bAQBxcXF2t4+Li8PRo0fdPt7MmTPxwgsvNOg2ExHRH09lZSWsViuSk5MRGhra1JvzhxcSEoKAgAAcPXoUlZWVCA4OrvNjNfhsoAsuuADp6enYunUrHn74YYwePRr79u2r+b1jqlVKeUy6U6ZMQWFhYc0lOzu7wbadiIj+eM7lGz75pr72dYNXVgIDA2sabC+++GJs374ds2bNqulTycvLQ0JCQs3t8/PznaottoKCghAUFNSwG01ERESG0ejxUimFiooKdOjQAfHx8VizZk3N7yorK7FhwwYMGDCgsTeLiIiIDKpBw8rf/vY3bNq0CUeOHMGePXswdepUrF+/HnfddRdMJhMmTpyIGTNmYPny5fjll19w7733IjQ0FHfeeWdDbhYREdG5sViA9euBRYvkvw08DVophTFjxqBly5YwmUyIjo7GxIkTG/Q5jaRBh4F+++033H333cjNzUVUVBR69eqF//73vxgyZAgA4Omnn0ZZWRnGjx+PgoIC9O/fH9988w3XWCEiIuNatgx4/HEgJ0e/LikJmDULGD68QZ7yv//9Lz788EOsX78eHTt2xMiRIxvkeYyqQcPKe++95/H3JpMJ06ZNw7Rp0xpyM4iIiOrHsmXAyJGA4xJlx47J9Z9/3iCB5dChQ0hISKhpk/D3N9Z5iKuqqhAQENBgj8+WaCIiIm9YLFJRcbWWqnbdxIn1PiR077334tFHH0VWVhZMJhPat2/vdJuCggLcc889aNGiBUJDQ3HdddchIyPj901TiImJwdKlS2tu37t3b8TGxtb8vGXLFgQEBKCkpAQAUFhYiDFjxiA2NhaRkZG4+uqr8dNPP9Xcftq0aejduzfef/99dOzYEUFBQWjINWYZVoiIiLyxaZP90I8jpYDsbLldPZo1axZefPFFJCUlITc3F9u3b3e6zb333osdO3Zg5cqV2LJlC5RSuP7661FVVQWTyYQrr7wS69evByDBZt++faiqqqpZSmT9+vXo168fwsPDoZTCDTfcgLy8PKxevRo7d+5E3759cc011+D06dM1z3nw4EH8+9//xtKlS5Genl6vr9mRsepIRERERpWbW7+381JUVBQiIiJgNpsRHx/v9PuMjAysXLkSP/zwQ80w0aeffork5GSsWLECt912G9LS0jB//nwAwMaNG3HRRRehbdu2WL9+Pbp164b169cjLS0NALBu3Trs2bMH+fn5NUuFvP7661ixYgU+//xzjBkzBoDM4P3Xv/6FmJiYen29rrCyQkRE5A2bNcHq5Xb1ZP/+/fD390f//v1rrmvVqhUuuOAC7N+/HwCQlpaGvXv34uTJk9iwYQPS0tKQlpaGDRs2oLq6Gps3b8agQYMAADt37kRJSQlatWqF8PDwmktmZiYOHTpU8xzt2rVrlKACsLJCRETknYEDZdbPsWOu+1ZMJvn9wIGNulnuekVsV4Tv0aMHWrVqhQ0bNmDDhg148cUXkZycjOnTp2P79u0oKyvDFVdcAUDOoZSQkFAzbGQrOjq65v/DwsLq/bW4w7BCRETkDbNZpiePHCnBxDYkaKeJeestuV0j6tatG6qrq7Ft27aaYaBTp07h119/RdeuXX/fPOlb+eKLL/DLL79g4MCBiIiIQFVVFd555x307du3ZtmQvn37Ii8vD/7+/i6beZsCh4GIiIi8NXy4TE9u08b++qSkBpu2XJuUlBQMGzYMDz30EL7//nv89NNP+Mtf/oI2bdpg2LBhNbdLS0vDZ599hl69eiEyMrImwHz66ac1/SoAMHjwYKSmpuKWW27B//3f/+HIkSPYvHkznn32WezYsaPRXx/AsEJEROSb4cOBI0eAdeuAzz6T/2ZmNklQ0XzwwQfo168fbrzxRqSmpkIphdWrV9utfXLVVVfBYrHYBZNBgwbBYrHU9KsAUoVZvXo1rrzyStx///3o0qULRo0ahSNHjng8d19DMqmGnBjdCIqKihAVFYXCwkJERkY29eYQEZFBlZeXIzMzEx06dEBwcHBTb855wdM+9+X4zcoKERERGRrDChERERkawwoREREZGsMKERERGRrDChERERkawwoREREZGsMKERERGRrDChERERkawwoREZHBpaWlYeLEiU29GU2GYYWIiIgMjWGFiIiIDI1hhYiIqA5ycnKwbt065OTkNMrzVVdXY8KECYiOjkarVq3w7LPPQju9X2VlJZ5++mm0adMGYWFh6N+/P9avX293/82bN+PKK69ESEgIkpOT8dhjj6G0tLRRtv1cMawQEdF5SymF0tJSny9z585Fu3btcPXVV6Ndu3aYO3euT/evyzmEP/roI/j7+2Pbtm14++238Y9//AMLFy4EANx333344YcfsHjxYvz888+47bbb8Kc//QkZGRkAgD179uDaa6/F8OHD8fPPP2PJkiX4/vvvMWHChHrdnw2FZ10mIqLzgqszAJeWliI8PLzRt6WkpARhYWFe3z4tLQ35+fnYu3cvTCYTAOCZZ57BypUr8eWXXyIlJQU5OTlITEysuc/gwYNx6aWXYsaMGbjnnnsQEhKCd999t+b333//PQYNGoTS0tIGOwt1fZ112b9Bto6IiIjq1WWXXVYTVAAgNTUVb7zxBnbs2AGlFLp06WJ3+4qKCrRq1QoAsHPnThw8eBCffvppze+VUrBarcjMzETXrl0b50XUEcMKERGdt0JDQ1FSUuLTfY4dO4auXbvCarXWXGc2m7Fv3z60adPG6+etT2azGTt37oTZbLa7XqsaWa1WjB07Fo899pjTfdu2bVuv29IQGFaIiOi8ZTKZfBqOAYAuXbpg/vz5GDt2LCwWC8xmM959912nykZ927p1q9PPKSkp6NOnDywWC/Lz8zFw4ECX9+3bty/27t2Lzp07N+g2NhQ22BIREfnogQcewJEjR7Bu3TocOXIEDzzwQIM/Z3Z2NiZNmoQDBw5g0aJF+Oc//4nHH38cXbp0wV133YV77rkHy5YtQ2ZmJrZv345XXnkFq
"\n",
"\n",
"Hint, draw the flower first. Then, make a for loop which steps through each position of the bee. Inside the for loop, draw a line segment between the bee and the flower."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "38fbad4ec96d8ade393535b625140003",
"grade": true,
"grade_id": "cell-43f8774b1a82b15b",
"locked": false,
"points": 1,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "89805e9c9678ff01669528f20a596bf6",
"grade": false,
"grade_id": "cell-45a057824a59090e",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"## Q2 write a function called `my_distance` which takes two arguments, each of which is a length 2 sequence of `x`, `y` position and returns the Euclidean distance between these points."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "9bd3bd0fb3a886f4696138c95e0058ab",
"grade": false,
"grade_id": "cell-9d86e35ff582bf8f",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "b359ea8e38a47e5320e08ce6158dc39c",
"grade": true,
"grade_id": "cell-d96cb3c1a49758db",
"locked": true,
"points": 0,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"assert my_distance((0,0),(3,4)) == 5\n",
"assert my_distance((3,4), (0,0)) == 5\n",
"assert my_distance((13,14), (10,10)) == 5\n",
"assert my_distance((10,10), (13,14)) == 5"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "5220e92a49ceb61457be556c246b28ce",
"grade": false,
"grade_id": "cell-9426c238469156ae",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"## Q3 compute the distance between each point on `bee_track` and `flower`. Put the results in a 1D numpy array called `distance`.\n",
"\n",
"Hint: recall the function you wrote in the \"numpy basics\" exercise called `compute_distance`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "922ea2de206db155b31c1b6020e50c27",
"grade": false,
"grade_id": "cell-bf78a3429e48b28d",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "0304ff76ac1ade2c3221a53c5df5fbb2",
"grade": true,
"grade_id": "cell-70fd1e669decb646",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# If this runs without error, it means the answer in your previous cell was correct.\n",
"assert ads_hash(np.round(distance*1000).astype(np.int32))=='54f4f2edcb'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Q4 make a plot of the bee track parameter `t` on the X axis and `distance` on the Y axis.\n",
"\n",
"It should look like this:\n",
"\n",
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAoZklEQVR4nO3dd3hUdd7+8feH0HsLRap0RRQwEFhd197XhopSRCnK2suui4/uPrrFn+u6llXXlY6CKPa+u4K6ikJC6ChIEJEOASQEAqTM5/fHDDwRKQEyc2Yy9+u6cs3MyUzOTULuOTnne87X3B0REUkeFYIOICIisaXiFxFJMip+EZEko+IXEUkyKn4RkSRTMegApdGwYUNv3bp10DFERBLK7NmzN7l76r7LE6L4W7duTVZWVtAxREQSipl9v7/l2tUjIpJkVPwiIklGxS8ikmRU/CIiSUbFLyKSZFT8IiJJRsUvIpJkVPwiInFoZ0ExD77zFbn5hWX+tVX8IiJxpqAoxE0TZ/PCjBXMWflDmX/9hDhzV0QkWRQVh7jzlbl8tjSHv/TpwhmdGpX5OrTFLyISJ0Ih5743FvLBwvU8cNFx9O3RMirrUfGLiMQBd+eP73/Nq7NXc/tZ7Rn68zZRW5eKX0QkDjw5NZtxX6zghlNac9fZ7aO6LhW/iEjARn++nKemZXPlyc353U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vp0705D13SWaUfYyp+EYmplzJW8qf3F3NRl6b8pU8XzZMbABW/iMTMm3NXc/9bC/fOk1sxRRUUBH3XRSQm/rUoPE9ur2MbaJ7cgJXqO29mHcxsmpkti
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c03c9f9064ad82267ed7ad1ff2274116",
"grade": true,
"grade_id": "cell-acdc61a7b1539944",
"locked": false,
"points": 1,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Q5 Using `calc_distance_func` from the lecture, find the value of `t` that minimizes the distance between the bee and the flower. Save the result in `best_t`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "ea188c9450758aa26fecfdc16042a9f2",
"grade": false,
"grade_id": "cell-23d19427610d2072",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "7a33eaaaaca8781f883635cee037a71d",
"grade": true,
"grade_id": "cell-0a3594afd2952a33",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# If this runs without error, it means the answer in your previous cell was correct.\n",
"assert ads_hash(np.round(best_t*1000).astype(np.int32))=='dec1ab2f6d'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"make_bee_track(best_t)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Q6 What is the position of the bee when it is closest to the flower? Save the result as a numpy array in `best_pos`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "20073a563548884f84b927f1c1f154eb",
"grade": false,
"grade_id": "cell-cac598c7f739d146",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "4e73e4a1310b052d0bd683f8e5b40fd3",
"grade": true,
"grade_id": "cell-9d882991838f0996",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"# If this runs without error, it means the answer in your previous cell was correct.\n",
"assert type(best_pos)==np.ndarray\n",
"assert best_pos.ndim==1\n",
"assert best_pos.shape==(2,)\n",
"assert ads_hash(np.round(best_pos[0]*1000).astype(np.int32))=='e33b9415bc'\n",
"assert ads_hash(np.round(best_pos[1]*1000).astype(np.int32))=='f71cbfce4c'"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}