Ejemplo n.º 1
0
Archivo: BP.py Proyecto: birm/Elemental
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)
endBP = El.mpi.Time()
if worldRank == 0:
    print "BP time:", endBP - startBP, "seconds"
if display:
    El.Display(x, "x")

xOneNorm = El.EntrywiseNorm(x, 1)
e = El.DistMultiVec()
El.Copy(b, e)
El.Multiply(El.NORMAL, -1., A, x, 1., e)
if display:
    El.Display(e, "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()
if worldSize == 1:
    raw_input('Press Enter to exit')
Ejemplo n.º 2
0
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))

    Dx = El.DistMultiVec()
    El.Zeros(Dx, n - 1, 1)
    El.Multiply(El.NORMAL, 1., D, x, 0., Dx)
    if display:
        El.Display(x, "x")
        El.Display(Dx, "Dx")

    DxOneNorm = El.EntrywiseNorm(Dx, 1)
    e = El.DistMultiVec()
    El.Copy(b, e)
    El.Axpy(-1., x, e)
    if display:
        El.Display(e, "e")
    eTwoNorm = El.Nrm2(e)
    if worldRank == 0:
        print('|| D x ||_1   = {}'.format(DxOneNorm))
        print('|| x - b ||_2 = {}'.format(eTwoNorm))

El.Finalize()
Ejemplo n.º 3
0
x = El.LAV(A, b, ctrl)
endLAV = time.clock()
if worldRank == 0:
    print "LAV time:", endLAV - startLAV, "seconds"
if display:
    El.Display(x, "x")

bTwoNorm = El.Nrm2(b)
bInfNorm = El.MaxNorm(b)
r = El.DistMultiVec()
El.Copy(b, r)
El.SparseMultiply(El.NORMAL, -1., A, x, 1., r)
if display:
    El.Display(r, "r")
rTwoNorm = El.Nrm2(r)
rOneNorm = El.EntrywiseNorm(r, 1)
if worldRank == 0:
    print "|| b ||_2       =", bTwoNorm
    print "|| b ||_oo      =", bInfNorm
    print "|| A x - b ||_2 =", rTwoNorm
    print "|| A x - b ||_1 =", rOneNorm

startLS = time.clock()
xLS = El.LeastSquares(A, b)
endLS = time.clock()
if worldRank == 0:
    print "LS time:", endLS - startLS, "seconds"
if display:
    El.Display(xLS, "x_{LS}")
rLS = El.DistMultiVec()
El.Copy(b, rLS)