题目:使用l1-magic工具箱求解基追踪(BP)和基追踪降噪(BPDN)
基追踪(Basis Pursuit, BP)和基追踪降噪(Basis PursuitDe-Noising, BPDN)都不能称为是具体的算法,实际上分别是求解一个优化问题:
基追踪:
基追踪降噪:
BP和BPDN可以由多种优化求解方法去解。为了求解这两个优化问题,基追踪可以转化为一个线性规划问题(参见《压缩感知重构算法之基追踪(Basis Pursuit, BP)》,http://blog.youkuaiyun.com/jbb0523/article/details/51986554),可以使用MATLAB自带的linprog函数求解;而基追踪降噪可以转化为一个二次规划问题(参见《压缩感知重构算法之基追踪降噪(Basis Pursuit De-Noising, BPDN)》,http://blog.youkuaiyun.com/jbb0523/article/details/52013669),可以使用MATLAB自带的quadprog函数求解。
当然也可以用其它方法求解基追踪和基追踪降噪这两个问题。实际上同一个算法,不同的实现方式,运行效率也会有差异。
由Emmanuel Candès and JustinRomberg等人开发的l1-magic工具箱(主页链接:http://users.ece.gatech.edu/justin/l1magic/)可以求解七类优化问题,其中(P1)问题即为基追踪,(P2)问题等价于基追踪降噪,详情可参见工具箱的说明文档[2]。
(P1)问题:
(P2)问题:
1、(P1)问题
求解(P1)问题的函数是l1eq_pd.m,位于工具箱\l1magic\Optimization目录下。该函数的使用例程参见l1eq_example.m,位于工具箱根目录\l1magic下。在例程l1eq_example中,函数l1eq_pd共有两种调用方式,如下图所示:
默认情况是第一种,第二种为large scale(大规模),需要注意的是,当使用largescale这种调用方式时,需要额外使用工具箱中的cgsolve.m函数,位于工具箱\l1magic\Optimization目录下。若使用第二种方式,只需将第50行到54行解除注释即可(参见附录代码)。
2、(P2)问题
求解(P2)问题的函数是l1qc_logbarrier.m,位于工具箱\l1magic\Optimization目录下。该函数的使用例程参见l1qc_example.m,位于工具箱根目录\l1magic下。需要注意的是,该函数需要调用l1qc_newton.m函数(位于工具箱\l1magic\Optimization目录下),在例程l1qc_example中,函数l1qc_logbarrier.m共有两种调用方式,如下图所示:
默认情况是第一种,第二种为large scale(大规模),需要注意的是,当使用largescale这种调用方式时,也需要额外使用工具箱中的cgsolve.m函数。若使用第二种方式,只需将第49行到53行解除注释即可(参见附录代码)。
先简单了解这么一点即可,若实际需要,再详细琢磨一下。
3、总结
总结一下,对于(P1)问题,相关文件有三个:l1eq_pd.m(求解函数)、cgsolve.m(大规模方式时l1eq_pd需调用此文件)、l1eq_example.m(使用范例);对于(P2)问题,相关文件有四个:l1qc_logbarrier.m(求解函数)、l1qc_newton.m(l1qc_logbarrier需要调用此文件)、cgsolve.m(大规模方式时l1qc_logbarrier需调用此文件)、l1qc_example.m(使用范例)。
值得注意的是,函数l1qc_logbarrier求解基追踪降噪问题的效率和重构效果均要优于本人基于MATLAB自带的quadprog函数编写的BPDN_quadprog(参见《压缩感知重构算法之基追踪降噪(BasisPursuit De-Noising, BPDN)》,http://blog.youkuaiyun.com/jbb0523/article/details/52013669),具体原因没有深究。
4、参考文献
【1】ChenS S, Donoho D L, Saunders M A.Atomicdecomposition by basis pursuit[J]. SIAM review, 2001, 43(1): 129-159.(Available at:http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.37.4272&rep=rep1&type=pdf)
【2】Emmanuel Candès and Justin Romberg.l1-magic : Recovery of Sparse Signals via Convex Programming[EB/OL].http://users.ece.gatech.edu/justin/l1magic/downloads/l1magic.pdf
5、附录
作为一种备份,也作为一篇文档的完整性,这里将(P1)(P2)所涉及的MATLAB文件附在此,如果不愿意自己去下载,可以将这些代码保存为MATLAB文件即可。
(1)第一个是两个问题在large scale方式下都要调用的cgsolve.m
% cgsolve.m
%
% Solve a symmetric positive definite system Ax = b via conjugate gradients.
%
% Usage: [x, res, iter] = cgsolve(A, b, tol, maxiter, verbose)
%
% A - Either an NxN matrix, or a function handle.
%
% b - N vector
%
% tol - Desired precision. Algorithm terminates when
% norm(Ax-b)/norm(b) < tol .
%
% maxiter - Maximum number of iterations.
%
% verbose - If 0, do not print out progress messages.
% If and integer greater than 0, print out progress every 'verbose' iters.
%
% Written by: Justin Romberg, Caltech
% Email: jrom@acm.caltech.edu
% Created: October 2005
%
function [x, res, iter] = cgsolve(A, b, tol, maxiter, verbose)
if (nargin < 5), verbose = 1; end
implicit = isa(A,'function_handle');
x = zeros(length(b),1);
r = b;
d = r;
delta = r'*r;
delta0 = b'*b;
numiter = 0;
bestx = x;
bestres = sqrt(delta/delta0);
while ((numiter < maxiter) && (delta > tol^2*delta0))
% q = A*d
if (implicit), q = A(d); else q = A*d; end
alpha = delta/(d'*q);
x = x + alpha*d;
if (mod(numiter+1,50) == 0)
% r = b - Aux*x
if (implicit), r = b - A(x); else r = b - A*x; end
else
r = r - alpha*q;
end
deltaold = delta;
delta = r'*r;
beta = delta/deltaold;
d = r + beta*d;
numiter = numiter + 1;
if (sqrt(delta/delta0) < bestres)
bestx = x;
bestres = sqrt(delta/delta0);
end
if ((verbose) && (mod(numiter,verbose)==0))
disp(sprintf('cg: Iter = %d, Best residual = %8.3e, Current residual = %8.3e', ...
numiter, bestres, sqrt(delta/delta0)));
end
end
if (verbose)
disp(sprintf('cg: Iterations = %d, best residual = %14.8e', numiter, bestres));
end
x = bestx;
res = bestres;
iter = numiter;
(2)第二个是(P1)问题求解函数l1eq_pd.m
% l1eq_pd.m
%
% Solve
% min_x ||x||_1 s.t. Ax = b
%
% Recast as linear program
% min_{x,u} sum(u) s.t. -u <= x <= u, Ax=b
% and use primal-dual interior point method
%
% Usage: xp = l1eq_pd(x0, A, At, b, pdtol, pdmaxiter, cgtol, cgmaxiter)
%
% x0 - Nx1 vector, initial point.
%
% A - Either a handle to a function that takes a N vector and returns a K
% vector , or a KxN matrix. If A is a function handle, the algorithm
% operates in "largescale" mode, solving the Newton systems via the
% Conjugate Gradients algorithm.
%
% At - Handle to a function that takes a K vector and returns an N vector.
% If A is a KxN matrix, At is ignored.
%
% b - Kx1 vector of observations.
%
% pdtol - Tolerance for primal-dual algorithm (algorithm terminates if
% the duality gap is less than pdtol).
% Default = 1e-3.
%
% pdmaxiter - Maximum number of primal-dual iterations.
% Default = 50.
%
% cgtol - Tolerance for Conjugate Gradients; ignored if A is a matrix.
% Default = 1e-8.
%
% cgmaxiter - Maximum number of iterations for Conjugate Gradients; ignored
% if A is a matrix.
% Default = 200.
%
% Written by: Justin Romberg, Caltech
% Email: jrom@acm.caltech.edu
% Created: October 2005
%
function xp = l1eq_pd(x0, A, At, b, pdtol, pdmaxiter, cgtol, cgmaxiter)
largescale = isa(A,'function_handle');
if (nargin < 5), pdtol = 1e-3; end
if (nargin < 6), pdmaxiter = 50; end
if (nargin < 7), cgtol = 1e-8; end
if (nargin < 8), cgmaxiter = 200; end
N = length(x0);
alpha = 0.01;
beta = 0.5;
mu = 10;
gradf0 = [zeros(N,1); ones(N,1)];
% starting point --- make sure that it is feasible
if (largescale)
if (norm(A(x0)-b)/norm(b) > cgtol)
disp('Starting point infeasible; using x0 = At*inv(AAt)*y.');
AAt = @(z) A(At(z));
[w, cgres, cgiter] = cgsolve(AAt, b, cgtol, cgmaxiter, 0);
if (cgres > 1/2)
disp('A*At is ill-conditioned: cannot find starting point');
xp = x0;
return;
end
x0 = At(w);
end
else
if (norm(A*x0-b)/norm(b) > cgtol)
disp('Starting point infeasible; using x0 = At*inv(AAt)*y.');
opts.POSDEF = true; opts.SYM = true;
[w, hcond] = linsolve(A*A', b, opts);
if (hcond < 1e-14)
disp('A*At is ill-conditioned: cannot find starting point');
xp = x0;
return;
end
x0 = A'*w;
end
end
x = x0;
u = (0.95)*abs(x0) + (0.10)*max(abs(x0));
% set up for the first iteration
fu1 = x - u;
fu2 = -x - u;
lamu1 = -1./fu1;
lamu2 = -1./fu2;
if (largescale)
v = -A(lamu1-lamu2);
Atv = At(v);
rpri = A(x) - b;
else
v = -A*(lamu1-lamu2);
Atv = A'*v;
rpri = A*x - b;
end
sdg = -(fu1'*lamu1 + fu2'*lamu2);
tau = mu*2*N/sdg;
rcent = [-lamu1.*fu1; -lamu2.*fu2] - (1/tau);
rdual = gradf0 + [lamu1-lamu2; -lamu1-lamu2] + [Atv; zeros(N,1)];
resnorm = norm([rdual; rcent; rpri]);
pditer = 0;
done = (sdg < pdtol) | (pditer >= pdmaxiter);
while (~done)
pditer = pditer + 1;
w1 = -1/tau*(-1./fu1 + 1./fu2) - Atv;
w2 = -1 - 1/tau*(1./fu1 + 1./fu2);
w3 = -rpri;
sig1 = -lamu1./fu1 - lamu2./fu2;
sig2 = lamu1./fu1 - lamu2./fu2;
sigx = sig1 - sig2.^2./sig1;
if (largescale)
w1p = w3 - A(w1./sigx - w2.*sig2./(sigx.*sig1));
h11pfun = @(z) -A(1./sigx.*At(z));
[dv, cgres, cgiter] = cgsolve(h11pfun, w1p, cgtol, cgmaxiter, 0);
if (cgres > 1/2)
disp('Cannot solve system. Returning previous iterate. (See Section 4 of notes for more information.)');
xp = x;
return
end
dx = (w1 - w2.*sig2./sig1 - At(dv))./sigx;
Adx = A(dx);
Atdv = At(dv);
else
w1p = -(w3 - A*(w1./sigx - w2.*sig2./(sigx.*sig1)));
H11p = A*(sparse(diag(1./sigx))*A');
opts.POSDEF = true; opts.SYM = true;
[dv,hcond] = linsolve(H11p, w1p, opts);
if (hcond < 1e-14)
disp('Matrix ill-conditioned. Returning previous iterate. (See Section 4 of notes for more information.)');
xp = x;
return
end
dx = (w1 - w2.*sig2./sig1 - A'*dv)./sigx;
Adx = A*dx;
Atdv = A'*dv;
end
du = (w2 - sig2.*dx)./sig1;
dlamu1 = (lamu1./fu1).*(-dx+du) - lamu1 - (1/tau)*1./fu1;
dlamu2 = (lamu2./fu2).*(dx+du) - lamu2 - 1/tau*1./fu2;
% make sure that the step is feasible: keeps lamu1,lamu2 > 0, fu1,fu2 < 0
indp = find(dlamu1 < 0); indn = find(dlamu2 < 0);
s = min([1; -lamu1(indp)./dlamu1(indp); -lamu2(indn)./dlamu2(indn)]);
indp = find((dx-du) > 0); indn = find((-dx-du) > 0);
s = (0.99)*min([s; -fu1(indp)./(dx(indp)-du(indp)); -fu2(indn)./(-dx(indn)-du(indn))]);
% backtracking line search
suffdec = 0;
backiter = 0;
while (~suffdec)
xp = x + s*dx; up = u + s*du;
vp = v + s*dv; Atvp = Atv + s*Atdv;
lamu1p = lamu1 + s*dlamu1; lamu2p = lamu2 + s*dlamu2;
fu1p = xp - up; fu2p = -xp - up;
rdp = gradf0 + [lamu1p-lamu2p; -lamu1p-lamu2p] + [Atvp; zeros(N,1)];
rcp = [-lamu1p.*fu1p; -lamu2p.*fu2p] - (1/tau);
rpp = rpri + s*Adx;
suffdec = (norm([rdp; rcp; rpp]) <= (1-alpha*s)*resnorm);
s = beta*s;
backiter = backiter + 1;
if (backiter > 32)
disp('Stuck backtracking, returning last iterate. (See Section 4 of notes for more information.)')
xp = x;
return
end
end
% next iteration
x = xp; u = up;
v = vp; Atv = Atvp;
lamu1 = lamu1p; lamu2 = lamu2p;
fu1 = fu1p; fu2 = fu2p;
% surrogate duality gap
sdg = -(fu1'*lamu1 + fu2'*lamu2);
tau = mu*2*N/sdg;
rpri = rpp;
rcent = [-lamu1.*fu1; -lamu2.*fu2] - (1/tau);
rdual = gradf0 + [lamu1-lamu2; -lamu1-lamu2] + [Atv; zeros(N,1)];
resnorm = norm([rdual; rcent; rpri]);
done = (sdg < pdtol) | (pditer >= pdmaxiter);
disp(sprintf('Iteration = %d, tau = %8.3e, Primal = %8.3e, PDGap = %8.3e, Dual res = %8.3e, Primal res = %8.3e',...
pditer, tau, sum(u), sdg, norm(rdual), norm(rpri)));
if (largescale)
disp(sprintf(' CG Res = %8.3e, CG Iter = %d', cgres, cgiter));
else
disp(sprintf(' H11p condition number = %8.3e', hcond));
end
end
(3)第三个是 (P1)问题使用范例l1eq_example.m(处于large scale方式下)
% l1eq_example.m
%
% Test out l1eq code (l1 minimization with equality constraints).
%
% Written by: Justin Romberg, Caltech
% Email: jrom@acm.caltech.edu
% Created: October 2005
%
% put key subdirectories in path if not already there
% path(path, './Optimization');
% path(path, './Data');
% To reproduce the example in the documentation, uncomment the
% two lines below
%load RandomStates
%rand('state', rand_state);
%randn('state', randn_state);
% signal length
N = 512;
% number of spikes in the signal
T = 20;
% number of observations to make
K = 120;
% random +/- 1 signal
x = zeros(N,1);
q = randperm(N);
x(q(1:T)) = sign(randn(T,1));
% measurement matrix
disp('Creating measurment matrix...');
A = randn(K,N);
A = orth(A')';
disp('Done.');
% observations
y = A*x;
% initial guess = min energy
x0 = A'*y;
% solve the LP
% tic
% xp = l1eq_pd(x0, A, [], y, 1e-3);
% toc
% large scale
Afun = @(z) A*z;
Atfun = @(z) A'*z;
tic
xp = l1eq_pd(x0, Afun, Atfun, y, 1e-3, 30, 1e-8, 200);
toc
(4)第四个是 (P2)问题求解函数l1qc_logbarrier.m
% l1qc_logbarrier.m
%
% Solve quadratically constrained l1 minimization:
% min ||x||_1 s.t. ||Ax - b||_2 <= \epsilon
%
% Reformulate as the second-order cone program
% min_{x,u} sum(u) s.t. x - u <= 0,
% -x - u <= 0,
% 1/2(||Ax-b||^2 - \epsilon^2) <= 0
% and use a log barrier algorithm.
%
% Usage: xp = l1qc_logbarrier(x0, A, At, b, epsilon, lbtol, mu, cgtol, cgmaxiter)
%
% x0 - Nx1 vector, initial point.
%
% A - Either a handle to a function that takes a N vector and returns a K
% vector , or a KxN matrix. If A is a function handle, the algorithm
% operates in "largescale" mode, solving the Newton systems via the
% Conjugate Gradients algorithm.
%
% At - Handle to a function that takes a K vector and returns an N vector.
% If A is a KxN matrix, At is ignored.
%
% b - Kx1 vector of observations.
%
% epsilon - scalar, constraint relaxation parameter
%
% lbtol - The log barrier algorithm terminates when the duality gap <= lbtol.
% Also, the number of log barrier iterations is completely
% determined by lbtol.
% Default = 1e-3.
%
% mu - Factor by which to increase the barrier constant at each iteration.
% Default = 10.
%
% cgtol - Tolerance for Conjugate Gradients; ignored if A is a matrix.
% Default = 1e-8.
%
% cgmaxiter - Maximum number of iterations for Conjugate Gradients; ignored
% if A is a matrix.
% Default = 200.
%
% Written by: Justin Romberg, Caltech
% Email: jrom@acm.caltech.edu
% Created: October 2005
%
function xp = l1qc_logbarrier(x0, A, At, b, epsilon, lbtol, mu, cgtol, cgmaxiter)
largescale = isa(A,'function_handle');
if (nargin < 6), lbtol = 1e-3; end
if (nargin < 7), mu = 10; end
if (nargin < 8), cgtol = 1e-8; end
if (nargin < 9), cgmaxiter = 200; end
newtontol = lbtol;
newtonmaxiter = 50;
N = length(x0);
% starting point --- make sure that it is feasible
if (largescale)
if (norm(A(x0)-b) > epsilon)
disp('Starting point infeasible; using x0 = At*inv(AAt)*y.');
AAt = @(z) A(At(z));
[w, cgres] = cgsolve(AAt, b, cgtol, cgmaxiter, 0);
if (cgres > 1/2)
disp('A*At is ill-conditioned: cannot find starting point');
xp = x0;
return;
end
x0 = At(w);
end
else
if (norm(A*x0-b) > epsilon)
disp('Starting point infeasible; using x0 = At*inv(AAt)*y.');
opts.POSDEF = true; opts.SYM = true;
[w, hcond] = linsolve(A*A', b, opts);
if (hcond < 1e-14)
disp('A*At is ill-conditioned: cannot find starting point');
xp = x0;
return;
end
x0 = A'*w;
end
end
x = x0;
u = (0.95)*abs(x0) + (0.10)*max(abs(x0));
disp(sprintf('Original l1 norm = %.3f, original functional = %.3f', sum(abs(x0)), sum(u)));
% choose initial value of tau so that the duality gap after the first
% step will be about the origial norm
tau = max((2*N+1)/sum(abs(x0)), 1);
lbiter = ceil((log(2*N+1)-log(lbtol)-log(tau))/log(mu));
disp(sprintf('Number of log barrier iterations = %d\n', lbiter));
totaliter = 0;
for ii = 1:lbiter
[xp, up, ntiter] = l1qc_newton(x, u, A, At, b, epsilon, tau, newtontol, newtonmaxiter, cgtol, cgmaxiter);
totaliter = totaliter + ntiter;
disp(sprintf('\nLog barrier iter = %d, l1 = %.3f, functional = %8.3f, tau = %8.3e, total newton iter = %d\n', ...
ii, sum(abs(xp)), sum(up), tau, totaliter));
x = xp;
u = up;
tau = mu*tau;
end
(5)第五个是 (P2)问题求解函数须调用的l1qc_newton.m
% l1qc_newton.m
%
% Newton algorithm for log-barrier subproblems for l1 minimization
% with quadratic constraints.
%
% Usage:
% [xp,up,niter] = l1qc_newton(x0, u0, A, At, b, epsilon, tau,
% newtontol, newtonmaxiter, cgtol, cgmaxiter)
%
% x0,u0 - starting points
%
% A - Either a handle to a function that takes a N vector and returns a K
% vector , or a KxN matrix. If A is a function handle, the algorithm
% operates in "largescale" mode, solving the Newton systems via the
% Conjugate Gradients algorithm.
%
% At - Handle to a function that takes a K vector and returns an N vector.
% If A is a KxN matrix, At is ignored.
%
% b - Kx1 vector of observations.
%
% epsilon - scalar, constraint relaxation parameter
%
% tau - Log barrier parameter.
%
% newtontol - Terminate when the Newton decrement is <= newtontol.
% Default = 1e-3.
%
% newtonmaxiter - Maximum number of iterations.
% Default = 50.
%
% cgtol - Tolerance for Conjugate Gradients; ignored if A is a matrix.
% Default = 1e-8.
%
% cgmaxiter - Maximum number of iterations for Conjugate Gradients; ignored
% if A is a matrix.
% Default = 200.
%
% Written by: Justin Romberg, Caltech
% Email: jrom@acm.caltech.edu
% Created: October 2005
%
function [xp, up, niter] = l1qc_newton(x0, u0, A, At, b, epsilon, tau, newtontol, newtonmaxiter, cgtol, cgmaxiter)
% check if the matrix A is implicit or explicit
largescale = isa(A,'function_handle');
% line search parameters
alpha = 0.01;
beta = 0.5;
if (~largescale), AtA = A'*A; end
% initial point
x = x0;
u = u0;
if (largescale), r = A(x) - b; else r = A*x - b; end
fu1 = x - u;
fu2 = -x - u;
fe = 1/2*(r'*r - epsilon^2);
f = sum(u) - (1/tau)*(sum(log(-fu1)) + sum(log(-fu2)) + log(-fe));
niter = 0;
done = 0;
while (~done)
if (largescale), atr = At(r); else atr = A'*r; end
ntgz = 1./fu1 - 1./fu2 + 1/fe*atr;
ntgu = -tau - 1./fu1 - 1./fu2;
gradf = -(1/tau)*[ntgz; ntgu];
sig11 = 1./fu1.^2 + 1./fu2.^2;
sig12 = -1./fu1.^2 + 1./fu2.^2;
sigx = sig11 - sig12.^2./sig11;
w1p = ntgz - sig12./sig11.*ntgu;
if (largescale)
h11pfun = @(z) sigx.*z - (1/fe)*At(A(z)) + 1/fe^2*(atr'*z)*atr;
[dx, cgres, cgiter] = cgsolve(h11pfun, w1p, cgtol, cgmaxiter, 0);
if (cgres > 1/2)
disp('Cannot solve system. Returning previous iterate. (See Section 4 of notes for more information.)');
xp = x; up = u;
return
end
Adx = A(dx);
else
H11p = diag(sigx) - (1/fe)*AtA + (1/fe)^2*atr*atr';
opts.POSDEF = true; opts.SYM = true;
[dx,hcond] = linsolve(H11p, w1p, opts);
if (hcond < 1e-14)
disp('Matrix ill-conditioned. Returning previous iterate. (See Section 4 of notes for more information.)');
xp = x; up = u;
return
end
Adx = A*dx;
end
du = (1./sig11).*ntgu - (sig12./sig11).*dx;
% minimum step size that stays in the interior
ifu1 = find((dx-du) > 0); ifu2 = find((-dx-du) > 0);
aqe = Adx'*Adx; bqe = 2*r'*Adx; cqe = r'*r - epsilon^2;
smax = min(1,min([...
-fu1(ifu1)./(dx(ifu1)-du(ifu1)); -fu2(ifu2)./(-dx(ifu2)-du(ifu2)); ...
(-bqe+sqrt(bqe^2-4*aqe*cqe))/(2*aqe)
]));
s = (0.99)*smax;
% backtracking line search
suffdec = 0;
backiter = 0;
while (~suffdec)
xp = x + s*dx; up = u + s*du; rp = r + s*Adx;
fu1p = xp - up; fu2p = -xp - up; fep = 1/2*(rp'*rp - epsilon^2);
fp = sum(up) - (1/tau)*(sum(log(-fu1p)) + sum(log(-fu2p)) + log(-fep));
flin = f + alpha*s*(gradf'*[dx; du]);
suffdec = (fp <= flin);
s = beta*s;
backiter = backiter + 1;
if (backiter > 32)
disp('Stuck on backtracking line search, returning previous iterate. (See Section 4 of notes for more information.)');
xp = x; up = u;
return
end
end
% set up for next iteration
x = xp; u = up; r = rp;
fu1 = fu1p; fu2 = fu2p; fe = fep; f = fp;
lambda2 = -(gradf'*[dx; du]);
stepsize = s*norm([dx; du]);
niter = niter + 1;
done = (lambda2/2 < newtontol) | (niter >= newtonmaxiter);
disp(sprintf('Newton iter = %d, Functional = %8.3f, Newton decrement = %8.3f, Stepsize = %8.3e', ...
niter, f, lambda2/2, stepsize));
if (largescale)
disp(sprintf(' CG Res = %8.3e, CG Iter = %d', cgres, cgiter));
else
disp(sprintf(' H11p condition number = %8.3e', hcond));
end
end
(6)第六个是(P2)问题使用范例l1qc_example.m(处于large scale方式下)
% l1qc_example.m
%
% Test out l1qc code (l1 minimization with quadratic constraint).
%
% Written by: Justin Romberg, Caltech
% Email: jrom@acm.caltech.edu
% Created: October 2005
%
% put optimization code in path if not already there
path(path, './Optimization');
% signal length
N = 512;
% number of spikes to put down
T = 20;
% number of observations to make
K = 120;
% random +/- 1 signal
x = zeros(N,1);
q = randperm(N);
x(q(1:T)) = sign(randn(T,1));
% measurement matrix
disp('Creating measurment matrix...');
A = randn(K,N);
A = orth(A')';
disp('Done.');
% noisy observations
sigma = 0.005;
e = sigma*randn(K,1);
y = A*x + e;
% initial guess = min energy
x0 = A'*y;
% take epsilon a little bigger than sigma*sqrt(K)
epsilon = sigma*sqrt(K)*sqrt(1 + 2*sqrt(2)/sqrt(K));
% tic
% xp = l1qc_logbarrier(x0, A, [], y, epsilon, 1e-3);
% toc
% large scale
Afun = @(z) A*z;
Atfun = @(z) A'*z;
tic
xp = l1qc_logbarrier(x0, Afun, Atfun, y, epsilon, 1e-3, 50, 1e-8, 500);
toc