fit_vals = (M.b0.value, M.beta.value, M.A.value, M.omega.value) return traces, fit_vals traces, fit_vals = compute_MCMC_results() labels = ['$b_0$', '$A$', r'$\omega$', r'$\beta$'] limits = [(9.5, 11.3), (3.6, 6.4), (0.065, 0.115), (0.00975, 0.01045)] true = [b0_true, A_true, omega_true, beta_true] #---------------------------------------------------------------------- # Find the Maximum a posteriori values fig = plt.figure(figsize=(8, 8)) fig.subplots_adjust(bottom=0.1, top=0.95, left=0.12, right=0.95, hspace=0.05, wspace=0.05) ax = plt.axes([0.5, 0.7, 0.45, 0.25]) t_fit = np.linspace(0, 100, 1001) y_fit = chirp(t_fit, *fit_vals) plt.scatter(t, y_obs, s=9, lw=0, c='k') plt.plot(t_fit, y_fit, '-k') plt.xlim(0, 100) plt.xlabel('$t$') plt.ylabel('$h_{obs}$') # This function plots multiple panels with the traces plot_mcmc(traces, labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k', linewidths=2) plt.show()
traces = [S.trace(s)[:] for s in ['T', 'A', 'omega', 'beta']] return traces traces = compute_MCMC() labels = ['$T$', '$A$', r'$\omega$', r'$\beta$'] limits = [(29.75, 30.25), (0.75, 0.83), (0.085, 0.115), (0.0197, 0.0202)] true = [T_true, A_true, omega_true, beta_true] #------------------------------------------------------------ # Plot results fig = plt.figure(figsize=(5, 5)) # This function plots multiple panels with the traces axes_list = plot_mcmc(traces, labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k', bounds=[0.14, 0.08, 0.95, 0.95]) for ax in axes_list: for axis in [ax.xaxis, ax.yaxis]: axis.set_major_locator(plt.MaxNLocator(5)) ax = fig.add_axes([0.52, 0.7, 0.43, 0.25]) ax.scatter(t, y_obs, s=9, lw=0, c='k') ax.plot(t_fit, y_fit, '-k') ax.set_xlim(0, 100) ax.set_xlabel('$t$') ax.set_ylabel(r'$h_{\rm obs}$') plt.show()
#---------------------------------------------------------------------- # Find the Maximum a posteriori values fig = plt.figure(figsize=(8, 8)) fig.subplots_adjust(bottom=0.1, top=0.95, left=0.12, right=0.95, hspace=0.05, wspace=0.05) ax = plt.axes([0.5, 0.7, 0.45, 0.25]) t_fit = np.linspace(0, 100, 1001) y_fit = chirp(t_fit, *fit_vals) plt.scatter(t, y_obs, s=9, lw=0, c='k') plt.plot(t_fit, y_fit, '-k') plt.xlim(0, 100) plt.xlabel('$t$') plt.ylabel('$h_{obs}$') # This function plots multiple panels with the traces plot_mcmc(traces, labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k', linewidths=2) plt.show()
traces = [S.trace(s)[:] for s in ['T', 'A', 'omega', 'beta']] return traces traces = compute_MCMC() labels = ['$T$', '$A$', r'$\omega$', r'$\beta$'] limits = [(29.75, 30.25), (0.75, 0.83), (0.085, 0.115), (0.0197, 0.0202)] true = [T_true, A_true, omega_true, beta_true] #------------------------------------------------------------ # Plot results fig = plt.figure(figsize=(8, 8)) # This function plots multiple panels with the traces axes_list = plot_mcmc(traces, labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k', linewidths=2, bounds=[0.14, 0.08, 0.95, 0.95]) for ax in axes_list: for axis in [ax.xaxis, ax.yaxis]: axis.set_major_locator(plt.MaxNLocator(5)) ax = fig.add_axes([0.5, 0.7, 0.45, 0.25]) ax.scatter(t, y_obs, s=9, lw=0, c='k') ax.plot(t_fit, y_fit, '-k') ax.set_xlim(0, 100) ax.set_xlabel('$t$') ax.set_ylabel('$h_{obs}$') plt.show()
traces = compute_model() labels = ['$r_0$', '$a$', r'$\phi$', r'$\omega$'] limits = [(6.5, 13.5), (0.55, 1.1), (-0.3, 1.7), (3.75, 4.25)] true = [r0_true, a_true, phi_true, omega_true] # ------------------------------------------------------------ # Plot the results fig = plt.figure(figsize=(5, 5)) # This function plots multiple panels with the traces plot_mcmc([traces[i] for i in ['r0', 'a', 'phi']] + [np.exp(traces['log_omega'])], labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k') # Plot the model of arrival times ax = fig.add_axes([0.5, 0.75, 0.45, 0.2]) ax.fill_between(t, 0, rate_func(t, r0_true, a_true, omega_true, phi_true), facecolor='#DDDDDD', edgecolor='black') ax.xaxis.set_major_formatter(plt.NullFormatter()) ax.set_xlim(t[0], t[-1]) ax.set_ylim(0, 20) ax.set_ylabel('$r(t)$')
traces, fit_vals = compute_MCMC_results() labels = ['$b_0$', '$A$', r'$\omega$', r'$\beta$'] limits = [(9.5, 11.3), (3.6, 6.4), (0.065, 0.115), (0.00975, 0.01045)] true = [b0_true, A_true, omega_true, beta_true] #---------------------------------------------------------------------- # Find the Maximum a posteriori values fig = plt.figure(figsize=(5, 5)) ax = plt.axes([0.5, 0.7, 0.45, 0.25]) t_fit = np.linspace(0, 100, 1001) y_fit = chirp(t_fit, *fit_vals) plt.scatter(t, y_obs, s=9, lw=0, c='k') plt.plot(t_fit, y_fit, '-k') plt.xlim(0, 100) plt.xlabel('$t$') plt.ylabel(r'$h_{\rm obs}$') # This function plots multiple panels with the traces plot_mcmc(traces, labels=labels, limits=limits, true_values=true, fig=fig, bins=30, bounds=[0.12, 0.08, 0.95, 0.91], colors='k') plt.show()
# ------------------------------------------------------------ # Plot the results fig = plt.figure(figsize=(5, 5)) fig.subplots_adjust(bottom=0.1, top=0.95, left=0.1, right=0.95, hspace=0.05, wspace=0.05) # This function plots multiple panels with the traces plot_mcmc([traces[i] for i in ['b0', 'A', 'T']] + [ssig(traces['log_ssig'])], labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k') # plot the model fit ax = fig.add_axes([0.5, 0.75, 0.45, 0.20]) t_fit = np.linspace(0, 100, 101) y_fit = gauss(t_fit, **mean_vals) ax.scatter(t, y_obs, s=9, lw=0, c='k') ax.plot(t_fit, y_fit, '-k') ax.plot(t, y_true, ls="--", c="r", lw=1) ax.set_xlim(0, 100) ax.set_xlabel('$time$') ax.set_ylim(0, 25)
M = pymc.MAP(model) M.fit() fit_vals = (M.b0.value, M.beta.value, M.A.value, M.omega.value) return traces, fit_vals traces, fit_vals = compute_MCMC_results() labels = ['$b_0$', '$A$', r'$\omega$', r'$\beta$'] limits = [(9.5, 11.3), (3.6, 6.4), (0.065, 0.115), (0.00975, 0.01045)] true = [b0_true, A_true, omega_true, beta_true] #---------------------------------------------------------------------- # Find the Maximum a posteriori values fig = plt.figure(figsize=(5, 5)) ax = plt.axes([0.5, 0.7, 0.45, 0.25]) t_fit = np.linspace(0, 100, 1001) y_fit = chirp(t_fit, *fit_vals) plt.scatter(t, y_obs, s=9, lw=0, c='k') plt.plot(t_fit, y_fit, '-k') plt.xlim(0, 100) plt.xlabel('$t$') plt.ylabel(r'$h_{\rm obs}$') # This function plots multiple panels with the traces plot_mcmc(traces, labels=labels, limits=limits, true_values=true, fig=fig, bins=30, bounds=[0.12, 0.08, 0.95, 0.91], colors='k') plt.show()
traces = pm.sample(draws=5000, tune=2000, step=step) labels = ['$T$', '$A$', r'$\omega$', r'$\beta$'] limits = [(29.75, 30.25), (0.75, 0.83), (0.085, 0.115), (0.0197, 0.0202)] true = [T_true, A_true, omega_true, beta_true] # ------------------------------------------------------------ # Plot results fig = plt.figure(figsize=(5, 5)) # This function plots multiple panels with the traces axes_list = plot_mcmc([traces[i] for i in ['T', 'A', 'omega', 'beta']], labels=labels, limits=limits, true_values=true, fig=fig, bins=30, colors='k', bounds=[0.14, 0.08, 0.95, 0.95]) for ax in axes_list: for axis in [ax.xaxis, ax.yaxis]: axis.set_major_locator(plt.MaxNLocator(5)) ax = fig.add_axes([0.52, 0.7, 0.43, 0.25]) ax.scatter(t, y_obs, s=9, lw=0, c='k') ax.plot(t_fit, y_fit, '-k') ax.set_xlim(0, 100) ax.set_xlabel('$t$') ax.set_ylabel(r'$h_{\rm obs}$')
labels = ['$b_0$', '$A$', r'$\omega$', r'$\beta$'] limits = [(9.5, 11.3), (3.6, 6.4), (0.065, 0.115), (0.00975, 0.01045)] true = [b0_true, A_true, omega_true, beta_true] fig = plt.figure(figsize=(5, 5)) ax = plt.axes([0.5, 0.7, 0.45, 0.25]) t_fit = np.linspace(0, 100, 1001) y_fit = chirp(t_fit, **mean_vals) # ---------------------------------------------------------------------- # Plot multiple panels with the traces plt.scatter(t, y_obs, s=9, lw=0, c='k') plt.plot(t_fit, y_fit, '-k') plt.xlim(0, 100) plt.xlabel('$t$') plt.ylabel(r'$h_{\rm obs}$') plot_mcmc([traces[ii] for ii in ['b0', 'A']] + [np.exp(traces['log_omega']), np.exp(traces['log_beta'])], labels=labels, limits=limits, true_values=true, fig=fig, bins=30, bounds=[0.12, 0.08, 0.95, 0.91], colors='k') plt.show()