def optimize(solver, target='rosen', **kwds): if target == 'rosen': # 3d-rosenbrock # Rosenbrock function from dejong import rosen as the_model ndim = 3 actual_coeffs = [1.0] * ndim pprint = list else: # 4th-order chebyshev # Chebyshev cost function from poly import chebyshev4cost as the_model from poly import chebyshev4coeffs as actual_coeffs ndim = len(actual_coeffs) from mystic.math import poly1d as pprint # number of trials print("One trial:") print("===============") # initial guess import random x0 = [random.uniform(-100, 100) for i in range(ndim)] # minimize the function results = the_solver(the_model, x0, **kwds) print("===============") print("Actual params:\n %s" % pprint(actual_coeffs)) print("Solved params:\n %s" % pprint(results[0])) print("Function value: %s" % results[1]) print("Total function evals: %s" % results[3]) return
def optimize(solver, target='rosen', **kwds): if target == 'rosen': # 3d-rosenbrock # Rosenbrock function from dejong import rosen as the_model ndim = 3 actual_coeffs = [1.0] * ndim pprint = list else: # 4th-order chebyshev # Chebyshev cost function from poly import chebyshev4cost as the_model from poly import chebyshev4coeffs as actual_coeffs ndim = len(actual_coeffs) from mystic.math import poly1d as pprint # number of trials print("One trial:") print("===============") # initial guess import random x0 = [random.uniform(-100,100) for i in range(ndim)] # minimize the function results = the_solver(the_model, x0, **kwds) print("===============") print("Actual params:\n %s" % pprint(actual_coeffs)) print("Solved params:\n %s" % pprint(results[0])) print("Function value: %s" % results[1]) print("Total function evals: %s" % results[3]) return
def powell_chebyshev(x0, *args, **kwds): # Powell's Directonal solver from optimize_helper import fmin_powell as the_solver # Chebyshev cost function from poly import chebyshev4cost as the_model return the_solver(the_model, x0, monitor=False, *args, **kwds)
def powell_rosen(x0, *args, **kwds): # Powell's Directonal solver from optimize_helper import fmin_powell as the_solver # Rosenbrock function from dejong import rosen as the_model return the_solver(the_model, x0, monitor=False, *args, **kwds)
def diffev_chebyshev(x0, *args, **kwds): # Differential Evolution solver from optimize_helper import diffev as the_solver # Chebyshev cost function from poly import chebyshev4cost as the_model return the_solver(the_model, x0, monitor=True, *args, **kwds)