def optimize(cost,lower,upper): # generate arrays of points defining a grid in parameter space grid_dimensions = len(lower) bins = [] for i in range(grid_dimensions): step = abs(upper[i] - lower[i])/nbins[i] bins.append( [lower[i] + (j+0.5)*step for j in range(nbins[i])] ) # build a grid of starting points initial_values = gridpts(bins) # run optimizer for each grid point lb = [lower for i in range(len(initial_values))] ub = [upper for i in range(len(initial_values))] cf = [cost for i in range(len(initial_values))] # map:: params, energy, func_evals = local_optimize(cost,x0,lb,ub) results = map(local_optimize, cf, initial_values, lb, ub) #print "results = %s" % results # get the results with the lowest energy best = list(results[0][0]), results[0][1] func_evals = results[0][2] for result in results[1:]: func_evals += result[2] # add function evaluations if result[1] < best[1]: # compare energy best = list(result[0]), result[1] # return best print "solved: %s" % best[0] diameter_squared = -best[1] / scale #XXX: scale != 0 return diameter_squared, func_evals
def optimize(cost, lower, upper, nbins): from mystic.tools import random_seed from pyina.launchers import TorqueMpi as Pool random_seed(123) # generate arrays of points defining a grid in parameter space grid_dimensions = len(lower) bins = [] for i in range(grid_dimensions): step = abs(upper[i] - lower[i]) / nbins[i] bins.append([lower[i] + (j + 0.5) * step for j in range(nbins[i])]) # build a grid of starting points from mystic.math.grid import gridpts from pool_helper import local_optimize from pool_helper import nnodes, queue, timelimit initial_values = gridpts(bins) # run optimizer for each grid point lb = [lower for i in range(len(initial_values))] ub = [upper for i in range(len(initial_values))] cf = [cost for i in range(len(initial_values))] # map:: params, energy, func_evals = local_optimize(cost,x0,lb,ub) config = {'queue': queue, 'timelimit': timelimit} results = Pool(nnodes, **config).map(local_optimize, cf, initial_values, lb, ub) #print("results = %s" % results) # get the results with the lowest energy best = list(results[0][0]), results[0][1] func_evals = results[0][2] for result in results[1:]: func_evals += result[2] # add function evaluations if result[1] < best[1]: # compare energy best = list(result[0]), result[1] # return best print("solved: %s" % best[0]) scale = 1.0 diameter_squared = -best[1] / scale #XXX: scale != 0 return diameter_squared, func_evals
def optimize(cost,lower,upper,nbins): from mystic.tools import random_seed from pyina.launchers import TorqueMpi as Pool random_seed(123) # generate arrays of points defining a grid in parameter space grid_dimensions = len(lower) bins = [] for i in range(grid_dimensions): step = abs(upper[i] - lower[i])/nbins[i] bins.append( [lower[i] + (j+0.5)*step for j in range(nbins[i])] ) # build a grid of starting points from mystic.math.grid import gridpts from pool_helper import local_optimize from pool_helper import nnodes, queue, timelimit initial_values = gridpts(bins) # run optimizer for each grid point lb = [lower for i in range(len(initial_values))] ub = [upper for i in range(len(initial_values))] cf = [cost for i in range(len(initial_values))] # map:: params, energy, func_evals = local_optimize(cost,x0,lb,ub) config = {'queue':queue, 'timelimit':timelimit} results = Pool(nnodes, **config).map(local_optimize,cf,initial_values,lb,ub) #print "results = %s" % results # get the results with the lowest energy best = list(results[0][0]), results[0][1] func_evals = results[0][2] for result in results[1:]: func_evals += result[2] # add function evaluations if result[1] < best[1]: # compare energy best = list(result[0]), result[1] # return best print "solved: %s" % best[0] scale = 1.0 diameter_squared = -best[1] / scale #XXX: scale != 0 return diameter_squared, func_evals