{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### <p style=\"text-align: right;\"> &#9989; **Put your name here** </p>\n",
    "#### <p style=\"text-align: right;\"> &#9989; Put your group member names here</p>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Day 17 In-Class Assignment: Simulating Superbugs using agent-based modeling\n",
    "\n",
    "<img src=\"https://sites.psu.edu/siowfa16/files/2016/10/Screen-Shot-2016-10-18-at-12.50.26-AM-1egeuzd.png\" width=400px>\n",
    "<p style=\"text-align: right;\">Image from: https://sites.psu.edu/siowfa16/2016/10/18/what-are-superbugs/comment-page-1/</p>\n",
    "\n",
    "1. **Scientific motivation** \n",
    "    - Antibacterial Resistance\n",
    "    - Digital Evolution\n",
    "2. **Modeling tools** \n",
    "    - Agent Based Modeling\n",
    "3. **Programming concepts** \n",
    "    - Object Oriented programming\n",
    "    - Practice breaking down problems\n",
    "4. **Python Programming Concepts** \n",
    "    - Practice with Python objects\n",
    "    \n",
    "    \n",
    "    \n",
    "Design decisions early on can have a large impact on the final project.  Try to make design decisions that are flexible. Do not be afraid to refactor your code (i.e. start over with the design). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Agenda for today's class\n",
    "\n",
    "</p>\n",
    "\n",
    "1. Review Pre-class Assignment\n",
    "1. Problem Description\n",
    "1. Code Stub\n",
    "1. Preview Visualization"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "# 1. Pre-class assignment review\n",
    "\n",
    "Questions about the pre-class?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----\n",
    "# 2. Problem Description\n",
    "\n",
    "In this assignment we are going to build an agent based model to simulate the evolution of bacteria to become resistant to antibiotics.   To refresh your memory, please re-watch the following video that was in your pre-class assignment.  Our goal is to build a simulation that reconstructs this real world experiment. \n",
    "\n",
    "http://www.the-scientist.com/?articles.view/articleNo/46993/title/Giant-Petri-Dish-Displays-Evolution-in-Space-and-Time/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import YouTubeVideo\n",
    "YouTubeVideo(\"yybsSqcB7mE\",width=640,height=360)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To make this ABM work we would like you to build a system with the following assumptions.\n",
    "\n",
    "1. Assume a random rectangular petri dish of ```N``` locations wide and ```M``` locations tall (e.g. 90 x 45).\n",
    "1. Assume that each location on the board is given three (3) different types of antibiotics which each can have continuous values from min to max (e.g. 0 to 1).\n",
    "1. Assume that bacteria on the board do not move. \n",
    "1. Assume each bacteria has a genome sequence of three genes of continuous number (e.g. 0 to 1) that provide immunity to the antibiotics. Each gene will correspond to one of the antibiotic elements deposited on the petri dish\n",
    "1. Assume that at each iteration of the simulation each bacteria can randomly copy itself once to a random neighboring empty cell (up, down, left, or right). \n",
    "1. Assume that during the copy there is a chance of mutating each gene (randomly selecting a new value between zero and one) by some mutation rate (e.g. 20%). \n",
    "1. Assume that a bacteria will \"die\" if the value of it's gene does not contain resistance to any one of the three antibacteria. For example, if the gene is a number less than the value of it's corresponding antibiotic it will die.\n",
    "\n",
    "**NOTE:** Assumptions are very important.  Make sure you document any major changes, clarifications or deviations from the above.  Instead of asking your instructor for clarification, try looking at the end goal (simulate the petri dish experiment) and make your own clarification. There are many right answers.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Question**: What additional assumptions do you think you need to make for this project?  Did you need to modify or add to any of the above assumptions to make the problem more tractable?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font size=8 color=\"#009600\">&#9998;</font> Do This - Erase the contents of this cell and replace it with your answer to the above question!  (double-click on this text to edit this cell, and hit shift+enter to save the text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Consider the following example simulation as one possible solution to this problem."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import YouTubeVideo\n",
    "YouTubeVideo(\"p_wGHmNYE_0\",width=640,height=360)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This video was created with the following settings:\n",
    "\n",
    "* The bugs were initialized in the first and last column of the petri dish with randomly generated bacteria \n",
    "* Equal amounts of all three antibiotics in 9 different bins using the following pattern:  \n",
    "    | 0.0 | 0.50 | 0.75 | 0.80 | 0.90 | 0.80 | 0.75 | 0.5 | 0.0 |\n",
    "* The cells copied with a mutation rate of 20% (i.e. there is a 20% chance each gene will randomly mutate during each copy).\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----\n",
    "# 3. Code Stubs\n",
    "\n",
    "As a group decide on what classes and function that will be needed for the simulation and create stub functions for your classes.  Focus on the inputs, outputs and data types. \n",
    "\n",
    "Here are some hints:\n",
    "- you can use the `pass` keyword to create an empty class or an empty method. However, in creating an empty method you can specify the input parameters which can be useful\n",
    "- you might think about some class variables, values that can be stored and utilized by all instances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Put your stub functions here.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----\n",
    "# 4.  Initialize and draw world"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets start filling in the stub functions by focusing on the visualization. Try considering the following:\n",
    "\n",
    "* Use colors indicating the level of antibiotics in the petri dish. Since there are three antibiotics you can use the Red, Green and Blue Channels to indicate the amount of each of the three antibiotics. The `imshow` function can process a 2D array of RGB values.\n",
    "* Use colors to differentiate the types of the bugs. Since there are three genes you can use the Red, Green and Blue color channels to differentiate them. The `scatter` function can take in a list of RGB values to color a point.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets initialize the problem and see if we can visualize the start state.  See if you can create a board that looks similar to the following:\n",
    "\n",
    "<img src=\"https://i.imgur.com/dWL8CSZ.png\">\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Put your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-----\n",
    "### Congratulations, we're done!\n",
    "\n",
    "Now, you just need to submit this assignment by uploading it to the course <a href=\"https://d2l.msu.edu/\">Desire2Learn</a> web page for today's submission folder (Don't forget to add your names in the first cell).\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "&#169; Copyright  Michigan State University Board of Trustees"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
