SVD Only With Matrix of Full Rank?

04032015, 11:20 AM
Post: #1




SVD Only With Matrix of Full Rank?
I am testing some code for multiple correspondence analysis, which relies on the SVD for dimension reduction. The example is 5x4 (5 observations on 4 responses) that is essentially two dimensions (last two singular values are essentially 0):
M1 = [ [8 2 2 6], [5 0 3 4], [2 3 3 1], [2 3 3 1], [4 6 6 2] ] The result of SVD( M1 ) is this error (Textbook mode): "0 as singular value, not implemented Error: Bad Argument Value" (1) So the SVD() function does not allow less than full rank matrices? Also, putting M1 on the stack and evaluating SVD results in this error (RPN Mode): "SVD(NULL) Error: Bad Argument Type" (2) How is SVD supposed to work in RPN mode then? Thanks for help. I searched documentation (HP Prime and CAS) and other threads mentioning SVD first but did not see these questions yet. 

04032015, 03:07 PM
Post: #2




RE: SVD Only With Matrix of Full Rank?
(04032015 11:20 AM)mark4flies Wrote: I am testing some code for multiple correspondence analysis, which relies on the SVD for dimension reduction. The example is 5x4 (5 observations on 4 responses) that is essentially two dimensions (last two singular values are essentially 0): For (2), you would type: COMMAND(n) where n is the number of arguments to take from the stack. So in your case, SVD(1) in RPN mode. As for (1), this is due to an incomplete implementation in which the vectors of the unitary matrices are computed using the inverse of the singular values. Once I have some free time to finish up my own implementation of the SVD, I'll post it here. It's basically an implementation of the "standard" algorithm (Householder reflections + Givens rotations) Graph 3D  QPI  SolveSys 

04032015, 04:44 PM
Post: #3




RE: SVD Only With Matrix of Full Rank?
I have modified the implementation in Xcas. It will handle 0 as singular value.
Code:


04032015, 05:10 PM
Post: #4




RE: SVD Only With Matrix of Full Rank?
Thanks for the replies!
In the meantime, I tested this computation on the HP50G, SAS, JMP, and R. All give the correct answer for U, D, and V for this case. I was hoping to port some HP50G programs to the new HP Prime, but the newer ROM is not up to it. 

04032015, 06:51 PM
Post: #5




RE: SVD Only With Matrix of Full Rank?
Writing a good implementation of SVD takes time and it's not really part of a CAS. Inside Xcas, it is not required because LAPACK is called. On the calc, you will hopefully have my homemade quick and dirty implementation in a future firmware. If one can convince me that there is a real need for a state of the art implementation on a calc, I might improve this implementation later, otherwise it will stay like this, unless Han or someone else writes a user program for that.


04042015, 12:08 PM
Post: #6




RE: SVD Only With Matrix of Full Rank?
The SVD is one of the most important results of matrix theory for practical applications, such as statistics. Almost all of the multivariate statistical techniques, such as principle components analysis and multiple correspondence analysis, use SVD at their core. This single function would support many realworld applications with a handheld device.


04042015, 04:48 PM
(This post was last modified: 04042015 04:55 PM by parisse.)
Post: #7




RE: SVD Only With Matrix of Full Rank?
For
Code: m1:=[ [8 ,2 ,2 ,6], [5, 0, 3, 4], [2 ,3 ,3 ,1], [2 ,3 ,3, 1], [4, 6 ,6 ,2] ];u,s,q:=svd(evalf(m1),1);m:=u*[op(diag(s)*trn(q)),[0$4]]; Code: s=[9.58068546525e08,1.74628850627e07,9.82257667369,14.1250482296] 

04042015, 06:30 PM
(This post was last modified: 04042015 06:45 PM by parisse.)
Post: #8




RE: SVD Only With Matrix of Full Rank?
I just discovered I can cheat on degenerated matrices, I can replace the small computed singular values by 0, then precision becomes much better. However it would have a drawback, really small svl would be replaced by 0. Is it a problem?


04082015, 12:25 PM
Post: #9




RE: SVD Only With Matrix of Full Rank?
Thank you (Parisse) for looking into this matter. I am not an expert in numerical analysis. I have only started to learn HPP. I am just a user. I found this very recent article that might provide some help: it suggests a practical criterion for deciding if the singular value should be set to 0.
Again, thank you. 

04082015, 12:26 PM
Post: #10




RE: SVD Only With Matrix of Full Rank?
Link to article: http://blogs.sas.com/content/iml/2015/04...ofmatrix/


10202015, 07:18 PM
(This post was last modified: 10202015 07:36 PM by Han.)
Post: #11




RE: SVD Only With Matrix of Full Rank?
The svd2 program gives:
Code:
for U, S, and V respectively, where U*diag(S)*V = original matrix. The difference between U*diag(S)*V and m1 is Code: [ [−1.45803369378e−11, −2.13162820728e−12, −1.79767312147e−12, 4.64694949187e−11], Graph 3D  QPI  SolveSys 

11142015, 03:37 PM
Post: #12




RE: SVD Only With Matrix of Full Rank?
This result looks quite good compared to the result from other programs such as SAS IML or SAS JMP.
Is 'svd2' above the replacement for the builtin SVD function or a standalone program? I don't see 'svd2' in the catalog on my HP Prime with the latest ROM. Thanks for all your help! 

11142015, 05:21 PM
Post: #13




RE: SVD Only With Matrix of Full Rank?
(11142015 03:37 PM)mark4flies Wrote: This result looks quite good compared to the result from other programs such as SAS IML or SAS JMP. It's a standalone program: http://www.hpmuseum.org/forum/thread4976.html Graph 3D  QPI  SolveSys 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)