Section 6.1.2: Residual minimization with deadzone penalty

% Boyd & Vandenberghe "Convex Optimization"
% Joelle Skaf - 08/17/05
%
% The penalty function approximation problem has the form:
%               minimize    sum(deadzone(Ax - b))
% where 'deadzone' is the deadzone penalty function
%               deadzone(y) = max(abs(y)-1,0)

% Input data
randn('state',0);
m = 16; n = 8;
A = randn(m,n);
b = randn(m,1);

% deadzone penalty
% original formulation
fprintf(1,'Computing the optimal solution of the deadzone approximation problem: \n');

cvx_begin
    variable x(n)
    minimize( sum(max(abs(A*x-b)-1,0)) )
cvx_end

fprintf(1,'Done! \n');

% Compare
disp( sprintf( '\nResults:\n--------\nsum(max(abs(A*x-b)-1,0)): %6.4f\ncvx_optval: %6.4f\ncvx_status: %s\n', sum(max(abs(A*x-b)-1,0)), cvx_optval, cvx_status ) );
disp( 'Optimal vector:' );
disp( [ '   x     = [ ', sprintf( '%7.4f ', x ), ']' ] );
disp( 'Residual vector:' );
disp( [ '   A*x-b = [ ', sprintf( '%7.4f ', A*x-b ), ']' ] );
disp( ' ' );
Computing the optimal solution of the deadzone approximation problem: 
 
Calling SeDuMi: 56 variables (8 free), 32 equality constraints
------------------------------------------------------------------------
SeDuMi 1.1 by AdvOL, 2005 and Jos F. Sturm, 1998, 2001-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
Split 8 free variables
eqs m = 32, order n = 65, dim = 65, blocks = 1
nnz(A) = 336 + 0, nnz(ADA) = 304, nnz(L) = 168
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.38E+001 0.000
  1 :  1.22E+001 9.04E+000 0.000 0.3794 0.9000 0.9000   4.55  1  1  6.5E-001
  2 :  1.52E+001 1.98E+000 0.000 0.2186 0.9000 0.9000   1.37  1  1  1.3E-001
  3 :  1.60E+001 1.66E-002 0.000 0.0084 0.9990 0.9990   1.10  1  1  1.1E-003
  4 :  1.60E+001 4.85E-008 0.000 0.0000 1.0000 1.0000   1.00  1  1  
iter seconds digits       c*x               b*y
  4      0.1  15.3  1.6000000000e+001  1.6000000000e+001
|Ax-b| =  2.5e-015, [Ay-c]_+ =  1.4E-016, |x|= 4.8e+000, |y|= 4.0e+000

Detailed timing (sec)
   Pre          IPM          Post
0.000E+000    6.009E-002    0.000E+000    
Max-norms: ||b||=1.488490e+000, ||c|| = 1,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.30797.
------------------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0
Done! 

Results:
--------
sum(max(abs(A*x-b)-1,0)): 0.0000
cvx_optval: 0.0000
cvx_status: Solved

Optimal vector:
   x     = [  0.2921  0.1200 -0.3514  0.0522  0.6037  0.3546 -0.6392  0.6843 ]
Residual vector:
   A*x-b = [  0.5785  0.4111 -0.8196 -0.3117  0.3849  0.3361 -0.6416 -0.7070 -0.5074  0.7695  0.1929 -0.1898  0.5407  0.7482  0.2783 -0.3828 ]