def experiment(env, step_type, training_rounds, gamma, lr, train_ep, oneshot, test_ep, save_folder, device, config): """ Run an experiment where agents are trained and tested (including cross-play) training_rounds is the number of pairs of policies trained """ step_func = step_funcs[step_type] print("---- Starting ----") ### Train policies p1s, p2s = train_policies(env, training_rounds, step_func, train_ep, gamma, lr, device) qs = QuickSaver(subfolder=save_folder) qs.save_json(config, name='config') ### Save policies list_p1s = list(map(lambda p: p.tolist(), p1s)) list_p2s = list(map(lambda p: p.tolist(), p2s)) save_results(qs, 'Pols', list_p1s, list_p2s) for name, prior in env.generate_test_priors(): print("Testing prior", name, "...") ### Test policies r1s, r2s = several_test(env, prior, p1s, p2s) xr1s, xr2s = several_cross_test(env, prior, p1s, p2s, n_crosses=training_rounds) ### Plot results plot_results(env, prior, r1s, r2s, color='orange') plot_results(env, prior, xr1s, xr2s, color='blue') save_plot(qs, name + '_results') ### Save results save_results(qs, name + '_Pfs', r1s, r2s) save_results(qs, name + '_XPfs', xr1s, xr2s)
def validation(self): ntest = self.fit_nrows - self.ntrain steps_test = int(ntest / configs['data']['batch_size']) tesize = steps_test * configs['data']['batch_size'] data_gen_test = self.dl.generate_clean_data( configs['data']['filename_clean'], size=tesize, batch_size=configs['data']['batch_size'], start_index=self.ntrain) print('> Testing model on', ntest, 'data rows with', steps_test, 'steps') predictions = self.model.predict_generator( self.generator_strip_xy(data_gen_test), steps=steps_test) # Save our predictions with h5py.File(configs['model']['filename_predictions'], 'w') as hf: dset_p = hf.create_dataset('predictions', data=predictions) dset_y = hf.create_dataset('true_values', data=self.ture_values) plot.plot_results(predictions[:800], self.ture_values[:800])
# start_time_1 = time() # while model_f.t >= model_f.t_final and model_f.condition: # ''' # Generates the field, which can start at a different redshift from the cluster # ''' # start_time_2 = time() # model_f.evolve_field() # model_f.update_ssfr_params() # model_f.update_step() # advances t, z to next step # #print('\t time per step: {:.2f}s'.format(time() - start_time_2)) # #print('~~~~~~~~~~~~~~~~~~~~~~~') # print('Total ellapsed time for Field: {:.2f}s'.format(time() - start_time_1)) # model_f.parse_masked_mass_field() # model_c.parse_masked_mass_cluster() plot_results(params, model_c, model_f) # total_stel_mass = np.sum(np.power(10,model_c.final_mass_cluster_SF)) + np.sum(np.power(10, model_c.final_mass_cluster_Q)) # total_stel_mass_per_cluster = total_stel_mass/n_clusters # print('Total stellar mass of cluster: ', np.log10(total_stel_mass_per_cluster)) # p.close() # p.join()
image_path = f"{args.input_path}/frames/" detections_path = f"{args.input_path}/{'annotations.mat' if args.annotations else 'observations.mat'}" mat = scipy.io.loadmat(detections_path) detections = mat['annotations'] if args.annotations else mat['observations'] file_paths = sorted(glob(f"{image_path}/*.png")) tracker = Tracker(args.gating_area, args.use_hungarian, args.use_kalman, args.use_mahalanobis) for i, file_path in enumerate(file_paths): img = cv2.imread(file_path) img_tracks = img.copy() if i > 0: # previous measurement in red; indexing starts with 1 utils.plot_detections(img, detections[detections[:, 0] == i, 1:], (0, 0, 255)) # current measurement in blue utils.plot_detections(img, detections[detections[:, 0] == i + 1, 1:], (255, 255, 0)) tracks, debug_info = tracker.update([{'pos': pos} for pos in detections[detections[:, 0] == i+1, 1:]]) if args.use_kalman: # plot white predicted states utils.plot_detections(img, np.array(debug_info['predicted_positions']), (255, 255, 255)) utils.plot_tracks(img_tracks, tracks, num_colors=15) utils.plot_results(img, img_tracks)