def SolveWeighted(A, B, C, D, lambd): BScale = El.SparseMatrix() El.Copy(B, BScale) El.Scale(lambd, BScale) DScale = El.Matrix() El.Copy(D, DScale) El.Scale(lambd, DScale) AEmb = El.VCat(A, BScale) CEmb = El.VCat(C, DScale) X = El.LeastSquares(AEmb, CEmb, ctrl) El.Copy(C, E) El.Multiply(El.NORMAL, -1., A, X, 1., E) residNorm = El.FrobeniusNorm(E) if display: El.Display(E, "C - A X") print "lambda=", lambd, ": || C - A X ||_F / || C ||_F =", residNorm / CNorm El.Copy(D, E) El.Multiply(El.NORMAL, -1., B, X, 1., E) equalNorm = El.FrobeniusNorm(E) if display: El.Display(E, "D - B X") print "lambda=", lambd, ": || D - B X ||_F / || D ||_F =", equalNorm / DNorm
def SolveWeighted(A, B, D, lambd): AScale = El.DistSparseMatrix() El.Copy(A, AScale) El.Scale(lambd, AScale) AEmb = El.HCat(AScale, B) if display: El.Display(AEmb, "[lambda*A, B]") if output: El.Print(AEmb, "[lambda*A, B]") ctrl.alpha = baseAlpha if worldRank == 0: print "lambda=", lambd, ": ctrl.alpha=", ctrl.alpha XEmb = El.LeastSquares(AEmb, D, ctrl) X = XEmb[0:n0 * n1, 0:numRHS] Y = XEmb[n0 * n1:n0 * n1 + numColsB, 0:numRHS] El.Scale(lambd, X) YNorm = El.FrobeniusNorm(Y) if worldRank == 0: print "lambda=", lambd, ": || Y ||_F =", YNorm El.Copy(D, E) El.Multiply(El.NORMAL, -1., A, X, 1., E) El.Multiply(El.NORMAL, -1., B, Y, 1., E) residNorm = El.FrobeniusNorm(E) if worldRank == 0: print "lambda=", lambd, ": || D - A X - B Y ||_F / || D ||_F =", residNorm / DNorm
def SolveWeighted(A,B,C,D,lambd): BScale = El.DistSparseMatrix() El.Copy( B, BScale ) El.Scale( lambd, BScale ) DScale = El.DistMultiVec() El.Copy( D, DScale ) El.Scale( lambd, DScale ) AEmb = El.VCat(A,BScale) CEmb = El.VCat(C,DScale) if output: El.Print( AEmb, "AEmb" ) ctrl.alpha = baseAlpha if worldRank == 0: print('lambda={}, ctrl.alpha={}'.format(lambd,ctrl.alpha)) X=El.LeastSquares(AEmb,CEmb,ctrl) El.Copy( C, E ) El.Multiply( El.NORMAL, -1., A, X, 1., E ) residNorm = El.FrobeniusNorm( E ) if display: El.Display( E, "C - A X" ) if output: El.Print( E, "C - A X" ) if worldRank == 0: print('lambda={}: || C - A X ||_F / || C ||_F = {}'.format(lambd, \ residNorm/CNorm)) El.Copy( D, E ) El.Multiply( El.NORMAL, -1., B, X, 1., E ) equalNorm = El.FrobeniusNorm( E ) if display: El.Display( E, "D - B X" ) if output: El.Print( E, "D - B X" ) if worldRank == 0: print('lambda={}: || D - B X ||_F / || D ||_F = {}'.format(lambd, \ equalNorm/DNorm))
if x1 > 0: A.QueueLocalUpdate(sLoc, sRel - N0, -3) if x1 + 1 < N1: A.QueueLocalUpdate(sLoc, sRel + N0, 3) # The dense last column A.QueueLocalUpdate(sLoc, width - 1, -10 / height) A.ProcessQueues() return A # Stack two 2D finite-difference-like matrices on top of each other A = StackedFD2D(n0, n1) if display: El.Display(A, "A") El.Display(A[0:n0 * n1, 0:n0 * n1], "AT") El.Display(A[n0 * n1:2 * n0 * n1, 0:n0 * n1], "AB") # Regularize with 3 I G = El.DistSparseMatrix() El.Identity(G, n0 * n1, n0 * n1) El.Scale(3., G) y = El.DistMultiVec() El.Uniform(y, 2 * n0 * n1, 1) if display: El.Display(y, "y") yNrm = El.Nrm2(y) if worldRank == 0: print "|| y ||_2 =", yNrm
# # Copyright (c) 2009-2015, Jack Poulson # All rights reserved. # # This file is part of Elemental and is under the BSD 2-Clause License, # which can be found in the LICENSE file in the root directory, or at # http://opensource.org/licenses/BSD-2-Clause # import El import time n = 30 A = El.DistSparseMatrix() El.DynamicRegCounter(A, n) El.Display(A, "A") # Require the user to press a button before the figures are closed worldSize = El.mpi.WorldSize() El.Finalize() if worldSize == 1: raw_input('Press Enter to exit')
A.QueueLocalUpdate(sLoc, sRel + 1, -2) if x1 > 0: A.QueueLocalUpdate(sLoc, sRel - N0, -3) if x1 + 1 < N1: A.QueueLocalUpdate(sLoc, sRel + N0, 3) # The dense last column A.QueueLocalUpdate(sLoc, width - 1, -10 / height) A.MakeConsistent() return A A = StackedFD2D(n0, n1) if display: El.Display(A, "A") if output: El.Print(A, "A") # Run both the algorithm which only generates the Rayleigh quotient and the # algorithm which generates the entire (naive) Lanczos decomposition TOnly = El.ProductLanczos(A, basisSize) V, T, v, beta = El.ProductLanczosDecomp(A, basisSize) if display: El.Display(TOnly, "TOnly") El.Display(V, "V") El.Display(T, "T") El.Display(v, "v") if output: El.Print(TOnly, "TOnly")
El.Zeros(B, N0 * N1, numCols) localHeight = B.LocalHeight() B.Reserve(localHeight * numCols) for sLoc in xrange(localHeight): s = B.GlobalRow(sLoc) for j in xrange(numCols): B.QueueLocalUpdate(sLoc, j, random.uniform(0, 1)) B.ProcessQueues() return B A = FD2D(n0, n1) B = Constraints(numColsB, n0, n1) if display: El.Display(A, "A") El.Display(B, "B") if output: El.Print(A, "A") El.Print(B, "B") D = El.DistMultiVec() El.Uniform(D, A.Height(), numRHS) if display: El.Display(D, "D") if output: El.Print(D, "D") DNorm = El.FrobeniusNorm(D) baseAlpha = 1e-4 ctrl = El.LeastSquaresCtrl_d()
A.QueueLocalUpdate( sLoc, s%width, 11 ) A.QueueLocalUpdate( sLoc, (s-1)%width, -1 ) A.QueueLocalUpdate( sLoc, (s+1)%width, 2 ) A.QueueLocalUpdate( sLoc, (s-height)%width, -3 ) A.QueueLocalUpdate( sLoc, (s+height)%width, 4 ) # The dense last column #A.QueueLocalUpdate( sLoc, width-1, -5/height ); A.ProcessQueues() return A A = Rectang(m,n) b = El.DistMultiVec() El.Gaussian( b, m, 1 ) if display: El.Display( A, "A" ) El.Display( b, "b" ) ctrl = El.SOCPAffineCtrl_d() ctrl.mehrotraCtrl.progress = True ctrl.mehrotraCtrl.time = True ctrl.mehrotraCtrl.solveCtrl.progress = True # Solve *with* resolving the regularization ctrl.mehrotraCtrl.resolveReg = True startRNNLS = El.mpi.Time() x = El.RNNLS( A, b, rho, ctrl ) endRNNLS = El.mpi.Time() if worldRank == 0: print('RNNLS time (resolve reg.): {} seconds'.format(endRNNLS-startRNNLS)) if display:
A.Reserve(2 * localHeight) for iLoc in xrange(localHeight): i = A.GlobalRow(iLoc) A.QueueLocalUpdate(iLoc, i, 1.) A.QueueLocalUpdate(iLoc, i + 1, -1.) A.ProcessQueues() return A D = Deriv(n) b = El.DistMultiVec() El.Gaussian(b, n, 1) if display: El.Display(b, "b") ctrl = El.QPAffineCtrl_d() ctrl.mehrotraCtrl.progress = True for j in xrange(0, numLambdas): lambd = startLambda + j * (endLambda - startLambda) / (numLambdas - 1.) if worldRank == 0: print('lambda = {}'.format(lambd)) startTV = El.mpi.Time() x = El.TV(b, lambd, ctrl) endTV = El.mpi.Time() if worldRank == 0: print('TV time: {}'.format(endTV - startTV))
# # Copyright (c) 2009-2016, Jack Poulson # All rights reserved. # # This file is part of Elemental and is under the BSD 2-Clause License, # which can be found in the LICENSE file in the root directory, or at # http://opensource.org/licenses/BSD-2-Clause # import math, El n = 100 # matrix size realRes = imagRes = 100 # grid resolution # Display an instance of the pathological example A = El.DistMatrix() El.GEPPGrowth(A,n) El.Display(A,"GEPP growth matrix") # Display the spectral portrait portrait, box = El.SpectralPortrait(A,realRes,imagRes) El.DisplayPortrait(portrait,box,"spectral portrait of GEPP growth matrix") # Display the relevant pieces of pivoted LU factorization p = El.LU(A) El.Display(p,"LU permutation") El.EntrywiseMap(A,lambda x:math.log10(max(abs(x),1))) El.Display(A,"Logarithmically-scaled LU factors") El.Display(A[0:n,n-1],"Last column of logarithmic U") # Require the user to press a button before the figures are closed worldSize = El.mpi.WorldSize() El.Finalize()
def LCF(lcf): n = len(lcf) G = El.Graph() G.Resize(n,n) G.Reserve( 4*n ) for s in xrange(n): # Build the links to this node in the Hamiltonian cycle tL = (s-1) % n tR = (s+1) % n G.QueueConnection(s,tL) G.QueueConnection(s,tR) # Build the LCF links t = (s + lcf[s]) % n G.QueueConnection(s,t) G.QueueConnection(t,s) G.ProcessQueues() return G levi = [-13,-9,7,-7,9,13]*5 dodec = [10,7,4,-4,-7,10,-4,7,-7,4]*2 truncOct = [3,-7,7,-3]*6 if El.mpi.WorldRank() == 0: El.Display( LCF(levi), "Levi graph" ) El.Display( LCF(dodec), "Dodecahedral graph" ) El.Display( LCF(truncOct), "Trunacted octahedral graph" ) El.Finalize()
if x1 + 1 < N1: A.QueueLocalUpdate(sLoc, s + N0, 4) A.QueueLocalUpdate(sLoc, sRel + N0, 3) # The dense last column A.QueueLocalUpdate(sLoc, width - 1, -10 / height) A.MakeConsistent() return A A = ConcatFD2D(n0, n1) b = El.DistMultiVec() El.Gaussian(b, n0 * n1, 1) if display: El.Display(A, "A") El.Display(A[0:n0 * n1, 0:n0 * n1], "AL") El.Display(A[0:n0 * n1, n0 * n1:2 * n0 * n1], "AR") El.Display(b, "b") ctrl = El.QPAffineCtrl_d() ctrl.mehrotraCtrl.progress = True for j in xrange(0, numLambdas): lambd = startLambda + j * (endLambda - startLambda) / (numLambdas - 1.) if worldRank == 0: print "lambda =", lambd startBPDN = time.clock() x = El.BPDN(A, b, lambd, ctrl) endBPDN = time.clock()
offset = 0.3147 # Define a random set of points A = RectangSparse(m,n) # Label the points based upon their location relative to the hyperplane d = El.DistMatrix() El.Ones( d, m, 1 ) El.Gemv( El.NORMAL, 1., A, wGen, -offset, d ) El.EntrywiseMap( d, lambda alpha : 1. if alpha > 0 else -1. ) El.Print( A, "A" ) El.Print( d, "d" ) if display: El.Display( wGen, "wGen" ) if worldRank == 0: print "offset =", offset El.Display( A, "A" ) El.Display( d, "d" ) ctrl = El.QPAffineCtrl_d() ctrl.mehrotraCtrl.progress = True for j in xrange(0,numLambdas): lambd = startLambda + j*(endLambda-startLambda)/(numLambdas-1.) if worldRank == 0: print "lambda =", lambd startSVM = time.clock() x = El.SVM( A, d, lambd, ctrl )
# # Copyright (c) 2009-2016, Jack Poulson # All rights reserved. # # This file is part of Elemental and is under the BSD 2-Clause License, # which can be found in the LICENSE file in the root directory, or at # http://opensource.org/licenses/BSD-2-Clause # import El, time, math n=100 realRes = imagRes = 50 # grid resolution A = El.DistMatrix() El.JordanCholesky( A, n ) El.Display( A, "A" ) El.Cholesky( El.UPPER, A ) El.MakeTrapezoidal( El.UPPER, A ) El.Display( A, "U" ) portrait = El.SpectralWindow(A,0,6,4,realRes,imagRes) box = El.SpectralBox_d() box.center = El.TagToType(El.Complexify(A.tag))(0) box.realWidth = 6 box.imagWidth = 4 El.DisplayPortrait(portrait,box,"spectral portrait of 2*J_{1/2}(n)") # Require the user to press a button before the figures are closed worldSize = El.mpi.WorldSize() El.Finalize()
# # Copyright (c) 2009-2015, Jack Poulson # All rights reserved. # # This file is part of Elemental and is under the BSD 2-Clause License, # which can be found in the LICENSE file in the root directory, or at # http://opensource.org/licenses/BSD-2-Clause # import math, El k = 140 # matrix size realRes = imagRes = 100 # grid resolution # Display an instance of the pathological example A = El.DistMatrix() El.DruinskyToledo(A, k) El.Display(A, "Bunch-Kaufman growth matrix") # Display the spectral portrait portrait, box = El.SpectralPortrait(A, realRes, imagRes) El.DisplayPortrait(portrait, box, "spectral portrait of BK growth matrix") # Make a copy before overwriting with LDL factorization A_LU = El.DistMatrix() El.Copy(A, A_LU) # Display the relevant pieces of pivoted LDL factorization dSub, p = El.LDL(A, False, El.BUNCH_KAUFMAN_A) El.MakeTrapezoidal(El.LOWER, A) El.Display(dSub, "Subdiagonal of D from LDL") #P = El.DistMatrix(iTag,MC,MR,A.Grid()) # TODO: Construct P from p
y = s / xSize A.QueueUpdate(s, s, 2 * (hxInvSq + hyInvSq)) if x != 0: A.QueueUpdate(s, s - 1, -hxInvSq) if x != xSize - 1: A.QueueUpdate(s, s + 1, -hxInvSq) if y != 0: A.QueueUpdate(s, s - xSize, -hyInvSq) if y != ySize - 1: A.QueueUpdate(s, s + xSize, -hyInvSq) else: A.QueueUpdate(s, s - xSize * ySize, 2 * (hxInvSq + hyInvSq)) A.ProcessQueues() return A A = ExtendedLaplacian(n0, n1) if display: El.Display(A, "A") El.Display(A.Graph(), "Graph of A") y = El.Matrix() El.Uniform(y, 2 * n0 * n1, 1) if display: El.Display(y, "y") yNrm = El.Nrm2(y) print('|| y ||_2 = {}'.format(yNrm)) startLS = time.time() x = El.LeastSquares(A, y) endLS = time.time() print('LS time: {} seconds'.format(endLS - startLS)) xNrm = El.Nrm2(x) if display:
ctrl = El.BPCtrl_z() ctrl.ipmCtrl.mehrotraCtrl.minTol = 1e-4 ctrl.ipmCtrl.mehrotraCtrl.targetTol = 1e-8 ctrl.ipmCtrl.mehrotraCtrl.time = True ctrl.ipmCtrl.mehrotraCtrl.progress = True ctrl.ipmCtrl.mehrotraCtrl.outerEquil = False ctrl.ipmCtrl.mehrotraCtrl.innerEquil = True ctrl.ipmCtrl.mehrotraCtrl.qsdCtrl.progress = True startBP = El.mpi.Time() x = El.BP( A, b, ctrl ) endBP = El.mpi.Time() if worldRank == 0: print "BP time:", endBP-startBP, "seconds" if display: El.Display( x, "x" ) if output: El.Print( x, "x" ) xOneNorm = El.EntrywiseNorm( x, 1 ) e = El.DistMultiVec(El.zTag) El.Copy( b, e ) El.Multiply \ ( El.NORMAL, El.ComplexDouble(-1), A, x, El.ComplexDouble(1), e ) eTwoNorm = El.Nrm2( e ) if worldRank == 0: print "|| x ||_1 =", xOneNorm print "|| A x - b ||_2 =", eTwoNorm # Require the user to press a button before the figures are closed El.Finalize()
El.Copy( sGen, h ) El.Gemv( El.NORMAL, 1., G, xGen, 1., h ) # Generate a c which implies a dual feasible (y,z) # ================================================ yGen = El.DistMatrix() El.Gaussian(yGen,m,1) zGen = El.DistMatrix() El.Uniform(zGen,k,1,0.5,0.5) c = El.DistMatrix() El.Zeros( c, n, 1 ) El.Gemv( El.TRANSPOSE, -1., A, yGen, 1., c ) El.Gemv( El.TRANSPOSE, -1., G, zGen, 1., c ) if display: El.Display( A, "A" ) El.Display( G, "G" ) El.Display( b, "b" ) El.Display( c, "c" ) El.Display( h, "h" ) # Set up the control structure (and possibly initial guesses) # =========================================================== ctrl = El.LPAffineCtrl_d() xOrig = El.DistMatrix() yOrig = El.DistMatrix() zOrig = El.DistMatrix() sOrig = El.DistMatrix() if manualInit: El.Uniform(xOrig,n,1,0.5,0.4999) El.Uniform(yOrig,m,1,0.5,0.4999)
xGen = El.DistMultiVec() El.Uniform(xGen, n, 1, 0.5, 0.5) b = El.DistMultiVec() El.Zeros(b, m, 1) El.Multiply(El.NORMAL, 1., A, xGen, 0., b) # Generate a c which implies a dual feasible (y,z) # ================================================ yGen = El.DistMultiVec() El.Gaussian(yGen, m, 1) c = El.DistMultiVec() El.Uniform(c, n, 1, 0.5, 0.5) El.Multiply(El.TRANSPOSE, -1., A, yGen, 1., c) if display: El.Display(A, "A") El.Display(b, "b") El.Display(c, "c") # Set up the control structure (and possibly initial guesses) # =========================================================== ctrl = El.LPDirectCtrl_d(isSparse=True) xOrig = El.DistMultiVec() yOrig = El.DistMultiVec() zOrig = El.DistMultiVec() if manualInit: El.Uniform(xOrig, n, 1, 0.5, 0.4999) El.Uniform(yOrig, m, 1, 0.5, 0.4999) El.Uniform(zOrig, n, 1, 0.5, 0.4999) x = El.DistMultiVec() y = El.DistMultiVec()
if x0+1 < N0: A.QueueLocalUpdate( sLoc, sRel+1, -2.2 ) if x1 > 0: A.QueueLocalUpdate( sLoc, sRel-N0, -3.3 ) if x1+1 < N1: A.QueueLocalUpdate( sLoc, sRel+N0, 3.4 ) # The dense last column A.QueueLocalUpdate( sLoc, width-1, -10/height ); A.ProcessQueues() return A A = StackedFD2D(n0,n1) if display: El.Display( A, "A" ) if output: El.Print( A, "A" ) y = El.DistMultiVec() El.Uniform( y, 2*n0*n1, 1 ) if display: El.Display( y, "y" ) if output: El.Print( y, "y" ) yNrm = El.Nrm2(y) if worldRank == 0: print('|| y ||_2 = {}'.format(yNrm)) ctrl = El.LeastSquaresCtrl_d() ctrl.progress = True
A.QueueLocalUpdate(sLoc, sRel - N0, -3) if x1 + 1 < N1: A.QueueLocalUpdate(sLoc, sRel + N0, 3) # The dense last column A.QueueLocalUpdate(sLoc, width - 1, -10 / height) A.MakeConsistent() return A A = StackedFD2D(n0, n1) b = El.DistMultiVec() El.Gaussian(b, 2 * n0 * n1, 1) if display: El.Display(A, "A") El.Display(b, "b") ctrl = El.LPAffineCtrl_d() ctrl.mehrotraCtrl.qsdCtrl.progress = True ctrl.mehrotraCtrl.progress = True ctrl.mehrotraCtrl.outerEquil = True ctrl.mehrotraCtrl.time = True startLAV = time.clock() x = El.LAV(A, b, ctrl) endLAV = time.clock() if worldRank == 0: print "LAV time:", endLAV - startLAV, "seconds" if display: El.Display(x, "x")
# Copyright (c) 2009-2015, Jack Poulson # All rights reserved. # # This file is part of Elemental and is under the BSD 2-Clause License, # which can be found in the LICENSE file in the root directory, or at # http://opensource.org/licenses/BSD-2-Clause # import El n = 200 # matrix size realRes = imagRes = 100 # grid resolution # Display an instance of the Fourier matrix A = El.DistMatrix(El.zTag) El.Fourier(A, n) El.Display(A, "Fourier matrix") # Display a submatrix and subvector of the Fourier matrix El.Display(A[(n / 4):(3 * n / 4), (n / 4):(3 * n / 4)], "Middle submatrix") El.Display(A[1, 0:n], "Second row") # Display the spectral portrait portrait, box = El.SpectralPortrait(A, realRes, imagRes) El.DisplayPortrait(portrait, box, "spectral portrait of Fourier matrix") # 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')
A.QueueUpdate(s, s + N0, 4) A.QueueUpdate(s, sRel + N0, 3) # The dense last column #A.QueueUpdate( s, width-1, -10/height ); A.ProcessLocalQueues() return A A = ConcatFD2D(n0, n1) b = El.DistMultiVec() #El.Gaussian( b, n0*n1, 1 ) El.Ones(b, n0 * n1, 1) if display: El.Display(A, "A") El.Display(b, "b") ctrl = El.BPCtrl_d(isSparse=True) ctrl.useSOCP = False ctrl.lpIPMCtrl.mehrotraCtrl.system = El.NORMAL_KKT #ctrl.lpIPMCtrl.mehrotraCtrl.system = El.AUGMENTED_KKT ctrl.lpIPMCtrl.mehrotraCtrl.progress = True ctrl.lpIPMCtrl.mehrotraCtrl.qsdCtrl.progress = True ctrl.socpIPMCtrl.mehrotraCtrl.time = True ctrl.socpIPMCtrl.mehrotraCtrl.progress = True ctrl.socpIPMCtrl.mehrotraCtrl.outerEquil = False ctrl.socpIPMCtrl.mehrotraCtrl.innerEquil = True ctrl.socpIPMCtrl.mehrotraCtrl.qsdCtrl.progress = True startBP = El.mpi.Time() x = El.BP(A, b, ctrl)
if x1 + 1 < N1: A.QueueLocalUpdate(sLoc, s + N0, 4) A.QueueLocalUpdate(sLoc, sRel + N0, 3) # The dense last column A.QueueLocalUpdate(sLoc, width - 1, -10 / height) A.MakeConsistent() return A A = ConcatFD2D(n0, n1) b = El.DistMultiVec() El.Gaussian(b, n0 * n1, 1) if display: El.Display(A, "A") El.Display(b, "b") ctrl = El.LPAffineCtrl_d() ctrl.mehrotraCtrl.outerEquil = True ctrl.mehrotraCtrl.innerEquil = True ctrl.mehrotraCtrl.scaleTwoNorm = True ctrl.mehrotraCtrl.progress = True for j in xrange(0, numLambdas): lambd = startLambda + j * (endLambda - startLambda) / (numLambdas - 1.) if worldRank == 0: print "lambda =", lambd startDS = time.clock() x = El.DS(A, b, lambd, ctrl)
def Constraints(numRows, N0, N1): B = El.SparseMatrix() El.Zeros(B, numRows, N0 * N1) B.Reserve(numRows * N0 * N1) for s in xrange(numRows): for j in xrange(N0 * N1): B.QueueUpdate(s, j, random.uniform(0, 1)) B.ProcessQueues() return B A = FD2D(n0, n1) B = Constraints(numRowsB, n0, n1) if display: El.Display(A, "A") El.Display(B, "B") C = El.Matrix() D = El.Matrix() El.Uniform(C, A.Height(), numRHS) El.Uniform(D, B.Height(), numRHS) if display: El.Display(C, "C") El.Display(D, "D") CNorm = El.FrobeniusNorm(C) DNorm = El.FrobeniusNorm(D) ctrl = El.LeastSquaresCtrl_d() ctrl.progress = True ctrl.solveCtrl.relTol = 1e-10
h.Set(2, 0, 2.) h.Set(5, 0, 2.) h.Set(8, 0, 2.) h.Set(11, 0, 2.) output = True display = False if output: El.Print(A, "A") El.Print(G, "G") El.Print(b, "b") El.Print(c, "c") El.Print(h, "h") if display: El.Display(A, "A") El.Display(G, "G") El.Display(b, "b") El.Display(c, "c") El.Display(h, "h") x = El.DistMultiVec() y = El.DistMultiVec() z = El.DistMultiVec() s = El.DistMultiVec() ctrl = El.SOCPAffineCtrl_d() ctrl.mehrotraCtrl.qsdCtrl.progress = True ctrl.mehrotraCtrl.progress = True ctrl.mehrotraCtrl.outerEquil = True ctrl.mehrotraCtrl.time = True El.SOCPAffine(A, G, b, c, h, orders, firstInds, x, y, z, s, ctrl)
A.ProcessQueues() return A A = Laplacian(n0, n1) x = El.DistMultiVec() y = El.DistMultiVec() El.Uniform(x, n0 * n1, 1) El.Copy(x, y) yNrm = El.Nrm2(y) if worldRank == 0: print "|| y ||_2 =", yNrm El.Display(A, "Laplacian") El.Display(A.DistGraph(), "Laplacian graph") El.Display(y, "y") El.SymmetricSolve(A, x) El.Display(x, "x") xNrm = El.Nrm2(x) if worldRank == 0: print "|| x ||_2 =", xNrm El.Multiply(El.NORMAL, -1., A, x, 1., y) El.Display(y, "A x - y") eNrm = El.Nrm2(y) if worldRank == 0: print "|| A x - y ||_2 / || y ||_2 =", eNrm / yNrm
El.Gaussian(wGen, n0 * n1, 1) wGenNorm = El.FrobeniusNorm(wGen) El.Scale(1. / wGenNorm, wGen) # TODO: Add support for mpi::Broadcast and randomly generate this offset = 0.3147 A = StackedFD2D(n0, n1) # Label the points based upon their location relative to the hyperplane d = El.DistMultiVec() El.Ones(d, 2 * n0 * n1, 1) El.Multiply(El.NORMAL, 1., A, wGen, -offset, d) El.EntrywiseMap(d, lambda alpha: 1. if alpha > 0 else -1.) if display: El.Display(wGen, "wGen") if worldRank == 0: print "offset =", offset El.Display(A, "A") El.Display(d, "d") ctrl = El.SVMCtrl_d() ctrl.ipmCtrl.mehrotraCtrl.progress = True for j in xrange(0, numLambdas): lambd = startLambda + j * (endLambda - startLambda) / (numLambdas - 1.) if worldRank == 0: print "lambda =", lambd # TODO: Explicitly return w, beta, and z startSVM = El.mpi.Time()
# # Copyright (c) 2009-2016, Jack Poulson # All rights reserved. # # This file is part of Elemental and is under the BSD 2-Clause License, # which can be found in the LICENSE file in the root directory, or at # http://opensource.org/licenses/BSD-2-Clause # import math, El n = 100 # matrix size realRes = imagRes = 100 # grid resolution # Display an instance of the Fox-Li/Landau matrix A = El.DistMatrix(El.zTag) El.FoxLi(A,n) El.Display(A,"Fox-Li/Landau matrix") # Display its spectral portrait portrait, box = El.SpectralPortrait(A,realRes,imagRes) El.DisplayPortrait(portrait,box,"spectral portrait of Fox-Li/Landau matrix") # Display its singular values s = El.SingularValues(A) El.EntrywiseMap(s,math.log10) El.Display(s,"log10(svd(A))") # Require the user to press a button before the figures are closed worldSize = El.mpi.WorldSize() El.Finalize() if worldSize == 1: raw_input('Press Enter to exit')
c = El.DistMultiVec() #Zeros( c, height, 1 ) #localHeight = c.LocalHeight() #for iLoc in xrange(localHeight): # i = c.GlobalRow(iLoc) # c.SetLocal(iLoc,0,1.+1./i) El.Gaussian( c, height, 1 ) El.EntrywiseMap( c, lambda alpha : abs(alpha) ) return c d = CreateDiag(n) F = CreateFactor(n,r) c = CreateExpected(n) if display: El.Display( d, "d" ) El.Display( F, "F" ) El.Display( c, "c" ) ctrl = El.SOCPAffineCtrl_d() ctrl.mehrotraCtrl.progress = True ctrl.mehrotraCtrl.time = False ctrl.mehrotraCtrl.solveCtrl.progress = False ctrl.mehrotraCtrl.solveCtrl.time = False # Solve *with* resolving the regularization ctrl.mehrotraCtrl.resolveReg = True startLOP = El.mpi.Time() x = El.LongOnlyPortfolio(d,F,c,gamma,ctrl) endLOP = El.mpi.Time() if worldRank == 0: