def plot_haloness(skynum, kernel=exppow(), N=20.): gal_x,gal_y,gal_e1,gal_e2 = read_sky(skynum).T nhalo, halo_coords = read_halos(skynum) margin = 100 xplot = np.linspace(min(gal_x)-margin, max(gal_x)+margin, N) yplot = np.linspace(min(gal_y)-margin, max(gal_y)+margin, N) X,Y = np.meshgrid(xplot,yplot) Z = np.zeros(X.shape) f = optsky.fwrapper(gal_x=gal_x, gal_y=gal_y, gal_e1=gal_e1, gal_e2=gal_e2, nhalo=nhalo, kernel=kernel, has_width=False) for idx, x in enumerate(xplot): for idy, y in enumerate(yplot): coords = np.array([x,y]) Z[idy, idx] = f(coords) #plt.contourf(X, Y, Z) plt.pcolor(X, Y, Z) plt.colorbar() plt.hold(True) for ihalo in range(nhalo): plt.scatter(halo_coords[ihalo*2], halo_coords[ihalo*2 + 1],\ color='white', s=50) plt.axis((min(gal_x)-margin, max(gal_x)+margin, min(gal_y)-margin, max(gal_y)+margin)) plt.title("Objective function value for Sky " + str(skynum)) plt.show()
def diagnostic(Nrange, kernel=exppow()): plt.figure() plt.hold(True) for skynum in range(201, 231): nhalo, halo_coords = read_halos(skynum) gal_x,gal_y,gal_e1,gal_e2 = read_sky(skynum).T print skynum f = optsky.fwrapper(gal_x=gal_x, gal_y=gal_y, gal_e1=gal_e1, gal_e2=gal_e2, nhalo=nhalo, kernel=kernel) val_true = f(halo_coords) val_array = np.zeros(len(Nrange)) for ii in range(len(Nrange)): dm_x, dm_y, val = optsky.predict(skynum, Ngrid=Nrange[ii]) val_array[ii] = val val_array = (val_array - val_true)/val_true plt.plot(Nrange, val_array, linewidth=0.5, color='black', linestyle='-') #plt.title('Training Sky ' + str(skynum) + ': '\ # + str(nhalo) + ' halos') plt.xlabel(r'$\mathrm{number \ of \ random \ starts}$') plt.ylabel(r'$\mathrm{normalized \ objective \ value}$') plt.plot(Nrange, np.zeros(len(Nrange)), linewidth=2.0, color='blue', linestyle='--') plt.axis('tight') plt.show()
def plot_likelihood(skynum, pdf=None, kernel=exppow_lim(), N=20): if (pdf == None): pdf = optsky.build_pdf(kernel) nhalo, halo_coords = read_halos(skynum) sky = read_sky(skynum) gal_x, gal_y, gal_e1, gal_e2 = sky.T f = optsky.fwrapper(gal_x=gal_x, gal_y=gal_y, gal_e1=gal_e1, gal_e2=gal_e2, nhalo=nhalo, kernel=kernel, pdf=pdf) margin = 0 xplot = np.linspace(0.0, 4200.0, N) yplot = np.linspace(0.0, 4200.0, N) X,Y = np.meshgrid(xplot,yplot) Z = np.zeros(X.shape) for idx, x in enumerate(xplot): for idy, y in enumerate(yplot): Z[idy, idx] = f(np.array([x,y])) #plt.contourf(X, Y, Z) plt.pcolor(X, Y, Z) plt.colorbar() plt.hold(True) nhalo, halo_coords = read_halos(skynum) for ihalo in range(nhalo): plt.scatter(halo_coords[ihalo], halo_coords[ihalo + nhalo],\ color='white', s=50) plt.axis((min(gal_x)-margin, max(gal_x)+margin, min(gal_y)-margin, max(gal_y)+margin)) plt.show()