def evaluate(self, x: np.ndarray) -> np.ndarray: """ Computes the Expected Improvement. :param x: points where the acquisition is evaluated. """ mean, variance = self.model.predict(x) standard_deviation = np.sqrt(variance) y_minimum = np.min(self.model.Y, axis=0) pdf, cdf, u = get_quantiles(self.jitter, y_minimum, mean, standard_deviation) improvement = standard_deviation * (u * cdf + pdf) V_Ix = (standard_deviation**2) * ( ((u * standard_deviation)**2 + 1.0) * cdf + u * standard_deviation * pdf) - improvement**2 # u = u*standard_deviation #Phi=cdf #phi=pdf return improvement / np.sqrt(V_Ix)
def evaluate_with_gradients_II(self, x: np.ndarray) -> Tuple: """ Computes the Expected Improvement and its derivative. :param x: locations where the evaluation with gradients is done. """ mean, variance = self.model.predict(x) standard_deviation = np.sqrt(variance) y_minimum = np.min(self.model.Y, axis=0) dmean_dx, dvariance_dx = self.model.get_prediction_gradients(x) dstandard_deviation_dx = dvariance_dx / (2.0 * standard_deviation) pdf, cdf, u = get_quantiles(self.jitter, y_minimum, mean, standard_deviation) improvement = standard_deviation * (u * cdf + pdf) dimprovement_dx = dstandard_deviation_dx * pdf - cdf * dmean_dx V_Ix = (standard_deviation**2.0) * ( ((u * standard_deviation)**2 + 1.0) * cdf + u * standard_deviation * pdf) - improvement**2 dscaled_ei_dx = (dimprovement_dx * np.sqrt(V_Ix) - \ 0.5 * improvement * np.power(V_Ix, -0.5) * (2.0 * standard_deviation * (((u * standard_deviation) ** 2 + 1.0) * cdf + u * standard_deviation * pdf) * dstandard_deviation_dx + 2.0 * improvement * dimprovement_dx)) / V_Ix return improvement / np.sqrt(V_Ix), dscaled_ei_dx, V_Ix, improvement
def _compute_acq(self, x): m, s = self.model.predict(x) fmin = self.target if self.target is not None else self.model.get_fmin( ) _, Phi, _ = get_quantiles(self.jitter, fmin, m, s) f_acqu = Phi self.jitter *= .5 return f_acqu
def _compute_acq(self, x): """ Computes the Expected Improvement """ m, s = self.model.predict(x) fmin = self.model.get_fmin() phi, Phi, u = get_quantiles(self.jitter, fmin, m, s) f_acqu = s * (u * Phi + phi) return f_acqu
def _compute_acq_withGradients(self, x): """ Computes the Expected Improvement and its derivative """ fmin = self.model.get_fmin() m, s, dmdx, dsdx = self.model.predict_withGradients(x) phi, Phi, u = get_quantiles(self.jitter, fmin, m, s) f_acqu = s * (u * Phi + phi) df_acqu = dsdx * phi - Phi * dmdx return f_acqu, df_acqu
def _compute_acq_withGradients(self, x): fmin = self.target if self.target is not None else self.model.get_fmin( ) m, s, dmdx, dsdx = self.model.predict_withGradients(x) phi, Phi, u = get_quantiles(self.jitter, fmin, m, s) f_acqu = Phi df_acqu = -(phi / s) * (dmdx + dsdx * u) self.jitter *= .5 return f_acqu, df_acqu
def PI(self, x, pys, pss): num_samples = pys.shape[0] acq = 0 for i in range(num_samples): y = pys[i] s = pss[i] _, Phi, _ = get_quantiles(self.eps, self.tau, y, s) f_acqu = Phi acq += f_acqu acq /= self.s.shape[0] return acq
def _compute_acq(self, x): """ :param x: test location :return f_acqu: acqusition function value """ m, s = self.model.predict(x) fmin = self.model.get_fmin() phi, Phi, u = get_quantiles(self.jitter, fmin, m, s) f_acqu = s * (u * Phi + phi) return f_acqu
def EI(self, x, pys, pss): num_samples = pys.shape[0] acq = 0 for i in range(num_samples): y = pys[i] s = pss[i] phi, Phi, u = get_quantiles(self.eps, self.tau, y, s) f_acqu = s * (u * Phi + phi) acq += f_acqu acq /= self.s.shape[0] return acq
def evaluate(self, x: np.ndarray) -> np.ndarray: """ Computes the probability of improving over the current best :param x: points where the acquisition is evaluated. """ mean, variance = self.model.predict(x) standard_deviation = np.sqrt(variance) y_minimum = np.min(self.model.Y, axis=0) _, cdf, _ = get_quantiles(self.jitter, y_minimum, mean, standard_deviation) return cdf
def _compute_acq_withGradients(self, x): """ :param x: test location :return f_acqu: acqusition function value :return df_acqu: derivative of acqusition function values w.r.t test location """ fmin = self.model.get_fmin() m, s, dmdx, dsdx = self.model.predict_withGradients(x) phi, Phi, u = get_quantiles(self.jitter, fmin, m, s) f_acqu = s * (u * Phi + phi) df_acqu = dsdx * phi - Phi * dmdx return f_acqu, df_acqu
def _compute_acq(self, x): m, s = self.model.predict(x) fmin = self.model.get_fmin() phi, Phi, _ = get_quantiles(self.jitter, fmin, m, s) h = 0.5 * np.log(2 * math.pi * math.e * np.square(s)) if self.prev != None and abs(self.prev - fmin) < 1: self.prev = fmin return h self.prev = fmin f_acqu_x = h if ( self.explore % self.cycle) == 0 else (fmin - m + self.jitter) * Phi + s * phi self.explore += 1 self.explore %= self.cycle return f_acqu_x
def evaluate(self, x: np.ndarray) -> np.ndarray: """ Computes the Expected Improvement. :param x: points where the acquisition is evaluated. """ mean, variance = self.model.predict(x) standard_deviation = np.sqrt(variance) y_minimum = np.min(self.model.Y, axis=0) pdf, cdf, u = get_quantiles(self.jitter, y_minimum, mean, standard_deviation) improvement = standard_deviation * (u * cdf + pdf) return improvement
def evaluate_with_gradients(self, x: np.ndarray) -> Tuple: """ Computes the probability of improving over the current best and its derivative :param x: points where the acquisition is evaluated. """ mean, variance = self.model.predict(x) standard_deviation = np.sqrt(variance) dmean_dx, dvariance_dx = self.model.get_prediction_gradients(x) dstandard_devidation_dx = dvariance_dx / (2 * standard_deviation) y_minimum = np.min(self.model.Y, axis=0) pdf, cdf, u = get_quantiles(self.jitter, y_minimum, mean, standard_deviation) dcdf_dx = - (pdf / standard_deviation) * (dmean_dx + dstandard_devidation_dx * u) return cdf, dcdf_dx
def evaluate_with_gradients(self, x: np.ndarray) -> Tuple: """ Computes the Expected Improvement and its derivative. :param x: locations where the evaluation with gradients is done. """ mean, variance = self.model.predict(x) standard_deviation = np.sqrt(variance) y_minimum = np.min(self.model.Y, axis=0) dmean_dx, dvariance_dx = self.model.get_prediction_gradients(x) dstandard_deviation_dx = dvariance_dx / (2 * standard_deviation) pdf, cdf, u = get_quantiles(self.jitter, y_minimum, mean, standard_deviation) improvement = standard_deviation * (u * cdf + pdf) dimprovement_dx = dstandard_deviation_dx * pdf - cdf * dmean_dx return improvement, dimprovement_dx