Пример #1
0
        # The dense last column
        A.QueueLocalUpdate(sLoc, width - 1, -5 / height)

    A.ProcessQueues()
    return A


Q = Semidefinite(n)
A = Rectang(m, n)
G = Rectang(k, n)

# Generate a (b,h) which implies a primal feasible (x,s)
# ======================================================
# b := A xGen
# -----------
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)
# h := G xGen + sGen
# ------------------
sGen = El.DistMultiVec()
El.Uniform(sGen, k, 1, 0.5, 0.5)
h = El.DistMultiVec()
El.Copy(sGen, h)
El.Multiply(El.NORMAL, 1., G, xGen, 1., h)

# Generate a c which implies a dual feasible (y,z)
# ================================================
yGen = El.DistMultiVec()
Пример #2
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" )
  El.Display( A.DistGraph(), "Graph of A" )

y = El.DistMultiVec()
El.Uniform( y, 2*n0*n1, 1 )
if display:
  El.Display( y, "y" )
rank = El.mpi.WorldRank()
yNrm = El.Nrm2(y)
if rank == 0:
  print "|| y ||_2 =", yNrm

ctrl = El.LeastSquaresCtrl_d()
ctrl.progress = True
startLS = time.clock()
x = El.LeastSquares(A,y,ctrl)
endLS = time.clock()
if worldRank == 0:
  print "LS time:", endLS-startLS, "seconds"
Пример #3
0
            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()
ctrl.alpha = baseAlpha
ctrl.progress = True
ctrl.equilibrate = True
ctrl.qsdCtrl.relTol = 1e-10
ctrl.qsdCtrl.relTolRefine = 1e-12
ctrl.qsdCtrl.progress = True
Пример #4
0
        if x1 > 0:
            A.QueueLocalUpdate(sLoc, s - N0, -30)
            A.QueueLocalUpdate(sLoc, sRel - N0, -3)
        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.ProcessQueues()
    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.BPDNCtrl_d()
ctrl.ipmCtrl.mehrotraCtrl.time = True
ctrl.ipmCtrl.mehrotraCtrl.progress = True
ctrl.ipmCtrl.mehrotraCtrl.qsdCtrl.progress = True

for j in xrange(0, numLambdas):
    lambd = startLambda + j * (endLambda - startLambda) / (numLambdas - 1.)
    if worldRank == 0:
Пример #5
0
            if x0 + 1 < N0:
                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.ProcessQueues()
    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.progress = True
ctrl.mehrotraCtrl.solveCtrl.progress = True
startCP = El.mpi.Time()
x = El.CP(A, b, ctrl)
endCP = El.mpi.Time()
if worldRank == 0:
    print "CP time:", endCP - startCP, "seconds"
if display:
    El.Display(x, "x")
Пример #6
0
# which should have a solution of 1. The problem data used
# in the following script can be found by then running
#
#   data = prob.get_problem_data(ELEMENTAL)
#   print( data['A'] )
#   print( data['G'] )
#   print( data['b'] )
#   print( data['c'] )
#   print( data['h'] )
#
# which has three SOCs of size three.

import El
El.Initialize()

orders = El.DistMultiVec(El.iTag)
firstInds = El.DistMultiVec(El.iTag)
orders.Resize(12, 1)
firstInds.Resize(12, 1)
for c in xrange(0, 4):
    for i in xrange(0, 3):
        orders.Set(3 * c + i, 0, 3)
        firstInds.Set(3 * c + i, 0, 3 * c)

A = El.DistSparseMatrix(El.dTag)
A.Resize(4, 8)
A.Reserve(4)
A.QueueUpdate(0, 0, 1)
A.QueueUpdate(1, 1, 1)
A.QueueUpdate(2, 2, 1)
A.QueueUpdate(3, 3, 1)
Пример #7
0
      A.QueueUpdate( s, s+1,       2, passive=True )
    if s >= height and s-height < width:
      A.QueueUpdate( s, s-height, -3, passive=True )
    if s+height < width: 
      A.QueueUpdate( s, s+height,  4, passive=True )
    # The dense last column
    A.QueueUpdate( s, width-1, -5/height, passive=True );

  A.ProcessQueues()
  return A

A = Rectang(m,n)

# Generate a b which implies a primal feasible x
# ==============================================
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" )
Пример #8
0
            if x0 + 1 < N0:
                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


# Define a random (affine) hyperplane
wGen = El.DistMultiVec()
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.SparseMultiply(El.NORMAL, 1., A, wGen, -offset, d)
El.EntrywiseMap(d, lambda alpha: 1. if alpha > 0 else -1.)

if display: