def main(): """ Main function. """ # Get problem parameters worker_manager = SyntheticWorkerManager(NUM_WORKERS, time_distro='halfnormal') _, func_caller, mutation_op, init_points, init_vals = get_opt_problem( NN_TYPE) print('Best init value: %0.5f' % (max(init_vals))) for method in METHODS: print( 'Method: %s ==========================================================' % (method)) worker_manager.reset() # Iterate through each method if method in ['GA', 'randGA']: is_rand = method == 'randGA' options, reporter = get_options_and_reporter( method, init_points, init_vals) ga_optimiser.ga_optimise_from_args(func_caller, worker_manager, CAPITAL, 'asy', mutation_op, is_rand=is_rand, options=options, reporter=reporter) # Wrap up method print('')
def _ga_maximise(self, obj, num_evals, mutation_op, init_pool, init_pool_vals=None, expects_inputs_to_be_iterable=True): """ Maximise with genetic algorithms. if expects_inputs_as_list is True it means the function expects the inputs to be iterable by default. """ # Prep necessary variables obj, options, reporter, mutation_op = self._get_ga_optimiser_args( obj, num_evals, mutation_op, init_pool, init_pool_vals, expects_inputs_to_be_iterable) worker_manager = SyntheticWorkerManager(1, time_distro='const') func_caller = FunctionCaller(obj, self) opt_val, opt_pt, _ = ga_optimise_from_args(func_caller, worker_manager, num_evals, 'asy', mutation_op, options=options, reporter=reporter) return opt_val, opt_pt
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 test_rand_optimisation_synchronous(self): """ Tests optimisation of a single point. """ self.report('Testing NNRandomBandit with 4 synchronous workers.') worker_manager = SyntheticWorkerManager(4, time_distro='halfnormal') func_caller = FunctionCaller(cnn_syn_func1, self.cnn_domain) options, options_clone, reporter, _, _ = self._get_optimiser_args('cnn') opt_val, opt_pt, history = nasbot.nnrandbandit_from_func_caller( func_caller, worker_manager, 5, 'syn', options=options, reporter=reporter) self._test_optimiser_results(opt_val, opt_pt, history, options, options_clone) self.report('')
def test_instantiation(self): """ Test Creation of NNGPBandit object. """ self.report('Testing Random Optimiser instantiation.') func_caller = FunctionCaller(cnn_syn_func1, self.cnn_domain) worker_manager = SyntheticWorkerManager(1, time_distro='const') optimiser = nasbot.NNRandomBandit(func_caller, worker_manager, reporter='silent') for attr in dir(optimiser): if not attr.startswith('_'): self.report('optimiser.%s = %s'%(attr, str(getattr(optimiser, attr))), 'test_result')
def test_instantiation(self): """ Test creation of object. """ self.report('Testing GA Optimiser instantiation.') func_caller = FunctionCaller(cnn_syn_func1, self.nn_domain) worker_manager = SyntheticWorkerManager(1, time_distro='const') optimiser = ga_optimiser.GAOptimiser(func_caller, worker_manager, self.cnn_mutation_op, reporter='silent') self.report('Instantiated GAOptimiser object.') for attr in dir(optimiser): if not attr.startswith('_'): self.report( 'optimiser.%s = %s' % (attr, str(getattr(optimiser, attr))), 'test_result')
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('')
def test_optimisation_asynchronous(self): """ Test optimisation. """ self.report('Testing GA Optimiser with four workers asynchronously.') worker_manager = SyntheticWorkerManager(4, time_distro='halfnormal') func_caller = FunctionCaller(mlp_syn_func1, self.nn_domain) options, options_clone, reporter, _, mutation_op = self._get_optimiser_args( 'mlp') opt_val, opt_pt, history = ga_optimiser.ga_optimise_from_args( func_caller, worker_manager, 20, 'asy', mutation_op, options=options, reporter=reporter) self._test_optimiser_results(opt_val, opt_pt, history, options, options_clone) self.report('')
def test_ga_optimisation_single(self): """ Test optimisation. """ self.report('Testing GA Optimiser with just one worker.') worker_manager = SyntheticWorkerManager(1, time_distro='const') func_caller = FunctionCaller(cnn_syn_func1, self.nn_domain) options, options_clone, reporter, _, mutation_op = self._get_optimiser_args( 'cnn') opt_val, opt_pt, history = ga_optimiser.ga_optimise_from_args( func_caller, worker_manager, 20, 'asy', mutation_op, options=options, reporter=reporter) self._test_optimiser_results(opt_val, opt_pt, history, options, options_clone) self.report('')
def setUp(self): """ Set up. """ self.func_caller = get_syn_function_caller_from_name('Hartmann6') self.worker_manager_1 = SyntheticWorkerManager(1) self.worker_manager_4 = SyntheticWorkerManager(4, time_distro='halfnormal')