options["backend"] = "omp" options["grid"] = pygpc.Random options["grid_options"] = None # Define grid n_coeffs = pygpc.get_num_coeffs_sparse( order_dim_max=options["order"], order_glob_max=options["order_max"], order_inter_max=options["interaction_order"], dim=problem.dim) grid = pygpc.Random(parameters_random=problem.parameters_random, n_grid=options["matrix_ratio"] * n_coeffs, seed=1) # Define algorithm algorithm = pygpc.Static(problem=problem, options=options, grid=grid) #%% # Running the gpc # --------------- # Initialize gPC Session session = pygpc.Session(algorithm=algorithm) # run gPC algorithm session, coeffs, results = session.run() #%% # Postprocessing # --------------
def test_0_Static_gpc_quad(self): """ Algorithm: Static Method: Quadrature Solver: NumInt Grid: TensorGrid """ global folder, plot test_name = 'pygpc_test_0_Static_gpc_quad' print(test_name) # define model model = pygpc.testfunctions.Peaks() # define problem parameters = OrderedDict() parameters["x1"] = pygpc.Beta(pdf_shape=[1, 1], pdf_limits=[1.2, 2]) parameters["x2"] = 1.25 parameters["x3"] = pygpc.Beta(pdf_shape=[1, 1], pdf_limits=[0, 0.6]) problem = pygpc.Problem(model, parameters) # gPC options options = dict() options["method"] = "quad" options["solver"] = "NumInt" options["settings"] = None options["order"] = [9, 9] options["order_max"] = 9 options["interaction_order"] = 2 options["error_type"] = "nrmsd" options["n_cpu"] = 0 options["fn_results"] = os.path.join(folder, test_name) options["GPU"] = False # generate grid grid = pygpc.TensorGrid(parameters_random=problem.parameters_random, options={"grid_type": ["jacobi", "jacobi"], "n_dim": [9, 9]}) # define algorithm algorithm = pygpc.Static(problem=problem, options=options, grid=grid) # run gPC algorithm gpc, coeffs, results = algorithm.run() # Post-process gPC pygpc.get_sensitivities_hdf5(fn_gpc=options["fn_results"], output_idx=None, calc_sobol=True, calc_global_sens=True, calc_pdf=True, algorithm="standard", n_samples=1e3) # Validate gPC vs original model function (Monte Carlo) nrmsd = pygpc.validate_gpc_mc(gpc=gpc, coeffs=coeffs, n_samples=int(1e4), output_idx=0, fn_out=None, plot=plot) files_consistent, error_msg = pygpc.check_file_consistency(options["fn_results"] + ".hdf5") print("> Maximum NRMSD (gpc vs original): {:.2}%".format(np.max(nrmsd))) # self.expect_true(np.max(nrmsd) < 0.1, 'gPC test failed with NRMSD error = {:1.2f}%'.format(np.max(nrmsd)*100)) print("> Checking file consistency...") self.expect_true(files_consistent, error_msg) print("done!\n")