I'm trying to find a (relatively) fast way to minimise a function on the set of natural numbers given constraints and bounds. I know the mathematical form of the function and its constraints, so a brute force approach seems slow and not very elegant. What's the best way to go about this problem?
Basically I'm trying to generalise from a functional minimisation on the real numbers using scipy.optimize.minimize to one on the natural numbers. (I'm aware that this is a lot harder)
To make things easy. I'm thinking of something like this example:
from scipy import optimize
x0 = [0,0]
cons = ({'type': 'ineq', 'fun': lambda x: 0.4 - x[1]})
bounds = ((0,None),(0,None))
fun = lambda x: (x[0]-1.5)**2 + (x[1]-0.5)**2 + 3
res = optimize.minimize(fun, x0=x0, bounds=bounds, constraints=cons)
print(res)
Put differently, I'm looking to add constraints and bounds on
fun = lambda x: (x[0]-1.5)**2 + (x[1]-0.5)**2 + 3
xr = [(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(1,3),(2,0),(2,1),(2,2),(2,3),(3,0),(3,1),(3,2),(3,3),]
min_idx = min(xr, key=fun)
min_val = fun(min_idx)
print(min_idx,min_val)
(I know I could impose them by excluding those values from xr, but that seems very little elegant and less practical for the actual thing I have in mind)
So I'm expecting there to be some sort of different minimiser like scipy.optimize.basinhopping or something from mystic to do the trick? Any suggestions?