[Fwd: Re: [Fwd: query regarding output of jama svd]]


Sender: tbryan <tbryan@mathworks.com>
Subject: Re: [Fwd: query regarding output of jama svd]


Negating both U and V give a valid SVD, so both answers are correct.   
here's an illustration in MATLAB:

A = [
1 0 0 1 0 0 0 0 0
1 0 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
0 1 1 0 1 0 0 0 0
0 1 1 2 0 0 0 0 0
0 1 0 0 1 0 0 0 0
0 1 0 0 1 0 0 0 0
0 0 1 1 0 0 0 0 0
0 1 0 0 0 0 0 0 1
0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1];

[U,S,V] = svd(A)

U =

   -0.2214   -0.1132    0.2890   -0.4148   -0.1063   -0.3410    
-0.5227    0.0605    0.4067   -0.0759    0.3227   -0.0551
   -0.1976   -0.0721    0.1350   -0.5522    0.2818    0.4959     
0.0704    0.0099    0.1089   -0.0339   -0.4564   -0.2844
   -0.2405    0.0432   -0.1644   -0.5950   -0.1068   -0.2550     
0.3022   -0.0623   -0.4924    0.1098    0.1337    0.3395
   -0.4036    0.0571   -0.3378    0.0991    0.3317    0.3848    
-0.0029    0.0004   -0.0123   -0.1517    0.6453   -0.1102
   -0.6445   -0.1673    0.3611    0.3335   -0.1590   -0.2065     
0.1658   -0.0343   -0.2707   -0.1098   -0.1337   -0.3395
   -0.2650    0.1072   -0.4260    0.0738    0.0803   -0.1697    
-0.2829    0.0161    0.0539   -0.5750   -0.4324    0.3087
   -0.2650    0.1072   -0.4260    0.0738    0.0803   -0.1697    
-0.2829    0.0161    0.0539    0.7267   -0.2129   -0.1986
   -0.3008   -0.1413    0.3303    0.1881    0.1148    0.2722    
-0.0330    0.0190    0.1653    0.2954   -0.0552    0.7340
   -0.2059    0.2736   -0.1776   -0.0324   -0.5372    0.0809     
0.4669    0.0363    0.5794    0.0000    0.0000    0.0000
   -0.0127    0.4902    0.2311    0.0248    0.5942   -0.3921     
0.2883   -0.2546    0.2254   -0.0000    0.0000    0.0000
   -0.0361    0.6228    0.2231    0.0007   -0.0683    0.1149    
-0.1596    0.6811   -0.2320   -0.0000    0.0000   -0.0000
   -0.0318    0.4505    0.1411   -0.0087   -0.3005    0.2773    
-0.3395   -0.6784   -0.1825    0.0000   -0.0000    0.0000


S =

    3.3409         0         0         0         0         0          
0         0         0
         0    2.5417         0         0         0         0          
0         0         0
         0         0    2.3539         0         0         0          
0         0         0
         0         0         0    1.6445         0         0          
0         0         0
         0         0         0         0    1.5048         0          
0         0         0
         0         0         0         0         0    1.3064          
0         0         0
         0         0         0         0         0         0     
0.8459         0         0
         0         0         0         0         0         0          
0    0.5601         0
         0         0         0         0         0         0          
0         0    0.3637
         0         0         0         0         0         0          
0         0         0
         0         0         0         0         0         0          
0         0         0
         0         0         0         0         0         0          
0         0         0


V =

   -0.1974   -0.0559    0.1103   -0.9498    0.0457   -0.0766    
-0.1773    0.0144    0.0637
   -0.6060    0.1656   -0.4973   -0.0286   -0.2063   -0.2565     
0.4330   -0.0493   -0.2428
   -0.4629   -0.1273    0.2076    0.0416    0.3783    0.7244     
0.2369   -0.0088   -0.0241
   -0.5421   -0.2318    0.5699    0.2677   -0.2056   -0.3689    
-0.2648    0.0195    0.0842
   -0.2795    0.1068   -0.5054    0.1500    0.3272    0.0348    
-0.6723    0.0583    0.2624
   -0.0038    0.1928    0.0982    0.0151    0.3948   -0.3002     
0.3408   -0.4545    0.6198
   -0.0146    0.4379    0.1930    0.0155    0.3495   -0.2122     
