!pip install GPy
!pip install GPyOpt

import GPy
import GPyOpt
import numpy as np

#予備実験のデータ
initial_x = np.array([[-1, 0.5],[-1,0.5]])
initial_y = np.array([1, 0.25])

print(initial_x)

initial_x = initial_x.reshape((-1,1))
initial_y = initial_y.reshape((-1,1))

#実験回数
exp_num = 5

try_ = 1

def f(x):
    global try_

    print("Try : " , try_ , " / {0} , next x is ".format(exp_num) , x)
    score = float(input("Input y : "))

    try_ += 1

    return score
  

bounds = [
          {'name': 'x1', 'type': 'continuous', 'domain': (-2,2)},
          {'name': 'x2', 'type': 'continuous', 'domain': (-2,2)}
          ]#実験条件の範囲

print("Bayesian Optimization")

#予備実験のデータを持っていない場合はinitial_design_numdataの値を変更
myBopt = GPyOpt.methods.BayesianOptimization(f=f,
                                             domain=bounds)
myBopt.run_optimization(max_iter=exp_num)

#最適なパラメータ
print("Best x is ",myBopt.x_opt)

#これいいね
#https://nykergoto.hatenablog.jp/entry/2017/05/29/python%E3%81%A7%E3%82%AC%E3%82%A6%E3%82%B9%E9%81%8E%E7%A8%8B%E5%9B%9E%E5%B8%B0_~_%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%81%AE%E6%AF%94%E8%BC%83_~