Ejemplo n.º 1
0
def build_surrogates(problem_testbench, problem_name, nobjs, nvars, is_data,
                     x_data, y_data):
    x_names = [f'x{i}' for i in range(1, nvars + 1)]
    y_names = [f'f{i}' for i in range(1, nobjs + 1)]
    row_names = ['lower_bound', 'upper_bound']
    if is_data is False:
        prob = test_problem_builder(problem_name, nvars, nobjs)
        x = lhs(nvars, nsamples)
        y = prob.evaluate(x)
        data = pd.DataFrame(np.hstack((x, y.objectives)),
                            columns=x_names + y_names)
    else:
        data = pd.DataFrame(np.hstack((x_data, y_data)),
                            columns=x_names + y_names)
    if problem_testbench == 'DDMOPP':
        x_low = np.ones(nvars) * -1
        x_high = np.ones(nvars)
    elif problem_testbench == 'DTLZ':
        x_low = np.ones(nvars) * 0
        x_high = np.ones(nvars)
    bounds = pd.DataFrame(np.vstack((x_low, x_high)),
                          columns=x_names,
                          index=row_names)
    problem = DataProblem(data=data,
                          variable_names=x_names,
                          objective_names=y_names,
                          bounds=bounds)
    start = time.time()
    problem.train(SurrogateKriging)
    end = time.time()
    time_taken = end - start
    return problem, time_taken
def build_surrogates(problem_testbench,
                     problem_name,
                     nobjs,
                     nvars,
                     nsamples,
                     is_data,
                     x_data,
                     y_data,
                     surrogate_type,
                     Z=None,
                     z_samples=None):
    x_names = [f'x{i}' for i in range(1, nvars + 1)]
    y_names = [f'f{i}' for i in range(1, nobjs + 1)]
    row_names = ['lower_bound', 'upper_bound']
    if is_data is False:
        prob = test_problem_builder(problem_name, nvars, nobjs)
        x = lhs(nvars, nsamples)
        y = prob.evaluate(x)
        data = pd.DataFrame(np.hstack((x, y.objectives)),
                            columns=x_names + y_names)
    else:
        data = pd.DataFrame(np.hstack((x_data, y_data)),
                            columns=x_names + y_names)
    if problem_testbench == 'DDMOPP':
        x_low = np.ones(nvars) * -1
        x_high = np.ones(nvars)
    elif problem_testbench == 'DTLZ':
        x_low = np.ones(nvars) * 0
        x_high = np.ones(nvars)
    bounds = pd.DataFrame(np.vstack((x_low, x_high)),
                          columns=x_names,
                          index=row_names)
    problem = DataProblem(data=data,
                          variable_names=x_names,
                          objective_names=y_names,
                          bounds=bounds)
    start = time.time()
    if surrogate_type == "generic_fullgp":
        problem.train(fgp)
    elif surrogate_type == "generic_sparsegp":
        problem.train(sgp, model_parameters=z_samples)
    elif surrogate_type == "rf":
        problem.train(rf)
    elif surrogate_type == "htgp":
        problem.train(htgp)
    else:
        problem.train([sgp2] * nobjs, model_parameters=Z)

    end = time.time()
    time_taken = end - start
    return problem, time_taken
Ejemplo n.º 3
0
def read_dataset(problem_testbench, folder_data, problem_name, nobjs, nvars,
                 sampling, run):
    if problem_testbench == "DDMOPP":
        mat = scipy.io.loadmat(folder_data + '/Initial_Population_' +
                               problem_testbench + '_' + sampling + '_AM_' +
                               str(nvars) + '_109.mat')
        x = ((mat['Initial_Population_' + problem_testbench])[0][run])[0]
        mat = scipy.io.loadmat(folder_data + '/Obj_vals_DDMOPP_' + sampling +
                               '_AM_' + problem_name + '_' + str(nobjs) + '_' +
                               str(nvars) + '_109.mat')
        y = ((mat['Obj_vals_DDMOPP'])[0][run])[0]
    else:
        mat = scipy.io.loadmat(folder_data + '/Initial_Population_DTLZ_' +
                               sampling + '_AM_' + str(nvars) + '_109.mat')
        prob = test_problem_builder(name=problem_name,
                                    n_of_objectives=nobjs,
                                    n_of_variables=nvars)
        x = ((mat['Initial_Population_DTLZ'])[0][run])[0]
        y = prob.evaluate(x)[0]
    return x, y
