如何在相关矩阵中将较大的值移近矩阵对角线 [英] How to move larger values close to matrix diagonal in a correlation matrix
问题描述
我有一个包含五个元素(C1,C2,C3,C4,C5)的相关矩阵X
I have a correlation matrix X of five elements(C1,C2,C3,C4,C5)
C1 C2 C3 C4 C5
C1 * 1 0 1 0
C2 1 * 0 0 1
C3 0 0 * 1 1
C4 1 0 1 * 0
C5 0 1 1 0 *
我想使用MatLab移动尽可能多的非零单元格靠近对角线,同时保持对角线单元为"*".
I want to use MatLab to move as many as non-zero cells close to diagonal, while keep the diagonal cells are "*".
例如,您可能会注意到列和行在以下矩阵中移动,而对角线单元格为"*".
For example, you may notice that the columns and rows is shifting in the following matrix, while the diagonal cells are "*".
C1 C4 C2 C5 C3
C1 * 1 1 0 0
C4 1 * 0 0 1
C2 1 0 * 1 0
C5 0 0 1 * 1
C3 0 1 0 1 *
因为我想进行聚类,所以我希望有尽可能多的非零像元在平移后变得接近对角线.这是一个NP难题.
Because I want to do clustering, so I want as many as non-zero cells get close to diagonal after shifting. It's an NP-hard problem.
任何人都知道MatLab的哪些功能可以实现这一目标?
Anyone know what functions in MatLab can realize this?
推荐答案
您正在寻找的可能是反向Cuthill-McKee算法(RCM),该算法几乎可以满足您的要求:对于给定的矩阵,它会找到一个排列,该排列倾向于使其非零元素更接近对角线. MATLAB中有一个内置函数 symrcm
可以做到这一点
What you're looking for is probably the reverse Cuthill-McKee algorithm (RCM), which pretty much does what you want: for a given matrix it finds a permutation that tends to have its non-zero elements closer to the diagonal. There's a built-in function symrcm
in MATLAB that does just that.
因此,假设X
是您的矩阵,则可以执行以下操作:
So assuming that X
is your matrix, you can do the following:
p = symrcm(X);
Xnew = X(p, p);
Xnew
是新的重新排序矩阵,p
是新的行/列顺序.
Xnew
is the new reordered matrix, and p
is the new row/column order.
首先创建一个矩阵:
X = [10 0 0 7 0; 3 20 0 0 11; 0 0 30 0 29; 12 7 0 40 0; 0 33 0 0 50]
现在让我们重新排序:
p = symrcm(X);
Xnew = X(p, p)
结果是:
Xnew =
40 12 7 0 0
7 10 0 0 0
0 3 20 11 0
0 0 33 50 0
0 0 0 29 30
似乎正确.
这篇关于如何在相关矩阵中将较大的值移近矩阵对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!