Beispiel #1
0
    def test_hartmann3(self):
        f = synthetic_functions.Hartmann3()

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

    _hartmann = hpobench.Hartmann3()

    ORIGINAL_MAX_ARGUMENT = np.array([[0., 0., 0.]])
    ORIGINAL_MAX = _hartmann.objective_function(
        ORIGINAL_MAX_ARGUMENT[0])["function_value"]
    ORIGINAL_MIN = _hartmann.get_meta_information()["f_opt"]
    ORIGINAL_MIN_ARGUMENT = np.array(
        _hartmann.get_meta_information()["optima"])
    ORIGINAL_UPPER_BOUNDS = np.array([1., 1., 1.])
    ORIGINAL_LOWER_BOUNDS = np.array([0., 0., 0.])

    INVERT = True

    @classmethod
    def base_function(cls, x):
        return cls._hartmann.objective_function(x)["function_value"]
Beispiel #3
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),
))
 def __init__(self, path=None):
     super().__init__(synthetic_functions.Hartmann3(), path)