Пример #1
0
    print('%s ' % ('-'*78))
    print('Sample the Pareto frontier at 100 points:      ')
    print('                                              ')
    print('  phi(tau) = minimize ||Ax-b||_2 subject to ||x|| <= tau')
    print('                                              ')
    print('%s%s ' % ('-'*78, '\n'))
    print('Computing sample')


    # % Set up vector b, and run solver
    b = A.dot(x0)
    x = np.zeros(n)
    tau = np.linspace(0,1.05 * np.linalg.norm(x0,1),100)
    phi = np.zeros(tau.size)

    opts = spgSetParms({'iterations':1000})
    for i in range(tau.size):
        x,r,grad,info = spgl1(A,b,tau[i],0,x,opts)
        phi[i] = np.linalg.norm(r)
        if np.mod(i,10)==0:
            print('...%i'%i)

    figure()
    plot(tau,phi)
    title('(d) Pareto frontier')
    xlabel('||x||_1')
    ylabel('||Ax-b||_2')

    print('%s%s%s' % ('-'*35,' Solution ','-'*35))
    print('See figure 1(d)')
    print('%s%s ' % ('-'*78, '\n'))
Пример #2
0
while (dmisAll.eval(mwav) / survey.nD) > 0.5 and it < nits:

    problem.unpair()
    problem.pair(survey_r)

    def JS(x, mode):
        if mode == 1:
            return problem.Jvec(mwav, iwavmap * x)
        else:
            return wavmap * problem.Jtvec(mwav, x)

    b = survey_r.dpred(mwav) - survey_r.dpred(mtrue)

    print "# of data: ", b.shape

    opts = spgl1.spgSetParms({'iterations': 100, 'verbosity': 2})
    sigtol = np.linalg.norm(b) / np.maximum(ratio[it], min_progress)
    #tautol = 20000.

    tic = time.clock()

    x, resid, grad, info = spgl1.spg_bpdn(JS, b, sigma=sigtol, options=opts)

    toc = time.clock()
    print 'SPGL1 chronometer: ', toc - tic
    timespgl1.append(toc - tic)

    #x,resid,grad,info = spgl1.spg_lasso(JS,b,tautol,opts)
    #assert dmis.eval(mwav) > dmis.eval(mwav - iwavmap*x)
    mwav = mwav - iwavmap * x
    xlist.append(x)