def one_run(evaluator, config, frequencies): ''' Performs a single run of the given configuration. Returns a dictionary containing results. Parameters: - ``evaluator``: An object with the function get_fitness that takes an individual and returns its fitness value - ``config``: A dictionary containing all of the configuration information required to perform a experimental run, including: - All information required to initialize an individual. - All information required to run ``evolution.generate``. - ``verbose``: Boolean value for if extra runtime information should be displayed. - ``max_evals``: The maximum number of evaluations allowed before termination. - ``max_fitness``: The fitness required to cause a "successful" termination. - ``frequencies``: Dictionary used to return information about how often individuals of different lengths are evolved. ''' best = Individual(**config) last_improved = -1 generator = enumerate(generate(config, frequencies)) for evals, individual in generator: individual.fitness = evaluator.get_fitness(individual) if best < individual: best = individual last_improved = evals if config['verbose']: print '\t', last_improved, best.fitness, len(best.active) if (evals >= config['max_evals'] or best.fitness >= config['max_fitness']): break if config['verbose']: print "Best Found" best.show_active() return { 'fitness': best.fitness, 'evals': evals, 'success': best.fitness >= config['max_fitness'], 'phenotype': len(best.active) }
def one_run(evaluator, config, frequencies): ''' Performs a single run of the given configuration. Returns a dictionary containing results. Parameters: - ``evaluator``: An object with the function get_fitness that takes an individual and returns its fitness value - ``config``: A dictionary containing all of the configuration information required to perform a experimental run, including: - All information required to initialize an individual. - All information required to run ``evolution.generate``. - ``verbose``: Boolean value for if extra runtime information should be displayed. - ``max_evals``: The maximum number of evaluations allowed before termination. - ``max_fitness``: The fitness required to cause a "successful" termination. - ``frequencies``: Dictionary used to return information about how often individuals of different lengths are evolved. ''' best = Individual(**config) last_improved = -1 generator = enumerate(generate(config, frequencies)) for evals, individual in generator: individual.fitness = evaluator.get_fitness(individual) if best < individual: best = individual last_improved = evals if config['verbose']: print '\t', last_improved, best.fitness, len(best.active) if (evals >= config['max_evals'] or best.fitness >= config['max_fitness']): break if config['verbose']: print "Best Found" best.show_active() return {'fitness': best.fitness, 'evals': evals, 'success': best.fitness >= config['max_fitness'], 'phenotype': len(best.active)}
def one_run(evaluator, config): ''' Performs a single run of the given configuration. Returns a dictionary containing results. Parameters: - ``evaluator``: An object with the function get_fitness that takes an individual and returns its fitness value - ``config``: A dictionary containing all of the configuration information required to perform a experimental run, including: - All information required to initialize an individual. - All information required to run ``evolution.generate``. - ``verbose``: Boolean value for if extra runtime information should be displayed. - ``max_evals``: The maximum number of evaluations allowed before termination. - ``max_fitness``: The fitness required to cause a "successful" termination. ''' best = Individual(**config) output = {} for evals, individual in enumerate(generate(config, output)): individual.fitness = evaluator.get_fitness(individual) if best < individual: best = individual if config['verbose']: print '\t', evals, best.fitness, len(best.active) if (evals >= config['max_evals'] or best.fitness >= config['max_fitness']): break if config['verbose']: print "Best Found" best.show_active() output.update({'fitness': best.fitness, 'evals': evals, 'success': best.fitness >= config['max_fitness'], 'phenotype': len(best.active), # When running 'Skip' this will correctly give the number # of evaluations required by 'Normal'. Otherwise its junk. 'normal': output['skipped'] + evals}) return output