{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Homework 6\n", "====\n", "#### CHE 116: Numerical Methods and Statistics\n", "\n", "2/22/2018\n", "\n", "----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Review Questions (10 Points)\n", "=====\n", "\n", "1. [1 point] A probability mass function must give a positive number for each element in the sample space and $\\underline{\\hspace{0.5in}}$?\n", "\n", "2. [1 point] Which of these are invalid sample spaces and which are valid: $\\{1,3,-2\\}$, $\\{A, B\\}$, $\\{\\textrm{Ace of hearts}, \\textrm{king of diamonds}\\}$, all real numbers.\n", "\n", "3. [1 point] What rule allows me to rewrite $P(x \\,|\\,y)P(y)$ as $P(x, y)$?\n", "\n", "4. [2 points] If there is a 10% chance of rain for 3 days in a row, what's the probability of there being rain at least once within those days?\n", "\n", "5. [2 points] Harry says that expected value is like an average, so you can compute two ways: $ E[X] = \\sum_i^N \\frac{x_i}{N} $ and the way we learned in class: $E[X] = \\sum_i P(x) \\cdot x$. Is Harry correct or is there an issue with his logic?\n", "\n", "6. [1 point] How many elements will I have in my list if I create it using `list(range(5,8))`?\n", "\n", "7. [2 points] In the binomial distribution, we only consider number of successes. Let's try considering each permutation as unique. For example, if $N = 3$ and $n = 1$, you could have $100$, $010$, and $001$. If $N = 10$, how many unique permutations are possible for all numbers of successes? Review your HW 5, questions 1.2-1.5. \n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Marginal Probability Review (19 Points)\n", "===\n", "\n", "You are a baby being carried in a stork to your parents. Your parents live in either:\n", "\n", "1. USA (u, 320)\n", "2. China (c, 1300)\n", "3. Germany (g, 80)\n", "\n", "The probability of your birth location is proportional to the populations. As a baby, you are concerned with your career options, which are\n", "\n", "1. Rock star (r)\n", "2. Professor (p)\n", "3. Doctor (d)\n", "\n", "Answer the following using $B$ as the random variable for birthplace and $J$ as the random variable for job. We have the following information:\n", "\n", "$$P(J = r \\,|\\, B = c) = 0.05$$\n", "\n", "$$P(J = d \\,|\\, B = c) = 0.5$$\n", "\n", "$$P(J = r \\,|\\, B = u) = 0.8$$\n", "\n", "$$P(J = p\\,|\\, B = u) = 0.01$$\n", "\n", "$$P(J = p\\,|\\, B = g) = 0.75$$\n", "\n", "$$P(J = d \\,|\\, B = g) = 0.2$$\n", "\n", "0. [2 point] Write out the missing conditionals and marginal probabilities.\n", "1. [4 points] What is the probability that you will be a professor?\n", "2. [3 points] What is the probability that you will be a rock star born in China?\n", "3. [2 point] You were born in Germany. What's the probability of becoming a doctor?\n", "4. [4 points] Consider the random variable $Z$, which indicates if you are a doctor or rockstar (true for $J=d$ and $J=r$). What is $P(Z = 1 \\,|\\, B=u)$?\n", "5. [4 points] What is $P(B=g \\,|\\, Z = 0)$? Find a way to re-use the calculation you did in 2.2 to help" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. Plotting Probability Distributions (18 Points)\n", "===\n", "\n", "*Label your axes, add a title, and use LaTeX in your labels when necessary. Use dots connected by lines for discrete and lines for continuous.*\n", "\n", "1. [6 points] Plot three different parameter of the geometric distribution: $p = 0.2, p = 0.5, p = 0.8$. Add vertical lines at their means. Extra credit: accomplish the plot of the three lines using a `for` loop.\n", "\n", "2. [4 points] Plot the binomial distribution for $N = 25, p = 0.7$. Recall that the Poisson is an approximation to the Binomial. Plot the Poisson approximation to this Binomial distribution on the same plot. \n", "\n", "3. [2 points] Make a second plot with the binomial and Poisson, but use $N = 25, p = 0.10$. How good is the approximation? \n", "\n", "4. [6 points] The command `plt.fill_between` can be used to plot an area under a curve. For example, `fill_between(x, 0, y)` will fill the area between 0 and `y`, where `y` could be a `numpy` array. Using `fill_between`, show the cumulative probability function for the exponential distribution from $t = 0$ to $t = 5$ with $\\lambda = 0.25$. Ensure that there are two lines on your plot: one that is the exponential pdf and one that is the `fill_between`. The pdf should extend further than your `fill_between` line. Add a vertical line at $t=5$. No legend necessary." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. Prediction Intervals and Loops (19 Points + 12 EC)\n", "===\n", "\n", "1. [1 point] \"The 95% prediction interval for a geometric probability distribution\" can be described with what mathematical equation? Answer as a $\\LaTeX$ equation. \n", "\n", "1. [6 points] Using a `for` loop, compute a lower (starting at 0) 90% prediction interval for the binomial distribution with $N = 12, p = 0.3$. \n", "\n", "2. [6 points] Using a `for` loop, compute an upper (ending at N) 95% prediction interval for the binomial distribution with $N = 20, p = 0.6$.\n", "\n", "3. [6 points] Using a `for` loop, compute a 80% prediction interval for the geomemtric distribution for $p = 0.02$. Just pick a large number for the upper-bound of the `for` loop. \n", "\n", "4. [12 Extra Credit Points]. Repeat 4.3 using a `while` loop. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. Normal Distribution (8 Points)\n", "====\n", "*Use scipy.stats here as needed. Except for 5.1 and 5.3, answer in Python*.\n", "\n", "1. [2 points] In the $Z$-score equation $ Z = (x - \\mu) / \\sigma$, what is $x$?\n", "2. [1 point] What is $P(x < -2)$ for a *standard* normal distribution?\n", "3. [1 point] What is $P(x > 2)$ for a standard normal distribution? Use your knowledge of probability expression, not `scipy.stats` to answer this one.\n", "4. [2 points] Given that $\\mu = 2$, $\\sigma = 1.2$, what is the probability of observing a sample between -2 and 0? Answer using a $Z$-score.\n", "\n", "5. [2 points] Given that $\\mu = 2$, $\\sigma = 1.2$, what is the probability of observing a sample between -2 and 0? Answer *without* using a $Z$-score." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "6. Sentiment (6 Points)\n", "===\n", "*Answer in 1-2 sentences. No correct answer, just give an honest, meaningful answer to receive credit.*\n", "\n", "1. Why is probability important to know as a chemical engineer?\n", "\n", "2. Do you feel confident in understanding probability expressions, like conditionals and marginals?\n", "\n", "4. Can you imagine yourself using Python in your fluid mechanics or other courses?\n", "\n", "5. What topic are you most confident in?\n", "\n", "6. Do you have any feedback for the course?" ] } ], "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.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }