Example #1
0
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!"
Example #2
0
class Service(object):

    def __init__(self):
        """ We need the name later for heuristic stuff """
        self.heuristic = Heuristic(self.__class__.short_name())

    def applies_to_me(self, client, feature_request_type):
        """ Returns true if this service is a potentially relevant to the
            specified client and request type.
        """
        raise NotImplementedError()

    def get_confidence(self, params):
        """ Returns a number between -Inf and +Inf indicating the confidence of
            this service that it is relevant to the specified features.
        """
        return self.heuristic.run_heuristic(params['features']['keywords'])

    def go(self, features):
        """ Returns a response to the specified features, making calls to
            exernal APIs as needed.
        """
        raise NotImplementedError()

    @classmethod
    def short_name(cls):
        name = cls.__name__
        return re.match('(\w+)Service', name).group(1).lower()
Example #3
0
class Service(object):
    def __init__(self):
        """ We need the name later for heuristic stuff """
        self.heuristic = Heuristic(self.__class__.short_name())

    def applies_to_me(self, client, feature_request_type):
        """ Returns true if this service is a potentially relevant to the
            specified client and request type.
        """
        raise NotImplementedError()

    def get_confidence(self, params):
        """ Returns a number between -Inf and +Inf indicating the confidence of
            this service that it is relevant to the specified features.
        """
        return self.heuristic.run_heuristic(params['features']['keywords'])

    def go(self, features):
        """ Returns a response to the specified features, making calls to
            exernal APIs as needed.
        """
        raise NotImplementedError()

    @classmethod
    def short_name(cls):
        name = cls.__name__
        return re.match('(\w+)Service', name).group(1).lower()
Example #4
0
 def __init__(self):
     """ We need the name later for heuristic stuff """
     self.heuristic = Heuristic(self.__class__.short_name())
Example #5
0
 def __init__(self):
     """ We need the name later for heuristic stuff """
     self.heuristic = Heuristic(self.__class__.short_name())
Example #6
0
# 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)