示例#1
0
    def test_search_expression(self, leading_at_0, leading_at_inf,
                               hard_penalty_default_value,
                               include_leading_powers):
        # Test search several expressions.
        evolutionary.set_creator()

        evolutionary.search_expression(
            input_values=np.array([1., 2., 3.]),
            output_values=np.array([2., 3., 4.]),
            pset=self.pset,
            max_height=50,
            population_size=10,
            cxpb=0.5,
            mutpb=0.1,
            num_evals_limit=30,
            leading_at_0=leading_at_0,
            leading_at_inf=leading_at_inf,
            hard_penalty_default_value=hard_penalty_default_value,
            include_leading_powers=include_leading_powers,
            default_value=50.)

        evolutionary.search_expression(
            input_values=np.array([1., 2., 3.]),
            output_values=np.array([1., 4., 9.]),
            pset=self.pset,
            max_height=50,
            population_size=10,
            cxpb=0.5,
            mutpb=0.1,
            num_evals_limit=30,
            leading_at_0=leading_at_0,
            leading_at_inf=leading_at_inf,
            hard_penalty_default_value=hard_penalty_default_value,
            include_leading_powers=include_leading_powers,
            default_value=50.)
示例#2
0
    def test_evolutionary_algorithm_with_num_evals_limit(self):
        evolutionary.set_creator()
        toolbox = evolutionary.get_toolbox(pset=self.pset, max_height=50)
        toolbox.register('evaluate',
                         evolutionary.evaluate_individual,
                         input_values=np.array([1., 2., 3.]),
                         output_values=np.array([2., 3., 4.]),
                         toolbox=toolbox)
        population = toolbox.population(n=10)
        halloffame = tools.HallOfFame(1)

        evolutionary.evolutionary_algorithm_with_num_evals_limit(
            population=population,
            toolbox=toolbox,
            cxpb=0.5,
            mutpb=0.1,
            num_evals_limit=500,
            halloffame=halloffame)

        func = toolbox.compile(expr=halloffame[0])
        np.testing.assert_allclose(func(np.array([5., 6., 7.])), [6., 7., 8.])