eckity.multi_objective_evolution.crowding_termination_checker

 1from eckity.termination_checkers.termination_checker import TerminationChecker
 2
 3
 4class CrowdingTerminationChecker(TerminationChecker):
 5	"""
 6	Concrete Termination Checker that checks the distance from best existing fitness value to target fitness value.
 7
 8	Parameters
 9	----------
10	threshold: float, default=0.1
11		what is the maximal value of crowding that should be allowed in he population
12	"""
13
14	def __init__(self, threshold=0.1):
15		super().__init__()
16		self.threshold = threshold
17
18	def should_terminate(self, population=None, best_individual=None, gen_number=None):
19		"""
20		Parameters
21		----------
22		population: Population
23			The evolutionary experiment population of individuals.
24
25		best_individual: Individual
26			The individual that has the best fitness of the current generation.
27
28		gen_number: int
29			Current generation number.
30
31		Returns
32		-------
33		bool
34			True if the algorithm should terminate early, False otherwise.
35		"""
36		max_crowding_in_pop = self._find_max_crowding(population)
37		return max_crowding_in_pop < self.threshold and max_crowding_in_pop != 0
38
39	def _find_max_crowding(self, population):
40		crowdings = []
41		for sup_pop in population.sub_populations:
42			values = [ind.fitness.crowding for ind in sup_pop.individuals if ind.fitness.crowding != float("inf")]
43			if values:
44				crowdings.append(max(values))
45			else:
46				crowdings.append(float("inf"))
47		return max(crowdings)
class CrowdingTerminationChecker(eckity.termination_checkers.termination_checker.TerminationChecker):
 5class CrowdingTerminationChecker(TerminationChecker):
 6	"""
 7	Concrete Termination Checker that checks the distance from best existing fitness value to target fitness value.
 8
 9	Parameters
10	----------
11	threshold: float, default=0.1
12		what is the maximal value of crowding that should be allowed in he population
13	"""
14
15	def __init__(self, threshold=0.1):
16		super().__init__()
17		self.threshold = threshold
18
19	def should_terminate(self, population=None, best_individual=None, gen_number=None):
20		"""
21		Parameters
22		----------
23		population: Population
24			The evolutionary experiment population of individuals.
25
26		best_individual: Individual
27			The individual that has the best fitness of the current generation.
28
29		gen_number: int
30			Current generation number.
31
32		Returns
33		-------
34		bool
35			True if the algorithm should terminate early, False otherwise.
36		"""
37		max_crowding_in_pop = self._find_max_crowding(population)
38		return max_crowding_in_pop < self.threshold and max_crowding_in_pop != 0
39
40	def _find_max_crowding(self, population):
41		crowdings = []
42		for sup_pop in population.sub_populations:
43			values = [ind.fitness.crowding for ind in sup_pop.individuals if ind.fitness.crowding != float("inf")]
44			if values:
45				crowdings.append(max(values))
46			else:
47				crowdings.append(float("inf"))
48		return max(crowdings)

Concrete Termination Checker that checks the distance from best existing fitness value to target fitness value.

Parameters
  • threshold (float, default=0.1): what is the maximal value of crowding that should be allowed in he population
CrowdingTerminationChecker(threshold=0.1)
15	def __init__(self, threshold=0.1):
16		super().__init__()
17		self.threshold = threshold
threshold
def should_terminate(self, population=None, best_individual=None, gen_number=None):
19	def should_terminate(self, population=None, best_individual=None, gen_number=None):
20		"""
21		Parameters
22		----------
23		population: Population
24			The evolutionary experiment population of individuals.
25
26		best_individual: Individual
27			The individual that has the best fitness of the current generation.
28
29		gen_number: int
30			Current generation number.
31
32		Returns
33		-------
34		bool
35			True if the algorithm should terminate early, False otherwise.
36		"""
37		max_crowding_in_pop = self._find_max_crowding(population)
38		return max_crowding_in_pop < self.threshold and max_crowding_in_pop != 0
Parameters
  • population (Population): The evolutionary experiment population of individuals.
  • best_individual (Individual): The individual that has the best fitness of the current generation.
  • gen_number (int): Current generation number.
Returns
  • bool: True if the algorithm should terminate early, False otherwise.