def main(): ax_graph_list, _ = plot.init_figure(n_graphs=1, n_sliders=0) a, b = A, B m = l = 0 mu_list = np.arange(0.0, 1.0, 0.001) prior_dist = np.repeat([1.0], 1000) # p(μ) の最初の予想。一様分布。 frame_list = [] for D in range(1, MAX_D): is_face = random() < REAL_MU # 「表」が出たらTrue if is_face: m += 1 else: l += 1 frame_list.append(ax_graph_list[0].plot(mu_list, prior_dist)) _posterior_dist = posterior_dist(mu_list, {'m': m, 'l': l, 'a': a, 'b': b}) prior_dist = _posterior_dist animation.ArtistAnimation(ax_graph_list[0].figure, frame_list, interval=10, repeat=False) ax_graph_list[0].set_xlabel('$\mu$') ax_graph_list[0].text(0, 1.0, 'Learning $\mu$ = %.2f , with %d iterations' % (REAL_MU, MAX_D)) plt.show()
def main(): ax_graph_list, ax_slider_list = plot.init_figure(n_graphs=2, n_sliders=6) ax_graph_contour, ax_graph_cond_simul = ax_graph_list slider_x2 = SliderWrapper( param_name='x2', axis=ax_slider_list[0], label='$x_2$', min_val=-1.0, max_val=1.0, init_val=0.0) slider_mu1 = SliderWrapper( param_name='mu1', axis=ax_slider_list[1], label='$\mu_1$', min_val=-1.0, max_val=1.0, init_val=0.0) slider_mu2 = SliderWrapper( param_name='mu2', axis=ax_slider_list[2], label='$\mu_2$', min_val=-1.0, max_val=1.0, init_val=0.0) slider_sigma1 = SliderWrapper( param_name='sigma1', axis=ax_slider_list[3], label='$\sigma_1$', min_val=0.1, max_val=2.0, init_val=1.0) slider_sigma2 = SliderWrapper( param_name='sigma2', axis=ax_slider_list[4], label='$\sigma_2$', min_val=0.1, max_val=2.0, init_val=1.0) slider_sigma12 = SliderWrapper( param_name='sigma12', axis=ax_slider_list[5], label='$\sigma_{12}$', min_val=-2.0, max_val=2.0, init_val=0.8) _x = np.arange(-1.0, 1.0, 0.01) _y = np.arange(-1.0, 1.0, 0.01) x, y = np.meshgrid(_x, -_y) plotter = plot.Plotter( param_widget_wrappers=[slider_x2, slider_mu1, slider_mu2, slider_sigma1, slider_sigma2, slider_sigma12]) # 等高線グラフ plotter.register( ax_graph_contour, dist_f=normal_dist_3d, x=x, y=y, xlabel='$x_1$', ylabel='$x_2$', extent=[-1.0, 1.0, -1.0, 1.0]) # 条件付きガウス分布と、周辺ガウス分布 plotter.register(ax_graph_cond_simul, dist_f=normal_dist_cond, x=_x, label='$p(x_1|x_2)$', xlabel='$x_1$') plotter.register(ax_graph_cond_simul, dist_f=normal_dist_simul, x=_x, label='$p(x_1)$', xlabel='$x_1$') ax_graph_cond_simul.legend() plt.show()
def main(): ax_graph_list, ax_slider_list = plot.init_figure(n_graphs=1, n_sliders=2) slider_a = SliderWrapper( param_name='a', axis=ax_slider_list[0], label='$a$', min_val=0.00, max_val=10.0, init_val=INIT_A) slider_b = SliderWrapper( param_name='b', axis=ax_slider_list[1], label='$b$', min_val=0.00, max_val=10.0, init_val=INIT_B) mu_list = np.arange(0.0 + 0.001, 1.0 - 0.001, 0.001) plotter = plot.Plotter(param_widget_wrappers=[slider_a, slider_b]) plotter.register(ax_graph_list[0], dist_f=beta_dist, x=mu_list, xlabel='$\mu$') plt.show()
def main(): ax_graph_list, ax_slider_list = plot.init_figure(n_graphs=1, n_sliders=2) slider_mu = SliderWrapper( param_name='mu', axis=ax_slider_list[0], label='$\mu$', min_val=0.0, max_val=1.0, init_val=INIT_MU) slider_sigma = SliderWrapper( param_name='sigma', axis=ax_slider_list[1], label='$\sigma$', min_val=0.01, max_val=0.10, init_val=INIT_SIGMA) x_list = np.arange(0.0, 1.0, 0.001) plotter = plot.Plotter(param_widget_wrappers=[slider_mu, slider_sigma]) plotter.register( ax_graph_list[0], dist_f=normal_dist, x=x_list, xlabel='$x$') plt.show()
def main(): ax_graph_list, ax_slider_list = plot.init_figure(n_graphs=1, n_sliders=5) slider_mu1 = SliderWrapper( param_name='mu1', axis=ax_slider_list[0], label='$\mu_1$', min_val=-1.0, max_val=1.0, init_val=0.0) slider_mu2 = SliderWrapper( param_name='mu2', axis=ax_slider_list[1], label='$\mu_2$', min_val=-1.0, max_val=1.0, init_val=0.0) slider_sigma1 = SliderWrapper( param_name='sigma1', axis=ax_slider_list[2], label='$\sigma_1$', min_val=0.1, max_val=2.0, init_val=1.0) slider_sigma2 = SliderWrapper( param_name='sigma2', axis=ax_slider_list[3], label='$\sigma_2$', min_val=0.1, max_val=2.0, init_val=1.0) slider_sigma12 = SliderWrapper( param_name='sigma12', axis=ax_slider_list[4], label='$\sigma_{12}$', min_val=-2.0, max_val=2.0, init_val=0.8) _x1 = np.arange(-1.0, 1.0, 0.01) _x2 = np.arange(-1.0, 1.0, 0.01) x1, x2 = np.meshgrid(_x1, -_x2) # meshgridの形的に、x2を符号逆転すると図示がうまくいく。x1 + x2を図示するとよくわかる。 plotter = plot.Plotter(param_widget_wrappers=[slider_mu1, slider_mu2, slider_sigma1, slider_sigma2, slider_sigma12]) plotter.register( ax_graph_list[0], dist_f=normal_dist_3d, x=x1, y=x2, xlabel='$x_1$', ylabel='$x_2$', extent=[-1.0, 1.0, -1.0, 1.0]) plt.show()