def read_dataset(problem_testbench, problem_name, nobjs, nvars, sampling,
                 nsamples, run):
    mat = scipy.io.loadmat('./data/initial_samples/Initial_Population_' +
                           problem_testbench + '_' + sampling + '_AM_' +
                           str(nvars) + '_' + str(nsamples) + '.mat')
    x = ((mat['Initial_Population_' + problem_testbench])[0][run])[0]
    if problem_testbench == 'DDMOPP':
        mat = scipy.io.loadmat('./data/initial_samples/Obj_vals_DDMOPP_' +
                               sampling + '_AM_' + problem_name + '_' +
                               str(nobjs) + '_' + str(nvars) + '_' +
                               str(nsamples) + '.mat')
        y = ((mat['Obj_vals_DDMOPP'])[0][run])[0]
    elif problem_testbench == 'DTLZ':
        prob = test_problem_builder(name=problem_name,
                                    n_of_objectives=nobjs,
                                    n_of_variables=nvars)
        y = prob.evaluate(x)[0]
    #elif problem_testbench == 'GAA':
    #    mat = scipy.io.loadmat('./'+folder_data+'/Obj_vals_GAA_'+sampling+'_AM_'+self.name+'_'
    #                            + str(self.num_of_objectives) + '_' + str(self.num_of_variables)
    #                            + '_'+str(sample_size)+'.mat')
    #    y = ((mat['Obj_vals_GAA'])[0][self.run])[0]
    return x, y
Ejemplo n.º 5
0
from desdeo_problem.surrogatemodels.SurrogateModels import GaussianProcessRegressor
from desdeo_problem.surrogatemodels.lipschitzian import LipschitzianRegressor

from desdeo_problem.testproblems.TestProblems import test_problem_builder
from pyDOE import lhs

from desdeo_emo.EAs.RVEA import RVEA, oRVEA, robust_RVEA

from pygmo import non_dominated_front_2d as nd2

problem_names = ["ZDT1", "ZDT2", "ZDT3", "ZDT4", "ZDT6"]
num_var = {"ZDT1": 30, "ZDT2": 30, "ZDT3": 30, "ZDT4": 10, "ZDT6": 10}

for problem_name in problem_names:
    prob = test_problem_builder(problem_name)

    x = lhs(num_var[problem_name], 250)
    y = prob.evaluate(x)

    data_pareto = nd2(y.objectives)
    data_pareto = y.objectives[data_pareto]

    x_names = [f"x{i}" for i in range(1, num_var[problem_name] + 1)]
    y_names = ["f1", "f2"]

    data = pd.DataFrame(np.hstack((x, y.objectives)),
                        columns=x_names + y_names)

    problem = DataProblem(data=data,
                          variable_names=x_names,
Ejemplo n.º 6
0
data_row = pd.DataFrame(columns=column_names, index=[1])

# ADM parameters
L = 4  # number of iterations for the learning phase
D = 3  # number of iterations for the decision phase
lattice_resolution = 5  # density variable for creating reference vectors

counter = 1
total_count = len(num_gen_per_iter) * len(n_objs) * len(problem_names)
for gen in num_gen_per_iter:
    for n_obj, n_var in zip(n_objs, n_vars):
        for problem_name in problem_names:
            print(f"Loop {counter} of {total_count}")
            counter += 1
            problem = test_problem_builder(name=problem_name,
                                           n_of_objectives=n_obj,
                                           n_of_variables=n_var)

            problem.ideal = np.asarray([0] * n_obj)
            problem.nadir = abs(np.random.normal(size=n_obj, scale=0.15)) + 1

            true_nadir = np.asarray([1] * n_obj)

            # interactive
            int_rvea = RVEA(problem=problem, interact=True, n_gen_per_iter=gen)
            int_nsga = NSGAIII(problem=problem,
                               interact=True,
                               n_gen_per_iter=gen)

            # initial reference point is specified randomly
            response = np.random.rand(n_obj)
from desdeo_problem.testproblems.TestProblems import test_problem_builder
from desdeo_emo.EAs.RVEA import RVEA
from desdeo_emo.EAs.NSGAIII import NSGAIII
from desdeo_emo.othertools.plotlyanimate import animate_init_, animate_next_


dtlz3 = test_problem_builder("DTLZ3", n_of_variables=12, n_of_objectives=11)
evolver = RVEA(dtlz3, n_iterations=10)
figure = animate_init_(evolver.population.objectives, filename="dtlz3.html")
while evolver.continue_evolution():
    evolver.iterate()
    figure = animate_next_(
        evolver.population.objectives,
        figure,
        filename="dtlz3.html",
        generation=evolver._iteration_counter,
    )
Ejemplo n.º 8
0
from desdeo_problem.testproblems.TestProblems import test_problem_builder
from desdeo_emo.EAs.RVEA import RVEA
from desdeo_emo.EAs.NSGAIII import NSGAIII
from desdeo_emo.othertools.plotlyanimate import animate_init_, animate_next_

dtlz3 = test_problem_builder("DTLZ7", n_of_variables=30, n_of_objectives=2)
evolver = RVEA(dtlz3, n_iterations=10)
figure = animate_init_(evolver.population.objectives, filename="dtlz3.html")
while evolver.continue_evolution():
    evolver._next_iteration()
    figure = animate_next_(
        evolver.population.objectives,
        figure,
        filename="dtlz3.html",
        generation=evolver._iteration_counter - 2,
    )