def run_ga_on_odd_test(parallelism): X = np.arange(-10, 10).reshape(-1, 1) y = [[bool(x[0] % 2)] for x in X] instruction_set = (InstructionSet().register_core_by_stack( {"int"}, exclude_stacks={"str", "exec", "code"})) spawner = GeneSpawner(n_inputs=1, instruction_set=instruction_set, literals=[], erc_generators=[ partial(random.randint, 0, 10), ]) est = PushEstimator(spawner=spawner, population_size=30, max_generations=3, simplification_steps=10, parallelism=parallelism) est.fit(X, y) assert isinstance(est.solution, Individual) assert len(est.solution.program.code) > 0 path = "tmp.push" solution = est.solution.copy(deep=True) est.save(path) est.load(path) assert solution == est.solution os.remove(path)
def run_ga_on_odd_test(spawner, parallelism): X = np.arange(-10, 10).reshape(-1, 1) y = [[bool(x[0] % 2)] for x in X] est = PushEstimator( spawner=spawner, population_size=10, max_generations=3, simplification_steps=3, parallelism=parallelism) est.fit(X, y) assert isinstance(est.solution, Individual) assert len(est.solution.program.code) > 0 path = "tmp.push" solution = est.solution.copy(deep=True) est.save(path) est.load(path) assert solution == est.solution os.remove(path)