gesvd

The gesvd operator produces a result matrix containing any one of the three components of the singular value decomposition of a dense matrix.

Synopsis

gesvd(input_matrix, factor);

Library

The gesvd operator resides in the Dense Linear Algebra library. Run this query to load the library:

AFL% load_library('dense_linear_algebra');

Summary

For a matrix M, GESVD returns the matrix factorization:

The gesvd operator produces a singular value decomposition (SVD) of the input matrix and returns one of the three factors. For more details of the SVD, see Wikipedia's article on Singular Value Decomposition.

The factor must be one of the following values:

  • U (or 'left'): the matrix of left-singular vectors.
  • S (or 'values'): a vector that contains the singular values in decreasing numerical order.
  • VT (or 'right'): the transpose of the matrix of right-singular vectors.

If the input matrix is an m × n matrix, and letting MIN = min(m,n), then dim(U) is m × MIN, dim(S) is MIN, and dim(VT) is MIN × n.

Limitations

The input matrix requires the following characteristics:

  • It must be dense: that is, it cannot have any empty cells.
  • The first attribute must be of type double. All other attributes are ignored.
  • The chunks of the input array must be square, and must have a chunk interval between 32 and 1024.
  • Each dimension requires the following characteristics:
    • The starting index must be zero.
    • The ending index cannot be '*'.
    • The chunk overlap must be zero.

Example

To create a matrix and calculate its singular value decomposition, do the following:

  1. Load the dense_linear_algebra library.

    AFL% load_library('dense_linear_algebra'); 
  2. Construct a rotation matrix, A, that rotates by π/6.

    AFL% store(build(<val:double>[i=0:1; j=0:1],
             iif(i=j,sqrt(3)/2, iif(i=1,0.5,-0.5))),A); 


    The result is: 

    AFL% set format text;
    AFL% scan(A);
    [
    [(0.866025),(-0.5)],
    [(0.5),(0.866025)]
    ] 
  3. Construct a scaling matrix, B, that distorts by a factor of 2.

    AFL% store(build(<val:double>[i=0:1; j=0:1],iif(i!=j, 0, iif(i=0,2,1))),B);  

     
    The result is:

    AFL% scan(B);
    [
    [(2),(0)],
    [(0),(1)]
    ]

     

  4. Construct a rotation matrix, C, that rotates by -π/6.

    AFL% store(build(<val:double>[i=0:1; j=0:1],
            iif(i=j,sqrt(3)/2, iif(i=1,-0.5,0.5))),C);    


    The result is:

    AFL% scan(C);
    [
    [(0.866025),(0.5)],
    [(-0.5),(0.866025)]
    ] 
  5. Multiply the matrices together. The product becomes the input to the gesvd operator.

    AFL% store(gemm(gemm(A,B, build(A,0)),C, build(A,0)),product); 

     
    The result is:

    AFL% scan(product);
    [
    [(1.75),(0.433013)],
    [(0.433013),(1.25)]
    ] 

     

  6. Calculate the U, S, and VT decompositions.

    AFL% gesvd(product,'U');  


    The output is:

    [
    [(-0.866025),(-0.5)],
    [(-0.5),(0.866025)]
    ] 


    AFL% gesvd(product,'S');  


    The output is:

    [(2),(1)] 


    AFL% gesvd(product,'VT');  


    The output is:

    [
    [(-0.866025),(-0.5)],
    [(-0.5),(0.866025)]
    ] 

Note that the factors match the matrices used to construct the input to gesvd, except for the signs of some of the matrix values. This is because SVD is only unique up to the sign of the matrix entries.