Dinar Abdullin
Dinar Abdullin

Reputation: 165

Singular Value Decomposition algorithm

I am trying to use Singular Value Decomposition algorithm from numpy library (numpy-MKL-1.6.2.win-amd64-py2.7), but I propose that this function doesn't correct. This function has the following statement:

from numpy.linalg import *

U, S, V = svd(A, full_matrices=0)

My assumption is based on comparison comparison with the same function in Matlab, which gives a correct answer. I also found that the problems related to the wrong calculation of V matrix.

For example, I have matrix A:

A =[-15.5714,   19.2143,   15.0000; -2.8462,    7.7692,   -3.9615; -19.5000,   3.1111,    4.5556]

In python I receive:

V = [0.7053,  -0.5629,   -0.4308; -0.6863,   -0.6945,   -0.2161; -0.1776,    0.4481,   -0.8762]

and in Matlab:

V = [0.7053,   -0.6863,   -0.1776; -0.5629,   -0.6945,    0.4481; -0.4308,   -0.2161,   -0.8762]

Differences are not so evident, but they become critical during LLS calculations. How can I overcome this problem?

OK, I found the answer: [U,S,V]=svd(a) - Matlab U, S, Vh = linalg.svd(a), V = Vh.T - Python Maybe my question helps someone in future.

Upvotes: 2

Views: 4088

Answers (2)

dantopa
dantopa

Reputation: 635

The domain matrices U and V in the singular value decomposition are not unique, so it is difficult to compare results from different math engines. (The matrix of singular values is unique. Unfortunately it is not posted.)

A quick quality check is to look at the column vectors of the domain matrices. As these matrices are unitary each column vector has unit length in the 2 norm. For the python result these norms are (0.999947, 1.00002, 1.00003); for MATLAB we have a superior result (0.999999, 0.99999, 1.00001). Mathematica surpasses this with (1.0000000000000002, 1.0000000000000004, 1.0000000000000000).

• Addendum: The SVD aligns the vectors spaces of the domain and codomain. There may be only one alignment. There may be a discrete set of alignment angles. There may be a continuous set of angles as shown here:

enter image description here

Upvotes: 1

cyon
cyon

Reputation: 9538

Your Matlab V matrix and numpy V matrix are transposes of each other.

You can use the transpose() function to obtain the transposed version.

Upvotes: 3

Related Questions