0.1522    0.7615   -0.0180
   -0.0241    0.6151    0.2529    0.0102    0.1498    0.0001    
-0.2491   -0.4496   -0.5199
   -0.0820    0.5299    0.0793   -0.0246   -0.6020    0.3622    
-0.0380    0.0696    0.4535

%%
U*S*V' - A

ans =

   1.0e-14 *

    0.0888    0.0215    0.0230         0   -0.0396   -0.0625    
-0.0361   -0.0652   -0.0389
    0.1110    0.0893   -0.0333    0.0125    0.0307    0.0007    
-0.0588   -0.1103   -0.0361
    0.1554    0.0888    0.0566   -0.0002   -0.0118    0.0125     
0.0299    0.0291    0.0250
   -0.0173    0.1332    0.0666    0.1654    0.0444    0.0193     
0.0016    0.0368    0.0365
   -0.0533    0.2442    0.1110    0.2665    0.0364   -0.0049    
-0.0029   -0.0264   -0.0007
   -0.0017    0.0444    0.0964    0.0945   -0.0111   -0.0114    
-0.0122    0.0068    0.0305
   -0.0037    0.0444    0.0938    0.0937   -0.0222   -0.0175    
-0.0082    0.0141    0.0274
   -0.0314    0.1277    0.0444    0.1332    0.0642    0.0007     
0.0023   -0.0111   -0.0250
   -0.0099    0.0888    0.0936   -0.0156    0.0118    0.0583     
0.0452    0.0555   -0.0444
   -0.0476    0.0226   -0.0018   -0.0141    0.0170    0.0444     
0.0222    0.0444    0.1311
   -0.0475   -0.0035   -0.0023   -0.0016    0.0288    0.0465     
0.0666    0.0888    0.0666
   -0.0426    0.0073   -0.0019   -0.0393    0.0579    0.0479     
0.0364    0.0444         0


%% Negating U and V still gives a valid SVD
(-U)*S*(-V)' - A

ans =

   1.0e-14 *

    0.0888    0.0215    0.0230         0   -0.0396   -0.0625    
-0.0361   -0.0652   -0.0389
    0.1110    0.0893   -0.0333    0.0125    0.0307    0.0007    
-0.0588   -0.1103   -0.0361
    0.1554    0.0888    0.0566   -0.0002   -0.0118    0.0125     
0.0299    0.0291    0.0250
   -0.0173    0.1332    0.0666    0.1654    0.0444    0.0193     
0.0016    0.0368    0.0365
   -0.0533    0.2442    0.1110    0.2665    0.0364   -0.0049    
-0.0029   -0.0264   -0.0007
   -0.0017    0.0444    0.0964    0.0945   -0.0111   -0.0114    
-0.0122    0.0068    0.0305
   -0.0037    0.0444    0.0938    0.0937   -0.0222   -0.0175    
-0.0082    0.0141    0.0274
   -0.0314    0.1277    0.0444    0.1332    0.0642    0.0007     
0.0023   -0.0111   -0.0250
   -0.0099    0.0888    0.0936   -0.0156    0.0118    0.0583     
0.0452    0.0555   -0.0444
   -0.0476    0.0226   -0.0018   -0.0141    0.0170    0.0444     
0.0222    0.0444    0.1311
   -0.0475   -0.0035   -0.0023   -0.0016    0.0288    0.0465     
0.0666    0.0888    0.0666
   -0.0426    0.0073   -0.0019   -0.0393    0.0579    0.0479     
0.0364    0.0444         0


On Oct 26, 2007, at 10:26 AM, Ron Boisvert wrote:

