def __init__(self,
                 search_space,
                 reward_attr,
                 max_generation=2,
                 population_size=10,
                 population_decay=0.95,
                 keep_top_ratio=0.2,
                 selection_bound=0.4,
                 crossover_bound=0.4):
        """
        Initialize GeneticSearcher.

        Args:
            search_space (SearchSpace): The space to search.
            reward_attr: The attribute name of the reward in the result.
            max_generation: Max iteration number of genetic search.
            population_size: Number of trials of the initial generation.
            population_decay: Decay ratio of population size for the
                next generation.
            keep_top_ratio: Ratio of the top performance population.
            selection_bound: Threshold for performing selection.
            crossover_bound: Threshold for performing crossover.
        """
        super(GeneticSearch, self).__init__(search_space, reward_attr)

        self._cur_generation = 1
        self._max_generation = max_generation
        self._population_size = population_size
        self._population_decay = population_decay
        self._keep_top_ratio = keep_top_ratio
        self._selection_bound = selection_bound
        self._crossover_bound = crossover_bound

        self._cur_config_list = []
        self._cur_encoding_list = []
        for _ in range(population_size):
            one_hot = self.search_space.generate_random_one_hot_encoding()
            self._cur_encoding_list.append(one_hot)
            self._cur_config_list.append(
                self.search_space.apply_one_hot_encoding(one_hot))
def __init__ ( self , search_space , reward_attr , max_generation = 2 , population_size = 10 , population_decay = 0.95 , keep_top_ratio = 0.2 , selection_bound = 0.4 , crossover_bound = 0.4 ) : super ( GeneticSearch , self ) . __init__ ( search_space , reward_attr ) self . _cur_generation = 1 self . _max_generation = max_generation self . _population_size = population_size self . _population_decay = population_decay self . _keep_top_ratio = keep_top_ratio self . _selection_bound = selection_bound self . _crossover_bound = crossover_bound self . _cur_config_list = [ ] self . _cur_encoding_list = [ ] for _ in range ( population_size ) : one_hot = self . search_space . generate_random_one_hot_encoding ( ) self . _cur_encoding_list . append ( one_hot ) self . _cur_config_list . append ( self . search_space . apply_one_hot_encoding ( one_hot ) )
Initialize GeneticSearcher.

        Args:
            search_space (SearchSpace): The space to search.
            reward_attr: The attribute name of the reward in the result.
            max_generation: Max iteration number of genetic search.
            population_size: Number of trials of the initial generation.
            population_decay: Decay ratio of population size for the
                next generation.
            keep_top_ratio: Ratio of the top performance population.
            selection_bound: Threshold for performing selection.
            crossover_bound: Threshold for performing crossover.