def main(): examples = parse_examples() services = {s: Heuristic(s) for s in get_all_service_names()} step_size = float(FIRST_STEP_SIZE) services_to_step = climbing(examples, services, int(step_size)) counter = 0 while len(services_to_step): if step_size != 1.0: step_size -= 0.5 counter += 1 sys.stdout.flush() services_to_step = climbing(examples, services, int(step_size)) # Write to file after so many steps, that way we don't lose # progress if we end early. if counter == STEPS_BETWEEN_WRITES or not len(services_to_step): counter = 0 for name, heuristic in services.iteritems(): fname = path.realpath( path.join( path.dirname(__file__), 'climbed_values', name + '_climbed_values.txt')) heuristic.write_to_file(fname) print "Success! You did it! Hills have been climbed!"
def __init__(self): """ We need the name later for heuristic stuff """ self.heuristic = Heuristic(self.__class__.short_name())
# Runs an example heuristic # Takes a feature extraction dictionary and returns a numerical value # for the hueristic. from pal.heuristics.hill_climber import hill_climb from pal.heuristics.heuristic import Heuristic dummy_dict = {'keywords': ['Movie', 'actor'], 'Proper Nouns': ['Tom Hanks']} dummy_evil_dict = {'keywords': ['time', 'theatre'], 'Proper Nouns': ['SATAN', 'Satin']} if __name__ == '__main__': heuristic = Heuristic('movie') hill_climb([dummy_dict], [dummy_evil_dict], 100, heuristic) heuristic = Heuristic('stalkernet') hill_climb([dummy_dict], [dummy_evil_dict], 100, heuristic)