我剛剛對我的數據(M = UDV^t)執行了SVD,並且我有3個svd矩陣U,D,Vt。這些矩陣按最高奇異值D (這意味着U的第一列和V的第一行對應於最高奇異值等)通過自定義排序重新排列矩陣行
我想根據特定的排序標準交換此順序:我不希望按絕對奇異值進行排序而是奇異值di在Vt的
實施例(僞代碼,R下面的代碼)乘以其對應的向量的第一個元素:
Singular_values = [ sV[1]=100, sV[2]=1, sv[3]=50 ]
Dt = [
0.1, xxx, ... # 1st row Dt1 associated to 1st singular Value
100, yyy, ... # 2nd row Dt2 associated to 2nd singular Value
1 , zzz, ... #
]
產品sV[i]*Dti[1]
得出:
100*0.1 = 10, # sV1*Dt1[1]
1*100 = 100, # sV2*Dt2[1]
50*1 = 50 # sv3*Dt3[1]
其中需要重新排序降序[1,2,3]> [2,3,1]
100 # sV2*Dt2[1]
50 # sv3*Dt3[1]
10 # sV1*Dt1[1]
...並將這些更改傳播在矩陣申
Dt_reordered [
100, yyy, ... # 2nd row Dt2 associated to 2nd singular Value
1, zzz, ... # 3rd row Dt3 associated to 3rd singular Value
0.1, xxx, ... #
]
R代碼裏面
dataToSVD = matrix(rexp(200), 10)
theSVD = svd(dataToSVD) # Generates ...
# theSVD$u (Matrix U : I don't care about this one),
# theSVD$d (List D : singularValues),
# theSVD$v (Matrix V : Right singular vectors, not transposed)
theSVD$newValues <- theSVD$d*theSVD$v[1,] # This is a list of the "new" values that should be used for sorting
# The idea is now to sort theSVD$newValues by decreasing values, and the corresponding permutation must be applied also to theSVD$d and theSVD$v[1,]
這看起來並不如R代碼。你在使用一些僞代碼嗎?這將有助於做一個[可重現的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – MrFlick
對不起,我用的是僞代碼來描述問題,我對R不是很好,但我想它會生成一個隨機矩陣並對其執行svd ... –