def main(): if args.cuda and torch.cuda.is_available(): device = torch.device("cuda") else: device = torch.device("cpu") print("Using device", type(device)) algorithmopts = yaml.safe_load(open(args.algorithm_specs, "r")) testcase = load_example(algorithmopts["example"]) # start_time = time.time() ####### model, likelihood = init_gp(testcase, algorithmopts, algorithmopts["ninit"], device) # time1 = time.time() #### # print("--- init_gp %s seconds ---" % (time1 - start_time)) ### estimator = ExcursionSetEstimator(testcase, algorithmopts, model, likelihood, device) timestampStr = datetime.datetime.now().strftime("%d-%b-%Y_%H:%M:%S") + "/" os.mkdir(args.outputfolder + timestampStr) while estimator.this_iteration < algorithmopts["nupdates"]: time2 = time.time() estimator.step(testcase, algorithmopts, model, likelihood) time3 = time.time() #### print("--- step %s seconds ---" % (time3 - time2)) ### model = estimator.update_posterior(testcase, algorithmopts, model, likelihood) time4 = time.time() #### print("--- posterior %s seconds ---" % (time4 - time3)) ### estimator.plot_status(testcase, algorithmopts, model, estimator.acq_values, args.outputfolder + timestampStr) estimator.get_diagnostics(testcase, model, likelihood) time5 = time.time() #### print("--- get_diagnostics %s seconds ---" % (time5 - time4)) ### estimator.print_results(args.outputfolder + timestampStr, testcase, algorithmopts)
def test_init_gp(): device = torch.device("cpu") ninit = 1 algorithmopts = yaml.safe_load(open("testing/algorithm_specs.yaml", "r")) # three toy examples for example in ["1Dtoyanalysis", "2Dtoyanalysis", "3Dtoyanalysis"]: print(example) testcase = load_example(example) gp, likelihood = init_gp(testcase, algorithmopts, ninit, device) assert type(gp.train_inputs[0]) != type(None) assert type(gp.train_targets) != type(None)
def test_init_excursion(): device = torch.device("cpu") ninit = 1 algorithmopts = yaml.safe_load(open("testing/algorithm_specs.yaml", "r")) # three toy examples for example in ["1Dtoyanalysis", "2Dtoyanalysis", "3Dtoyanalysis"]: testcase = load_example(example) gp, likelihood = init_gp(testcase, algorithmopts, ninit, device) estimator = ExcursionSetEstimator(testcase, algorithmopts, gp, likelihood, device) assert type(estimator) != type(None) assert type(estimator._X_grid) != type(None) assert type(estimator._n_dims) != type(None) assert type(estimator._acq_type) != type(None)
def test_full_simple(): tol = 1e-6 device = torch.device("cpu") ninit = 1 algorithmopts = yaml.safe_load( open("testing/algorithm_specs_full_test.yaml", "r")) # three toy examples for example in ["1D_test"]: testcase = load_example(example) model, likelihood = init_gp(testcase, algorithmopts, ninit, device) estimator = ExcursionSetEstimator(testcase, algorithmopts, model, likelihood, device) while estimator.this_iteration < algorithmopts["nupdates"]: estimator.step(testcase, algorithmopts, model, likelihood) model = estimator.update_posterior(testcase, algorithmopts, model, likelihood) assert type(torch.abs(model.train_targets) <= tol) != type(None)
def test_step_excursion(): device = torch.device("cpu") ninit = 1 algorithmopts = yaml.safe_load(open("testing/algorithm_specs.yaml", "r")) # three toy examples for example in ["1Dtoyanalysis", "2Dtoyanalysis", "3Dtoyanalysis"]: testcase = load_example(example) gp, likelihood = init_gp(testcase, algorithmopts, ninit, device) estimator = ExcursionSetEstimator(testcase, algorithmopts, gp, likelihood, device) # one iteration only to test estimator.step(testcase, algorithmopts, gp, likelihood) assert type(estimator) != type(None) assert type(estimator.x_new) != type(None) assert type(estimator.y_new) != type(None) assert estimator.walltime_step != 0.0 assert estimator.this_iteration == 1
plt.savefig('plots/test_fast2D.png') #load algorithm options file = open('excursion/testcases/algorithms/algorithm_specs.yaml', "r") algorithm_opts = yaml.safe_load(file) print('algorithm_opts =') print(json.dumps(algorithm_opts, indent=4)) ## Step 2: Init the Gaussian Proces #We initialize the gaussian process and likelihood according to `algorithm_opts['init_type']` if (torch.cuda.is_available()): device = torch.device('cuda') else: device = torch.device('cpu') model, likelihood = init_gp(testcase_details, \ algorithm_opts, \ algorithm_opts["ninit"], \ device) # X_init and y_init are random points so that we can fit the GP posterior wrt these points # fit hyperparameters model.train() likelihood.train() excursion.fit_hyperparams(model, likelihood) # plot the fitting plots.plot_GP_init(plt, model, testcase_details, device=device, dtype=torch.float64) ## Step 3: Init the ExcursionEstimator estimator = ExcursionSetEstimator(testcase_details, \