def main(): """ Main function. """ # Obtain the search space nn_domain = get_nn_domain_from_constraints('cnn', MAX_NUM_LAYERS, MIN_NUM_LAYERS, MAX_MASS, MIN_MASS, MAX_IN_DEGREE, MAX_OUT_DEGREE, MAX_NUM_EDGES, MAX_NUM_UNITS_PER_LAYER, MIN_NUM_UNITS_PER_LAYER) # Obtain a worker manager: A worker manager (defined in opt/worker_manager.py) is used # to manage (possibly) multiple workers. For a synthetic experiment, we will use a # synthetic worker manager with 1 worker. worker_manager = SyntheticWorkerManager(1) # Obtain a function caller: A function_caller is used to evaluate a function defined on # neural network architectures. Here, we have obtained a function_caller from a # synthetic function, but for real experiments, you might have to write your own caller. # See the MLP/CNN demos for an example. func_caller = FunctionCaller(cnn_syn_func1, nn_domain) # Finally, specify the budget. In this case, it will be just the number of evaluations. budget = 20 # Run nasbot opt_val, opt_nn, _ = nasbot.nasbot(func_caller, worker_manager, budget) # Print the optimal value and visualise the best network. print '\nOptimum value found: ', opt_val print 'Optimal network visualised in syn_opt_network.eps.' visualise_nn(opt_nn, 'syn_opt_network')
def main(): """ Main function. """ # Obtain the search space nn_domain = get_nn_domain_from_constraints('cnn', MAX_NUM_LAYERS, MIN_NUM_LAYERS, MAX_MASS, MIN_MASS, MAX_IN_DEGREE, MAX_OUT_DEGREE, MAX_NUM_EDGES, MAX_NUM_UNITS_PER_LAYER, MIN_NUM_UNITS_PER_LAYER) # Obtain a worker manager: A worker manager (defined in opt/worker_manager.py) is used # to manage (possibly) multiple workers. For a RealWorkerManager, the budget should be # given in wall clock seconds. worker_manager = RealWorkerManager(GPU_IDS, EXP_DIR) # Obtain a function caller: A function_caller is used to evaluate a function defined on # neural network architectures. We have defined the CNNFunctionCaller in # demos/cnn_function_caller.py. The train_params argument can be used to specify # additional training parameters such as the learning rate etc. train_params = Namespace(data_dir=DATA_DIR) func_caller = CNNFunctionCaller('cifar10', nn_domain, train_params, tmp_dir=TMP_DIR, reporter=REPORTER) # Run nasbot opt_val, opt_nn, _ = nasbot.nasbot(func_caller, worker_manager, BUDGET, reporter=REPORTER) # Print the optimal value and visualise the best network. REPORTER.writeln('\nOptimum value found: %f' % opt_val) visualise_file = os.path.join(EXP_DIR, 'cnn_opt_network') REPORTER.writeln('Optimal network visualised in %s.eps' % (visualise_file)) visualise_nn(opt_nn, EXP_DIR + visualise_file)
def main(): """ Main function. """ # Obtain the search space nn_domain = get_nn_domain_from_constraints('mlp-reg', MAX_NUM_LAYERS, MIN_NUM_LAYERS, MAX_MASS, MIN_MASS, MAX_IN_DEGREE, MAX_OUT_DEGREE, MAX_NUM_EDGES, MAX_NUM_UNITS_PER_LAYER, MIN_NUM_UNITS_PER_LAYER) # Obtain a worker manager: A worker manager (defined in opt/worker_manager.py) is used # to manage (possibly) multiple workers. For a RealWorkerManager, the budget should be # given in wall clock seconds. worker_manager = RealWorkerManager(GPU_IDS) # Obtain a function caller: A function_caller is used to evaluate a function defined on # neural network architectures. We have defined the MLPFunctionCaller in # demos/mlp_function_caller.py. The train_params can be used to specify additional # training parameters such as the learning rate etc. train_params = Namespace(data_train_file=get_train_file_name(DATASET)) func_caller = MLPFunctionCaller(DATASET, nn_domain, train_params, reporter=REPORTER, tmp_dir=TMP_DIR) # Run nasbot opt_val, opt_nn, _ = nasbot.nasbot(func_caller, worker_manager, BUDGET, reporter=REPORTER) # Print the optimal value and visualise the best network. REPORTER.writeln('\nOptimum value found: ' % (opt_val)) REPORTER.writeln('Optimal network visualised in mlp_opt_network.eps.') visualise_nn(opt_nn, 'mlp_opt_network')
def test_nasbot_optimisation_asynchronous(self): """ Tests optimisation of a single point. """ self.report('Testing NASBOT with 4 asynchronous workers.') worker_manager = SyntheticWorkerManager(4, time_distro='halfnormal') func_caller = FunctionCaller(mlp_syn_func1, self.mlp_domain) tp_comp = get_tp_comp('mlp-reg') options, options_clone, reporter, _, _ = self._get_optimiser_args( 'mlp-reg') opt_val, opt_pt, history = nasbot.nasbot(func_caller, worker_manager, 5, tp_comp, options=options, reporter=reporter) self._test_optimiser_results(opt_val, opt_pt, history, options, options_clone) self.report('')
def test_nasbot_optimisation_single(self): """ Tests optimisation with a single worker. """ self.report('Testing NASBOT with a single worker.') worker_manager = SyntheticWorkerManager(1, time_distro='const') func_caller = FunctionCaller(cnn_syn_func1, self.cnn_domain) tp_comp = get_tp_comp('cnn') options, options_clone, reporter, _, _ = self._get_optimiser_args( 'cnn') opt_val, opt_pt, history = nasbot.nasbot(func_caller, worker_manager, 10, tp_comp, options=options, reporter=reporter) self._test_optimiser_results(opt_val, opt_pt, history, options, options_clone) self.report('')