Created
June 13, 2017 13:14
-
-
Save josejimenezluna/ed222c4cf6b21cbd7d4b5186f3f132b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from pyGPGO.covfunc import matern32 | |
from pyGPGO.acquisition import Acquisition | |
from pyGPGO.surrogates.GaussianProcess import GaussianProcess | |
from pyGPGO.GPGO import GPGO | |
def f(x, y): | |
# Franke's function (https://www.mathworks.com/help/curvefit/franke.html) | |
one = 0.75 * np.exp(-(9 * x - 2) ** 2 / 4 - (9 * y - 2) ** 2 / 4) | |
two = 0.75 * np.exp(-(9 * x + 1) ** 2/ 49 - (9 * y + 1) / 10) | |
three = 0.5 * np.exp(-(9 * x - 7) ** 2 / 4 - (9 * y -3) ** 2 / 4) | |
four = 0.25 * np.exp(-(9 * x - 4) ** 2 - (9 * y - 7) ** 2) | |
return one + two + three - four | |
cov = matern32() | |
gp = GaussianProcess(cov, optimize=True, usegrads=True) | |
acq = Acquisition(mode='ExpectedImprovement') | |
param = {'x': ('cont', [0, 1]), | |
'y': ('cont', [0, 1])} | |
X = np.array([[0.25, 0.25], [0.75, 0.5], [0.25, 0.4]]) | |
y = np.array([f(x[0], x[1]) for x in X]) | |
gp.fit(X, y) # We need to fit the GP manually before | |
np.random.seed(1337) | |
gpgo = GPGO(gp, acq, f, param) | |
gpgo.tau = np.max(y) # Need to set tau and init_evals manually | |
gpgo.init_evals = len(y) | |
gpgo.run(max_iter=10, resume=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment