eckity.statistics.best_avg_worst_size_tree_statistics
1import logging 2 3import numpy as np 4 5from eckity.statistics.statistics import Statistics 6 7logger = logging.getLogger(__name__) 8 9 10class BestAverageWorstSizeTreeStatistics(Statistics): 11 def __init__(self, format_string=None): 12 if format_string is None: 13 format_string = "best fitness {}\nworst fitness {}\naverage fitness {}\naverage size {}\n" 14 super().__init__(format_string) 15 16 def write_statistics(self, sender, data_dict): 17 logger.info(f'generation #{data_dict["generation_num"]}') 18 for index, sub_pop in enumerate( 19 data_dict["population"].sub_populations 20 ): 21 logger.info(f"subpopulation #{index}") 22 best_individual = sub_pop.get_best_individual() 23 logger.info( 24 self.format_string.format( 25 best_individual.get_pure_fitness(), 26 sub_pop.get_worst_individual().get_pure_fitness(), 27 sub_pop.get_average_fitness(), 28 np.average([ind.size() for ind in sub_pop.individuals]), 29 ), 30 )
logger =
<Logger eckity.statistics.best_avg_worst_size_tree_statistics (INFO)>
11class BestAverageWorstSizeTreeStatistics(Statistics): 12 def __init__(self, format_string=None): 13 if format_string is None: 14 format_string = "best fitness {}\nworst fitness {}\naverage fitness {}\naverage size {}\n" 15 super().__init__(format_string) 16 17 def write_statistics(self, sender, data_dict): 18 logger.info(f'generation #{data_dict["generation_num"]}') 19 for index, sub_pop in enumerate( 20 data_dict["population"].sub_populations 21 ): 22 logger.info(f"subpopulation #{index}") 23 best_individual = sub_pop.get_best_individual() 24 logger.info( 25 self.format_string.format( 26 best_individual.get_pure_fitness(), 27 sub_pop.get_worst_individual().get_pure_fitness(), 28 sub_pop.get_average_fitness(), 29 np.average([ind.size() for ind in sub_pop.individuals]), 30 ), 31 )
Abstract Statistics class. Provides statistics about the current evolution state.
Parameters
- format_string (str): String format of the data to output. Value depends on the information the statistics provides. For more information, check out the concrete classes who extend this class.
def
write_statistics(self, sender, data_dict):
17 def write_statistics(self, sender, data_dict): 18 logger.info(f'generation #{data_dict["generation_num"]}') 19 for index, sub_pop in enumerate( 20 data_dict["population"].sub_populations 21 ): 22 logger.info(f"subpopulation #{index}") 23 best_individual = sub_pop.get_best_individual() 24 logger.info( 25 self.format_string.format( 26 best_individual.get_pure_fitness(), 27 sub_pop.get_worst_individual().get_pure_fitness(), 28 sub_pop.get_average_fitness(), 29 np.average([ind.size() for ind in sub_pop.individuals]), 30 ), 31 )
Write the statistics information using the format string field.
Parameters
- sender (object): The object that this statistics provides information about. This class registers to a certain event that the sender object publishes. The statistics are shown as a callback to the event publication. For example, we can register a concrete Statistics sub-class to provide statistics after every generation of a concrete Algorithm sub-class.
- data_dict (dict(str, object)): Relevant data to the statistics. Used to gain and provide information from the sender.
Returns
- None.