"""Acquisition functions derived from Bayesian optimization"""fromtypingimportSequenceimportnumpyasnpfrommodAL.acquisitionimportEIfromexamol.select.baseimportRankingSelector,_extract_observationsfromexamol.store.db.baseimportMoleculeStorefromexamol.store.recipesimportPropertyRecipe
[docs]classExpectedImprovement(RankingSelector):"""Rank entries according to their expected improvement Args: to_select: How many computations to select per batch maximize: Whether to select entries with the highest score epsilon: Parameter which controls degree of exploration """def__init__(self,to_select:int,maximize:bool,epsilon:float=0):super().__init__(to_select,maximize)self.epsilon=epsilonself.best_so_far=0
def_assign_score(self,samples:np.ndarray)->np.ndarray:# Compute the mean and standard deviation for each entrymean=samples.mean(axis=(0,2))std=samples.std(axis=(0,2))# If we are minimizing, invert the valuesmax_y=self.best_so_farreturnEI(mean,std,max_val=max_y,tradeoff=self.epsilon)