Spaces:
Build error
Build error
File size: 1,165 Bytes
783053f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from sklearn.gaussian_process import GaussianProcessRegressor
from scipy.stats import norm
from typing import *
def PI_acquisition(X: List, X_prime: List, model: GaussianProcessRegressor, maximize: bool = True):
"""Acquisition function for bayesian optimization using probability of improvement
Args:
X (List): A list containing the input data
X_prime (List): A list containing the generate samples
model (GaussianProcessRegressor): The gaussian model to use
maximize (bool, optional): A boolean value indicating the optimization objective. Defaults to True.
Returns:
List: A list containing the probabilities
"""
# let us predict the means for the input data
mu = model.predict(X)
# let us calculate the means and standard deviation for the random samples
mu_e, std_e = model.predict(X_prime, return_std=True)
if not maximize:
mu = -mu
mu_e = -mu_e
# let us take the best mean
mu_best = max(mu)
# let us calculate the probability of improvement
probs = norm.cdf((mu_e - mu_best) / std_e)
return probs
|