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 SDPT3: 48 variables, 24 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 24
 dim. of socp   var  = 32,   num. of socp blk  = 16
 dim. of linear var  = 16
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      mean(obj)   cputime
-------------------------------------------------------------------
 0|0.000|0.000|3.5e+00|4.2e+00|4.0e+02| 1.131371e+01| 0:0:00| chol  1  1 
 1|1.000|1.000|9.4e-07|8.9e-02|4.9e+01|-1.963977e+01| 0:0:00| chol  1  1 
 2|1.000|0.927|8.7e-08|1.5e-02|3.5e+00| 7.092649e-01| 0:0:00| chol  1  1 
 3|0.961|0.927|2.2e-08|1.9e-03|2.1e-01| 2.356638e-02| 0:0:00| chol  1  1 
 4|0.986|0.986|6.8e-09|1.1e-04|2.9e-03| 1.111115e-03| 0:0:00| chol  1  1 
 5|0.989|0.989|6.5e-11|1.0e-05|3.2e-05| 9.138164e-05| 0:0:00| chol  1  1 
 6|0.994|0.996|4.0e-10|4.2e-08|4.0e-07| 3.988559e-07| 0:0:00| chol  1  1 
 7|0.562|1.000|8.1e-10|1.9e-11|1.5e-07| 3.958563e-08| 0:0:00| chol  1  1 
 8|0.568|1.000|6.9e-10|2.9e-11|8.4e-08| 2.063452e-08| 0:0:00| chol  1  1 
 9|0.569|1.000|4.7e-10|4.4e-11|4.5e-08| 1.098730e-08| 0:0:00| chol  1  1 
10|0.568|1.000|2.0e-10|6.6e-11|2.5e-08| 5.876924e-09| 0:0:00| chol  1  1 
11|0.570|1.000|8.7e-11|4.0e-11|1.3e-08| 3.126465e-09| 0:0:00|
  stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 11
 primal objective value =  9.47832403e-09
 dual   objective value = -3.22539364e-09
 gap := trace(XZ)       = 1.34e-08
 relative gap           = 1.34e-08
 actual relative gap    = 1.27e-08
 rel. primal infeas     = 8.68e-11
 rel. dual   infeas     = 4.04e-11
 norm(X), norm(y), norm(Z) = 4.0e+00, 1.3e+00, 4.5e+00
 norm(A), norm(b), norm(C) = 1.3e+01, 5.0e+00, 6.4e+00
 Total CPU time (secs)  = 0.3  
 CPU time per iteration = 0.0  
 termination code       =  0
 DIMACS: 2.2e-10  0.0e+00  1.0e-10  0.0e+00  1.3e-08  1.3e-08
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +3.22539e-09
Done! 

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

Optimal vector:
   x     = [  0.3277  0.1286 -0.3457  0.0835  0.6215  0.3876 -0.6669  0.7427 ]
Residual vector:
   A*x-b = [  0.6014  0.3841 -0.8444 -0.3032  0.3440  0.4154 -0.6405 -0.6744 -0.4713  0.7752  0.1084 -0.1713  0.4948  0.7508  0.3017 -0.3906 ]