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


Python optimize.rosen_der方法代码示例

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


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

示例1: test_minimize_l_bfgs_b_maxfun_interruption

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def test_minimize_l_bfgs_b_maxfun_interruption(self):
        # gh-6162
        f = optimize.rosen
        g = optimize.rosen_der
        values = []
        x0 = np.ones(7) * 1000

        def objfun(x):
            value = f(x)
            values.append(value)
            return value

        # Look for an interesting test case.
        # Request a maxfun that stops at a particularly bad function
        # evaluation somewhere between 100 and 300 evaluations.
        low, medium, high = 30, 100, 300
        optimize.fmin_l_bfgs_b(objfun, x0, fprime=g, maxfun=high)
        v, k = max((y, i) for i, y in enumerate(values[medium:]))
        maxfun = medium + k
        # If the minimization strategy is reasonable,
        # the minimize() result should not be worse than the best
        # of the first 30 function evaluations.
        target = min(values[:low])
        xmin, fmin, d = optimize.fmin_l_bfgs_b(f, x0, fprime=g, maxfun=maxfun)
        assert_array_less(fmin, target) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:27,代码来源:test_optimize.py

示例2: test_translate_bound_f_jac

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def test_translate_bound_f_jac():
    from scipy.optimize import rosen_der
    def rosen_test(x):
        x, y = x
        return (1.0 - x)**2 + 100.0*(y - x**2)**2

    low, high = [-2, -.2], [3.0, 4]
    f_j, into, outof = translate_bound_f_jac(rosen_test, rosen_der, low=low, high=high)
    
    point = [3, -2]
    f0, j0 = f_j(point)
    f0_check = translate_bound_func(rosen_test, low=low, high=high)[0](point)
    assert_allclose(f0_check, f0, rtol=1e-13)
    
    j0_check = translate_bound_jac(rosen_der, low=low, high=high)[0](point)
    assert_allclose(j0_check, j0, rtol=1e-13) 
开发者ID:CalebBell,项目名称:fluids,代码行数:18,代码来源:test_numerics.py

示例3: compute_dr_wrt

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def compute_dr_wrt(self, wrt):
        if wrt is self.x:
            if visualize:
                import matplotlib.pyplot as plt
                residuals = np.sum(self.r**2)
                print('------> RESIDUALS %.2e' % (residuals,))
                print('------> CURRENT GUESS %s' % (str(self.x.r),))
                plt.figure(123)
                
                if not hasattr(self, 'vs'):
                    self.vs = []
                    self.xs = []
                    self.ys = []
                self.vs.append(residuals)
                self.xs.append(self.x.r[0])
                self.ys.append(self.x.r[1])
                plt.clf();
                plt.subplot(1,2,1)
                plt.plot(self.vs)
                plt.subplot(1,2,2)
                plt.plot(self.xs, self.ys)
                plt.draw()


            return row(rosen_der(self.x.r)) 
开发者ID:mattloper,项目名称:chumpy,代码行数:27,代码来源:test_optimization.py

示例4: test_rosenbrock

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def test_rosenbrock(self):
        x0 = np.array([-1.2, 1.0])
        sol = optimize.minimize(optimize.rosen, x0,
                                jac=optimize.rosen_der,
                                hess=optimize.rosen_hess,
                                tol=1e-5,
                                method='Newton-CG')
        assert_(sol.success, sol.message)
        assert_allclose(sol.x, np.array([1, 1]), rtol=1e-4) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_optimize.py

示例5: test_minimize_l_bfgs_maxls

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def test_minimize_l_bfgs_maxls(self):
        # check that the maxls is passed down to the Fortran routine
        sol = optimize.minimize(optimize.rosen, np.array([-1.2,1.0]),
                                method='L-BFGS-B', jac=optimize.rosen_der,
                                options={'disp': False, 'maxls': 1})
        assert_(not sol.success) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:test_optimize.py

