Skip to content

Commit

Permalink
complete bayesian optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
IHIaadj committed Jun 20, 2023
1 parent cf2c70e commit 80a3279
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion analogainas/search_algorithms/bo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,46 @@ def acquisition(self, X, Xsamples, model):
probs = (mu - best) / (std+1E-9)
return probs

def maximize(self):
for _ in range(self.n_iter):
x_next = self.propose_next_point()
y_next = self.evaluate_func(x_next)

self.X.append(x_next)
self.y.append(y_next)

best_idx = np.argmax(self.y)
best_x = self.X[best_idx]
best_y = self.y[best_idx]
return best_x, best_y

def propose_next_point(self):
x_candidates = self.random_state.uniform(
low=self.search_space[:, 0],
high=self.search_space[:, 1],
size=(100, self.search_space.shape[0])
)

best_x = None
best_acquisition = float('-inf')

for x in x_candidates:
acquisition = self.acquisition(x)
if acquisition > best_acquisition:
best_x = x
best_acquisition = acquisition

return best_x

def gaussian_process_regression(self):
# Define your surrogate model (Gaussian Process) and fit it to the data
# Example: Mean of 0, Standard Deviation of 1
mean = 0.0
std = 1.0
return mean, std

# optimize the acquisition function
def bayesian_search(self, X, y, model):
def run(self, X, y, model):
# random search, generate random samples
Xsamples = self.rs_search(100)
Xsamples = Xsamples.reshape(len(Xsamples), 1)
Expand Down

0 comments on commit 80a3279

Please sign in to comment.