def numerical_norm(kappa, beta, eta, alpha, rho): """ Compare log-c8 (series) vs numerical integration log-c8 """ xvals, xlabel, text, textx, args = build_args(kappa, beta, eta, alpha, rho) plt.figure() plt.plot(xvals, [np.log(fb8(*_).normalize()) for _ in args], label='Series', color='k', linewidth=3.5) plt.plot(xvals, [np.log(fb8(*_)._nnormalize()) for _ in args], linestyle='--', color='gray', label='Numerical integration') plt.plot(xvals, [spa(fb8(*_[:-2])).log_c3() for _ in args], linestyle=':', color='gray', label='Saddlepoint') plt.xlabel(rf'$\{xlabel}$') plt.ylabel(rf'$\ln c_8(\{xlabel})$') plt.legend() plt.text(textx, 0.7, text, transform=plt.gca().transAxes, fontsize=14) _ = fb8(0., 0., 0., 100., 10., -0.5, alpha, rho) textnu = rf'$\vec{{\nu}}=({_.nu[0]:.3g},{_.nu[1]:.3g},{_.nu[2]:.3g})$' plt.text(textx, 0.6, textnu, transform=plt.gca().transAxes, fontsize=14) plt.tight_layout(0.1)
def toy(seed=92518): from matplotlib.patches import Circle from mpl_toolkits.mplot3d import art3d np.random.seed(seed) toyf8 = fb8(np.pi / 16, -np.pi / 3, 0, 55, 60, -1., 0.07, 0.3) xs = toyf8.rvs(100) fit5 = fb8_mle(xs, fb5_only=True) print(fit5, -fit5.log_likelihood(xs)) plot_fb8(fit5, 200) ax = plt.gca() for (_z, _x, _y) in xs: p = Circle((_x, _y), 0.01, ec='w', fc="none") ax.add_patch(p) art3d.pathpatch_2d_to_3d(p, z=_z, zdir='z') plt.savefig('figs/Fig4_toyfb5.png') fit8 = fb8_mle(xs) print(fit8, -fit8.log_likelihood(xs)) plot_fb8(fit8, 200) ax = plt.gca() for (_z, _x, _y) in xs: p = Circle((_x, _y), 0.01, ec='w', fc="none") ax.add_patch(p) art3d.pathpatch_2d_to_3d(p, z=_z) plt.savefig('figs/Fig4_toyfb8.png')
def appendix(th, ph, ps): for x in product([th], [ph], [ps], [ 10, ], [1, 10], [-1, -0.8, 1], [0, np.pi / 2], [0]): plot_fb8(fb8(*x), 200) plt.savefig( 'figs/appendix/fb8_k{:.0f}_b{:.0f}_e{:.1f}_a{:.2f}.png'.format( *x[3:-1]))
def __main__(): th, ph, ps = (np.pi / 16, -np.pi / 3, 0) # FB4 plot_fb8(fb8(th, ph, ps, 10, 10, -1, 0, 0), 200) plt.savefig('figs/Fig1_fb4.png') # FB5 plot_fb8(fb8(th, ph, ps, 10, 4, 1, 0, 0), 200) plt.savefig('figs/Fig1_fb5.png') # FB6 plot_fb8(fb8(th + np.pi / 6, ph, ps, 10, 10, -0.5, 0, 0), 200) plt.savefig('figs/Fig2_fb6.png') # FB8 plot_fb8(fb8(th, ph, ps, 10, 10, -1, 0.5, 0.3), 200) plt.savefig('figs/Fig2_fb8.png') # approx_c6 approx_norm(None, 100., -0.5) plt.savefig('figs/Fig3_approxc6_kappa.pdf') approx_norm(100., None, -0.5) plt.savefig('figs/Fig3_approxc6_beta.pdf') approx_norm(100., 100., None) plt.savefig('figs/Fig3_approxc6_eta.pdf') # ln_c8 numerical_norm(None, 100., -0.5, 0.5, 0.3) plt.savefig('figs/Fig3_lnc8_kappa.pdf') numerical_norm(100., None, -0.5, 0.5, 0.3) plt.savefig('figs/Fig3_lnc8_beta.pdf') numerical_norm(100., 100., None, 0.5, 0.3) plt.savefig('figs/Fig3_lnc8_eta.pdf') # time_c8 time_norm(None, 100., -0.5, 0.5, 0.3) plt.savefig('figs/Fig3_timec8_kappa.pdf') time_norm(100., None, -0.5, 0.5, 0.3) plt.savefig('figs/Fig3_timec8_beta.pdf') time_norm(100., 100., None, 0.5, 0.3) plt.savefig('figs/Fig3_timec8_eta.pdf') # toy application toy() # bright stars catalog bsc5() # appendixfb8s appendix(0, 0, 0)
def approx_norm(kappa, beta, eta): """ Compare log-c6 vs approx log-c6 """ xvals, xlabel, text, textx, args = build_args(kappa, beta, eta) plt.figure() plt.plot(xvals, [np.log(fb8(*_).normalize()) for _ in args], label='Series', color='k', linewidth=3.5) plt.plot(xvals, [fb8(*_)._approx_log_normalize() for _ in args], linestyle='--', color='gray', label='Approximate') plt.plot(xvals, [spa(fb8(*_)).log_c3() for _ in args], linestyle=':', color='gray', label='Saddlepoint') plt.xlabel(rf'$\{xlabel}$') plt.ylabel(rf'$\ln c_6(\{xlabel})$') plt.legend() plt.text(textx,0.7,text, transform=plt.gca().transAxes, fontsize=14) plt.tight_layout(0.1)
def time_norm(kappa, beta, eta, alpha, rho): """ Plot execution time of .normalize to ._nnormalize """ xvals, xlabel, text, textx, args = build_args(kappa, beta, eta, alpha, rho) tfile = os.path.join('figs', 'time', 'timec8.pkl') if os.path.isfile(tfile) and str(args) in pickle.load(open(tfile, 'rb')): times_normalize, times_nnormalize = pickle.load(open(tfile, 'rb'))[str(args)] else: times_normalize = [] times_nnormalize = [] setup = 'from sphere.distribution import fb8' for _ in args: times_normalize.append( min( timeit.repeat( stmt=('fb8(' + ','.join(['{}'] * 8) + ').normalize(cache=dict())').format(*_), setup=setup, repeat=3, number=1))) times_nnormalize.append( min( timeit.repeat(stmt=('fb8(' + ','.join(['{}'] * 8) + ')._nnormalize()').format(*_), setup=setup, repeat=3, number=1))) if os.path.isfile(tfile): ddd = pickle.load(open(tfile, 'rb')) else: ddd = {} ddd[str(args)] = [times_normalize, times_nnormalize] with open(tfile, 'wb') as f: pickle.dump(ddd, f) plt.figure() plt.plot(xvals, times_normalize, label='Series', color='k', linewidth=3.5) plt.plot(xvals, times_nnormalize, linestyle='--', color='gray', label='Numerical integration') plt.xlabel(rf'$\{xlabel}$') plt.ylabel(rf'Runtime [s]') # plt.yscale('log') plt.legend() plt.text(0.42, 0.38, text, transform=plt.gca().transAxes, fontsize=14) _ = fb8(0., 0., 0., 100., 10., -0.5, alpha, rho) textnu = rf'$\vec{{\nu}}=({_.nu[0]:.3g},{_.nu[1]:.3g},{_.nu[2]:.3g})$' plt.text(0.42, 0.28, textnu, transform=plt.gca().transAxes, fontsize=14) plt.tight_layout(0.1)