最小化受块对角线约束的矩阵差异

Minimize matrix-difference subject to block-diagonal constraints

我有一个矩阵 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

浮点数的数值运算在计算机上只是近似值(任何数字只能用有限位数表示,例如,这意味着您无法准确表示 Pi)。有关详细信息,请参阅 this link

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

此外,正如其他人在评论中所建议的,两个矩阵之间的 "distance" 通常使用某种范数(例如 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 应该警告您尽可能使用 /\;除非您知道自己在做什么,否则我建议您遵循此建议。