|
797 | 797 | " label = \"$N$: %d, $p$: %.1f\"%(N,p), \n", |
798 | 798 | " linewidth=3)\n", |
799 | 799 | " \n", |
800 | | - "\n", |
801 | 800 | "plt.legend(loc=\"upper left\")\n", |
802 | 801 | "plt.xlim(0, 10.5)\n", |
803 | 802 | "plt.xlabel(\"$k$\")\n", |
|
1341 | 1340 | "\n", |
1342 | 1341 | "def logistic( x, beta):\n", |
1343 | 1342 | " return 1.0/( 1.0 + np.exp( beta*x) )\n", |
| 1343 | + "\n", |
1344 | 1344 | "x = np.linspace( -4, 4, 100 )\n", |
1345 | 1345 | "plt.plot(x, logistic( x, 1), label = r\"$\\beta = 1$\")\n", |
1346 | 1346 | "plt.plot(x, logistic( x, 3), label = r\"$\\beta = 3$\")\n", |
|
1430 | 1430 | "collapsed": false, |
1431 | 1431 | "input": [ |
1432 | 1432 | "import scipy.stats as stats\n", |
| 1433 | + "\n", |
1433 | 1434 | "nor = stats.norm\n", |
1434 | 1435 | "x = np.linspace( -8, 7, 150 )\n", |
1435 | 1436 | "mu = (-2, 0, 3)\n", |
|
1442 | 1443 | " label =\"$\\mu = %d,\\;\\\\tau = %.1f$\"%(_mu, _tau), color = _color )\n", |
1443 | 1444 | " plt.fill_between( x, nor.pdf( x, _mu, scale =1./_tau ), color = _color, \\\n", |
1444 | 1445 | " alpha = .33)\n", |
1445 | | - " \n", |
1446 | | - "\n", |
1447 | 1446 | "\n", |
1448 | 1447 | "plt.legend(loc = \"upper right\")\n", |
1449 | 1448 | "plt.xlabel(\"$x$\")\n", |
|
1634 | 1633 | "collapsed": false, |
1635 | 1634 | "input": [ |
1636 | 1635 | "figsize( 12.5, 4)\n", |
| 1636 | + "\n", |
1637 | 1637 | "plt.plot( t, mean_prob_t, lw = 3, label = \"average posterior \\nprobability \\\n", |
1638 | 1638 | "of defect\")\n", |
1639 | 1639 | "plt.plot( t, p_t[0, :], ls=\"--\",label=\"realization from posterior\" )\n", |
|
1671 | 1671 | "collapsed": false, |
1672 | 1672 | "input": [ |
1673 | 1673 | "from scipy.stats.mstats import mquantiles\n", |
| 1674 | + "\n", |
1674 | 1675 | "# vectorized bottom and top 5% quantiles for \"confidence interval\"\n", |
1675 | 1676 | "qs = mquantiles(p_t,[0.05,0.95],axis=0)\n", |
1676 | 1677 | "plt.fill_between(t[:,0],*qs,alpha = 0.7,\n", |
|
1723 | 1724 | "collapsed": false, |
1724 | 1725 | "input": [ |
1725 | 1726 | "figsize(12.5, 2.5)\n", |
| 1727 | + "\n", |
1726 | 1728 | "prob_31 = logistic( 31, beta_samples, alpha_samples )\n", |
1727 | 1729 | "\n", |
1728 | 1730 | "plt.xlim( 0.995, 1)\n", |
|
1768 | 1770 | "simulated = mc.Bernoulli( \"bernoulli_sim\", p)\n", |
1769 | 1771 | "N = 10000\n", |
1770 | 1772 | "\n", |
1771 | | - "\n", |
1772 | 1773 | "mcmc = mc.MCMC( [simulated, alpha, beta, observed ] )\n", |
1773 | 1774 | "mcmc.sample( N )" |
1774 | 1775 | ], |
|
1798 | 1799 | "collapsed": false, |
1799 | 1800 | "input": [ |
1800 | 1801 | "figsize(12.5, 5)\n", |
| 1802 | + "\n", |
1801 | 1803 | "simulations = mcmc.trace(\"bernoulli_sim\")[:]\n", |
1802 | 1804 | "print simulations.shape\n", |
1803 | 1805 | "\n", |
|
1962 | 1964 | "cell_type": "code", |
1963 | 1965 | "collapsed": false, |
1964 | 1966 | "input": [ |
1965 | | - "figsize( 11., 1.5 )\n", |
1966 | 1967 | "from separation_plot import separation_plot\n", |
1967 | 1968 | "\n", |
| 1969 | + "figsize( 11., 1.5 )\n", |
| 1970 | + "\n", |
1968 | 1971 | "separation_plot(posterior_probability, D )" |
1969 | 1972 | ], |
1970 | 1973 | "language": "python", |
|
2071 | 2074 | "input": [ |
2072 | 2075 | "#type your code here.\n", |
2073 | 2076 | "figsize(12.5, 4 )\n", |
| 2077 | + "\n", |
2074 | 2078 | "plt.scatter( alpha_samples, beta_samples, alpha = 0.1 )\n", |
2075 | 2079 | "plt.title( \"Why does the plot look like this?\" )\n", |
2076 | 2080 | "plt.xlabel( r\"$\\alpha$\")\n", |
|
0 commit comments