Skip to content

Commit

Permalink
#12 - remove LIPO from sequential.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleypick committed Jul 12, 2018
1 parent 34df14e commit d384b09
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,6 @@

import numpy as np
from scipy.spatial.distance import pdist, squareform

def lipo(func, bounds, k, n):
"""
Parameters
----------
- func: the (expensive) function to be maximized
- bounds: list of tuples containing boundaries defining the domain of f
- k: the lipschitz constant of f
- n: number of iterations to perform
Returns
------
- x within bounds that returned largest value f(x)
"""

# initialization
y = []
x = []
best = []

bound_mins = np.array([bnd[0] for bnd in bounds])
bound_maxs = np.array([bnd[1] for bnd in bounds])

u = np.random.uniform(size=len(bounds))
x_prop = u * (bound_maxs - bound_mins) + bound_mins

x.append(x_prop)
y.append(func(x[0]))

#lower_bound = lambda x_prop, y, x, k: np.max(y-k*np.linalg.norm(x_prop-x))
upper_bound = lambda x_prop, y, x, k: np.min(y+k*np.linalg.norm(x_prop-x))

# iteration
for t in np.arange(n):
u = np.random.uniform(size=len(bounds))
x_prop = u * (bound_maxs - bound_mins) + bound_mins
if upper_bound(x_prop, y, x, k) >= np.max(y):
x.append(x_prop)
y.append(func(x_prop))
best.append(np.max(y))

output = {
'loss': np.array(best).reshape(n),
'x': np.array(x),
'y': np.array(y)
}
return output

def pure_random_search(func, bounds, n, seed=None):
"""
Expand Down

0 comments on commit d384b09

Please sign in to comment.