def test_rosenbrock(): param_dict = { 'x': range(-10, 10), 'y': range(-10, 10), } a = 1 b = 100 x_opt = a y_opt = a**2 def objfunc(args_list): results = [] for hyper_par in args_list: x = hyper_par['x'] y = hyper_par['y'] result = -(b * ((y - x**2)**2) + ((a - x)**2)) results.append(result) return results tuner = Tuner(param_dict, objfunc, conf_dict=dict(domain_size=100000)) results = tuner.run() print('best hyper parameters:', results['best_params']) print('best Accuracy:', results['best_objective']) assert abs(results['best_params']['x'] - x_opt) <= 2 assert abs(results['best_params']['x'] - y_opt) <= 2
def test_six_hump(): def camel(x, y): x2 = math.pow(x, 2) x4 = math.pow(x, 4) y2 = math.pow(y, 2) return (4.0 - 2.1 * x2 + (x4 / 3.0)) * x2 + x * y + (-4.0 + 4.0 * y2) * y2 param_dict = { 'x': uniform(-3, 3), 'y': uniform(-2, 2), } x_opt = 0.0898 # or -0;0898 y_opt = -0.7126 # or 0.7126 def objfunc(args_list): results = [] for hyper_par in args_list: x = hyper_par['x'] y = hyper_par['y'] result = -camel(x, y) results.append(result) return results tuner = Tuner(param_dict, objfunc) results = tuner.run() print('best hyper parameters:', results['best_params']) print('best objective:', results['best_objective']) assert abs(results['best_params']['x']) - abs(x_opt) <= 0.1 assert abs(results['best_params']['y']) - abs(y_opt) <= 0.2
def test_tuner(): tuner_user = Tuner(param_dict, objectiveFunction) results = tuner_user.run() # max objective is 8, and minimum is 1 assert results['best_objective'] > 1