Please read ALL the instructions carefully. Read the whole assignment before you begin.
For this assignment, you may use a Python program or a JupyterLab notebook.
NOTE: This HW maybe more challenging. Start early and come to office hours if you need help!
(0) Completion of Labs and Reading
If you have not yet completed the in-class work or the weekly reading, then you may want to finish that first. Recent lecture notes on Collab may also be useful...
(1) Checkout the repository:
Use this link to accept the assignment and create your repository on GitHub: https://classroom.github.com/a/CpoGKYP3
After you accept the assignment and the repository and it exists in your GitHub, clone the repository into your working area on Rivanna.
(2) BITE!!! - A simple simulation using probability distributions and random numbers (9 Points)
For this exercise, you will perform a simulation of a real-world situation. Consider the following, it is a hot and damp August on Grounds and the mosquitoes are very hungry. For any given meter you walk, there are 100 mosquitoes that may draw blood. Fortunately, mosquitoes aren't very well organized, so the probability of a given mosquito biting is only 0.0001. But another 100 mosquitoes await you in the next meter, et cetera…
The basic binomial nature of this problem should be evident (mosquitos either bite you or don't). For each meter, you are “flipping 100 coins with a probability of heads of 0.0001”. Review the slides from the lecture about probability distributions for a more complete understanding.
Perform a discrete simulation of this scenario where you run your program for walks of 200m and 2500m. Start with the program from your repository named bite.py (or you may make a Jupyter Notebook), then use the following guidelines:
- For each meter walked, give each mosquito a chance to bite and count the number of bites (you need to draw a random number from the correct probability distribution)
- Repeat until the entire distance is covered, counting the total number of bites
- Enter the total number of bites in a histogram for the walk
- Repeat the walk many times, say 500, entering the total number for that walk into the histogram each time
- Plot your histogram to the screen and save as a .png file
Write your program so the distance walked is easy to enter at the command line (or if you use a Jupyter Notebook, use the 'input' function in the first block of code to let the user provide the distance walked).
Usage: python bite.py <distance>
Comment on these in your code:
- Compare your plots with the Poisson Distribution and the Gaussian ("Normal") Distribution.
- Which distribution is most similar to each of your plots?
Your program should check “argv” (or the value from the input in Jupyter) to make sure the user has supplied a valid distance value and tell them to add one if they've left it off.
Submit the histograms with your code, where you should have one for the two discrete simulations: bite_200.png and bite_2500.png.
(2) Want to be an A student? (1 pt)
Make a new version of the plots above and draw the relevant probability distribution on the figure. We don't know how to fit yet, so do it by hand (play with the parameters of the functions until it looks good), or use Google and online documentation to figure out how to fit the data. When you get the function to look reasonable, print the value of μ (the mean) on the figure with the probability distribution name and save the files bite_200_mu.png and bite_2500_mu.png. For example if you used a Gaussian: "Gaussian mean=X.XX".
Done? Make sure you answered any questions, then clean up your code and include some useful comments, then post bite.py, bite_200.png, bite_2500.png to GitHub.