annotate 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
rev   line source
nikcleju@13 1 # -*- coding: utf-8 -*-
nikcleju@13 2 """
nikcleju@13 3 Created on Fri Mar 09 14:06:13 2012
nikcleju@13 4
nikcleju@13 5 @author: ncleju
nikcleju@13 6 """
nikcleju@13 7
nikcleju@13 8 import numpy
nikcleju@13 9 import pyCSalgos.BP.l1eq_pd
nikcleju@14 10 import pyCSalgos.BP.cvxopt_lp
nikcleju@13 11 import pyCSalgos.OMP.omp_QR
nikcleju@13 12 import pyCSalgos.SL0.SL0
nikcleju@13 13 import pyCSalgos.TST.RecommendedTST
nikcleju@13 14
nikcleju@14 15 def bp(y,M,Omega,x0, pdtol=1e-3, pdmaxiter=50, cgtol=1e-8, cgmaxiter=200, verbose=False):
nikcleju@13 16
nikcleju@13 17 N,n = Omega.shape
nikcleju@13 18 D = numpy.linalg.pinv(Omega)
nikcleju@13 19 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 20 Aextra = Vt[-(N-n):,:]
nikcleju@13 21
nikcleju@13 22 # Create aggregate problem
nikcleju@13 23 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 24 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 25
nikcleju@14 26 return numpy.dot(D , pyCSalgos.BP.l1eq_pd.l1eq_pd(x0,Atilde,Atilde.T,ytilde, pdtol, pdmaxiter, cgtol, cgmaxiter, verbose))
nikcleju@14 27
nikcleju@14 28 def bp_cvxopt(y,M,Omega):
nikcleju@14 29
nikcleju@14 30 N,n = Omega.shape
nikcleju@14 31 D = numpy.linalg.pinv(Omega)
nikcleju@14 32 U,S,Vt = numpy.linalg.svd(D)
nikcleju@14 33 Aextra = Vt[-(N-n):,:]
nikcleju@14 34
nikcleju@14 35 # Create aggregate problem
nikcleju@14 36 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@14 37 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@14 38
nikcleju@14 39 return numpy.dot(D , pyCSalgos.BP.cvxopt_lp.cvxopt_lp(ytilde, Atilde))
nikcleju@14 40
nikcleju@13 41
nikcleju@13 42 def ompeps(y,M,Omega,epsilon):
nikcleju@13 43
nikcleju@13 44 N,n = Omega.shape
nikcleju@13 45 D = numpy.linalg.pinv(Omega)
nikcleju@13 46 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 47 Aextra = Vt[-(N-n):,:]
nikcleju@13 48
nikcleju@13 49 # Create aggregate problem
nikcleju@13 50 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 51 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 52
nikcleju@13 53 opts = dict()
nikcleju@13 54 opts['stopCrit'] = 'mse'
nikcleju@13 55 opts['stopTol'] = epsilon
nikcleju@14 56 return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(ytilde,Atilde,Atilde.shape[1],opts)[0])
nikcleju@13 57
nikcleju@13 58 def ompk(y,M,Omega,k):
nikcleju@13 59
nikcleju@13 60 N,n = Omega.shape
nikcleju@13 61 D = numpy.linalg.pinv(Omega)
nikcleju@13 62 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 63 Aextra = Vt[-(N-n):,:]
nikcleju@13 64
nikcleju@13 65 # Create aggregate problem
nikcleju@13 66 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 67 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 68
nikcleju@13 69 opts = dict()
nikcleju@13 70 opts['stopTol'] = k
nikcleju@14 71 return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(ytilde,Atilde,Atilde.shape[1],opts)[0])
nikcleju@13 72
nikcleju@13 73 def sl0(y,M,Omega, sigma_min, sigma_decrease_factor=0.5, mu_0=2, L=3, true_s=None):
nikcleju@13 74
nikcleju@13 75 N,n = Omega.shape
nikcleju@13 76 D = numpy.linalg.pinv(Omega)
nikcleju@13 77 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 78 Aextra = Vt[-(N-n):,:]
nikcleju@13 79
nikcleju@13 80 # Create aggregate problem
nikcleju@13 81 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 82 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 83
nikcleju@13 84 return numpy.dot(D, pyCSalgos.SL0.SL0.SL0(Atilde,ytilde,sigma_min,sigma_decrease_factor,mu_0,L,true_s))
nikcleju@13 85
nikcleju@13 86 def tst_recom(y,M,Omega, nsweep=300, tol=0.00001, xinitial=None, ro=None):
nikcleju@13 87
nikcleju@13 88 N,n = Omega.shape
nikcleju@13 89 D = numpy.linalg.pinv(Omega)
nikcleju@13 90 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 91 Aextra = Vt[-(N-n):,:]
nikcleju@13 92
nikcleju@13 93 # Create aggregate problem
nikcleju@13 94 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 95 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 96
nikcleju@14 97 return numpy.dot(D, pyCSalgos.TST.RecommendedTST.RecommendedTST(Atilde, ytilde, nsweep, tol, xinitial, ro))
nikcleju@13 98