Mercurial > hg > absrec
diff ABSexact.py @ 14:f2eb027ed101
test_exact.py working. Added bp_cvxopt(). Commented the code that made the operator Omega more coherent.
author | Nic Cleju <nikcleju@gmail.com> |
---|---|
date | Fri, 16 Mar 2012 13:42:31 +0200 |
parents | a2d881253324 |
children | 7fdf964f4edd |
line wrap: on
line diff
--- a/ABSexact.py Mon Mar 12 17:04:00 2012 +0200 +++ b/ABSexact.py Fri Mar 16 13:42:31 2012 +0200 @@ -7,11 +7,12 @@ import numpy import pyCSalgos.BP.l1eq_pd +import pyCSalgos.BP.cvxopt_lp import pyCSalgos.OMP.omp_QR import pyCSalgos.SL0.SL0 import pyCSalgos.TST.RecommendedTST -def bp(y,M,Omega,x0, lbtol=1e-3, mu=10, cgtol=1e-8, cgmaxiter=200, verbose=False): +def bp(y,M,Omega,x0, pdtol=1e-3, pdmaxiter=50, cgtol=1e-8, cgmaxiter=200, verbose=False): N,n = Omega.shape D = numpy.linalg.pinv(Omega) @@ -22,7 +23,21 @@ Atilde = numpy.vstack((numpy.dot(M,D), Aextra)) ytilde = numpy.concatenate((y,numpy.zeros(N-n))) - return numpy.dot(D , pyCSalgos.BP.l1eq_pd.l1eq_pd(x0,Atilde,Atilde.T,ytilde, lbtol, mu, cgtol, cgmaxiter, verbose)) + return numpy.dot(D , pyCSalgos.BP.l1eq_pd.l1eq_pd(x0,Atilde,Atilde.T,ytilde, pdtol, pdmaxiter, cgtol, cgmaxiter, verbose)) + +def bp_cvxopt(y,M,Omega): + + N,n = Omega.shape + D = numpy.linalg.pinv(Omega) + U,S,Vt = numpy.linalg.svd(D) + Aextra = Vt[-(N-n):,:] + + # Create aggregate problem + Atilde = numpy.vstack((numpy.dot(M,D), Aextra)) + ytilde = numpy.concatenate((y,numpy.zeros(N-n))) + + return numpy.dot(D , pyCSalgos.BP.cvxopt_lp.cvxopt_lp(ytilde, Atilde)) + def ompeps(y,M,Omega,epsilon): @@ -38,7 +53,7 @@ opts = dict() opts['stopCrit'] = 'mse' opts['stopTol'] = epsilon - return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(aggy,aggD,aggD.shape[1],opts)[0]) + return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(ytilde,Atilde,Atilde.shape[1],opts)[0]) def ompk(y,M,Omega,k): @@ -53,7 +68,7 @@ opts = dict() opts['stopTol'] = k - return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(aggy,aggD,aggD.shape[1],opts)[0]) + return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(ytilde,Atilde,Atilde.shape[1],opts)[0]) def sl0(y,M,Omega, sigma_min, sigma_decrease_factor=0.5, mu_0=2, L=3, true_s=None): @@ -79,5 +94,5 @@ Atilde = numpy.vstack((numpy.dot(M,D), Aextra)) ytilde = numpy.concatenate((y,numpy.zeros(N-n))) - return numpy.dot(D, pyCSalgos.RecomTST.RecommendedTST.RecommendedTST(Atilde, ytilde, nsweep, tol, xinitial, ro)) + return numpy.dot(D, pyCSalgos.TST.RecommendedTST.RecommendedTST(Atilde, ytilde, nsweep, tol, xinitial, ro)) \ No newline at end of file