【问题标题】:Minimize matrix-difference subject to block-diagonal constraints最小化矩阵差异受块对角约束
【发布时间】:2020-03-03 18:25:49
【问题描述】:

我有一个矩阵 W,它是一个尺寸为 2*4 的块对角矩阵,它的两个块对角线中的每一个都是 1*2 向量。我想找到其条目的值,以最小化以下函数之间的差异: (F = BH-AW) 其中:W是需要优化的块对角矩阵,B是2*2矩阵,H是给定的2*4矩阵,A是2*2矩阵。 A 和 B 使用附加代码中使用的函数计算。 我尝试了这个附加代码,但我认为它现在处于无限循环中,我不知道该怎么办?

    %% My code is:

while ((B*H)-(A*W)~=zeros(2,4))
            w1=randn(1,2); 
% generate the first block diagonal vector with dimensions 1*2. The values of each entry of the block diagonal vector maybe not the same.

            w2=randn(1,2); 
% generate the second block diagonal vector with dimensions 1*2.
            W=blkdiag(w1,w2); 
% build the block diagonal matrix that I want to optimize with dimensions 2*4.

            R=sqrtm(W*inv(inv(P)+(H'*inv(eye(2)+D)*H))*W'); 
% R is a 2*2 matrix that will be used to calculate matrix A using the LLL lattice reduction algorithm. The values of P (4*4 matrix), H (2*4 matrix) and D (2*2 matrix) are given. It's clear here that matrix R is a function of W.

            A= LLL(R,3/4); 
% I use here LLL lattice reduction algorithm to obtain 2*2 matrix A which is function of R.

            B=A'*W*P*H'*inv(eye(2)+D+H*P*H'); 
% B is 2*2 matrix which is function of A and W. The values of P (4*4 matrix), H (2*4 matrix) and D (2*2 matrix) are given.

        end

【问题讨论】:

  • “函数”F 是 2x4 矩阵。你在什么意义上试图最小化F?您可以最小化其 2 范数、Frobenius 范数、元素绝对值之和等。
  • 我没有试图理解你的循环体,但是循环测试while ((B*H)-(A*W)~=zeros(2,4)) 永远不会满足于常规浮点,即使你有一个最佳A 的公式和B 以精确的算术实现该结果。你应该改用监视器norm((B*H)-(A*W)) 之类的方法,并在它变得足够小时停止。
  • 所以,你认为如果我使用 ``` while (norm((BH)-(AW))~=0) ``` 而不是使用``` while ((BH)-(AW)~=zeros(2,4)) ``` 这样能解决问题吗?
  • 我尝试使用while (norm((BH)-(AW))~=0),但到现在还没有任何输出,似乎进入了无限循环。有没有其他方法可以优化矩阵W?
  • @bg2b 建议类似while norm((B*H)-(A*W))>tol,其中tol 是您的容忍度,例如10^-5.

标签: matlab matrix optimization linear-algebra


【解决方案1】:

浮点数的数值运算仅在计算机上是近似的(任何数字都只能用有限的位数表示,这意味着您不能精确地表示 Pi)。如需更多信息,请参阅this link

因此,您编写的循环极不可能终止,因为B*HA*W 之间的差异不会完全为零。相反,您需要使用容差系数来决定您何时对所获得的相似性感到满意。

此外,正如其他人在评论中所建议的那样,两个矩阵之间的“距离”通常使用某种范数(例如 Frobenius 范数)来衡量。默认情况下,Matlab 中的norm 函数将给出输入矩阵的 2 范数。

在您的情况下,这将给出如下内容:

tol = 1e-6;

while norm(B*H-A*W) > tol

    % generate the first block diagonal vector with dimensions 1*2. 
    % The values of each entry of the block diagonal vector maybe not the same.
    w1=randn(1,2); 

    % generate the second block diagonal vector with dimensions 1*2.
    w2=randn(1,2); 

    % build the block diagonal matrix that I want to optimize with dimensions 2*4.
    W=blkdiag(w1,w2); 

    % R is a 2*2 matrix that will be used to calculate matrix A using the LLL lattice reduction algorithm. 
    % The values of P (4*4 matrix), H (2*4 matrix) and D (2*2 matrix) are given. 
    % It's clear here that matrix R is a function of W.
    R=sqrtm(W/(inv(P)+(H'/(eye(2)+D)*H))*W'); 

    % I use here LLL lattice reduction algorithm to obtain 2*2 matrix A which is function of R.
    A= LLL(R,3/4); 

    % B is 2*2 matrix which is function of A and W. The values of P (4*4 matrix), 
    % H (2*4 matrix) and D (2*2 matrix) are given.
    B=A'*W*P*H'/(eye(2)+D+H*P*H'); 

end

请注意:

  • 关于实际算法,我有点担心您的循环似乎永远不会更新W 的值,而是更新矩阵AB。这表明您对问题的描述可能不正确或不完整,但这超出了本论坛的范围(如果您想了解更多信息,请咨询Maths.SE)。

  • 在许多情况下不鼓励直接使用inv()。这是因为计算矩阵逆的算法不如求解AX=B 类型系统的算法可靠。 Matlab 应该警告您在可能的情况下使用/\;除非您知道自己在做什么,否则我建议您遵循此建议。

【讨论】:

  • 我尝试了这个想法,但它并没有给我最佳解决方案,因为每次运行我的代码时,结果都有不同的 W 矩阵!我想找到最合适的!我怎样才能找到它?
  • @CassidyTom 是什么让您认为存在独特的“最佳解决方案”?无论如何,这是一个不同的问题,您应该在数学论坛上发布该问题,并附上问题的数学描述。这个论坛是关于编程的,我的回答是这方面的有效解决方案。
  • 我不明白这怎么可能是公认的(正确)答案。您正在尝试“找到最小化以下函数之间差异的 W 值:(F = BH-AW )”,但 W 在每次迭代中随机更新。除非您以某种方式偶然发现满足容差条件的W,否则该算法无法收敛。
  • @Kavka 算法不正确的事实与原始尝试进入无限循环的事实无关。 OP 中对问题的描述显然与代码所做的不符(更新的是 A 和 B,而不是 W),但鉴于这是一个编程论坛,我修复了代码,而不是算法。跨度>
  • @Kavka “除非您以某种方式偶然发现满足容差条件的 W,否则该算法无法收敛。”所以..有办法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 2019-07-06
  • 2020-08-03
  • 2014-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多