{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 2. Rewrite the code to look like it would in your wildest dreams!\n",
    "\n",
    "How could you restructure the interface of the `walker` library so that the functionality stays the same, but the code is less smelly?\n",
    "\n",
    "1. could this code work better/more efficiently as a class?\n",
    "    - e.g. `walker = Walker(...)`\n",
    "2. how should the setup/initialization work?\n",
    "    - e.g. which parameters would you pass to instantiate the Walker class? How do you pass them to the class?\n",
    "3. which functions should be part of the class? \n",
    "    - e.g. is `sample_next_step` a method of `Walker`? Is `create_context_map` a method of Walker?  How about `plot_trajectory`? If so, call them with `walker.sample_next_step()`\n",
    "4. what would the import statement look like?\n",
    "\n",
    "**Important:** We are *not* asking you to implement the changes in `walker.py`! Imagine the new interface, and write the code that would use it in the next cell. Of course it won't run (yet)\n",
    "\n",
    "Here are some things to keep in mind:\n",
    "- Which things will you do a lot? They should be easy to do. The interface for doing those things should be simple.\n",
    "- Which things should be modifiable from external code?\n",
    "- As a rule of thumb, think about how it sounds when you read it aloud\n",
    "    - “Giving orders”-style\n",
    "    - “Telling a story“-style\n",
    "\n",
    "    \n",
    "For inspiration think about how you call code from other libraries. Here is an example of instantiating an object and calling one of its methods:\n",
    "````python\n",
    "import scipy as sp\n",
    "\n",
    "#  Sampling from a gaussian with specific mean and sd:\n",
    "# Create a Gaussian (normal) distribution object\n",
    "gaussian_dist = sp.stats.norm(loc=mean, scale=sd)\n",
    "# Sample 10 values from the Gaussian distribution\n",
    "samples = gaussian_dist.rvs(size=10)\n",
    "````\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-18T09:45:09.308173Z",
     "start_time": "2022-08-18T11:45:08.852431+02:00"
    },
    "execution": {
     "iopub.execute_input": "2022-08-20T06:21:31.332Z",
     "iopub.status.busy": "2022-08-20T06:21:31.327Z",
     "iopub.status.idle": "2022-08-20T06:21:31.339Z",
     "shell.execute_reply": "2022-08-20T06:21:31.343Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "from walker import Walker, plot_trajectory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-20T06:21:31.938Z",
     "iopub.status.busy": "2022-08-20T06:21:31.932Z",
     "iopub.status.idle": "2022-08-20T06:21:32.867Z",
     "shell.execute_reply": "2022-08-20T06:21:32.871Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# Create a Walker instance\n",
    "walker = Walker(sigma_i=3, sigma_j=4, size=200, map_type='hills')\n",
    "\n",
    "# Sample a next step 1000 times\n",
    "i, j = 100, 50\n",
    "trajectory = []\n",
    "for _ in range(1000):\n",
    "    i, j = walker.sample_next_step(i, j)\n",
    "    trajectory.append((i, j))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-20T06:21:32.883Z",
     "iopub.status.busy": "2022-08-20T06:21:32.879Z",
     "iopub.status.idle": "2022-08-20T06:21:33.026Z",
     "shell.execute_reply": "2022-08-20T06:21:33.033Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 115464 characters]",
      "text/plain": [
       "<Figure size 480x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_trajectory(trajectory, walker.context_map)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": false,
     "source_hidden": false
    },
    "nteract": {
     "transient": {
      "deleting": false
     }
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "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.3"
  },
  "nteract": {
   "version": "0.28.0"
  },
  "toc": {
   "nav_menu": {
    "height": "12px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
