コード例 #1
0
ファイル: hill_climb.py プロジェクト: Machyne/pal
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!"
コード例 #2
0
 def process(cls, params):
     # Get the names of potentially relevant services
     service_names = get_all_service_names()
     features = params['features']
     client = params['client']
     request_type = (features['questionType'] if 'questionType' in features
                     else features['actionType'])
     key = client, request_type
     if key not in cls._CACHE:
         service_names = filter(
             lambda service: get_service_by_name(service)
             .applies_to_me(*key),
             service_names)
         cls._CACHE[key] = service_names
     else:
         service_names = cls._CACHE[key]
     # Pick the service with the highest confidence
     conf_levels = {service_name: get_service_by_name(service_name)
                    .get_confidence(params)
                    for service_name in service_names}
     params['confidences'] = conf_levels
     params['service'] = (max(conf_levels, key=conf_levels.get) if
                          max(conf_levels.itervalues()) > 0 else None)