annotate ABSexact.py @ 13:a2d881253324

In working, not debugged yet
author Nic Cleju <nikcleju@gmail.com>
date Mon, 12 Mar 2012 17:04:00 +0200
parents b48f725ceafa
children f2eb027ed101
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@13 10 import pyCSalgos.OMP.omp_QR
nikcleju@13 11 import pyCSalgos.SL0.SL0
nikcleju@13 12 import pyCSalgos.TST.RecommendedTST
nikcleju@13 13
nikcleju@13 14 def bp(y,M,Omega,x0, lbtol=1e-3, mu=10, cgtol=1e-8, cgmaxiter=200, verbose=False):
nikcleju@13 15
nikcleju@13 16 N,n = Omega.shape
nikcleju@13 17 D = numpy.linalg.pinv(Omega)
nikcleju@13 18 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 19 Aextra = Vt[-(N-n):,:]
nikcleju@13 20
nikcleju@13 21 # Create aggregate problem
nikcleju@13 22 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 23 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 24
nikcleju@13 25 return numpy.dot(D , pyCSalgos.BP.l1eq_pd.l1eq_pd(x0,Atilde,Atilde.T,ytilde, lbtol, mu, cgtol, cgmaxiter, verbose))
nikcleju@13 26
nikcleju@13 27 def ompeps(y,M,Omega,epsilon):
nikcleju@13 28
nikcleju@13 29 N,n = Omega.shape
nikcleju@13 30 D = numpy.linalg.pinv(Omega)
nikcleju@13 31 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 32 Aextra = Vt[-(N-n):,:]
nikcleju@13 33
nikcleju@13 34 # Create aggregate problem
nikcleju@13 35 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 36 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 37
nikcleju@13 38 opts = dict()
nikcleju@13 39 opts['stopCrit'] = 'mse'
nikcleju@13 40 opts['stopTol'] = epsilon
nikcleju@13 41 return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(aggy,aggD,aggD.shape[1],opts)[0])
nikcleju@13 42
nikcleju@13 43 def ompk(y,M,Omega,k):
nikcleju@13 44
nikcleju@13 45 N,n = Omega.shape
nikcleju@13 46 D = numpy.linalg.pinv(Omega)
nikcleju@13 47 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 48 Aextra = Vt[-(N-n):,:]
nikcleju@13 49
nikcleju@13 50 # Create aggregate problem
nikcleju@13 51 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 52 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 53
nikcleju@13 54 opts = dict()
nikcleju@13 55 opts['stopTol'] = k
nikcleju@13 56 return numpy.dot(D , pyCSalgos.OMP.omp_QR.greed_omp_qr(aggy,aggD,aggD.shape[1],opts)[0])
nikcleju@13 57
nikcleju@13 58 def sl0(y,M,Omega, sigma_min, sigma_decrease_factor=0.5, mu_0=2, L=3, true_s=None):
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 return numpy.dot(D, pyCSalgos.SL0.SL0.SL0(Atilde,ytilde,sigma_min,sigma_decrease_factor,mu_0,L,true_s))
nikcleju@13 70
nikcleju@13 71 def tst_recom(y,M,Omega, nsweep=300, tol=0.00001, xinitial=None, ro=None):
nikcleju@13 72
nikcleju@13 73 N,n = Omega.shape
nikcleju@13 74 D = numpy.linalg.pinv(Omega)
nikcleju@13 75 U,S,Vt = numpy.linalg.svd(D)
nikcleju@13 76 Aextra = Vt[-(N-n):,:]
nikcleju@13 77
nikcleju@13 78 # Create aggregate problem
nikcleju@13 79 Atilde = numpy.vstack((numpy.dot(M,D), Aextra))
nikcleju@13 80 ytilde = numpy.concatenate((y,numpy.zeros(N-n)))
nikcleju@13 81
nikcleju@13 82 return numpy.dot(D, pyCSalgos.RecomTST.RecommendedTST.RecommendedTST(Atilde, ytilde, nsweep, tol, xinitial, ro))
nikcleju@13 83