eckity.statistics.minimal_print_statistics

 1import logging
 2
 3from eckity.statistics.statistics import Statistics
 4
 5logger = logging.getLogger(__name__)
 6
 7
 8class MinimalPrintStatistics(Statistics):
 9    """
10    Concrete Statistics class.
11    Provides statistics about the best fitness, average fitness and worst fitness of every sub-population in
12    some generation.
13
14    Parameters
15    ----------
16    format_string: str
17        String format of the data to output.
18        Value depends on the information the statistics provides.
19        For more information, check out the concrete classes who extend this class.
20    """
21
22    def __init__(self, format_string=None):
23        if format_string is None:
24            format_string = (
25                "best fitness {}\nworst fitness {}\naverage fitness {}\n"
26            )
27        super().__init__(format_string)
28
29    def write_statistics(self, sender, data_dict):
30        logger.info(f'generation #{data_dict["generation_num"]}')
31
32    # TODO tostring to indiv
33
34    # Necessary for valid pickling, since modules cannot be pickled
35    def __getstate__(self):
36        state = self.__dict__.copy()
37        return state
38
39    # Necessary for valid unpickling, since modules cannot be pickled
40    def __setstate__(self, state):
41        self.__dict__.update(state)
class MinimalPrintStatistics(eckity.statistics.statistics.Statistics):
 9class MinimalPrintStatistics(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    def __init__(self, format_string=None):
24        if format_string is None:
25            format_string = (
26                "best fitness {}\nworst fitness {}\naverage fitness {}\n"
27            )
28        super().__init__(format_string)
29
30    def write_statistics(self, sender, data_dict):
31        logger.info(f'generation #{data_dict["generation_num"]}')
32
33    # TODO tostring to indiv
34
35    # Necessary for valid pickling, since modules cannot be pickled
36    def __getstate__(self):
37        state = self.__dict__.copy()
38        return state
39
40    # Necessary for valid unpickling, since modules cannot be pickled
41    def __setstate__(self, state):
42        self.__dict__.update(state)

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.
MinimalPrintStatistics(format_string=None)
23    def __init__(self, format_string=None):
24        if format_string is None:
25            format_string = (
26                "best fitness {}\nworst fitness {}\naverage fitness {}\n"
27            )
28        super().__init__(format_string)
def write_statistics(self, sender, data_dict):
30    def write_statistics(self, sender, data_dict):
31        logger.info(f'generation #{data_dict["generation_num"]}')

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.