>
>
> -------- Original Message --------
> Subject: 	query regarding output of jama svd
> Date: 	Fri, 26 Oct 2007 01:05:46 -0400
> From: 	Jundy Raga <jundy.raga@gmail.com>
> Reply-To: 	jundy.raga@gmail.com
> To: 	jama@nist.gov
>
>
>
> Greetings to everyone...
>
> Just want to inquire regarding a problem I encountered while using  
> the SVD class of JAMA. I noticed that when the SVD class generates
> the corresponding matrix decomposition some of the cell values  
> generated have mixed-up negative/positive values (meaning some  
> values which are supposed to be negative are returned as positive  
> and vice-versa). This occurred in both matrix u and v (i.e., on the  
> first column of U and first row of V), the S matrix however is fine.
>
> I became aware of this when I multiplied the generated  
> decomposition matrix (without dimension reduction) and I was not  
> able to acquire the initial input matrix. later on I used an online  
> matrix calculator to process my input matrix and compared the  
> result of Jama SVD with its output. The results are indeed  
> different, but when I remultiplied the USV matrices generated by  
> the online matrix calculator (http://www.bluebit.gr/matrix- 
> calculator/) it was able to generate the input matrix. below is the  
> input matrix I used:
>
> 1 0 0 1 0 0 0 0 0
> 1 0 1 0 0 0 0 0 0
> 1 1 0 0 0 0 0 0 0
> 0 1 1 0 1 0 0 0 0
> 0 1 1 2 0 0 0 0 0
> 0 1 0 0 1 0 0 0 0
> 0 1 0 0 1 0 0 0 0
> 0 0 1 1 0 0 0 0 0
> 0 1 0 0 0 0 0 0 1
> 0 0 0 0 0 1 1 1 0
> 0 0 0 0 0 0 1 1 1
> 0 0 0 0 0 0 0 1 1
>
> below are the output of the online matrix calculator for the matrix U
>
> -0.221 -0.113  0.289 -0.415 -0.106 -0.341 -0.523  0.060  0.407
> -0.198 -0.072  0.135 -0.552  0.282  0.496  0.070  0.010  0.109
> -0.240  0.043 -0.164 -0.595 -0.107 -0.255  0.302 -0.062 -0.492
> -0.404  0.057 -0.338
>  0.099  0.332  0.385 -0.003  0.000 -0.012
> -0.644 -0.167  0.361  0.333 -0.159 -0.207  0.166 -0.034 -0.271
> -0.265  0.107 -0.426  0.074  0.080 -0.170 -0.283  0.016  0.054
> -0.265  0.107 -0.426  0.074  0.080 -0.170 -
> 0.283  0.016  0.054
> -0.301 -0.141  0.330  0.188  0.115  0.272 -0.033  0.019  0.165
> -0.206  0.274 -0.178 -0.032 -0.537  0.081  0.467  0.036  0.579
> -0.013  0.490  0.231  0.025  0.594 -0.392  0.288 -0.255  0.225
>
> -0.036  0.623  0.223  0.001 -0.068  0.115 -0.160  0.681 -0.232
> -0.032  0.451  0.141 -0.009 -0.300  0.277 -0.339 -0.678 -0.183
>
> while below are the output of the JAMA SVD for the matrix U
> 0.221    -0.113    0.289     -0.415    -0.106    -0.341      
> 0.523    -0.060     0.407
> 0.198    -0.072     0.135    -0.552     0.282     0.496     
> -0.070    -0.010     0.109
> 0.240     0.043    -0.164    -0.595    -0.107    -0.255     
> -0.302     0.062    -0.492
> 0.404     0.057    -0.338     0.099     0.332     0.385      
> 0.003    -0.000    -0.012
> 0.644    -0.167     0.361     0.333    -0.159    -0.207     
> -0.166     0.034    -0.271
> 0.265     0.107    -0.426     0.074     0.080    -0.170      
> 0.283    -0.016     0.054
> 0.265     0.107    -0.426     0.074     0.080    -0.170      
> 0.283    -0.016     0.054
> 0.301    -0.141     0.330     0.188     0.115     0.272      
> 0.033    -0.019     0.165
> 0.206     0.274    -0.178    -0.032    -0.537     0.081     
> -0.467    -0.036     0.579
> 0.013     0.490     0.231     0.025     0.594    -0.392     
> -0.288     0.255     0.225
> 0.036     0.623     0.223     0.001    -0.068     0.115      
> 0.160    -0.681    -0.232
> 0.032     0.451     0.141    -0.009    -0.300     0.277      
> 0.339     0.678    -0.183
>
> notice the different signs for the first column, the same  
> difference can also be observed on the V matrix. Would just like to  
> ask if this is a real flaw of JAMA or am I just doing something wrong.
>
> hope somebody can help me on this.
> -- 
> ==================================================================
> "The only necessary thing for the triumph of evil is for good men  
> to do nothing."
>                                         -Edmund Burke-
> ============ http://jundyraga.blogs.friendster.com/jundys_blog/  
> =============
>
>






Date Index | Thread Index | Problems or questions? Contact list-master@nist.gov