eckity.evaluators.simple_individual_evaluator

 1from abc import abstractmethod
 2
 3from overrides import overrides
 4
 5from eckity.evaluators.individual_evaluator import IndividualEvaluator
 6
 7
 8class SimpleIndividualEvaluator(IndividualEvaluator):
 9    """
10    Computes fitness value for the given individuals.
11    All simple classes assume only one sub-population.
12    Evaluates each individual separately.
13    You will need to extend this class with your fitness evaluation methods.
14    """
15
16    @overrides
17    def evaluate(self, individual, environment_individuals):
18        """
19        Updates the fitness score of the given individuals, then returns the best individual
20
21        Parameters
22        ----------
23        individual: Individual
24                the current individual to evaluate its fitness
25
26        environment_individuals: list of Individuals
27                the individuals in the current individual's environment
28                those individuals will affect the current individual's fitness
29                (not used in simple case)
30
31        Returns
32        -------
33        Individual
34                the individual with the best fitness of the given individuals
35        """
36        super().evaluate(individual, environment_individuals)
37        fitness_score = self.evaluate_individual(individual)
38        individual.fitness.set_fitness(fitness_score)
39        return individual
40
41    @abstractmethod
42    def evaluate_individual(self, individual):
43        """
44        Evaluate the fitness score for the given individual.
45        This function must be implemented by subclasses of this class
46
47        Parameters
48        ----------
49        individual: Individual
50                The individual to compute the fitness for
51
52        Returns
53        -------
54        float
55                The evaluated fitness value for the given individual
56        """
57        raise ValueError(
58            "evaluate_individual is an abstract method in SimpleIndividualEvaluator"
59        )
class SimpleIndividualEvaluator(eckity.evaluators.individual_evaluator.IndividualEvaluator):
 9class SimpleIndividualEvaluator(IndividualEvaluator):
10    """
11    Computes fitness value for the given individuals.
12    All simple classes assume only one sub-population.
13    Evaluates each individual separately.
14    You will need to extend this class with your fitness evaluation methods.
15    """
16
17    @overrides
18    def evaluate(self, individual, environment_individuals):
19        """
20        Updates the fitness score of the given individuals, then returns the best individual
21
22        Parameters
23        ----------
24        individual: Individual
25                the current individual to evaluate its fitness
26
27        environment_individuals: list of Individuals
28                the individuals in the current individual's environment
29                those individuals will affect the current individual's fitness
30                (not used in simple case)
31
32        Returns
33        -------
34        Individual
35                the individual with the best fitness of the given individuals
36        """
37        super().evaluate(individual, environment_individuals)
38        fitness_score = self.evaluate_individual(individual)
39        individual.fitness.set_fitness(fitness_score)
40        return individual
41
42    @abstractmethod
43    def evaluate_individual(self, individual):
44        """
45        Evaluate the fitness score for the given individual.
46        This function must be implemented by subclasses of this class
47
48        Parameters
49        ----------
50        individual: Individual
51                The individual to compute the fitness for
52
53        Returns
54        -------
55        float
56                The evaluated fitness value for the given individual
57        """
58        raise ValueError(
59            "evaluate_individual is an abstract method in SimpleIndividualEvaluator"
60        )

Computes fitness value for the given individuals. All simple classes assume only one sub-population. Evaluates each individual separately. You will need to extend this class with your fitness evaluation methods.

@overrides
def evaluate(self, individual, environment_individuals):
17    @overrides
18    def evaluate(self, individual, environment_individuals):
19        """
20        Updates the fitness score of the given individuals, then returns the best individual
21
22        Parameters
23        ----------
24        individual: Individual
25                the current individual to evaluate its fitness
26
27        environment_individuals: list of Individuals
28                the individuals in the current individual's environment
29                those individuals will affect the current individual's fitness
30                (not used in simple case)
31
32        Returns
33        -------
34        Individual
35                the individual with the best fitness of the given individuals
36        """
37        super().evaluate(individual, environment_individuals)
38        fitness_score = self.evaluate_individual(individual)
39        individual.fitness.set_fitness(fitness_score)
40        return individual

Updates the fitness score of the given individuals, then returns the best individual

Parameters
  • individual (Individual): the current individual to evaluate its fitness
  • environment_individuals (list of Individuals): the individuals in the current individual's environment those individuals will affect the current individual's fitness (not used in simple case)
Returns
  • Individual: the individual with the best fitness of the given individuals
@abstractmethod
def evaluate_individual(self, individual):
42    @abstractmethod
43    def evaluate_individual(self, individual):
44        """
45        Evaluate the fitness score for the given individual.
46        This function must be implemented by subclasses of this class
47
48        Parameters
49        ----------
50        individual: Individual
51                The individual to compute the fitness for
52
53        Returns
54        -------
55        float
56                The evaluated fitness value for the given individual
57        """
58        raise ValueError(
59            "evaluate_individual is an abstract method in SimpleIndividualEvaluator"
60        )

Evaluate the fitness score for the given individual. This function must be implemented by subclasses of this class

Parameters
  • individual (Individual): The individual to compute the fitness for
Returns
  • float: The evaluated fitness value for the given individual