startMehrotra = El.mpi.Time() El.QPAffine(Q, A, G, b, c, h, x, y, z, s, ctrl) endMehrotra = El.mpi.Time() if worldRank == 0: print('Mehrotra time: {} seconds'.format(endMehrotra - startMehrotra)) if display: El.Display(x, "x Mehrotra") El.Display(y, "y Mehrotra") El.Display(z, "z Mehrotra") El.Display(s, "s Mehrotra") d = El.DistMatrix() El.Zeros(d, n, 1) El.Hemv(El.LOWER, 1., Q, x, 0., d) obj = El.Dot(x, d) / 2 + El.Dot(c, x) if worldRank == 0: print('Mehrotra (1/2) x^T Q x + c^T x = {}'.format(obj)) if testIPF: ctrl.approach = El.QP_IPF ctrl.ipfCtrl.primalInit = manualInit ctrl.ipfCtrl.dualInit = manualInit ctrl.ipfCtrl.progress = progress ctrl.ipfCtrl.lineSearchCtrl.progress = progress El.Copy(xOrig, x) El.Copy(yOrig, y) El.Copy(zOrig, z) El.Copy(sOrig, s) startIPF = El.mpi.Time() El.QPAffine(Q, A, G, b, c, h, x, y, z, s, ctrl)
ctrl.mehrotraCtrl.progress = progress El.Copy(xOrig, x) El.Copy(yOrig, y) El.Copy(zOrig, z) startMehrotra = El.mpi.Time() El.LPDirect(A, b, c, x, y, z, ctrl) endMehrotra = El.mpi.Time() if worldRank == 0: print "Mehrotra time:", endMehrotra - startMehrotra if display: El.Display(x, "x Mehrotra") El.Display(y, "y Mehrotra") El.Display(z, "z Mehrotra") obj = El.Dot(c, x) if worldRank == 0: print "Mehrotra c^T x =", obj if testIPF: ctrl.approach = El.LP_IPF ctrl.ipfCtrl.primalInit = manualInit ctrl.ipfCtrl.dualInit = manualInit ctrl.ipfCtrl.progress = progress ctrl.ipfCtrl.lineSearchCtrl.progress = progress El.Copy(xOrig, x) El.Copy(yOrig, y) El.Copy(zOrig, z) startIPF = El.mpi.Time() El.LPDirect(A, b, c, x, y, z, ctrl) endIPF = El.mpi.Time()
ctrl.mehrotraCtrl.resolveReg = False startLOP = El.mpi.Time() x = El.LongOnlyPortfolio(d,F,c,gamma,ctrl) endLOP = El.mpi.Time() if worldRank == 0: print('LOP time (no resolve reg. w/ equil): {} seconds'.format( \ endLOP-startLOP)) if display: El.Display( x, "x" ) # Compute the risk-adjusted return # ================================ e = El.DistMultiVec() f = El.DistMultiVec() El.Copy( x, e ) El.DiagonalScale( El.LEFT, El.NORMAL, d, e ) El.Zeros( f, r, 1 ) El.Multiply( El.TRANSPOSE, 1., F, x, 0., f ) El.Multiply( El.NORMAL, 1., F, f, 1., e ) rar = El.Dot(c,x) - gamma*El.Dot(x,e) if worldRank == 0: print('c^T x - gamma x^T (D + F F^T) x = {}'.format(rar)) xOneNorm = El.EntrywiseNorm( x, 1 ) xTwoNorm = El.Nrm2( x ) if worldRank == 0: print('|| x ||_1 = {}'.format(xOneNorm)) print('|| x ||_2 = {}'.format(xTwoNorm)) El.Finalize()