示例6: setup_method

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def setup_method(self):
        self.x0 = [5, 5]
        self.func = optimize.rosen
        self.jac = optimize.rosen_der
        self.hess = optimize.rosen_hess
        self.hessp = optimize.rosen_hess_prod
        self.bounds = [(0., 10.), (0., 10.)] 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_optimize.py

示例7: test_translate_bound_jac

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def test_translate_bound_jac():
    from scipy.optimize import rosen_der
    def rosen_test(x):
        x, y = x
        return (1.0 - x)**2 + 100.0*(y - x**2)**2
    j, into, outof = translate_bound_jac(rosen_der, low=[-2, -.2], high=[3.0, 4])
    f, into, outof = translate_bound_func(rosen_test, low=[-2, -.2], high=[3.0, 4])
    
    point = [3, -2]
    jac_num = jacobian(f, point, perturbation=1e-8)
    jac_anal = j(point)
    assert_allclose(jac_num, jac_anal, rtol=1e-6) 
开发者ID:CalebBell,项目名称:fluids,代码行数:14,代码来源:test_numerics.py

示例8: rosen_for_sensi

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def rosen_for_sensi(max_sensi_order, integrated=False, x=None):
    """
    Rosenbrock function from scipy.optimize.
    """
    if x is None:
        x = [0, 1]

    return obj_for_sensi(so.rosen,
                         so.rosen_der,
                         so.rosen_hess,
                         max_sensi_order, integrated, x) 
开发者ID:ICB-DCM,项目名称:pyPESTO,代码行数:13,代码来源:test_objective.py

示例9: create_problem

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def create_problem():
    # define a pypesto objective
    objective = pypesto.Objective(fun=so.rosen,
                                  grad=so.rosen_der,
                                  hess=so.rosen_hess)

    # define a pypesto problem
    (lb, ub) = create_bounds()
    problem = pypesto.Problem(objective=objective, lb=lb, ub=ub)

    return problem 
开发者ID:ICB-DCM,项目名称:pyPESTO,代码行数:13,代码来源:test_visualize.py

示例10: test_minimize_callback_copies_array

# 需要导入模块: from scipy import optimize [as 别名]
# 或者: from scipy.optimize import rosen_der [as 别名]
def test_minimize_callback_copies_array(self, method):
        # Check that arrays passed to callbacks are not modified
        # inplace by the optimizer afterward

        if method in ('fmin_tnc', 'fmin_l_bfgs_b'):
            func = lambda x: (optimize.rosen(x), optimize.rosen_der(x))
        else:
            func = optimize.rosen
            jac = optimize.rosen_der
            hess = optimize.rosen_hess

        x0 = np.zeros(10)

        # Set options
        kwargs = {}
        if method.startswith('fmin'):
            routine = getattr(optimize, method)
            if method == 'fmin_slsqp':
                kwargs['iter'] = 5
            elif method == 'fmin_tnc':
                kwargs['maxfun'] = 100
            else:
                kwargs['maxiter'] = 5
        else:
            def routine(*a, **kw):
                kw['method'] = method
                return optimize.minimize(*a, **kw)

            if method == 'TNC':
                kwargs['options'] = dict(maxiter=100)
            else:
                kwargs['options'] = dict(maxiter=5)

        if method in ('fmin_ncg',):
            kwargs['fprime'] = jac
        elif method in ('Newton-CG',):
            kwargs['jac'] = jac
        elif method in ('trust-krylov', 'trust-exact', 'trust-ncg', 'dogleg',
                        'trust-constr'):
            kwargs['jac'] = jac
            kwargs['hess'] = hess

        # Run with callback
        results = []

        def callback(x, *args, **kwargs):
            results.append((x, np.copy(x)))

        sol = routine(func, x0, callback=callback, **kwargs)

        # Check returned arrays coincide with their copies and have no memory overlap
        assert_(len(results) > 2)
        assert_(all(np.all(x == y) for x, y in results))
        assert_(not any(np.may_share_memory(x[0], y[0]) for x, y in itertools.combinations(results, 2))) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:56,代码来源:test_optimize.py


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