Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save josejimenezluna/624db7feb941a0efdacf4b784ddf557d to your computer and use it in GitHub Desktop.
Save josejimenezluna/624db7feb941a0efdacf4b784ddf557d to your computer and use it in GitHub Desktop.
custom_init.py
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