eckity.statistics.best_average_worst_statistics
1from sys import stdout 2import logging 3 4from eckity.statistics.statistics import Statistics 5 6logger = logging.getLogger(__name__) 7 8 9class BestAverageWorstStatistics(Statistics): 10 """ 11 Concrete Statistics class. 12 Provides statistics about the best fitness, average fitness and worst fitness of every sub-population in 13 some generation. 14 15 Parameters 16 ---------- 17 format_string: str 18 String format of the data to output. 19 Value depends on the information the statistics provides. 20 For more information, check out the concrete classes who extend this class. 21 22 """ 23 24 def __init__(self, format_string=None): 25 if format_string is None: 26 format_string = ( 27 "best fitness {}\nworst fitness {}\naverage fitness {}\n" 28 ) 29 super().__init__(format_string) 30 31 def write_statistics(self, sender, data_dict): 32 logger.info(f'generation #{data_dict["generation_num"]}') 33 for index, sub_pop in enumerate( 34 data_dict["population"].sub_populations 35 ): 36 logger.info(f"subpopulation #{index}") 37 best_individual = sub_pop.get_best_individual() 38 logger.info( 39 self.format_string.format( 40 best_individual.get_pure_fitness(), 41 sub_pop.get_worst_individual().get_pure_fitness(), 42 sub_pop.get_average_fitness(), 43 ) 44 )
logger =
<Logger eckity.statistics.best_average_worst_statistics (INFO)>
10class BestAverageWorstStatistics(Statistics): 11 """ 12 Concrete Statistics class. 13 Provides statistics about the best fitness, average fitness and worst fitness of every sub-population in 14 some generation. 15 16 Parameters 17 ---------- 18 format_string: str 19 String format of the data to output. 20 Value depends on the information the statistics provides. 21 For more information, check out the concrete classes who extend this class. 22 23 """ 24 25 def __init__(self, format_string=None): 26 if format_string is None: 27 format_string = ( 28 "best fitness {}\nworst fitness {}\naverage fitness {}\n" 29 ) 30 super().__init__(format_string) 31 32 def write_statistics(self, sender, data_dict): 33 logger.info(f'generation #{data_dict["generation_num"]}') 34 for index, sub_pop in enumerate( 35 data_dict["population"].sub_populations 36 ): 37 logger.info(f"subpopulation #{index}") 38 best_individual = sub_pop.get_best_individual() 39 logger.info( 40 self.format_string.format( 41 best_individual.get_pure_fitness(), 42 sub_pop.get_worst_individual().get_pure_fitness(), 43 sub_pop.get_average_fitness(), 44 ) 45 )
Concrete Statistics class. Provides statistics about the best fitness, average fitness and worst fitness of every sub-population in some generation.
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):
32 def write_statistics(self, sender, data_dict): 33 logger.info(f'generation #{data_dict["generation_num"]}') 34 for index, sub_pop in enumerate( 35 data_dict["population"].sub_populations 36 ): 37 logger.info(f"subpopulation #{index}") 38 best_individual = sub_pop.get_best_individual() 39 logger.info( 40 self.format_string.format( 41 best_individual.get_pure_fitness(), 42 sub_pop.get_worst_individual().get_pure_fitness(), 43 sub_pop.get_average_fitness(), 44 ) 45 )
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.