Example #1
0
    def test_approximate_symmetric_svd(self):
        """Compute the SVD of symmetric **A** such that **SVD(A) = V S V^T**"""
        n = 100
        A = El.DistMatrix()
        El.Uniform(A, n, n)
        A = A.Matrix()

        # Make A symmetric
        for i in xrange(0, A.Height()):
            for j in xrange(0, i + 1):
                A.Set(j, i, A.Get(i, j))

        # Usign symmetric SVD
        SA = El.Matrix()
        VA = El.Matrix()

        sl_nla.approximate_symmetric_svd(A, SA, VA, k=n)

        # Check result
        VAT = El.Matrix()
        El.Copy(VA, VAT)

        RESULT = El.Matrix()
        El.Zeros(RESULT, n, n)

        El.DiagonalScale(El.RIGHT, El.NORMAL, SA, VAT)
        El.Gemm(El.NORMAL, El.ADJOINT, 1, VAT, VA, 1, RESULT)

        self.assertTrue(utils.equal(A, RESULT))
Example #2
0
    def test_approximate_svd(self):
        """Compute the SVD of **A** such that **SVD(A) = U S V^T**."""

        n = 100

        # Generate random matrix
        A = El.DistMatrix()
        El.Uniform(A, n, n)
        A = A.Matrix()

        # Dimension to apply along.
        k = n

        U = El.Matrix()
        S = El.Matrix()
        V = El.Matrix()

        sl_nla.approximate_svd(A, U, S, V, k=k)

        # Check result
        RESULT = El.Matrix()
        El.Zeros(RESULT, n, n)

        El.DiagonalScale(El.RIGHT, El.NORMAL, S, U)
        El.Gemm(El.NORMAL, El.ADJOINT, 1, U, V, 1, RESULT)

        self.assertTrue(utils.equal(A, RESULT))
Example #3
0
  x = El.SVM( A, d, lambd, ctrl )
  endSVM = time.clock()
  if worldRank == 0:
    print "SVM time: ", endSVM-startSVM

  w = x[0:n,0]
  beta = x.Get(n,0)
  z = x[n+1:n+m+1,0]
  if display:
    El.Display( w, "w" )
    if worldRank==0:
      print "beta=", beta
    El.Display( z, "z" )

  e = El.DistMatrix()
  El.Zeros( e, m, 1 )
  El.Gemv( El.NORMAL, 1., A, w, 1., e )
  El.Shift( e, beta )
  El.DiagonalScale( El.LEFT, El.NORMAL, d, e )
  if display:
    El.Display( e, "diag(d)*(A w + beta)" )
  eTwoNorm = El.Nrm2( e )
  if worldRank == 0:
    print "|| A w + beta - d ||_2 =", eTwoNorm

# Require the user to press a button before the figures are closed
commSize = El.mpi.Size( El.mpi.COMM_WORLD() )
El.Finalize()
if commSize == 1:
  raw_input('Press Enter to exit')