Example #1
0
def run_test():
    print('===== Test Start =====')
    # Define Search Space
    space = sp.Space()
    x1 = sp.Real("x1", -5, 10, default_value=0)
    x2 = sp.Real("x2", 0, 15, default_value=0)
    space.add_variables([x1, x2])

    # Run
    try:
        max_runs = 10
        opt = Optimizer(
            branin,
            space,
            max_runs=max_runs,
            time_limit_per_trial=30,
            task_id='test_install',
        )
        history = opt.run()
    except Exception:
        print(traceback.format_exc())
        print('===== Exception in run_test()! Please check. =====')
    else:
        cnt = history.trial_states.count(SUCCESS)
        if cnt == max_runs:
            print('===== Congratulations! All trials succeeded. =====')
        else:
            print('===== %d/%d trials failed! Please check. =====' %
                  (max_runs - cnt, max_runs))
Example #2
0
    result = dict()
    result['objs'] = [
        t1 + t2 + t3,
    ]
    result['constraints'] = [
        np.sum((X + 5)**2) - 25,
    ]
    return result


if __name__ == "__main__":
    params = {'float': {'x0': (-10, 0, -5), 'x1': (-6.5, 0, -3.25)}}
    space = sp.Space()
    space.add_variables(
        [sp.Real(name, *para) for name, para in params['float'].items()])

    opt = Optimizer(
        mishra,
        space,
        num_constraints=1,
        num_objs=1,
        surrogate_type='gp',
        acq_optimizer_type='random_scipy',
        max_runs=50,
        time_limit_per_trial=10,
        task_id='soc',
    )
    history = opt.run()

    print(history)
# License: MIT

import numpy as np
import matplotlib.pyplot as plt
from openbox import Advisor, sp, Observation

# Define Search Space
space = sp.Space()
x1 = sp.Real("x1", -5, 10, default_value=0)
x2 = sp.Real("x2", 0, 15, default_value=0)
space.add_variables([x1, x2])


# Define Objective Function
def branin(config):
    x1, x2 = config['x1'], config['x2']
    y = (x2 - 5.1 / (4 * np.pi ** 2) * x1 ** 2 + 5 / np.pi * x1 - 6) ** 2 \
        + 10 * (1 - 1 / (8 * np.pi)) * np.cos(x1) + 10
    return {'objs': (y, )}


# Run
if __name__ == "__main__":
    advisor = Advisor(
        space,
        # surrogate_type='gp',
        surrogate_type='auto',
        task_id='quick_start',
    )

    MAX_RUNS = 50
    px2 = 15 * x2

    f1 = (px2 - 5.1 / (4 * np.pi ** 2) * px1 ** 2 + 5 / np.pi * px1 - 6) ** 2 \
         + 10 * (1 - 1 / (8 * np.pi)) * np.cos(px1) + 10
    f2 = (1 - np.exp(-1 / (2 * x2))) * (2300 * x1 ** 3 + 1900 * x1 ** 2 + 2092 * x1 + 60) \
         / (100 * x1 ** 3 + 500 * x1 ** 2 + 4 * x1 + 20)

    result = dict()
    result['objs'] = [f1, f2]
    return result


if __name__ == "__main__":
    # search space
    space = sp.Space()
    x1 = sp.Real("x1", 0, 1)
    x2 = sp.Real("x2", 0, 1)
    space.add_variables([x1, x2])

    # provide reference point if using EHVI method
    ref_point = [18.0, 6.0]

    # run
    opt = Optimizer(
        BraninCurrin,
        space,
        num_objs=2,
        num_constraints=0,
        max_runs=50,
        surrogate_type='gp',
        acq_type='ehvi',
Example #5
0
    obj1 = x1
    obj2 = (1.0 + x2) / x1

    c1 = 6.0 - 9.0 * x1 - x2
    c2 = 1.0 - 9.0 * x1 + x2

    result = dict()
    result['objs'] = [obj1, obj2]
    result['constraints'] = [c1, c2]
    return result


if __name__ == "__main__":
    # search space
    space = sp.Space()
    x1 = sp.Real("x1", 0.1, 10.0)
    x2 = sp.Real("x2", 0.0, 5.0)
    space.add_variables([x1, x2])

    # provide reference point if using EHVI method
    ref_point = [10.0, 10.0]

    # run
    opt = Optimizer(
        CONSTR,
        space,
        num_objs=2,
        num_constraints=2,
        max_runs=20,
        surrogate_type='gp',
        acq_type='ehvic',