Rewrite funcs/calls to fix interactive output [02]

This commit is contained in:
jEzEk 2020-01-20 15:44:57 +01:00
parent a954974bc1
commit 5e0d219a21

View File

@ -1220,25 +1220,28 @@
" return priors, posteriors\n",
"\n",
"\n",
"def plot_posterior(posteriors, i):\n",
"def plot_posterior(hallway, posteriors, i):\n",
" plt.title('Posterior')\n",
" book_plots.bar_plot(hallway, c='k')\n",
" book_plots.bar_plot(posteriors[i], ylim=(0, 1.0))\n",
" plt.axvline(i % len(hallway), lw=5) \n",
" \n",
"def plot_prior(priors, i):\n",
"def plot_prior(hallway, priors, i):\n",
" plt.title('Prior')\n",
" book_plots.bar_plot(hallway, c='k')\n",
" book_plots.bar_plot(priors[i], ylim=(0, 1.0), c='#ff8015')\n",
" plt.axvline(i % len(hallway), lw=5) \n",
"\n",
"def animate_discrete_bayes(step):\n",
" step -= 1\n",
" i = step // 2 \n",
" if step % 2 == 0:\n",
" plot_prior(priors, i)\n",
" else:\n",
" plot_posterior(posteriors, i)"
"def animate_discrete_bayes(hallway, priors, posteriors):\n",
" def animate(step):\n",
" step -= 1\n",
" i = step // 2 \n",
" if step % 2 == 0:\n",
" plot_prior(hallway, priors, i)\n",
" else:\n",
" plot_posterior(hallway, posteriors, i)\n",
" \n",
" return animate"
]
},
{
@ -1278,7 +1281,7 @@
"zs = [hallway[i % len(hallway)] for i in range(50)]\n",
"\n",
"priors, posteriors = discrete_bayes_sim(prior, kernel, zs, z_prob, hallway)\n",
"interact(animate_discrete_bayes, step=IntSlider(value=1, max=len(zs)*2));"
"interact(animate_discrete_bayes(hallway, priors, posteriors), step=IntSlider(value=1, max=len(zs)*2));"
]
},
{
@ -1328,7 +1331,7 @@
"zs = [1, 0, 1, 0, 0, 1]\n",
"z_prob = 0.75\n",
"priors, posteriors = discrete_bayes_sim(prior, kernel, zs, z_prob, hallway)\n",
"interact(animate_discrete_bayes, step=IntSlider(value=12, max=len(zs)*2));"
"interact(animate_discrete_bayes(hallway, priors, posteriors), step=IntSlider(value=12, max=len(zs)*2));"
]
},
{
@ -1359,7 +1362,7 @@
"source": [
"measurements = [1, 0, 1, 0, 0, 1, 1]\n",
"priors, posteriors = discrete_bayes_sim(prior, kernel, measurements, z_prob, hallway);\n",
"plot_posterior(posteriors, 6)"
"plot_posterior(hallway, posteriors, 6)"
]
},
{