def base_optimizer(black_box_function, mp_opt=False): global max_cc limit_obs, count, init_points = 30, 0, 6 if mp_opt else 5 if mp_opt: search_space = [ Integer(1, 32), # Concurrency Integer(1, 4), # Parallesism Integer(1, 10), # Pipeline ] else: search_space = [ Integer(1, max_cc), # Concurrency ] optimizer = BO( dimensions=search_space, base_estimator="GP", #[GP, RF, ET, GBRT], acq_func="gp_hedge", # [LCB, EI, PI, gp_hedge] acq_optimizer="auto", #[sampling, lbfgs, auto] n_initial_points=init_points, model_queue_size= limit_obs, ) while True: count += 1 if len(optimizer.yi) > limit_obs: optimizer.yi = optimizer.yi[-limit_obs:] optimizer.Xi = optimizer.Xi[-limit_obs:] logger.info("Iteration {0} Starts ...".format(count)) t1 = time.time() res = optimizer.run(func=black_box_function, n_iter=1) t2 = time.time() logger.info("Iteration {0} Ends, Took {3} Seconds. Best Params: {1} and Score: {2}.".format( count, res.x, np.round(res.fun), np.round(t2-t1, 2))) if optimizer.yi[-1] == -1: logger.info("Optimizer Exits ...") break
def base_optimizer(configurations, black_box_function, logger, verbose=True): limit_obs, count = 25, 0 max_thread = configurations["thread_limit"] iterations = configurations["bayes"]["num_of_exp"] mp_opt = configurations["mp_opt"] if mp_opt: search_space = [ Integer(1, max_thread), # Concurrency Integer(1, 10), # Parallesism Integer(1, 10), # Pipeline Integer(5, 20), # Chunk/Block Size in KB: power of 2 ] else: search_space = [ Integer(1, max_thread), # Concurrency ] params = [] optimizer = Optimizer( dimensions=search_space, base_estimator="GP", #[GP, RF, ET, GBRT], acq_func="gp_hedge", # [LCB, EI, PI, gp_hedge] acq_optimizer="auto", #[sampling, lbfgs, auto] n_random_starts=configurations["bayes"]["initial_run"], model_queue_size=limit_obs, # acq_func_kwargs= {}, # acq_optimizer_kwargs={} ) while True: count += 1 if len(optimizer.yi) > limit_obs: optimizer.yi = optimizer.yi[-limit_obs:] optimizer.Xi = optimizer.Xi[-limit_obs:] if verbose: logger.info("Iteration {0} Starts ...".format(count)) t1 = time.time() res = optimizer.run(func=black_box_function, n_iter=1) t2 = time.time() if verbose: logger.info( "Iteration {0} Ends, Took {3} Seconds. Best Params: {1} and Score: {2}." .format(count, res.x, res.fun, np.round(t2 - t1, 2))) last_value = optimizer.yi[-1] if last_value == 10**10: logger.info("Optimizer Exits ...") break cc = optimizer.Xi[-1][0] if iterations < 1: reset = False if (last_value > 0) and (cc < max_thread): max_thread = max(cc, 2) reset = True if (last_value < 0) and (cc == max_thread) and ( cc < configurations["thread_limit"]): max_thread = min(cc + 5, configurations["thread_limit"]) reset = True if reset: search_space[0] = Integer(1, max_thread) optimizer = Optimizer( dimensions=search_space, n_initial_points=configurations["bayes"]["initial_run"], acq_optimizer="lbfgs", model_queue_size=limit_obs) if iterations == count: logger.info("Best parameters: {0} and score: {1}".format( res.x, res.fun)) params = res.x break return params