Skip to content

Instantly share code, notes, and snippets.

@gaulinmp
Created November 15, 2021 16:23
Show Gist options
  • Save gaulinmp/915f04f79a965911a68f729f050e35c5 to your computer and use it in GitHub Desktop.
Save gaulinmp/915f04f79a965911a68f729f050e35c5 to your computer and use it in GitHub Desktop.
Normal dist question
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Imports\n",
"import numpy as np\n",
"from scipy.stats import norm\n",
"import pandas as pd\n",
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Set up constants\n",
"MEAN = 1000\n",
"VARIANCE = 2500\n",
"STD_DEV = np.sqrt(VARIANCE)\n",
"\n",
"TOLERANCE = .1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solve Analytically\n",
"\n",
"The question asks what portion of resistors from a normal process: $\\Phi(1000, 2500)$ will lie within 10% of 1,000, or between 900 and 1,100.\n",
"Because the distribution does not have skewness and is symmetrical, this is the same as asking how many resistors would fall below 900, then multiplying by 2.\n",
"\n",
"Note: The variance is 2,500, meaning the standard deviation is 50, so 10% tolerance is outside 2 stdev. So knowing from significance testing that 95% is about 1.96 stdev, we can guess the answer will be about 5%."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Probability of a resistor being below 900 ohms: 0.023\n",
"Probability of a resistor being below 900 ohms OR greater than 1,100 ohms = *2: 0.046\n"
]
}
],
"source": [
"# CDF is cumulative density, i.e. 'area to the left of X', which is what we want.\n",
"prob_below_900 = norm.cdf(MEAN - (TOLERANCE * MEAN), loc=MEAN, scale=STD_DEV)\n",
"\n",
"print(f\"Probability of a resistor being below 900 ohms: {prob_below_900:.3f}\")\n",
"print(f\"Probability of a resistor being below 900 ohms OR greater than 1,100 ohms = *2: {prob_below_900*2:.3f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solve empirically\n",
"\n",
"We can also simulate a bunch of these resistors, then just add up how many fail.\n",
"I prefer this method because I'm bad at math."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ohms</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>981.348547</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ohms\n",
"0 981.348547"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"simulated_resistors = pd.DataFrame(norm.rvs(loc=MEAN, scale=STD_DEV, size=100_000), columns=['ohms'])\n",
"simulated_resistors.head(1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEWCAYAAABMoxE0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAl20lEQVR4nO3de5xeVX3v8c/XREK4hHCRKSTRBInUhFgLI41aPVOihQol2EqNjRJOaXNEpF7iBbTnqD1NBStVKQfaVCgBKZhSlNgWBUNHtE2IQdEQICaSQIZEIuBARiRmht/5Y62RnSfPXDL7uczl+3695jX7+e219157zZ79e9a+KiIwMzMbqhc1uwJmZjayOZGYmVkpTiRmZlaKE4mZmZXiRGJmZqU4k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zAMeJD2GZVEuswi4LQ+vBBZImiBpBunE89oG17mhJB2df78U+APgJtw+lfarPfLhr12S5ubt7tzCNGOJ24f08j7go8BZEfFsYdTwaZ9mX6Uw3H+ATwEPkc4H3EC6QuJIYBXp2/cq4IhC+Y+Trp7YyCi5kmSA9vk26f0vPwDm5diYbR9SIt0B7CF9Mzx/KO0BtOZt7sfAleSnUIz0nz7a5615eDfwOPANt89e7bOZdC7kvvzz98OtffyIFDMzK8WHtszMrBQnEjMzK8WJxMzMSnEiMTOzUpxIzMysFCcSszqQNFXSbfmJvz+W9AVJB0g6T9KVza6fWS05kZjVWL4J7FbgqxExE3gFcAiwtKkVM6sTJxKz2jsVeC4i/gkgInqAD5AeuHcQcKykr+feymd6J5LUJekySfdK+qakUyS1S3pY0lm5zGxJayXdl99PMbMJ62e2FycSs9qbDdxbDETEM6RH7owHXg28HZgDvF1S7/OSDgbaI+JkYBfwV8CbSXd+/2Uu827gCxHxatLdy8WnvJo1xfhmV8BsFBLVn7baG18VEU8DSHoAeBnpERi/JD1FGWA9sDsi9khaD0zP8dXAxyVNBW6NiE11WwuzQXKPxKz2NpB6C78iaRLpSa09pGdK9erhhS90e+KFZxY931suIp7vLRMR/wycBfwC+IakU+u0DmaD5kRiVnurgIMknQsgaRxwOXAd8Gw/0w1I0nHAwxFxBenpr68qV1Wz8pxIzGos9yreCpwjaRPwI+A54GM1mP3bgfsl3Qf8Ouk1qmZN5af/mplZKe6RmJlZKU4kZmZWihOJmZmV4kRiZmalOJGYmVkpTiRmZlaKE4mZmZXy/wHlfmwKFm0cqwAAAABJRU5ErkJggg==",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"simulated_resistors.ohms.hist(bins=20)\n",
"# Plot our bounds\n",
"plt.axvline((1 - TOLERANCE) * MEAN, color='black')\n",
"plt.axvline((1 + TOLERANCE) * MEAN, color='black')\n",
"plt.xlabel('Ohms')\n",
"plt.ylabel(\"Count\")\n",
"_ = plt.title(\"Histogram of Ohms for simulated resistors\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can just count up what portion of the resistors fall outside the tollerance:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number out of tolerance: 4,634\n",
"Portion out of tolerance: 0.046\n"
]
}
],
"source": [
"# outside tolerance is just NOT inside tolerance :)\n",
"num_outside_tolerance = len(simulated_resistors[~simulated_resistors.ohms.between((1 - TOLERANCE) * MEAN, (1 + TOLERANCE) * MEAN)])\n",
"\n",
"print(f\"Number out of tolerance: {num_outside_tolerance:,d}\")\n",
"print(f\"Portion out of tolerance: {num_outside_tolerance / len(simulated_resistors):.3f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Same answer! Go simulations.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "22b1d2e947589d08d1a8a0ceb6394177e0f3285f1d9bca1e991c833e07e20449"
},
"kernelspec": {
"display_name": "Python 3.8.10 64-bit ('notebooks': conda)",
"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.8.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment