I have just performed an SVD on my data (M = U.D.V^t), and I have the 3 svd matrices U, D, Vt. These matrices are sorted by the highest singular value of D (meaning the first column of U and first row of V corresponds to the highest singular value, etc.)
I want to swap this order according to a particular sort criteria : I am not interested in sorting by the absolute singular value but rather the singular value di multiplied by the first element of its corresponding vector in Vt
Example (pseudo-code, R code below) :
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, ... #
]
The products sV[i]*Dti[1]
give :
100*0.1 = 10, # sV1*Dt1[1]
1*100 = 100, # sV2*Dt2[1]
50*1 = 50 # sv3*Dt3[1]
Which should be reordered descending [1,2,3] > [2,3,1]
100 # sV2*Dt2[1]
50 # sv3*Dt3[1]
10 # sV1*Dt1[1]
... and propagate those changes to Matrix Dt
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 Code
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,]