{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-18T09:35:27.540830Z",
     "start_time": "2022-08-18T11:35:27.028238+02:00"
    },
    "execution": {
     "iopub.execute_input": "2022-08-20T06:18:30.408Z",
     "iopub.status.busy": "2022-08-20T06:18:30.402Z",
     "iopub.status.idle": "2022-08-20T06:18:30.968Z",
     "shell.execute_reply": "2022-08-20T06:18:30.957Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from walker import create_context_map, next_step_proposal, plot_trajectory, sample_next_step"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Examples of how the code works"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "nteract": {
     "transient": {
      "deleting": false
     }
    }
   },
   "source": [
    "The walker code works in the following way:\n",
    "\n",
    "The function `next_step_proposal` to creates a map of the probability of ending up in any position, given the current position, some map parameters, and the size of the map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-20T06:18:30.980Z",
     "iopub.status.busy": "2022-08-20T06:18:30.974Z",
     "iopub.status.idle": "2022-08-20T06:18:31.108Z",
     "shell.execute_reply": "2022-08-20T06:18:31.138Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7fc6b6844400>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 7800 characters]\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "proposal = next_step_proposal(current_i=100, current_j=50, sigma_i=10, sigma_j=5, size=200)\n",
    "plt.matshow(proposal)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "nteract": {
     "transient": {
      "deleting": false
     }
    }
   },
   "source": [
    "The function `create_context_map` creates a context map that tell us regions in the image with a higher probability of being looked at (e.g., very bright spots in an image)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-20T06:18:31.125Z",
     "iopub.status.busy": "2022-08-20T06:18:31.119Z",
     "iopub.status.idle": "2022-08-20T06:18:31.352Z",
     "shell.execute_reply": "2022-08-20T06:18:31.385Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7fc6b68df080>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 47636 characters]\n",
      "text/plain": [
       "<Figure size 288x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "context_map = create_context_map(size=150, map_type='hills')\n",
    "plt.matshow(context_map)\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "nteract": {
     "transient": {
      "deleting": false
     }
    }
   },
   "source": [
    "The function `sample_next_step` calls `next_step_proposal`, combines it with the context map that is passed to it (in `compute_next_step_probability`), and then stochastically selects the next step."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# How to simulate a trajectory\n",
    "\n",
    "in order to use the walker, the user has to create a context map. Then, for a number of timesteps, sample a step, always passing along the new position information."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-20T06:18:31.369Z",
     "iopub.status.busy": "2022-08-20T06:18:31.360Z",
     "iopub.status.idle": "2022-08-20T06:18:32.535Z",
     "shell.execute_reply": "2022-08-20T06:18:32.542Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "i, j = 100, 50  # initial position\n",
    "sigma_i, sigma_j = 3, 4  # parameters of the next step map\n",
    "size = 200  # size of the image\n",
    "context_map = create_context_map(size, 'hills')  # fixed context map\n",
    "\n",
    "# Sample a next step 1000 times\n",
    "trajectory = []\n",
    "for _ in range(1000):\n",
    "    i, j = sample_next_step(i, j, sigma_i, sigma_j, context_map)\n",
    "    trajectory.append((i, j))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-20T06:18:32.556Z",
     "iopub.status.busy": "2022-08-20T06:18:32.553Z",
     "iopub.status.idle": "2022-08-20T06:18:32.670Z",
     "shell.execute_reply": "2022-08-20T06:18:32.701Z"
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 82352 characters]\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_trajectory(trajectory, context_map)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "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.10.11"
  },
  "nteract": {
   "version": "0.28.0"
  },
  "toc": {
   "nav_menu": {
    "height": "83px",
    "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
}
