【问题标题】:Steepest descent to find the solution to a linear system with a Hilbert matrix最速下降法求解具有希尔伯特矩阵的线性系统
【发布时间】:2017-02-14 15:39:47
【问题描述】:

我正在使用最速下降法来计算具有 5x5 希尔伯特矩阵的线性系统的解。我相信代码很好,因为它给了我正确的答案。

我的问题是:

  1. 我认为需要进行太多迭代才能得出正确的答案。我相信我可能遗漏了算法中的某些内容,但目前我不确定是什么。

  2. 我不确定这是否是实现算法的最有效方法,此外,选择哪个“tol”有点混乱。

对这些的任何见解将不胜感激(尤其是 1.)。谢谢!

% Method of Steepest Descent with tol 10^-6
h = hilb(5);                            %Hilbert 5x5 matrix
b = [1;1;1;1;1];                        %solution matrix
solution = zeros(d,1);                  %Initialization 
residual = h*solution - b;
tol = 10^(-6)
count = 0; 

while residual'*residual > tol;
    roe = (residual'*residual)/(residual'*h*residual);
    solution = solution - roe*residual;
    residual = h*solution - b;
    count = count + 1;
end

count 
solution 


%Method of Steepest Descent with tol 10^-12
solution = zeros(d,1);
residual = h*solution - b;
tol = 10^(-12)
count = 0; 

while residual'*residual > tol;
    roe = (residual'*residual)/(residual'*h*residual);
    solution = solution - roe*residual;
    residual = residual - roe*h*residual;
    count = count + 1;
end

count
solution

%another_solution = invhilb(5)*b           %Check for solution

【问题讨论】:

标签: matlab optimization mathematical-optimization numerical-methods gradient-descent


【解决方案1】:

我不具备从数学方面处理您的问题的知识,但从编程的角度来看,我可以指出一点。

确实你是对的。在得到结果之前需要进行太多迭代:

Elapsed time is 6.487824 seconds.

count =

      292945

当您定义步长以接近最终结果时,必须优化步长。否则,要么你接近答案的速度太慢,要么因为你的步长太大,你多次通过最佳答案并绕着它做曲折。

为了优化步长,我先根据你的脚本形成一个函数(加上一些小的修改):

function [solution, count, T] = SDhilb(d, step)
h = hilb(d);
tic
b = ones(d, 1);
solution = zeros(d, 1);
residual = h * solution - b;
res2 = residual' * residual;
tol = 10^(-6);
count = 0;
while res2 > tol;
    roe = res2/(residual' * h * residual);
    solution = solution - step * roe * residual; % here the step size appears
    residual = h * solution - b;
    count = count + 1;
    res2 = residual' * residual; % let's calculate this once per iteration
end
T = toc;

现在将此函数用于一系列步长 (0.1:0.1:1.3) 和几个希尔伯特矩阵 (d = 2, 3, 4, 5),很明显1 不是一个有效的步长:

相反,step = 0.9 似乎效率更高。让我们看看在hilb(5)的情况下它的效率如何:

[result, count, T] = SDhilb(5, 0.9)

result =

    3.1894
  -85.7689
  481.4906
 -894.8742
  519.5830


count =

        1633


T =

    0.0204

这快了两个数量级以上。

以类似的方式,您可以尝试tol 的不同值,看看它对速度的影响有多大。在这种情况下,没有最优值:容差越小,您需要等待的时间就越长。

【讨论】:

  • 从编程的角度来看,这是一条很有启发性的信息。我非常感谢您花时间解释这一点。非常感谢。
【解决方案2】:

看起来你正确地实现了算法(最速下降/梯度下降,精确线搜索以最小化凸二次函数)。

收敛速度很慢,因为问题是病态的:您考虑的希尔伯特矩阵的条件数高于 400000。当问题是病态的时,梯度下降会很慢。 p>

考虑一个条件良好的问题,例如通过将恒等添加到希尔伯特矩阵 (h = hilb(5)+eye(5)),相同的代码仅在 7 次迭代后终止(以及该条件的条件数)矩阵小于 3)。

【讨论】:

  • 感谢您的帮助。这很有意义。
猜你喜欢
  • 1970-01-01
  • 2018-01-17
  • 2019-05-18
  • 1970-01-01
  • 1970-01-01
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
相关资源
最近更新 更多