options["error_type"] = "loocv" options["qoi"] = "all" options["n_grid_gradient"] = 5 options["classifier"] = "learning" options["classifier_options"] = {"clusterer": "KMeans", "n_clusters": 2, "classifier": "MLPClassifier", "classifier_solver": "lbfgs"} options["fn_results"] = fn_results options["save_session_format"] = save_session_format options["grid"] = pygpc.Random options["grid_options"] = None # generate grid grid = pygpc.Random(parameters_random=problem.parameters_random, n_grid=1000, # options["matrix_ratio"] * n_coeffs seed=1) # define algorithm algorithm = pygpc.MEStatic(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()
# Example # ^^^^^^^ import time import pygpc import numpy as np import multiprocessing import seaborn as sns from matplotlib import pyplot as plt from collections import OrderedDict SurfaceCoverageSpecies = pygpc.SurfaceCoverageSpecies() # generate grid with 1000 sampling points grid = pygpc.Random( parameters_random=SurfaceCoverageSpecies.problem.parameters_random, n_grid=100) # define different values for n_cpu n_cpu_list = [0, 1, multiprocessing.cpu_count()] t_eval = dict() # evaluate model with different values for n_cpu for n_cpu in n_cpu_list: # initialize computation class; this is done in the algorithm with options["n_cpu"] com = pygpc.Computation(n_cpu=n_cpu) # run model and determine computation time t_n_cpu = []
# define problem parameters = OrderedDict() parameters["x1"] = pygpc.Beta(pdf_shape=[1, 1], pdf_limits=[1.2, 2]) parameters["x2"] = 1. parameters["x3"] = pygpc.Beta(pdf_shape=[1, 1], pdf_limits=[0, 0.6]) problem = pygpc.Problem(model, parameters) #%% # Depending on the grid and its density, the methods will behave differently. # Here, we use 100 random sampling points in the parameter space defined before. # define grid n_grid = 100 grid = pygpc.Random(parameters_random=problem.parameters_random, n_grid=n_grid, seed=1) #%% # We are setting up a Computation instance to evaluate the model function in the 100 grid points # initializing Computation class com = pygpc.Computation(n_cpu=0, matlab_model=False) # evaluating model function res = com.run(model=model, problem=problem, coords=grid.coords, coords_norm=grid.coords_norm, i_iter=None, i_subiter=None,
model = pygpc.testfunctions.DiscontinuousRidgeManufactureDecay() # define parameters parameters = OrderedDict() for i_dim in range(n_dim): parameters["x" + str(i_dim)] = pygpc.Beta(pdf_shape=[1, 1], pdf_limits=[1.2, 2]) # define problem problem = pygpc.Problem(model, parameters) # define grid options = dict() grid = pygpc.Random(parameters_random=problem.parameters_random, n_grid=n_samples, options={ "n_grid": n_samples, "seed": 1 }) # define gPC gpc = pygpc.Reg(problem=problem, order=[n_basis_order] * n_dim, order_max=n_basis_order, order_max_norm=1, interaction_order=n_dim, interaction_order_current=n_dim, options=options) gpc.grid = grid # get number of basis functions