コード例 #1
0
def test_BO(dim, obj_fun, ftarget, max_FEs, lb, ub, logfile):
    sys.path.insert(0, '../')
    from bayes_optim import AnnealingBO, BO, ContinuousSpace
    from bayes_optim.Surrogate import GaussianProcess, trend

    space = ContinuousSpace(list(zip(lb, ub)))
    mean = trend.constant_trend(dim,
                                beta=None)  # equivalent to Ordinary Kriging
    thetaL = 1e-10 * (ub - lb) * np.ones(dim)
    thetaU = 10 * (ub - lb) * np.ones(dim)
    theta0 = np.random.rand(dim) * (thetaU - thetaL) + thetaL

    model = GaussianProcess(mean=mean,
                            corr='matern',
                            theta0=theta0,
                            thetaL=thetaL,
                            thetaU=thetaU,
                            noise_estim=False,
                            nugget=1e-6,
                            optimizer='BFGS',
                            wait_iter=5,
                            random_start=5 * dim,
                            likelihood='concentrated',
                            eval_budget=100 * dim)

    return BO(search_space=space,
              obj_fun=obj_fun,
              model=model,
              DoE_size=dim * 5,
              max_FEs=max_FEs,
              verbose=False,
              n_point=1,
              minimize=True,
              ftarget=ftarget,
              logger=logfile)
コード例 #2
0
def test_pickling2():
    dim = 5
    lb, ub = -1, 5

    def fitness(x):
        x = np.asarray(x)
        return np.sum(x**2)

    space = ContinuousSpace([lb, ub]) * dim

    mean = trend.constant_trend(dim, beta=None)
    thetaL = 1e-10 * (ub - lb) * np.ones(dim)
    thetaU = 10 * (ub - lb) * np.ones(dim)
    theta0 = np.random.rand(dim) * (thetaU - thetaL) + thetaL

    model = GaussianProcess(mean=mean,
                            corr='squared_exponential',
                            theta0=theta0,
                            thetaL=thetaL,
                            thetaU=thetaU,
                            nugget=0,
                            noise_estim=False,
                            optimizer='BFGS',
                            wait_iter=3,
                            random_start=dim,
                            likelihood='concentrated',
                            eval_budget=100 * dim)
    opt = BO(search_space=space,
             obj_fun=fitness,
             model=model,
             DoE_size=5,
             max_FEs=10,
             verbose=True,
             n_point=1,
             logger='log')
    opt.save('test')
    opt = BO.load('test')

    print(opt.run())

    os.remove('test')
    os.remove('log')
コード例 #3
0
def test_BO(dim, obj_fun, ftarget, max_FEs, lb, ub, logfile):
    sys.path.insert(0, "../")
    from bayes_optim import BO, AnnealingBO, RealSpace
    from bayes_optim.Surrogate import GaussianProcess, trend

    space = RealSpace([lb, ub]) * dim

    mean = trend.constant_trend(dim, beta=0)  # equivalent to Ordinary Kriging
    thetaL = 1e-10 * (ub - lb) * np.ones(dim)
    thetaU = 10 * (ub - lb) * np.ones(dim)
    theta0 = np.random.rand(dim) * (thetaU - thetaL) + thetaL

    model = GaussianProcess(
        mean=mean,
        corr="matern",
        theta0=theta0,
        thetaL=thetaL,
        thetaU=thetaU,
        noise_estim=False,
        nugget=1e-6,
        optimizer="BFGS",
        wait_iter=5,
        random_start=5 * dim,
        likelihood="concentrated",
        eval_budget=100 * dim,
    )

    return BO(
        search_space=space,
        obj_fun=obj_fun,
        model=model,
        DoE_size=dim * 5,
        max_FEs=max_FEs,
        verbose=False,
        n_point=1,
        minimize=True,
        ftarget=ftarget,
        logger=logfile,
    )
コード例 #4
0
from bayes_optim import BO, ContinuousSpace
from bayes_optim.Surrogate import GaussianProcess, trend

np.random.seed(123)
dim = 5
lb, ub = -1, 5


def fitness(x):
    x = np.asarray(x)
    return np.sum(x**2)


space = ContinuousSpace([lb, ub]) * dim

mean = trend.constant_trend(dim, beta=None)
thetaL = 1e-10 * (ub - lb) * np.ones(dim)
thetaU = 10 * (ub - lb) * np.ones(dim)
theta0 = np.random.rand(dim) * (thetaU - thetaL) + thetaL

model = GaussianProcess(theta0=theta0,
                        thetaL=thetaL,
                        thetaU=thetaU,
                        nugget=0,
                        noise_estim=False,
                        optimizer='BFGS',
                        wait_iter=3,
                        random_start=dim,
                        likelihood='concentrated',
                        eval_budget=100 * dim)