ActiveBOToytask/AcquistionFunctions/ExpectedImprovement.py
2023-04-21 12:27:29 +02:00

17 lines
533 B
Python

import numpy as np
from scipy.stats import norm
def ExpectedImprovement(gp, X, nr_test, nr_weights, kappa=2.576, seed=None, lower=-1.0, upper=1.0):
y_hat = gp.predict(X)
best_y = max(y_hat)
rng = np.random.default_rng(seed=seed)
X_test = rng.uniform(lower, upper, (nr_test, nr_weights))
mu, sigma = gp.predict(X_test, return_std=True)
z = (mu - best_y - kappa) / sigma
ei = (mu - best_y - kappa) * norm.cdf(z) + sigma * norm.pdf(z)
idx = np.argmax(ei)
X_next = X_test[idx, :]
return X_next