Contents
function [z, history] = lasso(A, b, lambda, rho, alpha)
t_start = tic;
Global constants and defaults
QUIET = 0;
MAX_ITER = 1000;
ABSTOL = 1e-4;
RELTOL = 1e-2;
Data preprocessing
[m, n] = size(A);
Atb = A'*b;
ADMM solver
x = zeros(n,1);
z = zeros(n,1);
u = zeros(n,1);
[L U] = factor(A, rho);
if ~QUIET
fprintf('%3s\t%10s\t%10s\t%10s\t%10s\t%10s\n', 'iter', ...
'r norm', 'eps pri', 's norm', 'eps dual', 'objective');
end
for k = 1:MAX_ITER
q = Atb + rho*(z - u);
if( m >= n )
x = U \ (L \ q);
else
x = q/rho - (A'*(U \ ( L \ (A*q) )))/rho^2;
end
zold = z;
x_hat = alpha*x + (1 - alpha)*zold;
z = shrinkage(x_hat + u, lambda/rho);
u = u + (x_hat - z);
history.objval(k) = objective(A, b, lambda, x, z);
history.r_norm(k) = norm(x - z);
history.s_norm(k) = norm(-rho*(z - zold));
history.eps_pri(k) = sqrt(n)*ABSTOL + RELTOL*max(norm(x), norm(-z));
history.eps_dual(k)= sqrt(n)*ABSTOL + RELTOL*norm(rho*u);
if ~QUIET
fprintf('%3d\t%10.4f\t%10.4f\t%10.4f\t%10.4f\t%10.2f\n', k, ...
history.r_norm(k), history.eps_pri(k), ...
history.s_norm(k), history.eps_dual(k), history.objval(k));
end
if (history.r_norm(k) < history.eps_pri(k) && ...
history.s_norm(k) < history.eps_dual(k))
break;
end
end
if ~QUIET
toc(t_start);
end
end
function p = objective(A, b, lambda, x, z)
p = ( 1/2*sum((A*x - b).^2) + lambda*norm(z,1) );
end
function z = shrinkage(x, kappa)
z = max( 0, x - kappa ) - max( 0, -x - kappa );
end
function [L U] = factor(A, rho)
[m, n] = size(A);
if ( m >= n )
L = chol( A'*A + rho*speye(n), 'lower' );
else
L = chol( speye(m) + 1/rho*(A*A'), 'lower' );
end
L = sparse(L);
U = sparse(L');
end