Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kappa decay #224

Merged
merged 1 commit into from May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion bayes_opt/bayesian_optimization.py
Expand Up @@ -154,6 +154,8 @@ def maximize(self,
n_iter=25,
acq='ucb',
kappa=2.576,
kappa_decay=1,
kappa_decay_delay=0,
xi=0.0,
**gp_params):
"""Mazimize your function"""
Expand All @@ -162,12 +164,17 @@ def maximize(self,
self._prime_queue(init_points)
self.set_gp_params(**gp_params)

util = UtilityFunction(kind=acq, kappa=kappa, xi=xi)
util = UtilityFunction(kind=acq,
kappa=kappa,
xi=xi,
kappa_decay=kappa_decay,
kappa_decay_delay=kappa_decay_delay)
iteration = 0
while not self._queue.empty or iteration < n_iter:
try:
x_probe = next(self._queue)
except StopIteration:
util.update_params()
x_probe = self.suggest(util)
iteration += 1

Expand Down
16 changes: 12 additions & 4 deletions bayes_opt/util.py
Expand Up @@ -76,13 +76,15 @@ class UtilityFunction(object):
An object to compute the acquisition functions.
"""

def __init__(self, kind, kappa, xi):
"""
If UCB is to be used, a constant kappa is needed.
"""
def __init__(self, kind, kappa, xi, kappa_decay=1, kappa_decay_delay=0):

self.kappa = kappa
self._kappa_decay = kappa_decay
self._kappa_decay_delay = kappa_decay_delay

self.xi = xi

self._iters_counter = 0

if kind not in ['ucb', 'ei', 'poi']:
err = "The utility function " \
Expand All @@ -92,6 +94,12 @@ def __init__(self, kind, kappa, xi):
else:
self.kind = kind

def update_params(self):
self._iters_counter += 1

if self._kappa_decay < 1 and self._iters_counter > self._kappa_decay_delay:
self.kappa *= self._kappa_decay

def utility(self, x, gp, y_max):
if self.kind == 'ucb':
return self._ucb(x, gp, self.kappa)
Expand Down