Contents
function [x, history] = total_variation(b, lambda, rho, alpha)
t_start = tic;
Global constants and defaults
QUIET = 0;
MAX_ITER = 1000;
ABSTOL = 1e-4;
RELTOL = 1e-2;
Data preprocessing
n = length(b);
e = ones(n,1);
D = spdiags([e -e], 0:1, n,n);
ADMM solver
x = zeros(n,1);
z = zeros(n,1);
u = zeros(n,1);
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
I = speye(n);
DtD = D'*D;
for k = 1:MAX_ITER
x = (I + rho*DtD) \ (b + rho*D'*(z-u));
zold = z;
Ax_hat = alpha*D*x +(1-alpha)*zold;
z = shrinkage(Ax_hat + u, lambda/rho);
u = u + Ax_hat - z;
history.objval(k) = objective(b, lambda, D, x, z);
history.r_norm(k) = norm(D*x - z);
history.s_norm(k) = norm(-rho*D'*(z - zold));
history.eps_pri(k) = sqrt(n)*ABSTOL + RELTOL*max(norm(D*x), norm(-z));
history.eps_dual(k)= sqrt(n)*ABSTOL + RELTOL*norm(rho*D'*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 obj = objective(b, lambda, D, x, z)
obj = .5*norm(x - b)^2 + lambda*norm(z,1);
end
function y = shrinkage(a, kappa)
y = max(0, a-kappa) - max(0, -a-kappa);
end