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


Python linesearch.line_search_wolfe1方法代码示例

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


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

示例1: test_line_search_wolfe1

# 需要导入模块: from scipy.optimize import linesearch [as 别名]
# 或者: from scipy.optimize.linesearch import line_search_wolfe1 [as 别名]
def test_line_search_wolfe1(self):
        c = 0
        smax = 100
        for name, f, fprime, x, p, old_f in self.line_iter():
            f0 = f(x)
            g0 = fprime(x)
            self.fcount = 0
            s, fc, gc, fv, ofv, gv = ls.line_search_wolfe1(f, fprime, x, p,
                                                           g0, f0, old_f,
                                                           amax=smax)
            assert_equal(self.fcount, fc+gc)
            assert_fp_equal(ofv, f(x))
            if s is None:
                continue
            assert_fp_equal(fv, f(x + s*p))
            assert_array_almost_equal(gv, fprime(x + s*p), decimal=14)
            if s < smax:
                c += 1
                assert_line_wolfe(x, p, s, f, fprime, err_msg=name)

        assert_(c > 3)  # check that the iterator really works... 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_linesearch.py

示例2: _line_search_wolfe12

# 需要导入模块: from scipy.optimize import linesearch [as 别名]
# 或者: from scipy.optimize.linesearch import line_search_wolfe1 [as 别名]
def _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval,
                         **kwargs):
    """
    Same as line_search_wolfe1, but fall back to line_search_wolfe2 if
    suitable step length is not found, and raise an exception if a
    suitable step length is not found.

    Raises
    ------
    _LineSearchError
        If no suitable step size is found

    """
    ret = line_search_wolfe1(f, fprime, xk, pk, gfk,
                             old_fval, old_old_fval,
                             **kwargs)

    if ret[0] is None:
        # line search failed: try different one.
        ret = line_search_wolfe2(f, fprime, xk, pk, gfk,
                                 old_fval, old_old_fval, **kwargs)

    if ret[0] is None:
        raise _LineSearchError()

    return ret 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:28,代码来源:optimize.py


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