示例#1
0
        Y_init = np.reshape(np.array(array_y), (-1, 1))
        for ind, cost in enumerate(array_cost):
            list_sampled_x.append(array_sampled_x[ind, :])
            list_y.append(array_y[ind])
            list_cost.append(array_cost[ind])
        max_iter = max_iter_ - len(list_y)
        obj_count = len(list_y) - 1

    myBO = BayesianOptimization(f=obj_val,
                                domain=domain,
                                constraints=constraints,
                                X=X_init,
                                Y=Y_init,
                                initial_design_numdata=initial_design_numdata,
                                initial_design_type='latin',
                                acquisition_type=acq,
                                maximize=is_max)
    myBO.run_optimization(max_iter=max_iter)
    myBO.save_report(report_file=txt_path + '_report.txt')
    myBO.save_evaluations(evaluations_file=txt_path + '_evaluations.txt')
    myBO.save_models(txt_path + '_models.txt')
    result = {
        'sampled_x': np.array(list_sampled_x),
        'observed_y': np.array(list_y),
        'cost': np.array(list_cost),
        'random_seeds': random_seeds
    }
    with open(txt_path + '_result.txt', "w") as file:
        file.write(str(result))
    with open(txt_path + '_result.pickle', "wb") as file:
        pickle.dump(result, file)
示例#2
0
        synthesized_programs = int(out.decode("utf-8"))
        print(synthesized_programs)
        return synthesized_programs


domainMax = None
try:
    domainMax = int(os.environ['DOMAIN_MAX'])
    acquisition_type = os.environ['ACQUISITION']
except KeyError:
    domainMax = 2 if domainMax is None else domainMax
    acquisition_type = 'EI'

domain = [{
    'name': "var-" + gadget,
    'type': 'discrete',
    'domain': tuple(range(0, domainMax))
} for gadget in vocab]
print(domain, acquisition_type)

myBopt = BayesianOptimization(f,
                              domain,
                              maximize=True,
                              exact_feval=True,
                              acquisition_optimizer_type='lbfgs',
                              acquisition_type=acquisition_type)
myBopt.run_optimization(max_iter=35)
myBopt.save_report("report")
myBopt.save_evaluations("evals")
myBopt.plot_convergence("convergence.png")
示例#3
0
# --- Load GPyOpt
from GPyOpt.methods import BayesianOptimization
#import numpy as np

bounds = [#{'name': 'x0', 'type': 'discrete', 'domain': (40,70)},\
         #{'name': 'x1', 'discrete': 'discrete', 'domain': (20,40)},\
          {'name': 'x2', 'type': 'continuous', 'domain': (0.001,0.0000001)}]#,\
          #{'name': 'x3', 'type': 'discrete', 'domain': (20,50)},\
          #{'name': 'x4', 'type': 'continuous', 'domain': (0.95,0.999)},\
           #{'name': 'x5', 'type': 'discrete', 'domain': (20,30)},\
          #{'name': 'x6', 'type': 'continuous', 'domain': (0.01,0.00001)},]



#bounds = [{'name': 'x', 'type': 'continuous', 'domain': [(-1,1),(-1,1)]}]
# --- Solve your problem


test = BayesianOptimization(f=obj_function,domain=bounds)#bounds)
#myBopt = BayesianOptimization(f=f, domain=domain)

test.run_optimization(max_iter=20,verbosity=True,report_file='./report.txt')
test.save_evaluations('./evaluations.txt')
test.plot_acquisition()
test.plot_convergence()

#test.plot_acquisition(filename='./test.png')
test.plot_convergence(filename='./test2.png')
#myBopt.run_optimization(max_iter=5)
#myBopt.plot_acquisition()
示例#4
0
            else:
                sess.run(tf.global_variables_initializer())

            # This is where the asynchronous magic happens.
            # Start the "work" process for each worker in a separate threat.

            worker_threads = []
            temp_best_solutions = np.zeros([len(workers)])
            for worker in workers:
                worker_work = lambda: worker.work(
                    max_episode_length, gamma, sess, coord, saver, saver_best)
                t = threading.Thread(target=(worker_work))
                t.start()
                sleep(0.5)
                worker_threads.append(t)
            coord.join(worker_threads)
            for index, worker in enumerate(workers):
                temp_best_solutions[index] = worker.best_solution
            best_solution_found = np.min(temp_best_solutions)
            return -best_solution_found


if __name__ == "__main__":
    BO = BayesianOptimization(f=objective, domain=dec_ranges)
    BO.run_optimization(max_iter=25,
                        verbosity=True,
                        report_file='./report.txt')
    BO.save_evaluations('./evaluations.txt')
    BO.plot_acquisition()
    BO.plot_convergence()
示例#5
0
            {'name': 'attention_dropout', 'type': 'continuous', 'domain': (0.0, 0.3)},
            {'name': 'relu_dropout', 'type': 'continuous', 'domain': (0.0, 0.3)},
            {'name': 'emb_dim', 'type': 'discrete', 'domain': tuple((i for i in range(60, 500+1))) },
            {'name': 'hop', 'type': 'discrete', 'domain': tuple((i for i in range(1, 10+1)))},
            {'name': 'heads', 'type': 'discrete', 'domain': tuple((i for i in range(1, 10+1)))},
            {'name': 'depth_key', 'type': 'discrete', 'domain': tuple((i for i in range(20, 80+1)))},
            {'name': 'depth_val', 'type': 'discrete', 'domain': tuple((i for i in range(20, 80+1)))},
            {'name': 'filter', 'type': 'discrete', 'domain': tuple((i for i in range(60, 300+1)))},
            {'name': 'batch_size', 'type': 'discrete', 'domain': tuple((i for i in range(32, 64+1)))}]

    X_init = np.array([[0.001,0.0,0.0,0.0,0.0,100,6,4,40,40,50,32]])
    Y_init = h_trs(X_init)
    optimizer = BayesianOptimization(f=h_trs, 
                                    domain=bds,
                                    model_type='GP',
                                    acquisition_type ='EI',
                                    acquisition_jitter = 0.05,
                                    exact_feval=False, 
                                    maximize=True,
                                    X=X_init,
                                    Y=np.array([[Y_init]]),
                                    verbosity_model=True)

    # # Only 20 iterations because we have 5 initial random points
    optimizer.run_optimization(max_iter=100,verbosity=True,report_file="save/{}/report.txt".format(gp_folder))
    optimizer.save_evaluations(evaluations_file="save/{}/evaluation.txt".format(gp_folder))
    optimizer.plot_acquisition(filename="save/{}/acquisition.pdf".format(gp_folder))
    optimizer.plot_convergence(filename="save/{}/convergence.pdf".format(gp_folder))