源代码出自boyd

https://web.stanford.edu/~boyd/papers/admm/basis_pursuit/basis_pursuit.html

给出详细备注

function [z, history] = basis_pursuit(A, b, rho, alpha)
     % 解决如下 ADMM问题:
     %   minimize     ||x||_1
     %   subject to   Ax = b
     %其中返回的 history变量包含 目标值、原始残差和对偶残差,以及每次迭代时原始残差和对偶残差的容差(the objective %value, the primal and  dual residual norms, and the tolerances for the primal and dual residual  norms at each iteration.)
     % rho is the augmented Lagrangian parameter.   
     % alpha is the over-relaxation parameter (typical values for alpha are between 1.0 and 1.8).


     t_start = tic;
     % Global constants and defaults
     QUIET    = 0;
     MAX_ITER = 1000;
     ABSTOL   = 1e-4;
     RELTOL   = 1e-2;     
     %% Data preprocessing
     [m n] = size(A);
     %% ADMM solver

基本上是按paper中写的顺序来的

ADMM笔记_basis Pursuit 代码重点详解
     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       %不断输出状态量
     % precompute static variables for x-update (projection on to Ax=b)
     AAt = A*A';
     P = eye(n) - A' * (AAt \ A);
     q = A' * (AAt \ b);
     
     for k = 1:MAX_ITER   %迭代
         % x-update
         x = P*(z - u) + q;
     
         % z-update with relaxation
         zold = z;
         x_hat = alpha*x + (1 - alpha)*zold; 

%x这儿做了一个over-relaxation

ADMM笔记_basis Pursuit 代码重点详解
         z = shrinkage(x_hat + u, 1/rho);

%shrinkage是一个soft thresholding  operator,如下所示:

ADMM笔记_basis Pursuit 代码重点详解
     
         u = u + (x_hat - z);
     
         % diagnostics, reporting, termination checks
         history.objval(k)  =norm(x,1);    %目标函数
     
         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);

%这边是如下的一种终止条件,
     ADMM笔记_basis Pursuit 代码重点详解
         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 y = shrinkage(a, kappa)
         y = max(0, a-kappa) - max(0, -a-kappa);
     end

相关文章:

  • 2022-12-23
  • 2021-08-10
  • 2021-08-16
  • 2022-01-15
  • 2022-12-23
  • 2021-10-28
  • 2021-08-12
  • 2022-12-23
猜你喜欢
  • 2021-09-10
  • 2021-08-20
  • 2021-10-23
相关资源
相似解决方案