当前位置: 首页>>代码示例>>Python>>正文


Python DifferentialEvolutionSolver.solve方法代码示例

本文整理汇总了Python中scipy.optimize._differentialevolution.DifferentialEvolutionSolver.solve方法的典型用法代码示例。如果您正苦于以下问题:Python DifferentialEvolutionSolver.solve方法的具体用法?Python DifferentialEvolutionSolver.solve怎么用?Python DifferentialEvolutionSolver.solve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.optimize._differentialevolution.DifferentialEvolutionSolver的用法示例。


在下文中一共展示了DifferentialEvolutionSolver.solve方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_deferred_updating

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_deferred_updating(self):
     # check setting of deferred updating, with default workers
     bounds = [(0., 2.), (0., 2.)]
     solver = DifferentialEvolutionSolver(rosen, bounds, updating='deferred')
     assert_(solver._updating == 'deferred')
     assert_(solver._mapwrapper._mapfunc is map)
     solver.solve()
开发者ID:toddrjen,项目名称:scipy,代码行数:9,代码来源:test__differential_evolution.py

示例2: test_quadratic

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_quadratic(self):
     # test the quadratic function from object
     solver = DifferentialEvolutionSolver(self.quadratic,
                                          [(-100, 100)],
                                          tol=0.02)
     solver.solve()
     assert_equal(np.argmin(solver.population_energies), 0)
开发者ID:toddrjen,项目名称:scipy,代码行数:9,代码来源:test__differential_evolution.py

示例3: test_maxfun_stops_solve

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
    def test_maxfun_stops_solve(self):
        # test that if the maximum number of function evaluations is exceeded
        # during initialisation the solver stops
        solver = DifferentialEvolutionSolver(rosen, self.bounds, maxfun=1,
                                             polish=False)
        result = solver.solve()

        assert_equal(result.nfev, 2)
        assert_equal(result.success, False)
        assert_equal(result.message,
                     'Maximum number of function evaluations has '
                     'been exceeded.')

        # test that if the maximum number of function evaluations is exceeded
        # during the actual minimisation, then the solver stops.
        # Have to turn polishing off, as this will still occur even if maxfun
        # is reached. For popsize=5 and len(bounds)=2, then there are only 10
        # function evaluations during initialisation.
        solver = DifferentialEvolutionSolver(rosen,
                                             self.bounds,
                                             popsize=5,
                                             polish=False,
                                             maxfun=40)
        result = solver.solve()

        assert_equal(result.nfev, 41)
        assert_equal(result.success, False)
        assert_equal(result.message,
                         'Maximum number of function evaluations has '
                              'been exceeded.')
开发者ID:alpaco42,项目名称:ML_Spring_2018,代码行数:32,代码来源:test__differential_evolution.py

示例4: test_maxiter_none_GH5731

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_maxiter_none_GH5731(self):
     # Pre 0.17 the previous default for maxiter and maxfun was None.
     # the numerical defaults are now 1000 and np.inf. However, some scripts
     # will still supply None for both of those, this will raise a TypeError
     # in the solve method.
     solver = DifferentialEvolutionSolver(rosen, self.bounds, maxiter=None,
                                          maxfun=None)
     solver.solve()
开发者ID:toddrjen,项目名称:scipy,代码行数:10,代码来源:test__differential_evolution.py

示例5: test_exp_runs

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
    def test_exp_runs(self):
        # test whether exponential mutation loop runs
        solver = DifferentialEvolutionSolver(rosen,
                                             self.bounds,
                                             strategy='best1exp',
                                             maxiter=1)

        solver.solve()
开发者ID:toddrjen,项目名称:scipy,代码行数:10,代码来源:test__differential_evolution.py

示例6: test_maxiter_stops_solve

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_maxiter_stops_solve(self):
     # test that if the maximum number of iterations is exceeded
     # the solver stops.
     solver = DifferentialEvolutionSolver(rosen, self.bounds, maxiter=1)
     result = solver.solve()
     assert_equal(result.success, False)
     assert_equal(result.message,
                     'Maximum number of iterations has been exceeded.')
开发者ID:toddrjen,项目名称:scipy,代码行数:10,代码来源:test__differential_evolution.py

