def __init__(self, signature: ProgramSignature, evaluator: Evaluator, spawner: GeneSpawner, selection: Union[Selector, DiscreteProbDistrib, str] = "lexicase", variation: Union[VariationOperator, DiscreteProbDistrib, str] = "umad", population_size: int = 500, max_generations: int = 100, error_threshold: float = 0.0, initial_genome_size: Tuple[int, int] = (10, 50), simplification_steps: int = 2000, parallelism: Union[int, bool] = True, verbose: int = 0, **kwargs): self.signature = signature self.evaluator = evaluator self.spawner = spawner self.population_size = population_size self.max_generations = max_generations self.error_threshold = error_threshold self.initial_genome_size = initial_genome_size self.simplification_steps = simplification_steps self.verbose = verbose self.ext = kwargs set_verbosity(self.verbose) self.parallel_context = None if isinstance(parallelism, bool): if parallelism: self.parallel_context = ParallelContext(spawner, evaluator) elif parallelism > 1: self.parallel_context = ParallelContext(spawner, evaluator, parallelism) if isinstance(selection, Selector): self.selection = DiscreteProbDistrib().add(selection, 1.0) elif isinstance(selection, DiscreteProbDistrib): self.selection = selection else: selector = get_selector(selection, **self.ext) self.selection = DiscreteProbDistrib().add(selector, 1.0) if isinstance(variation, VariationOperator): self.variation = DiscreteProbDistrib().add(variation, 1.0) elif isinstance(variation, DiscreteProbDistrib): self.variation = variation else: variation_op = get_variation_operator(variation, **self.ext) self.variation = DiscreteProbDistrib().add(variation_op, 1.0)
def __init__(self, evaluator: Evaluator, spawner: GeneSpawner, selection: Union[Selector, DiscreteProbDistrib, str] = "lexicase", variation: Union[VariationOperator, DiscreteProbDistrib, str] = "umad", population_size: int = 500, max_generations: int = 100, error_threshold: float = 0.0, initial_genome_size: Tuple[int, int] = (10, 50), simplification_steps: int = 2000, verbosity_config: Union[VerbosityConfig, str] = "default", **kwargs): self.evaluator = evaluator self.spawner = spawner self.population_size = population_size self.max_generations = max_generations self.error_threshold = error_threshold self.initial_genome_size = initial_genome_size self.simplification_steps = simplification_steps self.ext = kwargs if isinstance(selection, Selector): self._selection = DiscreteProbDistrib().add(selection, 1.0) elif isinstance(selection, DiscreteProbDistrib): self._selection = selection else: selector = get_selector(selection, **self.ext) self._selection = DiscreteProbDistrib().add(selector, 1.0) if isinstance(variation, VariationOperator): self._variation = DiscreteProbDistrib().add(variation, 1.0) elif isinstance(variation, DiscreteProbDistrib): self._variation = variation else: variationOp = get_variation_operator(variation, **self.ext) self._variation = DiscreteProbDistrib().add(variationOp, 1.0) if verbosity_config == "default": self.verbosity_config = DEFAULT_VERBOSITY_LEVELS[0] else: self.verbosity_config = verbosity_config
def __init__(self, evaluator: Evaluator, spawner: GeneSpawner, selection: Union[Selector, DiscreteProbDistrib, str] = "lexicase", variation: Union[VariationOperator, DiscreteProbDistrib, str] = "umad", population_size: int = 500, max_generations: int = 100, error_threshold: float = 0.0, initial_genome_size: Tuple[int, int] = (10, 50), simplification_steps: int = 2000, verbosity_config: Union[VerbosityConfig, str] = "default", **kwargs): self.evaluator = evaluator self.spawner = spawner self.population_size = population_size self.max_generations = max_generations self.error_threshold = error_threshold self.initial_genome_size = initial_genome_size self.simplification_steps = simplification_steps self.ext = kwargs if isinstance(selection, Selector): self._selection = DiscreteProbDistrib().add(selection, 1.0) elif isinstance(selection, DiscreteProbDistrib): self._selection = selection else: selector = get_selector(selection, **self.ext) self._selection = DiscreteProbDistrib().add(selector, 1.0) if isinstance(variation, VariationOperator): self._variation = DiscreteProbDistrib().add(variation, 1.0) elif isinstance(variation, DiscreteProbDistrib): self._variation = variation else: variationOp = get_variation_operator(variation, **self.ext) self._variation = DiscreteProbDistrib().add(variationOp, 1.0) if verbosity_config == "default": self.verbosity_config = DEFAULT_VERBOSITY_LEVELS[0] else: self.verbosity_config = verbosity_config self.verbosity_config._update_log_level()
def _build_search_algo(self): if isinstance(self.variation_strategy, dict): var_strat = vr.VariationStrategy() for op_name, prob in self.variation_strategy.items(): var_op = vr.get_variation_operator(op_name) if not isinstance(var_op, vr.VariationOperator): var_op = self._build_component(var_op) var_strat.add(var_op, prob) self.variation_strategy = var_strat search_config = sr.SearchConfiguration( spawner=self.spawner, evaluator=self.evaluator, selection=self.selector, variation=self.variation_strategy, population_size=self.population_size, max_generations=self.max_generations, initial_genome_size=self.initial_genome_size, simplification_steps=self.simplification_steps, verbosity_config=self.verbosity_config ) self.search = sr.get_search_algo(self._search_name, config=search_config, **self.ext)
def _build_search_algo(self): if isinstance(self.variation_strategy, dict): var_strat = vr.VariationStrategy() for op_name, prob in self.variation_strategy.items(): var_op = vr.get_variation_operator(op_name) var_strat.add(var_op, prob) self.variation_strategy = var_strat search_config = sr.SearchConfiguration( signature=self.signature, spawner=self.spawner, evaluator=self.evaluator, selection=self.selector, variation=self.variation_strategy, population_size=self.population_size, max_generations=self.max_generations, initial_genome_size=self.initial_genome_size, simplification_steps=self.simplification_steps, parallelism=self.parallelism, push_config=self.push_config) self.search = sr.get_search_algo(self._search_name, config=search_config, **self.ext)
def _build_search_algo(self): if isinstance(self.variation_strategy, dict): var_strat = vr.VariationStrategy() for op_name, prob in self.variation_strategy.items(): var_op = vr.get_variation_operator(op_name) if not isinstance(var_op, vr.VariationOperator): var_op = self._build_component(var_op) var_strat.add(var_op, prob) self.variation_strategy = var_strat search_config = sr.SearchConfiguration( spawner=self.spawner, evaluator=self.evaluator, selection=self.selector, variation=self.variation_strategy, population_size=self.population_size, max_generations=self.max_generations, initial_genome_size=self.initial_genome_size, simplification_steps=self.simplification_steps, verbosity_config=DEFAULT_VERBOSITY_LEVELS[self.verbose]) self.search = sr.get_search_algo(self._search_name, config=search_config, **self.ext)