Skip to content

Instantly share code, notes, and snippets.

@avisheknag17
Created June 13, 2021 05:17
Show Gist options
  • Save avisheknag17/95bf5796578643cdbd23cb4592d5a7c3 to your computer and use it in GitHub Desktop.
Save avisheknag17/95bf5796578643cdbd23cb4592d5a7c3 to your computer and use it in GitHub Desktop.
def _extend_prior_with_posterior_data(self, x,y):
self.x_init = np.append(self.x_init, np.array([x]), axis = 0)
self.y_init = np.append(self.y_init, np.array(y), axis = 0)
def optimize(self):
y_max_ind = np.argmax(self.y_init)
y_max = self.y_init[y_max_ind]
optimal_x = self.x_init[y_max_ind]
optimal_ei = None
for i in range(self.n_iter):
self.gauss_pr.fit(self.x_init, self.y_init)
x_next, ei = self._get_next_probable_point()
y_next = self.target_func(np.array([x_next]))
self._extend_prior_with_posterior_data(x_next,y_next)
if y_next[0] > y_max:
y_max = y_next[0]
optimal_x = x_next
optimal_ei = ei[0]
if i == 0:
prev_x = x_next
else:
self.distances_.append(np.linalg.norm(prev_x - x_next))
prev_x = x_next
self.best_samples_ = self.best_samples_.append({"y": y_max, "ei": optimal_ei},ignore_index=True)
return optimal_x, y_max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment