thursday/thursday/dlibcube2.py

18 lines
590 B
Python
Raw Normal View History

2023-05-04 15:08:14 -07:00
from dlib import find_min_global
2023-05-07 05:30:53 -07:00
from .randomcube2 import another_random_cube
from .utils import wrap_untrustworthy, final
2023-05-04 15:08:14 -07:00
def dlib_cube(objective, n_trials, n_dim, with_count):
if n_dim > 35:
return another_random_cube(objective, n_trials, n_dim, with_count)
_objective = wrap_untrustworthy(objective, n_trials)
def __objective(*args):
return _objective(list(args))
find_min_global(__objective, [0.0] * n_dim, [1.0] * n_dim, n_trials)
fopt, xopt, feval_count = _objective(final)
return (fopt, xopt, feval_count) if with_count else (fopt, xopt)