diff options
Diffstat (limited to 'sem6')
-rw-r--r-- | sem6/prob/miniexam/Untitled.ipynb | 346 | ||||
-rw-r--r-- | sem6/prob/shell.nix | 1 | ||||
-rw-r--r-- | sem6/prob/stat6/Opgaver.ipynb | 280 |
3 files changed, 627 insertions, 0 deletions
diff --git a/sem6/prob/miniexam/Untitled.ipynb b/sem6/prob/miniexam/Untitled.ipynb new file mode 100644 index 0000000..3d81069 --- /dev/null +++ b/sem6/prob/miniexam/Untitled.ipynb @@ -0,0 +1,346 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from scipy import stats" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 1\n", + "\n", + "Man kan sige at distribution af et enkelt kast af den 8 kantede terning er $1/8$ for hver værdi i $[1, 8]$.\n", + "Ved at summe dem sammen kommer de til at ligne en gaussian random variable.\n", + "\n", + "Man ved også de to limits for distributionen, nemlig $[50 \\cdot 1, 50 \\cdot 8]$, og hver imellem må mean ligge.\n", + "Ud fra intervallet og mean kan man regne varience." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# Man kan først finde størrelsen af intervallet, eller var * 2\n", + "var2 = 50 * 8 - 50 * 1\n", + "sigma2 = var2/2\n", + "mean = 50 * 1 + sigma2\n", + "\n", + "# Ved coin flip får man egentlig det samme distribution" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Part A\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<BarContainer object of 500 artists>" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90b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1S+BHwJ7me6erwf+LMlpepc8P57kn5nunqmqV7vlAvAIvUsiE+25hQDfarfsPwbs69b3AY8uG/9ckvcmuQK4EnhmA+obWnqn2vcCJ6vqnmVPTXPPM92ZN0neD3wCeJEp7rmqvlRVl1XVLL1/r/9WVX/OFPec5ANJLlxaBz4FHGfSPW/0J7cDfrp7M70ZCz8FvrLR9YyxrweAM8D/0fuNfAfw28AR4FS3vGjZ/l/p3oOXgJs2uv4h+v1Dev9NfB441j1unvKefx/4SdfzceCvu/Gp7XlF/zfwm1koU9szvVlyz3WPE0s5NemevZVekhrVwiUUSdIqDHBJapQBLkmNMsAlqVEGuCQ1ygCXpEYZ4JLUqP8HvlS2LghG5EEAAAAASUVORK5CYII=\n", + "text/plain": [ + "<Figure size 432x288 with 1 Axes>" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "slots = np.zeros(500)\n", + "x = np.arange(500)\n", + "for exp in range(1000):\n", + " s = 0\n", + " for i in range(50):\n", + " r = np.random.randint(1, 9)\n", + " #r = [1, 8][np.random.randint(0, 2)]\n", + " s += r\n", + " slots[s] += 1\n", + "\n", + "plt.bar(x, slots)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 2\n", + "\n", + "The distribution function is given by:\n", + "$$\n", + "f(x)_\\theta = \\frac x {\\theta^2} e ^ {- \\frac x \\theta }\n", + "$$\n", + "\n", + "Then we can find the likelyhood function $f(x_1,...,x_n | \\theta)$.\n", + "\n", + "$$\n", + "f(x_1,...,x_n | \\theta) = f(x_1)_\\theta \\cdot ... \\cdot f(x_n)_\\theta = \\frac {\\prod_i x_i} {\\theta^{2n}} \\cdot \\exp \\left( -\\frac {\\sum_i} \\theta \\right)\n", + "$$\n", + "\n", + "Her kan man tage log på hver side\n", + "\n", + "$$\n", + "\\log f(x_1,...,x_n | \\theta) = \\log \\left( \\frac {\\prod_i x_i} {\\theta^{2n}} \\right) - \\frac 1 \\theta \\sum_i x_i\n", + "$$\n", + "\n", + "Og diff i forhold til $\\theta$.\n", + "\n", + "$$\n", + "\\frac d {d\\theta} \\log f(x_1,...,x_n | \\theta) = -\\frac {2n} \\theta + \\frac 1 {\\theta^2} \\sum_i x_i\n", + "$$\n", + "\n", + "Og man kan løse for $0$.\n", + "\n", + "$$\n", + "\\theta = \\frac {\\sum_i x_i} {2n}\n", + "$$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Estimated theta = 1.2944444444444445\n" + ] + } + ], + "source": [ + "# Part B\n", + "# Her indsættes samples\n", + "\n", + "samples = np.array([3.2, 1.4, 6.5, 2.2, 1.8, 2.6, 3.9, 0.5, 1.2])\n", + "N = len(samples)\n", + "\n", + "sum_samples = np.sum(samples)\n", + "\n", + "theta_est = sum_samples / (2 * N)\n", + "print(f\"Estimated theta = {theta_est}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "argmax: 1.2962962962962963\n" + ] + }, + { + "data": { + "text/plain": [ + "[<matplotlib.lines.Line2D at 0x7faf4d186640>]" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEDCAYAAAAlRP8qAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAj/ElEQVR4nO3deXScd33v8fd3NFqsxZK12JYtyWtsx3glirOTACELJKSl0JPALYUbbnALHLhcLnB7Tttzy+npdtsLtKQhDbRwaUlDSblprklCIAtJSLCdeInj2JZ3LbY2S9a+ze/+MTPORJbssT0zz6LP6xxFmplnnueryP74p9/zW8w5h4iIBF/E6wJERCQzFOgiIiGhQBcRCQkFuoh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uisqgWeMbMdhFvtPzMOTcjhvHNMPOAF8xsJ/Br4P85557I5AUCNWxRRESmF6gWuoiITE+BLiISEgp0EZGQUKCLiISEAl1EJCQU6CIiIaFAFxEJif8P0+PrXvkm6SQAAAAASUVORK5CYII=\n", + "text/plain": [ + "<Figure size 432x288 with 1 Axes>" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Prøver lige at løse den programmerbart også\n", + "thetas = np.linspace(0, 5, 1000)[1:]\n", + "res = np.empty(thetas.shape)\n", + "\n", + "for i, theta in enumerate(thetas):\n", + " f = lambda x: ((x / (theta**2)) * np.exp(-x / theta))\n", + " score = 1\n", + " for sample in samples:\n", + " score *= f(sample)\n", + " \n", + " res[i] = score\n", + "\n", + "maxtheta = thetas[np.argmax(res)]\n", + "print(f\"argmax: {maxtheta}\")\n", + "plt.plot(thetas, res)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 3\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [], + "source": [ + "radial = np.array([5.2, 5.7, 7.6, 8.0, 7.7, 5.5, 6.7, 7.0, 8.4, 5.9])\n", + "\n", + "belted = np.array([5.1, 5.9, 7.2, 7.9, 7.8, 5.4, 6.7, 6.8, 7.9, 5.7])\n", + "belted_mean = np.mean(belted)\n", + "N = len(belted)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part A\n", + "\n", + "Here we don't know the varience, and will therefore have to use the t distribution method.\n", + "The interval is given by:\n", + "$$\n", + "\\bar X \\pm t_{\\alpha/2,n-1} \\frac S {\\sqrt{n}}\n", + "$$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Then the interval becomes [6.174311863003706, 7.105688136996291]\n" + ] + } + ], + "source": [ + "alpha = 0.1\n", + "# Lets start by calculating the t value\n", + "tval = stats.t.ppf(1 - alpha, N-1)\n", + "\n", + "S = np.sqrt(np.sum((belted - belted_mean)**2) / (N - 1))\n", + "\n", + "diff = tval * S / np.sqrt(N)\n", + "print(f\"Then the interval becomes [{belted_mean - diff}, {belted_mean + diff}]\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part B\n", + "\n", + "We can take the difference of the two and say that this should be less than or equal to $0$.\n", + "Thus the $H_0$ is $(\\mu_{belted} - \\mu_{radial}) \\leq 0$.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0.1 -0.2 0.4 0.1 -0.1 0.1 0. 0.2 0.5 0.2] 0.12999999999999998\n", + "ts: 1.9475670608117976\n", + "p-value: 0.04164574347828587\n", + "H_0 is accepted, thus radial does not make it better\n" + ] + } + ], + "source": [ + "mu_0 = 0\n", + "alpha = 0.05\n", + "diff = radial - belted\n", + "diff_mean = np.mean(diff)\n", + "print(diff, diff_mean)\n", + "\n", + "S = np.sqrt(np.sum((diff - diff_mean)**2) / (N - 1))\n", + "\n", + "ts = np.sqrt(N) * (diff_mean - mu_0) / S\n", + "print(f\"ts: {ts}\")\n", + "p_value = 1 - stats.t.cdf(ts, N - 1)\n", + "print(f\"p-value: {p_value}\")\n", + "\n", + "if p_value > alpha:\n", + " print(\"H_0 is rejected thus radial tires have better economy\")\n", + "else:\n", + " print(\"H_0 is accepted, thus radial does not make it better\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Part C\n", + "\n", + "Drivers can drive radically different in the way they brake, shift gears and apply power.\n", + "The driver is therefore as important a parameter as the car driven.\n", + "\n", + "When creating such tests it is very important to only change the variable in question, in this case the tires.\n", + "By keeping all other variables the same, one can say that a change in performance likely comes from the other tires." + ] + } + ], + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/sem6/prob/shell.nix b/sem6/prob/shell.nix new file mode 100644 index 0000000..11c21ce --- /dev/null +++ b/sem6/prob/shell.nix @@ -0,0 +1 @@ +import ../../shells/pymath.nix diff --git a/sem6/prob/stat6/Opgaver.ipynb b/sem6/prob/stat6/Opgaver.ipynb new file mode 100644 index 0000000..81a2213 --- /dev/null +++ b/sem6/prob/stat6/Opgaver.ipynb @@ -0,0 +1,280 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from IPython.display import display, Math\n", + "from scipy import stats" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 1\n", + "\n", + "> The following data indicate the relationship between x, the specific gravity of\n", + "a wood sample, and Y , its maximum crushing strength in compression parallel to\n", + "the grain.\n", + "> 1. Plot a scatter diagram. Does the linear relationship seem reasonable\n", + "> 2. Estimate the regression coefficients\n", + "> 3. Predict the maximum crushing strength of a wood sample whose specific gravity is $0.43$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "x_i = np.array([0.41, 0.46, 0.44, 0.47, 0.42, 0.39, 0.41, 0.44, 0.43, 0.44])\n", + "y_i = np.array([1.850, 2.620, 2.340, 2.690, 2.160, 1.760, 2.500, 2.750, 2.730, 3.120])\n", + "x_mean = np.mean(x_i)\n", + "y_mean = np.mean(y_i)\n", + "\n", + "t = np.linspace(np.min(x_i), np.max(x_i))\n", + "\n", + "n = len(x_i)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<matplotlib.collections.PathCollection at 0x7fa6ad4ab2e0>" + ] + }, + "execution_count": 7, + "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rP3nVcDTwI8OKtey+ffxysG0nh47qFxLxnbT/4OiF/P1CvAZ4OPD+PlaI9cE7YNnwDjwVeADw861bPx99Peg6MV8vd4IXLrk9teA64adq33/q8Ce9u3/ABwahVztsc8BN603w0jtoVfV+ST/GjhK60jvp6rqySS/1N5+GPgHwEeSnAMWgH9Y7a8E8ECSNwPngFuq6s8HmKunxw47F0CSz9IqgcuSnAZ+pVq/5Qwz17XAjcBMe70a4M6q+uKQc10OfDrJNlpLlb9bVX05RfBiv48b5SJzvQX4fHtP9BLgd6rqSyOQC1oHJe9vL288C9w0Crnax/7+HvCv1pvBl/5LUkOM2kFRSdI6WeiS1BAWuiQ1hIUuSQ1hoUtSQ1joktQQFrokNcT/B2/O3py1bbiSAAAAAElFTkSuQmCC\n", + "text/plain": [ + "<Figure size 432x288 with 1 Axes>" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Part A\n", + "plt.scatter(x_i, y_i)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A: -2.8259168241966486, B: 12.245746691871574\n" + ] + }, + { + "data": { + "text/plain": [ + "[<matplotlib.lines.Line2D at 0x7fa6ad289250>]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAkWElEQVR4nO3deXzV9Zn28c9NFggkEPYlEGKCgoBAaFwRg7UVd3Gp1bZ2tLWI085Mn+nYjs48M9On01lKp1NnOpNIwSJTrF2k1LF1qNM2IRQQQUAsi3qSsCRhJ4QlIcu5nz9yaCMGyHKS38nJ9X698uLkd74nuchy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sixF4FHO5ohpu6hu3ujmX0BWEXzI73PufvvzGxB5PpC4D7g02bWANQCH/fIRwJ4ycyGAg3A5939WDfmatdtg84FYGY/oLkEhpnZPuBvvfm3nCBzzQIeBrZFzlcDPO3uvwg412jgeTNLoPlU5Y/cPSojgp39PHaVTuYaCfw0ck80EXjB3f8nBnJB84OSyyOnN0qBR2MhV+Sxv48Cj3c0g576LyISJ2LtQVEREekgFbqISJxQoYuIxAkVuohInFChi4jECRW6iEicUKGLiMSJ/w9Xw43AN/vRfQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "<Figure size 432x288 with 1 Axes>" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Part B\n", + "\n", + "S_xY = sum((x * y for (x, y) in zip(x_i, y_i))) - n * x_mean * y_mean\n", + "S_xx = sum((x * x for x in x_i)) - n * x_mean * x_mean\n", + "\n", + "B = S_xY / S_xx\n", + "A = y_mean - B * x_mean\n", + "print(f\"A: {A}, B: {B}\")\n", + "\n", + "plt.scatter(x_i, y_i)\n", + "plt.plot(t, B * t + A)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No 'a' percentage is given, so we just fint the regression value at 0.43\n", + "The predicted maximum strength is 2.4397542533081285\n", + "Wait this makes no sense, 0.43 is in the sample set.b\n" + ] + } + ], + "source": [ + "# Part C\n", + "where = 0.43\n", + "print(f\"No 'a' percentage is given, so we just fint the regression value at {where}\")\n", + "\n", + "print(f\"The predicted maximum strength is {B * where + A}\")\n", + "\n", + "# TODO TODO GET HELP\n", + "print(\"Wait this makes no sense, 0.43 is in the sample set.b\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 2\n", + "\n", + "This seemes like a continuation.\n", + "\n", + "> In Problem 4.\n", + "> 1. Estimate the variance of an individual response.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The estimated variance is 0.10566006616257498\n" + ] + } + ], + "source": [ + "S_YY = sum((y*y for y in y_i)) - n * y_mean * y_mean\n", + "SS_R = (S_xx * S_YY - (S_xY)**2) / S_xx\n", + "sigma2 = SS_R / (n - 2)\n", + "print(f\"The estimated variance is {sigma2}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Problem 3\n", + "\n", + "> The following data set presents the heights of 12 male law school classmates whose\n", + "law school examination scores were roughly equal. It also gives their annual salaries\n", + "5 years after graduation. Each of them went into corporate law. The height is in\n", + "inches and the salary in units of $1,000.\n", + "> 1. Do the above data establish the hypothesis that a lawyer’s salary is related to\n", + "his height? Use the 5 percent level of significance.\n", + "> 2. What was the null hypothesis in part (a)?\n", + "\n", + "\n", + "## Part A\n", + "\n", + "We let the null hypothesis be that there is no relation between the salary and height, thus that $\\beta = 0$." + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "x_i = np.array([64, 65, 66, 67, 69, 70, 72, 72, 74, 74, 75, 76])\n", + "y_i = np.array([91, 94, 88, 103, 77, 96, 105, 88, 122, 102, 90, 114])\n", + "\n", + "alpha = 0.05\n", + "\n", + "n = len(x_i)\n", + "\n", + "x_mean = np.mean(x_i)\n", + "y_mean = np.mean(y_i)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "B: 1.4571428571428193\n", + "TS: 1.7483281067751004\n", + "p_value: 0.11098065306186689\n", + "h_0 is accepted and thus there is no connection, which kind of makes sense.\n" + ] + } + ], + "source": [ + "# Part A\n", + "S_xx = sum((x * x for x in x_i)) - n * x_mean**2\n", + "S_YY = sum((y * y for y in y_i)) - n * y_mean**2\n", + "S_xY = sum((x * y for (x, y) in zip(x_i, y_i))) - n * x_mean * y_mean\n", + "SS_R = (S_xx * S_YY - (S_xY)**2) / S_xx\n", + "\n", + "print(f\"B: {(B := S_xY / S_xx)}\")\n", + "TS = np.sqrt(((n - 2) * S_xx) / SS_R) * np.abs(B)\n", + "print(f\"TS: {TS}\")\n", + "\n", + "p_value = 2 * (1 - stats.t.cdf(TS, n-2))\n", + "print(f\"p_value: {p_value}\")\n", + "if p_value < alpha:\n", + " print(\"h_0 is rejected and there is a connection between salary and height. Why tho\")\n", + "else:\n", + " print(\"h_0 is accepted and thus there is no connection, which kind of makes sense.\") " + ] + } + ], + "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.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} |