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: <jt at lanl dot gov>
- Subject: Re: Problem with Singular Value Decomposition Algorithm
- From: "Jim Love" <Jim dot Love at asml dot com>
- Date: Wed, 12 Sep 2001 11:24:46 -0400
- Cc: <gsl-discuss at sources dot redhat dot com>
In every text that I have read dealing with the process of SVD, they have always placed the eigenvalues in a decreasing order. The stated reason is to provide a standard solution and methodology. Why would anybody build an API that does something different?? If you are using the SVD to find the least squares fit of a plane or a cylinder for example, order matters (if you want the right answer hehehe). Yes I can add to my code to re-order the output, but so will most everybody else that uses this function. So it should be done in the API. Just a suggestion.
James A. Love
X4477
Pager 1-800-286-1188 Pin# 400659
>>> James Theiler <jt@lanl.gov> 09/12/01 10:51AM >>>
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 -----