def prune(self, model):
assert isinstance(model, ClassifierSet)<EOL>assert model.algorithm is self<EOL>total_numerosity = sum(rule.numerosity for rule in model)<EOL>if total_numerosity <= self.max_population_size:<EOL><INDENT>return []  <EOL><DEDENT>total_fitness = sum(rule.fitness for rule in model)<EOL>average_fitness = total_fitness / total_numerosity<EOL>total_votes = <NUM_LIT:0><EOL>deletion_votes = {}<EOL>for rule in model:<EOL><INDENT>vote = rule.action_set_size * rule.numerosity<EOL>sufficient_experience = (<EOL>rule.experience > self.deletion_threshold<EOL>)<EOL>low_fitness = (<EOL>rule.fitness / rule.numerosity <<EOL>self.fitness_threshold * average_fitness<EOL>)<EOL>if sufficient_experience and low_fitness:<EOL><INDENT>vote *= average_fitness / (rule.fitness /<EOL>rule.numerosity)<EOL><DEDENT>deletion_votes[rule] = vote<EOL>total_votes += vote<EOL><DEDENT>selector = random.uniform(<NUM_LIT:0>, total_votes)<EOL>for rule, vote in deletion_votes.items():<EOL><INDENT>selector -= vote<EOL>if selector <= <NUM_LIT:0>:<EOL><INDENT>assert rule in model<EOL>if model.discard(rule):<EOL><INDENT>return [rule]<EOL><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT><DEDENT><DEDENT>assert False<EOL>
Reduce the classifier set's population size, if necessary, by
        removing lower-quality *rules. Return a list containing any rules
        whose numerosities dropped to zero as a result of this call. (The
        list may be empty, if no rule's numerosity dropped to 0.) The
        model argument is a ClassifierSet instance which utilizes this
        algorithm.

        Usage:
            deleted_rules = model.algorithm.prune(model)

        Arguments:
            model: A ClassifierSet instance whose population may need to
                be reduced in size.
        Return:
            A possibly empty list of ClassifierRule instances which were
            removed entirely from the classifier set because their
            numerosities dropped to 0.