Esempio n. 1
0
    def test_branin(self):
        f = synthetic_functions.Branin()

        for x in f.get_meta_information()["optima"]:
            np.testing.assert_approx_equal(f(x),
                                           f.get_meta_information()["f_opt"],
                                           significant=9)
Esempio n. 2
0
class Branin2D(AbstractFunction):

    _branin = hpobench.Branin()

    ORIGINAL_MAX_ARGUMENT = np.array([[-5, 0.]])
    ORIGINAL_MAX = _branin.objective_function(ORIGINAL_MAX_ARGUMENT[0])["function_value"]
    ORIGINAL_MIN = np.array(_branin.get_meta_information()["f_opt"])
    ORIGINAL_MIN_ARGUMENT = np.array(_branin.get_meta_information()["optima"])
    ORIGINAL_UPPER_BOUNDS = np.array([10., 15.])
    ORIGINAL_LOWER_BOUNDS = np.array([-5., 0.])

    INVERT = True

    @classmethod
    def base_function(cls, x):
        return cls._branin.objective_function(x)["function_value"]
Esempio n. 3
0
    smac = SMAC(scenario=scenario, tae_runner=b,
                rng=np.random.RandomState(seed))
    x_star = smac.optimize()

    print("Best value found:\n {:s}".format(str(x_star)))
    print("with {:s}".format(str(b.objective_function(x_star))))


if __name__ == "__main__":
    """
     This script tries to use the first given argument as a benchmark and the
     second as a seed, e.g.

     python smac_on_testfunction.py Branin 23
     python smac_on_testfunction.py hartmann3 23
    """

    try:
        benchmark = getattr(hpobench, sys.argv[1])()
    except AttributeError:
        print("Use Branin")
        benchmark = hpobench.Branin()

    try:
        seed = int(float(sys.argv[2]))
    except:
        seed = np.random.randn(1, 1)

    main(b=benchmark, seed=seed)
Esempio n. 4
0
import numpy as np
import scipy.optimize as spopt

import hpolib.benchmarks.synthetic_functions as hpobench

# Run Scipy.minimize on artificial testfunctions

h3 = hpobench.Hartmann3()
h6 = hpobench.Hartmann6()
b = hpobench.Branin()

for f in [b, h3, h6]:
    info = f.get_meta_information()

    print("=" * 50)
    print(info['name'])

    bounds = np.array(info['bounds'])

    res = spopt.minimize(f, (bounds[:, 0] + bounds[:, 1]) / 2,
                         bounds=bounds,
                         method='SLSQP')

    assert (np.allclose(res.fun, info['f_opt']))

    for o in info['optima']:
        print("There is an optimum at \t "
              "x={} with f(x) = {}".format(o, info['f_opt']))

    print("scipy.optimize found \t x={} with f(x) = {}".format(res.x, res.fun))
sys.path.insert(0, path_join(dirname(__file__), "robo"))
sys.path.insert(0, path_join(dirname(__file__), "pysgmcmc_development"))
from collections import OrderedDict
from functools import partial
from itertools import product

from pysgmcmc_experiments.experiment_wrapper import to_experiment

import numpy as np
from robo.fmin import (bayesian_optimization, entropy_search, random_search,
                       bohamiann)
from robo.fmin.keras_bohamiann import bohamiann as keras_bohamiann
import hpolib.benchmarks.synthetic_functions as hpobench

BENCHMARKS = OrderedDict(
    (("branin", hpobench.Branin()), ("hartmann3", hpobench.Hartmann3()),
     ("hartmann6", hpobench.Hartmann6()), ("camelback", hpobench.Camelback()),
     ("goldstein_price", hpobench.GoldsteinPrice()), ("rosenbrock",
                                                      hpobench.Rosenbrock()),
     ("sin_one", hpobench.SinOne()), ("sin_two", hpobench.SinTwo()),
     ("bohachevsky", hpobench.Bohachevsky()), ("levy", hpobench.Levy())))

METHODS = OrderedDict((
    ("rf", partial(bayesian_optimization, model_type="rf")),
    ("gp", partial(bayesian_optimization, model_type="gp")),
    ("gp_mcmc", partial(bayesian_optimization, model_type="gp_mcmc")),
    ("entropy_search", entropy_search),
    ("random_search", random_search),
    ("bohamiann", bohamiann),
    ("keras_bohamiann", keras_bohamiann),
))
Esempio n. 6
0
 def __init__(self, path=None):
     super().__init__(synthetic_functions.Branin(), path, min_value=-2)