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 create_submission(test=True, kernel=gen_exp(), has_width=False): if (test): SKY_LIST = TEST_SKIES else: SKY_LIST = TRAIN_SKIES timestamp = str(datetime.datetime.now()) with file('submission' + timestamp.replace(' ', '_').replace(':', '.') + '.csv', 'w') as out: for skynum in SKY_LIST: print "working on Sky" + str(skynum) + "..." dm_x, dm_y, val = optimizesky.predict(skynum, test=test, kernel=kernel, has_width=has_width) # convert from dm_x, dm_y to [x1,y1,x2,y2,...] halo_coords = [0.0] * 3 * 2 for idm in range(dm_x.size): halo_coords[idm*2] = dm_x[idm] halo_coords[idm*2+1] = dm_y[idm] print "dm_x = " + str(dm_x) + ", dm_y = " + str(dm_y) print halo_coords sky_id = 'Sky' + str(skynum) halo_strs = [str(x) for x in halo_coords] out.write(sky_id + ',' + ','.join(halo_strs) + "\n") out.flush()