Ejemplo n.º 1
0
# repeat = 2


for n, k in enumerate(obj_names):

    file_address = './IRL_solution_obj_name_' + obj_names[n] + '_maxiter_' + str(max_iter)\
                   + '_repeat_' + str(repeat) + '.pkl'


    if not os.path.isfile(file_address):
        solution = np.empty((repeat, sig_scale.shape[0]), object)
        # strategy_log = []
        for i in np.arange(repeat):
            for j, sigma_inv in enumerate(sig_scale):
                sig_inv = np.ones(boundss[n].shape[0])*sigma_inv
                solver = EGO(sig_inv, objs[n], boundss[n], max_iter, num_ini_guess)
                solver.irl_strat("rosen30_IRL_strat.csv")  # only for IRL ego
                solution_X, solution_y = solver.solve()
                # strategy_log += [solver.concentrated_likelihood_history]  # only for CLO ego
                solution[i, j] = (solution_X, solution_y)
        # print strategy_log
        # save the solution
        with open(file_address, 'w') as f:
            pickle.dump({'solution': solution.tolist(), 'sig_scale': sig_scale.tolist(), 'obj_name': obj_names[n],
                         'max_iter': max_iter}, f)
        f.close()
        # np.savetxt('CLO_strategy_log.txt', np.array(strategy_log))

    else:
        with open(file_address, 'r') as f:
            data = pickle.load(f)
# bounds = np.array([[-5, 5], [-5, 5], [-5, 5],
#                    [-5, 5], [-5, 5], [-5, 5]])  # for rosenbrock-6dim
repeat = 30
extreme = 1.
file_address = './solution_obj_name_' + obj_name + '_maxiter_' + str(max_iter) + \
               '_repeat_' + str(repeat) + 'x'+str(extreme) + '.pkl'


if not os.path.isfile(file_address):
    solution = np.empty((repeat, sig_scale.shape[0]), object)
    for i in np.arange(repeat):
        for j, sigma_inv in enumerate(sig_scale):
            # sig_inv = np.ones(2)*sigma_inv
            sig_inv = np.ones(2)*sigma_inv
            sig_inv[0] = extreme
            solver = EGO(sig_inv, obj, bounds, max_iter, num_ini_guess)
            solution_X, solution_y = solver.solve()
            solution[i, j] = (solution_X, solution_y)

    # save the solution
    with open(file_address, 'w') as f:
        pickle.dump({'solution': solution.tolist(), 'extreme': extreme, 'obj_name': obj_name,
                     'max_iter': max_iter}, f)
    f.close()
else:
    with open(file_address, 'r') as f:
        data = pickle.load(f)
    f.close()
    solution = np.array(data['solution'])
    # sig_scale = np.array(data['sig_scale'])
    max_iter = data['max_iter']
Ejemplo n.º 3
0
max_iter = 100

num_ini_guess = 5
bounds = np.array([[-5, 10], [0, 15]])
repeat = 30

file_address = './solution_obj_name_' + obj_name + '_maxiter_' + str(max_iter) + '_repeat_' + str(repeat) + '.pkl'


if not os.path.isfile(file_address):
    solution = np.empty((repeat, sig_scale.shape[0]), object)
    for i in np.arange(repeat):
        for j, sigma_inv in enumerate(sig_scale):
            sig_inv = np.ones(2)*sigma_inv

            solver = EGO(sig_inv, obj, bounds, max_iter, num_ini_guess)
            solution_X, solution_y = solver.solve()
            solution[i,j] = (solution_X, solution_y)

    # save the solution
    with open(file_address, 'w') as f:
        pickle.dump({'solution': solution.tolist(), 'sig_scale': sig_scale.tolist(), 'obj_name': obj_name,
                     'max_iter': max_iter}, f)
    f.close()
else:
    with open(file_address, 'r') as f:
        data = pickle.load(f)
    f.close()
    solution = np.array(data['solution'])
    sig_scale = np.array(data['sig_scale'])
    max_iter = data['max_iter']