This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: Problem with Singular Value Decomposition Algorithm
- To: Jim Love <Jim dot Love at asml dot com>
- Subject: Re: Problem with Singular Value Decomposition Algorithm
- From: James Theiler <jt at lanl dot gov>
- Date: Wed, 12 Sep 2001 08:51:22 -0600 (MDT)
- cc: <gsl-discuss at sources dot redhat dot com>
On Wed, 12 Sep 2001, Jim Love wrote:
] I have downloaded the latest beta release and the SVD algorithm
] produces the wrong answers. It appears that columns are swapped
] in the output and possibly a sign problem.
]
] Here was my test array:
]
] 1 1 0.975
] 1 -1 0.975
] -1 -1 -0.925
] -1 1 -1.025
]
] The correct answer for the S vector is: 2.7940 2.0000 0.0358
] The gls output was: 2.0000 2.7940 0.0358
]
] The Correct Q matrix is:
]
] -0.7155 0.0256 -0.6981
] 0.0183 0.9997 0.0179
] -0.6983 -0.0000 0.7158
]
] The gls output was:
]
] -0.025633 -0.715538 -0.698103
] -0.999671 0.018347 0.017900
] -0.000000 -0.698332 0.715774
]
] A similar problem was seen in the U matrix.
]
] Any ideas? Is this caused by my implementation or is it a real bug?
I don't believe this is a bug at all.
Both answers are correct. For SVD, the algorithm is
asked to find matrices U,S,Q such that U.S.Q' equals
the original matrix. If you swap the columns of Q
and swap the equivalent rows of U, and also swap the
corresponding elements of S, you have another solution.
Also if you multiply one of the columns of Q by -1,
and multiply the corresponding row of U by -1, you
will get another equivalent solution.
Sometimes you want the solution with the eigenvalues (the
diagonal elements of the S matrix -- represented as a vector)
sorted numerically, as the one you cite as "correct" but
that is a convenience that can be performed after the fact.
And in fact, I notice that the documentation says that
eigenvalues are "generally chosen" to form a non-decreasing
sequence. Maybe worth a sentence to say that these algorithms
do not always do that, or else add a utility that does this
postprocessing step.
jt
---------------------------------------------
James Theiler jt@lanl.gov
MS-D436, NIS-2, LANL tel: 505/665-5682
Los Alamos, NM 87545 fax: 505/665-4414
----- Space and Remote Sensing Sciences -----