Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions humpday/optimizers/dlibcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This library also provides global_function_search which is pretty darn cool

try:
from dlib import find_min_global
from dlib import find_min_global, global_function_search, function_spec
using_dlib = True
except ImportError:
using_dlib = False
Expand Down Expand Up @@ -35,8 +35,38 @@ def dlib_curl2_cube(objective ,n_trials, n_dim, with_count):
# Meh
return curl_factory(optimizer=dlib_default_cube,objective=objective, n_trials=n_trials, n_dim=n_dim, with_count=with_count, d=2)

DLIB_OPTIMIZERS = [dlib_cube, dlib_default_cube ]
DLIB_TOP_OPTIMIZERS = [dlib_cube, dlib_default_cube ]
def dlib_gfs_default_cube(objective, n_trials, n_dim, with_count=False):
global feval_count
feval_count = 0
lb = [0.0 for _ in range(n_dim)]
ub = [1.0 for _ in range(n_dim)]
func_spec = function_spec(lb, ub)
search = global_function_search(func_spec)
best_val = float('inf')
best_x = None
for _ in range(n_trials):
next_x = search.get_next_x()

feval_count += 1
y = objective(list(next_x.x))

if y < best_val:
best_val = y
best_x = list(next_x.x)

next_x.set(-y)

return (best_val, best_x, feval_count) if with_count else (best_val, best_x)

def dlib_gfs_cube(objective, n_trials, n_dim, with_count):
return dlib_gfs_default_cube(objective=objective, n_trials=n_trials, n_dim=n_dim, with_count=with_count) # It is useful to have a clone of one of the better algos

def dlib_gfs_curl2_cube(objective, n_trials, n_dim, with_count):
# Meh
return curl_factory(optimizer=dlib_gfs_default_cube, objective=objective, n_trials=n_trials, n_dim=n_dim, with_count=with_count, d=2)

DLIB_OPTIMIZERS = [dlib_cube, dlib_default_cube, dlib_gfs_cube, dlib_gfs_default_cube]
DLIB_TOP_OPTIMIZERS = [dlib_cube, dlib_default_cube, dlib_gfs_cube, dlib_gfs_default_cube]
else:
DLIB_OPTIMIZERS = []
DLIB_TOP_OPTIMIZERS = []
Expand All @@ -49,4 +79,4 @@ def dlib_curl2_cube(objective ,n_trials, n_dim, with_count):
print(' ')
print(objective.__name__)
for optimizer in DLIB_OPTIMIZERS:
print(optimizer(objective, n_trials=500, n_dim=34, with_count=True))
print(optimizer(objective, n_trials=500, n_dim=34, with_count=True))