示例7: test_constraint_solve

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
    def test_constraint_solve(self):
        def constr_f(x):
            return np.array([x[0] + x[1]])

        nlc = NonlinearConstraint(constr_f, -np.inf, 1.9)

        solver = DifferentialEvolutionSolver(rosen, [(0, 2), (0, 2)],
                                             constraints=(nlc))

        # trust-constr warns if the constraint function is linear
        with warns(UserWarning):
            res = solver.solve()

        assert constr_f(res.x) <= 1.9
        assert res.success
开发者ID:anntzer,项目名称:scipy,代码行数:17,代码来源:test__differential_evolution.py

示例8: test_impossible_constraint

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
    def test_impossible_constraint(self):
        def constr_f(x):
            return np.array([x[0] + x[1]])

        nlc = NonlinearConstraint(constr_f, -np.inf, -1)

        solver = DifferentialEvolutionSolver(rosen, [(0, 2), (0, 2)],
                                             constraints=(nlc), popsize=3)

        # a UserWarning is issued because the 'trust-constr' polishing is
        # attempted on the least infeasible solution found.
        with warns(UserWarning):
            res = solver.solve()

        assert_allclose(res.x, [0, 0], atol=1e-6)
        assert res.maxcv > 0
        assert not res.success

        # test _promote_lowest_energy works when none of the population is
        # feasible. In this case the solution with the lowest constraint
        # violation should be promoted.
        solver = DifferentialEvolutionSolver(rosen, [(0, 2), (0, 2)],
                                             constraints=(nlc), polish=False)
        next(solver)
        assert not solver.feasible.all()
        assert not np.isfinite(solver.population_energies).all()

        # now swap two of the entries in the population
        l = 20
        cv = solver.constraint_violation[0]

        solver.population_energies[[0, l]] = solver.population_energies[[l, 0]]
        solver.population[[0, l], :] = solver.population[[l, 0], :]
        solver.constraint_violation[[0, l], :] = (
            solver.constraint_violation[[l, 0], :])

        solver._promote_lowest_energy()
        assert_equal(solver.constraint_violation[0], cv)
开发者ID:anntzer,项目名称:scipy,代码行数:40,代码来源:test__differential_evolution.py

示例9: test_converged

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_converged(self):
     solver = DifferentialEvolutionSolver(rosen, [(0, 2), (0, 2)])
     solver.solve()
     assert_(solver.converged())
开发者ID:toddrjen,项目名称:scipy,代码行数:6,代码来源:test__differential_evolution.py

示例10: test_convergence

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_convergence(self):
     solver = DifferentialEvolutionSolver(rosen, self.bounds, tol=0.2,
                                          polish=False)
     solver.solve()
     assert_(solver.convergence < 0.2)
开发者ID:toddrjen,项目名称:scipy,代码行数:7,代码来源:test__differential_evolution.py

示例11: test_best_solution_retrieval

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_best_solution_retrieval(self):
     # test that the getter property method for the best solution works.
     solver = DifferentialEvolutionSolver(self.quadratic, [(-2, 2)])
     result = solver.solve()
     assert_almost_equal(result.x, solver.x)
开发者ID:toddrjen,项目名称:scipy,代码行数:7,代码来源:test__differential_evolution.py

示例12: test_differential_evolution

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_differential_evolution(self):
     # test that the Jmin of DifferentialEvolutionSolver
     # is the same as the function evaluation
     solver = DifferentialEvolutionSolver(self.quadratic, [(-2, 2)])
     result = solver.solve()
     assert_almost_equal(result.fun, self.quadratic(result.x))
开发者ID:toddrjen,项目名称:scipy,代码行数:8,代码来源:test__differential_evolution.py

示例13: test_quadratic

# 需要导入模块: from scipy.optimize._differentialevolution import DifferentialEvolutionSolver [as 别名]
# 或者: from scipy.optimize._differentialevolution.DifferentialEvolutionSolver import solve [as 别名]
 def test_quadratic(self):
     # test the quadratic function from object
     solver = DifferentialEvolutionSolver(self.quadratic,
                                          [(-100, 100)],
                                          tol=0.02)
     solver.solve()
开发者ID:AI-Org,项目名称:scipy,代码行数:8,代码来源:test__differential_evolution.py


注:本文中的scipy.optimize._differentialevolution.DifferentialEvolutionSolver.solve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。