Commit 485d4c83 authored by Chanelle Lee's avatar Chanelle Lee
Browse files

Merge branch 'master' of git.brl.ac.uk:c53-lee/BotSimBestOfN

Made changes to botSimMain remotely on desktop but was working on ProbConfusion notbook locally on laptop
parents 048e88bf 420951cf
......@@ -97,9 +97,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-15-9ba2372464a5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0msf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m100\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mss\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlinspace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mconfusions\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mprobConfusion\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mss\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m<ipython-input-15-9ba2372464a5>\u001b[0m in \u001b[0;36m<listcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0msf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m100\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mss\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlinspace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mconfusions\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mprobConfusion\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mss\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m<ipython-input-14-f48366cefba1>\u001b[0m in \u001b[0;36mprobConfusion\u001b[1;34m(i, j, s)\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[0msigma\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0mto\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mtested\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 22\u001b[0m \"\"\"\n\u001b[1;32m---> 23\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mintegrate\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquad\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mintegrand\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m-\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m~\\Anaconda2\\envs\\Py3\\lib\\site-packages\\scipy\\integrate\\quadpack.py\u001b[0m in \u001b[0;36mquad\u001b[1;34m(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)\u001b[0m\n\u001b[0;32m 339\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mweight\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 340\u001b[0m retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,\n\u001b[1;32m--> 341\u001b[1;33m points)\n\u001b[0m\u001b[0;32m 342\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 343\u001b[0m retval = _quad_weight(func, a, b, args, full_output, epsabs, epsrel,\n",
"\u001b[1;32m~\\Anaconda2\\envs\\Py3\\lib\\site-packages\\scipy\\integrate\\quadpack.py\u001b[0m in \u001b[0;36m_quad\u001b[1;34m(func, a, b, args, full_output, epsabs, epsrel, limit, points)\u001b[0m\n\u001b[0;32m 448\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0m_quadpack\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_qagse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfull_output\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mepsabs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mepsrel\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlimit\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 449\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 450\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0m_quadpack\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_qagie\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbound\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0minfbounds\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfull_output\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mepsabs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mepsrel\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlimit\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 451\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 452\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0minfbounds\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m<ipython-input-14-f48366cefba1>\u001b[0m in \u001b[0;36mintegrand\u001b[1;34m(x, i, j, s)\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0msigma\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0mto\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mtested\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \"\"\"\n\u001b[1;32m---> 12\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mqualities\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mF\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mqualities\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mprobConfusion\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m<ipython-input-11-94977a845123>\u001b[0m in \u001b[0;36mf\u001b[1;34m(x, mu, s)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmu\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mscipy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstats\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnorm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmu\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscale\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m~\\Anaconda2\\envs\\Py3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py\u001b[0m in \u001b[0;36mpdf\u001b[1;34m(self, x, *args, **kwds)\u001b[0m\n\u001b[0;32m 1665\u001b[0m \u001b[0mcond\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcond0\u001b[0m \u001b[1;33m&\u001b[0m \u001b[0mcond1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1666\u001b[0m \u001b[0moutput\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mzeros\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcond\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtyp\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1667\u001b[1;33m \u001b[0mputmask\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0moutput\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mcond0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0misnan\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbadvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1668\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0many\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcond\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1669\u001b[0m \u001b[0mgoodargs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0margsreduce\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcond\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mscale\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"s0 = 0.0000001\n",
"sf = 100\n",
......@@ -371,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
......@@ -513,7 +532,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
......@@ -683,7 +702,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
......@@ -851,7 +870,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
......@@ -1017,7 +1036,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
......@@ -1216,7 +1235,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
......@@ -1225,7 +1244,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
......@@ -1240,7 +1259,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
......@@ -1255,9 +1274,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" alpha chance note sigma\n",
"paramSet \n",
"1 0.000000 5% control 0.0717\n",
"2 0.100000 5% control 0.0717\n",
"3 0.200000 5% control 0.0717\n",
"4 0.300000 5% control 0.0717\n",
"5 0.400000 5% control 0.0717\n",
"6 0.050000 5% q2 prob 0.0717\n",
"7 0.006329 5% mean 0.0717\n",
"8 0.000000 10% control 0.0920\n",
"9 0.100000 10% control 0.0920\n",
"10 0.200000 10% control 0.0920\n",
"11 0.300000 10% control 0.0920\n",
"12 0.400000 10% control 0.0920\n",
"13 0.100000 10% q2 prob 0.0920\n",
"14 0.013170 10% mean 0.0920\n"
]
}
],
"source": [
"testParams_DF['paramSet'] = range(1, len(testParams_DF)+1)\n",
"testParams_DF = testParams_DF.set_index('paramSet')\n",
......@@ -1266,7 +1308,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
......
%% Cell type:code id: tags:
``` python
import numpy as np
import scipy
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
```
%% Cell type:markdown id: tags:
# Analysis of the probability of confusing qualities for different values of sigma
%% Cell type:markdown id: tags:
First need the pdf and cdf of the normal distributions which will represent the noise around each of the quality values
%% Cell type:code id: tags:
``` python
def f(x, mu, s):
return scipy.stats.norm.pdf(x, loc=mu, scale=s)
```
%% Cell type:code id: tags:
``` python
def F(x, mu, s):
return scipy.stats.norm.cdf(x, loc=mu, scale=s)
```
%% Cell type:markdown id: tags:
Qualities are set in the interval (0,1) and equally spaced
%% Cell type:code id: tags:
``` python
n = 5
qualities = {i: i/(n+1) for i in range(1, (n+1))} # i is the id of the site with corresponding quality
```
%% Cell type:code id: tags:
``` python
def integrand(x, i, j, s):
"""
x : float
point at which to evaluate the integrand
i : int
id of first site so the quality can be returned as the mean of the pdf
j : int
id of the second site so the quality can be returned as the mean of the cdf
s : float
sigma value to be tested
"""
return f(x, qualities[i], s)*F(x, qualities[j], s)
def probConfusion(i, j, s):
"""
i : int
id of the first site to be confused (will normally always be 1)
j : int
id of the site to be confused with
s : float
sigma value to be tested
"""
return scipy.integrate.quad(integrand, -np.inf, np.inf, args=(i, j, s))
```
%% Cell type:code id: tags:
``` python
s0 = 0.0000001
sf = 100
ss = np.linspace(s0, sf, 1000)
confusions = [probConfusion(1, 2, s)[0] for s in ss]
```
%%%% Output: error
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-15-9ba2372464a5> in <module>
2 sf = 100
3 ss = np.linspace(s0, sf, 1000)
----> 4 confusions = [probConfusion(1, 2, s)[0] for s in ss]
<ipython-input-15-9ba2372464a5> in <listcomp>(.0)
2 sf = 100
3 ss = np.linspace(s0, sf, 1000)
----> 4 confusions = [probConfusion(1, 2, s)[0] for s in ss]
<ipython-input-14-f48366cefba1> in probConfusion(i, j, s)
21 sigma value to be tested
22 """
---> 23 return scipy.integrate.quad(integrand, -np.inf, np.inf, args=(i, j, s))
~\Anaconda2\envs\Py3\lib\site-packages\scipy\integrate\quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
339 if weight is None:
340 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
--> 341 points)
342 else:
343 retval = _quad_weight(func, a, b, args, full_output, epsabs, epsrel,
~\Anaconda2\envs\Py3\lib\site-packages\scipy\integrate\quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
448 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
449 else:
--> 450 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
451 else:
452 if infbounds != 0:
<ipython-input-14-f48366cefba1> in integrand(x, i, j, s)
10 sigma value to be tested
11 """
---> 12 return f(x, qualities[i], s)*F(x, qualities[j], s)
13
14 def probConfusion(i, j, s):
<ipython-input-11-94977a845123> in f(x, mu, s)
1 def f(x, mu, s):
----> 2 return scipy.stats.norm.pdf(x, loc=mu, scale=s)
~\Anaconda2\envs\Py3\lib\site-packages\scipy\stats\_distn_infrastructure.py in pdf(self, x, *args, **kwds)
1665 cond = cond0 & cond1
1666 output = zeros(shape(cond), dtyp)
-> 1667 putmask(output, (1-cond0)+np.isnan(x), self.badvalue)
1668 if np.any(cond):
1669 goodargs = argsreduce(cond, *((x,)+args+(scale,)))
KeyboardInterrupt:
%% Cell type:code id: tags:
``` python
plt.plot(ss, confusions)
```
%%%% Output: execute_result
[<matplotlib.lines.Line2D at 0x96b9198>]
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:code id: tags:
``` python
ss = np.linspace(0.0000001, 10, 1000)
confusions = [probConfusion(1, 2, s)[0] for s in ss]
plt.plot(ss, confusions)
```
%%%% Output: execute_result
[<matplotlib.lines.Line2D at 0x9943c50>]
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:code id: tags:
``` python
ss = np.linspace(0.0000001, 10, 1000)
confusions = [[probConfusion(1, j, s)[0] for s in ss] for j in [2, 3, 4, 5]]
for confusion in confusions:
plt.plot(ss, confusion)
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:code id: tags:
``` python
ss = np.linspace(0.0000001, 10, 1000)
confusions = [[probConfusion(1, j, s)[0] for s in ss] for j in [2, 3, 4, 5]]
for confusion in confusions:
plt.plot(ss, confusion)
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:code id: tags:
``` python
ss = np.linspace(0.0000001, 5, 10000)
confusions = [[probConfusion(1, j, s)[0] for s in ss] for j in [2, 3, 4, 5]]
for confusion in confusions:
plt.plot(ss, confusion)
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:code id: tags:
``` python
d = {'sigma':ss, **{'q{}'.format(j): confusions[i] for i, j in enumerate([2, 3, 4, 5])}}
```
%% Cell type:code id: tags:
``` python
df = pd.DataFrame(data=d)
```
%% Cell type:code id: tags:
``` python
df.tail()
```
%%%% Output: execute_result
sigma q2 q3 q4 q5
9995 4.9980 0.490594 0.481193 0.471803 0.462428
9996 4.9985 0.490595 0.481195 0.471806 0.462432
9997 4.9990 0.490596 0.481197 0.471808 0.462436
9998 4.9995 0.490597 0.481199 0.471811 0.462439
9999 5.0000 0.490598 0.481201 0.471814 0.462443
%% Cell type:markdown id: tags:
## Investigating suitable noise ranges wrt q2:
%% Cell type:code id: tags:
``` python
noiseDict = {}
```
%% Cell type:markdown id: tags:
### 2.5% noise:
%% Cell type:code id: tags:
``` python
df.loc[(df['q2'] >= 0.025)].head()
```
%%%% Output: execute_result
sigma q2 q3 q4 q5
121 0.060506 0.025722 0.000049 2.733868e-09 3.208290e-15
122 0.061006 0.026693 0.000056 3.629824e-09 5.322023e-15
123 0.061506 0.027677 0.000064 4.787065e-09 8.720838e-15
124 0.062006 0.028675 0.000072 6.272245e-09 1.412178e-14
125 0.062506 0.029686 0.000081 8.166519e-09 2.260656e-14
%% Cell type:code id: tags:
``` python
print(probConfusion(1, 2, 0.060)[0])
print(probConfusion(1, 2, 0.0601)[0])
print(probConfusion(1, 2, 0.0602)[0])
print(probConfusion(1, 2, 0.0605)[0])
```
%%%% Output: stream
0.02475429167307887
0.02494433498561147
0.025134962669580048
0.02571031960745227
%% Cell type:markdown id: tags:
So sigma = 0.0602 is a sensible choices when the target is to have a 2.5% confusion with q2. (3sf accuracy to confusion)
%% Cell type:code id: tags:
``` python
noiseDict[2.5] = 0.0602
```
%% Cell type:code id: tags:
``` python
sns.lineplot(data=df.where(df['sigma'] <= 0.15).set_index('sigma'));
# plotting the values of sigma
plt.axvline(0.0602, alpha=0.3, color='grey');
# plotting P = 0.025
plt.axhline(0.025, alpha=0.3, color='grey');
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:markdown id: tags:
### 5% noise:
%% Cell type:code id: tags:
``` python
df.loc[(df['q2'] >= 0.05)].head()
```
%%%% Output: execute_result
sigma q2 q3 q4 q5
144 0.072007 0.050851 0.000531 4.554609e-07 2.935573e-11
145 0.072507 0.052042 0.000576 5.410073e-07 3.969403e-11
146 0.073007 0.053238 0.000622 6.404128e-07 5.334540e-11
147 0.073507 0.054439 0.000672 7.555478e-07 7.126576e-11
148 0.074007 0.055645 0.000724 8.884804e-07 9.465574e-11
%% Cell type:code id: tags:
``` python
print(probConfusion(1, 2, 0.0715)[0])
print(probConfusion(1, 2, 0.0716)[0])
print(probConfusion(1, 2, 0.0717)[0])
print(probConfusion(1, 2, 0.072)[0])
print(probConfusion(1, 2, 0.0725)[0])
```
%%%% Output: stream
0.049648889742545464
0.04988543051051232
0.050122205690951147
0.050833911844210954
0.05202453716771595
%% Cell type:markdown id: tags:
So sigma = 0.0717 is a sensible choices when the target is to have a 5% confusion with q2. (3sf accuracy to confusion)
%% Cell type:code id: tags:
``` python
noiseDict[5] = 0.0717
```
%% Cell type:code id: tags:
``` python
sns.lineplot(data=df.where(df['sigma'] <= 0.25).set_index('sigma'));
# plotting the values of sigma
plt.axvline(0.0717, alpha=0.3, color='grey');
# plotting P = 0.1
plt.axhline(0.05, alpha=0.3, color='grey');
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:markdown id: tags:
### 7.5% noise:
%% Cell type:code id: tags:
``` python
df.loc[(df['q2']) >= 0.075].head()
```
%%%% Output: execute_result
sigma q2 q3 q4 q5
164 0.082008 0.075350 0.002026 0.000008 4.518469e-09
165 0.082508 0.076595 0.002140 0.000009 5.548921e-09
166 0.083008 0.077840 0.002259 0.000010 6.789574e-09
167 0.083508 0.079086 0.002383 0.000011 8.278111e-09
168 0.084008 0.080331 0.002510 0.000013 1.003532e-08
%% Cell type:code id: tags:
``` python
print(probConfusion(1, 2, 0.080)[0])
print(probConfusion(1, 2, 0.081)[0])
print(probConfusion(1, 2, 0.0815)[0])
print(probConfusion(1, 2, 0.082)[0])
```
%%%% Output: stream
0.07035676242634634
0.07284124411849473
0.07408493545579492
0.0753293217492284
%% Cell type:markdown id: tags:
So sigma = 0.082 is a sensible choice when the target is to have a 7.5% confusion with q2. (3sf accuracy to confusion)
%% Cell type:code id: tags:
``` python
noiseDict[7.5] = 0.082
```
%% Cell type:code id: tags:
``` python
sns.lineplot(data=df.where(df['sigma'] <= 0.5).set_index('sigma'));
# plotting the values of sigma
plt.axvline(0.082, alpha=0.3, color='grey');
# plotting P = 0.075
plt.axhline(0.075, alpha=0.3, color='grey');
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:markdown id: tags:
### 10% noise:
%% Cell type:code id: tags:
``` python
df.loc[(df['q2'] >= 0.1)].head()
```
%%%% Output: execute_result
sigma q2 q3 q4 q5
184 0.092009 0.100121 0.005208 0.000061 1.500021e-07
185 0.092509 0.101343 0.005419 0.000066 1.736816e-07
186 0.093009 0.102562 0.005636 0.000072 2.006357e-07
187 0.093509 0.103778 0.005857 0.000078 2.312503e-07
188 0.094009 0.104992 0.006084 0.000085 2.659477e-07
%% Cell type:code id: tags:
``` python
print(probConfusion(1, 2, 0.0915)[0])
print(probConfusion(1, 2, 0.092)[0])
print(probConfusion(1, 2, 0.095)[0])
```
%%%% Output: stream
0.09887463613021713
0.10009849345738388
0.10738819470991004
%% Cell type:markdown id: tags:
So sigma = 0.092 is a sensible choice when the target is to have a 10% confusion with q2. (3sf accuracy to confusion)
%% Cell type:code id: tags:
``` python
noiseDict[10] = 0.092
```
%% Cell type:code id: tags:
``` python
sns.lineplot(data=df.where(df['sigma'] <= 0.5).set_index('sigma'));
# plotting the values of sigma
plt.axvline(0.092, alpha=0.3, color='grey');
# plotting P = 0.1
plt.axhline(0.1, alpha=0.3, color='grey');
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:markdown id: tags:
### 25% noise:
%% Cell type:code id: tags:
``` python
df.loc[(df['q2'] >= 0.25)].head()
```
%%%% Output: execute_result
sigma q2 q3 q4 q5
350 0.175018 0.250357 0.089033 0.021686 0.003536
351 0.175518 0.250967 0.089653 0.021987 0.003618
352 0.176018 0.251575 0.090272 0.022289 0.003701
353 0.176518 0.252180 0.090891 0.022592 0.003786
354 0.177018 0.252783 0.091509 0.022898 0.003872
%% Cell type:code id: tags:
``` python
print(probConfusion(1, 2, 0.17)[0])
print(probConfusion(1, 2, 0.1725)[0])
print(probConfusion(1, 2, 0.175)[0])
```
%%%% Output: stream
0.24407886543949514
0.24724182921706586
0.2503352846480645
%% Cell type:markdown id: tags:
So sigma = 0.175 is a sensible choice when the target is to have a 25% confusion with q2. (3sf accuracy to confusion)
%% Cell type:code id: tags:
``` python
sns.lineplot(data=df.where(df['sigma'] <= 0.5).set_index('sigma'));
# plotting the values of sigma
plt.axvline(0.175, alpha=0.3, color='grey');
# plotting P = 0.25
plt.axhline(0.25, alpha=0.3, color='grey');
```
%%%% Output: display_data
[Hidden Image Output]
%% Cell type:markdown id: tags:
### Creating test parameters dataframe
%% Cell type:code id: tags:
``` python
testParams_DF = pd.DataFrame(columns=['sigma', 'alpha', 'chance', 'note'])
```
%% Cell type:code id: tags:
``` python
desProb = 5
testParams_DF = testParams_DF.append([{'sigma': noiseDict[desProb], 'alpha': alpha, 'chance': '{}%'.format(desProb), 'note': 'control'} for alpha in [0, 0.1, 0.2, 0.3, 0.4]], sort=True)
testParams_DF = testParams_DF.append([{'sigma': noiseDict[desProb], 'alpha': desProb/100, 'chance': '{}%'.format(desProb), 'note': 'q2 prob'}], sort=True)
testParams_DF = testParams_DF.append([{'sigma': noiseDict[desProb],
'alpha': np.mean([probConfusion(1, i, noiseDict[desProb]) for i in [2, 3, 4, 5]]),
'chance': '{}%'.format(desProb),
'note': 'mean'}], sort=True)
```
%% Cell type:code id: tags:
``` python
desProb = 10
testParams_DF = testParams_DF.append([{'sigma': noiseDict[desProb], 'alpha': alpha, 'chance': '{}%'.format(desProb), 'note': 'control'} for alpha in [0, 0.1, 0.2, 0.3, 0.4]], sort=True)
testParams_DF = testParams_DF.append([{'sigma': noiseDict[desProb], 'alpha': desProb/100, 'chance': '{}%'.format(desProb), 'note': 'q2 prob'}], sort=True)
testParams_DF = testParams_DF.append([{'sigma': noiseDict[desProb],
'alpha': np.mean([probConfusion(1, i, noiseDict[desProb]) for i in [2, 3, 4, 5]]),
'chance': '{}%'.format(desProb),
'note': 'mean'}], sort=True)
```
%% Cell type:code id: tags:
``` python
testParams_DF['paramSet'] = range(1, len(testParams_DF)+1)
testParams_DF = testParams_DF.set_index('paramSet')
print(testParams_DF)
```
%%%% Output: stream
alpha chance note sigma
paramSet
1 0.000000 5% control 0.0717
2 0.100000 5% control 0.0717
3 0.200000 5% control 0.0717
4 0.300000 5% control 0.0717
5 0.400000 5% control 0.0717
6 0.050000 5% q2 prob 0.0717
7 0.006329 5% mean 0.0717
8 0.000000 10% control 0.0920
9 0.100000 10% control 0.0920
10 0.200000 10% control 0.0920
11 0.300000 10% control 0.0920
12 0.400000 10% control 0.0920
13 0.100000 10% q2 prob 0.0920
14 0.013170 10% mean 0.0920
%% Cell type:code id: tags:
``` python
testParams_DF.to_csv('testParams.csv')
```
%% Cell type:code id: tags:
``` python
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment