小编Col*_*man的帖子

最陡的下降吐出了不合理的大价值

我对最陡下降求解Ax = b的实现显示出一些奇怪的行为:对于任何足够大的矩阵(〜10 x 10,到目前为止只测试了方形矩阵),返回x包含所有巨大的值(大约为1x10^10).

def steepestDescent(A, b, numIter=100, x=None):
    """Solves Ax = b using steepest descent method"""
    warnings.filterwarnings(action="error",category=RuntimeWarning)

    # Reshape b in case it has shape (nL,)
    b = b.reshape(len(b), 1)

    exes = []
    res = []

    # Make a guess for x if none is provided
    if x==None:
        x = np.zeros((len(A[0]), 1))
        exes.append(x)

    for i in range(numIter):
        # Re-calculate r(i) using r(i) = b - Ax(i) every five iterations
        # …
Run Code Online (Sandbox Code Playgroud)

python numpy mathematical-optimization numerical-methods gradient-descent

6
推荐指数
1
解决办法
180
查看次数