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: 48 variables, 24 equality constraints
   For improved efficiency, sedumi is solving the dual problem.
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 24, order n = 49, dim = 49, blocks = 17
nnz(A) = 160 + 0, nnz(ADA) = 336, nnz(L) = 180
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            1.29E+01 0.000
  1 :   3.10E+00 4.39E+00 0.000 0.3402 0.9000 0.9000   3.82  1  1  1.1E+00
  2 :   8.64E-01 1.12E+00 0.000 0.2558 0.9000 0.9000   1.24  1  1  4.1E-01
  3 :   1.38E-02 2.26E-02 0.000 0.0202 0.9900 0.9900   1.06  1  1  2.5E-01
  4 :   1.01E-07 1.54E-07 0.000 0.0000 1.0000 1.0000   1.00  1  1  6.4E-05
  5 :   1.62E-14 3.11E-14 0.000 0.0000 1.0000 1.0000   1.00  1  1  1.2E-11

iter seconds digits       c*x               b*y
  5      0.0   8.9  5.3462956066e-14  1.6188637402e-14
|Ax-b| =   5.3e-15, [Ay-c]_+ =   1.6E-15, |x|=  4.0e+00, |y|=  1.3e+00

Detailed timing (sec)
   Pre          IPM          Post
1.000E-02    3.000E-02    0.000E+00    
Max-norms: ||b||=1, ||c|| = 1.488490e+00,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -1.61886e-14
Done! 

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

Optimal vector:
   x     = [  0.3169  0.1304 -0.3499  0.0768  0.6316  0.3917 -0.6683  0.7309 ]
Residual vector:
   A*x-b = [  0.6074  0.4106 -0.8179 -0.3119  0.3648  0.4208 -0.6525 -0.6823 -0.4734  0.7688  0.1175 -0.1827  0.5050  0.7438  0.3279 -0.3912 ]