Thread: [Lapackpp-devel] SVD that ignores U, Sigma or VT
Status: Beta
Brought to you by:
cstim
|
From: Jacob \(Jack\) G. <jg...@cs...> - 2004-09-02 19:53:59
|
Hi, I'm writing some code that only uses data from VT of an SVD, and don't need the data in U and Sigma. Although I can ignore it; the resulting U is significantly large (512^2x512^2), which is too large a matrix for the system to handle; and is clearly a waste. I've noticed that there is a function that ignores both U and VT, by essentially setting ldv and ldu to 0, that seemingly tells LAPACK to ignore the data. Maybe it would be better just to use a single LaSVD_IP function, and allow uninitialized LaGenMat[Double/Complex] as input. If, for example U is declared with the default constructor, since U.gdim(0) == 0, I would guess that LAPACK will ignore writing output to U. Any thoughts on this? Jack |
|
From: Christian S. <sti...@tu...> - 2004-09-03 08:24:07
|
Jacob (Jack) Gryn schrieb: > I=92m writing some code that only uses data from VT of an SVD, and don=92= t=20 > need the data in U and Sigma. Although I can ignore it; the resulting = U=20 > is significantly large (512^2x512^2), which is too large a matrix for=20 > the system to handle; and is clearly a waste. Absolutely agreed. I guess you mean the JOBZ argument of the LAPACK=20 function dgesdd http://docs.sun.com/source/817-6700/dgesdd.html, where=20 currently only the settings 'A' and 'N' are used, and instead you would=20 like to use either the 'O' or the 'S' setting. > I=92ve noticed that there is a function that ignores both U and VT, by=20 > essentially setting ldv and ldu to 0, that seemingly tells LAPACK to=20 > ignore the data. =20 The point here is that the argument JOBZ was set to 'N'. Only this is=20 the reason for LAPACK not to use the U and VT arguments. Look into the=20 man page mentioned above. > Maybe it would be better just to use a single LaSVD_IP=20 > function, and allow uninitialized LaGenMat[Double/Complex] as input.=20 > If, for example U is declared with the default constructor, since=20 > U.gdim(0) =3D=3D 0, I would guess that LAPACK will ignore writing outpu= t to U. For people who only want the singular values but not the vectors, I=20 would rather want to leave that extra function in there, since it is=20 totally unambiguous what this function will do. But for your case where=20 you want only some of the singular vectors, there are several=20 possibilities. As you say, one possibility would be to do different=20 things according to what the input arguments U and VT have been set to.=20 Let's assume A to be M-by-N and M !=3D N. Right now we do the following: If (U.size =3D=3D M-by-M) && (VT.size =3D=3D N-by-N) calculate all singular vectors (JOBZ=3D'A') else error. Instead, we could also do the following: MNmin =3D min(M,N); If (U.size =3D=3D M-by-M) && (VT.size =3D=3D N-by-N) calculate all singular vectors (JOBZ=3D'A') else if (U.size =3D=3D M-by-MNmin) && (VT.size =3D=3D MNmin-by-N) calculate the MNmin first singular vectors (JOBZ=3D'S') else if (M >=3D N) && (U.size =3D 0) && (VT.size =3D=3D N-by-N) calculate full VT and first N vectors of U (JOBZ=3D'O') else if (M < N) && (U.size =3D M-by-M) && (VT.size =3D 0) calculate full U and first M vectors of VT (JOBZ=3D'O') else error Does this meet your requirements? On the other hand, this increases the=20 risk of the programmer to be totally confused about what the arguments=20 are supposed to be. But nevertheless I think it would be possible. Do=20 you want me to implement this? Or do you want to give it a try for yourse= lf? Christian |
|
From: Jacob \(Jack\) G. <jg...@cs...> - 2004-09-03 19:34:21
|
It might get a little confusing to implement, or to understand, but as long as things don't change for those who want the FULL SVD, it should be ok. The only other probs I can think of is that the LWORK variable may be different if JOBZ is different; also, if a number is too big (hence the reason to ignore part of the SVD, LWORK may also get much larger. Would you mind implementing it? Thanks Jack -----Original Message----- From: Christian Stimming [mailto:sti...@tu...] Sent: September 3, 2004 4:23 AM To: Jacob (Jack) Gryn Cc: lap...@li... Subject: Re: [Lapackpp-devel] SVD that ignores U, Sigma or VT Jacob (Jack) Gryn schrieb: > I'm writing some code that only uses data from VT of an SVD, and don't > need the data in U and Sigma. Although I can ignore it; the resulting U > is significantly large (512^2x512^2), which is too large a matrix for > the system to handle; and is clearly a waste. Absolutely agreed. I guess you mean the JOBZ argument of the LAPACK function dgesdd http://docs.sun.com/source/817-6700/dgesdd.html, where currently only the settings 'A' and 'N' are used, and instead you would like to use either the 'O' or the 'S' setting. > I've noticed that there is a function that ignores both U and VT, by > essentially setting ldv and ldu to 0, that seemingly tells LAPACK to > ignore the data. The point here is that the argument JOBZ was set to 'N'. Only this is the reason for LAPACK not to use the U and VT arguments. Look into the man page mentioned above. > Maybe it would be better just to use a single LaSVD_IP > function, and allow uninitialized LaGenMat[Double/Complex] as input. > If, for example U is declared with the default constructor, since > U.gdim(0) == 0, I would guess that LAPACK will ignore writing output to U. For people who only want the singular values but not the vectors, I would rather want to leave that extra function in there, since it is totally unambiguous what this function will do. But for your case where you want only some of the singular vectors, there are several possibilities. As you say, one possibility would be to do different things according to what the input arguments U and VT have been set to. Let's assume A to be M-by-N and M != N. Right now we do the following: If (U.size == M-by-M) && (VT.size == N-by-N) calculate all singular vectors (JOBZ='A') else error. Instead, we could also do the following: MNmin = min(M,N); If (U.size == M-by-M) && (VT.size == N-by-N) calculate all singular vectors (JOBZ='A') else if (U.size == M-by-MNmin) && (VT.size == MNmin-by-N) calculate the MNmin first singular vectors (JOBZ='S') else if (M >= N) && (U.size = 0) && (VT.size == N-by-N) calculate full VT and first N vectors of U (JOBZ='O') else if (M < N) && (U.size = M-by-M) && (VT.size = 0) calculate full U and first M vectors of VT (JOBZ='O') else error Does this meet your requirements? On the other hand, this increases the risk of the programmer to be totally confused about what the arguments are supposed to be. But nevertheless I think it would be possible. Do you want me to implement this? Or do you want to give it a try for yourself? Christian |
|
From: Christian S. <sti...@tu...> - 2004-09-03 21:14:13
|
Am Freitag, 3. September 2004 21:34 schrieb Jacob \(Jack\) Gryn: > It might get a little confusing to implement, or to understand, but as long > as things don't change for those who want the FULL SVD, it should be ok. > > The only other probs I can think of is that the LWORK variable may be > different if JOBZ is different; also, if a number is too big (hence the > reason to ignore part of the SVD, LWORK may also get much larger. > > Would you mind implementing it? Ok, I just committed this into lasvd.h and lasvd.cc. Do you think you could test all cases of interest? I only made sure that the code makes sense, but I didn't actually test any of the routines -- they might well be broken. Also, I committed the matrix multiplication when you only want the diagonal, in blas3pp.h (formerly blas3++.h). Again, you need to check whether it calculates the right thing -- it might as well crash on each call. But maybe it works :-) Christian |
|
From: Jacob \(Jack\) G. <jg...@cs...> - 2004-09-03 21:20:11
|
Great, thanks.. I'll do some testing next week. Jack -----Original Message----- From: lap...@li... [mailto:lap...@li...] On Behalf Of Christian Stimming Sent: September 3, 2004 5:12 PM To: lap...@li... Subject: Re: [Lapackpp-devel] SVD that ignores U, Sigma or VT Am Freitag, 3. September 2004 21:34 schrieb Jacob \(Jack\) Gryn: > It might get a little confusing to implement, or to understand, but as long > as things don't change for those who want the FULL SVD, it should be ok. > > The only other probs I can think of is that the LWORK variable may be > different if JOBZ is different; also, if a number is too big (hence the > reason to ignore part of the SVD, LWORK may also get much larger. > > Would you mind implementing it? Ok, I just committed this into lasvd.h and lasvd.cc. Do you think you could test all cases of interest? I only made sure that the code makes sense, but I didn't actually test any of the routines -- they might well be broken. Also, I committed the matrix multiplication when you only want the diagonal, in blas3pp.h (formerly blas3++.h). Again, you need to check whether it calculates the right thing -- it might as well crash on each call. But maybe it works :-) Christian ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click _______________________________________________ lapackpp-devel mailing list lap...@li... https://lists.sourceforge.net/lists/listinfo/lapackpp-devel |