Skip to content

Instantly share code, notes, and snippets.

@bkj
Last active June 10, 2018 20:08
Show Gist options
  • Save bkj/5212eb173f9d6491d6233f31949e2161 to your computer and use it in GitHub Desktop.
Save bkj/5212eb173f9d6491d6233f31949e2161 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
dlib_find_min_global.py
Wrapper around `dlib.find_min_global` w/ (I think) better syntax
"""
import dlib
from math import *
def dlib_find_min_global(f, bounds, int_vars=None, **kwargs):
int_vars = [] if int_vars is None else int_vars
# varnames = f.__code__.co_varnames[:f.func_code.co_argcount] # python2.7
varnames = f.__code__.co_varnames[:f.__code__.co_argcount]
bound1_, bound2_, int_vars_ = [], [], []
for varname in varnames:
bound1_.append(bounds[varname][0])
bound2_.append(bounds[varname][1])
int_vars_.append(1 if varname in int_vars else 0)
return dlib.find_min_global(f, bound1=bound1_, bound2=bound2_, is_integer_variable=int_vars_, **kwargs)
def holder_table(x0, x1):
return -abs(sin(x0)*cos(x1)*exp(abs(1-sqrt(x0*x0+x1*x1)/pi)))
x, y = dlib_find_min_global(holder_table, {
"x0" : (-10, 10),
"x1" : (-10, 10),
}, num_function_calls=80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment