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 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('')