声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4332|回复: 6

[应用数学] L-Curve算法拐点判据与最大曲率点搜索问题

[复制链接]
发表于 2013-11-13 23:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本帖最后由 mxlzhenzhu 于 2013-11-13 23:20 编辑

最小二乘中有一种L-Curve算法,此为背景。

现在得到一个离散点变化趋势,如下图1所示。
L.jpg
图1 离散点变化趋势

数据特征是,
1),在该图左下角有一个曲率最大的点P,目前看起来有两个点(A&B)距离这个真实的曲率最大点也许很近了,但还不知道有多远,假如这个距离是distance。
2),可以计算这条曲线的曲率,因为有曲率表达式;但是不可以对表达式求导。在【0,1】区间,曲率变化理论趋势为图2,图3是图1中所有点的曲率,包括A&B,这是因为这个distance还是太大了,漏掉了尖峰,就算有了尖峰还不一定就是曲率k取最大值的点:

k_changes with nameda.jpg
图2 L曲线的曲率理论变化趋势,那个尖峰所在区间可能很小
Resolution too large will fail to locate the nameda.jpg
图3 如果分辨率不够就漏掉尖峰了


3),假如二分法去搜索这个点,会让计算量不可接受。


求算法。
回复
分享到:

使用道具 举报

 楼主| 发表于 2013-11-13 23:23 | 显示全部楼层
本帖最后由 mxlzhenzhu 于 2013-11-13 23:45 编辑

他这个函数不全:http://cda.psych.uiuc.edu/html/4regutools/l_corner.html

还是知识产权问题啊。

看完了,算法有点复杂,自己慢慢搞吧。
 楼主| 发表于 2013-11-13 23:52 | 显示全部楼层
发表于 2013-11-17 08:26 | 显示全部楼层
过来学习了参考了
发表于 2013-11-28 16:00 | 显示全部楼层
 楼主| 发表于 2013-12-1 19:07 | 显示全部楼层
发表于 2014-3-17 15:11 | 显示全部楼层
  1. function [reg_corner,rho,eta,reg_param] = l_curve(U,sm,b,method,L,V)
  2. %L_CURVE Plot the L-curve and find its "corner".
  3. %
  4. % [reg_corner,rho,eta,reg_param] =
  5. %                  l_curve(U,s,b,method)
  6. %                  l_curve(U,sm,b,method)  ,  sm = [sigma,mu]
  7. %                  l_curve(U,s,b,method,L,V)
  8. %
  9. % Plots the L-shaped curve of eta, the solution norm || x || or
  10. % semi-norm || L x ||, as a function of rho, the residual norm
  11. % || A x - b ||, for the following methods:
  12. %    method = 'Tikh'  : Tikhonov regularization   (solid line )
  13. %    method = 'tsvd'  : truncated SVD or GSVD     (o markers  )
  14. %    method = 'dsvd'  : damped SVD or GSVD        (dotted line)
  15. %    method = 'mtsvd' : modified TSVD             (x markers  )
  16. % The corresponding reg. parameters are returned in reg_param.  If no
  17. % method is specified then 'Tikh' is default.  For other methods use plot_lc.
  18. %
  19. % Note that 'Tikh', 'tsvd' and 'dsvd' require either U and s (standard-
  20. % form regularization) or U and sm (general-form regularization), while
  21. % 'mtvsd' requires U and s as well as L and V.
  22. %
  23. % If any output arguments are specified, then the corner of the L-curve
  24. % is identified and the corresponding reg. parameter reg_corner is
  25. % returned.  Use routine l_corner if an upper bound on eta is required.

  26. % Reference: P. C. Hansen & D. P. O'Leary, "The use of the L-curve in
  27. % the regularization of discrete ill-posed problems",  SIAM J. Sci.
  28. % Comput. 14 (1993), pp. 1487-1503.

  29. % Per Christian Hansen, IMM, July 26, 2007.

  30. % Set defaults.
  31. if (nargin==3), method='Tikh'; end  % Tikhonov reg. is default.
  32. npoints = 200;  % Number of points on the L-curve for Tikh and dsvd.
  33. smin_ratio = 16*eps;  % Smallest regularization parameter.

  34. % Initialization.
  35. [m,n] = size(U); [p,ps] = size(sm);
  36. if (nargout > 0), locate = 1; else locate = 0; end
  37. beta = U'*b; beta2 = norm(b)^2 - norm(beta)^2;
  38. if (ps==1)
  39.   s = sm; beta = beta(1:p);
  40. else
  41.   s = sm(p:-1:1,1)./sm(p:-1:1,2); beta = beta(p:-1:1);
  42. end
  43. xi = beta(1:p)./s;

  44. if (strncmp(method,'Tikh',4) | strncmp(method,'tikh',4))

  45.   eta = zeros(npoints,1); rho = eta; reg_param = eta; s2 = s.^2;
  46.   reg_param(npoints) = max([s(p),s(1)*smin_ratio]);
  47.   ratio = (s(1)/reg_param(npoints))^(1/(npoints-1));
  48.   for i=npoints-1:-1:1, reg_param(i) = ratio*reg_param(i+1); end
  49.   for i=1:npoints
  50.     f = s2./(s2 + reg_param(i)^2);
  51.     eta(i) = norm(f.*xi);
  52.     rho(i) = norm((1-f).*beta(1:p));
  53.   end
  54.   if (m > n & beta2 > 0), rho = sqrt(rho.^2 + beta2); end
  55.   marker = '-'; txt = 'Tikh.';

  56. elseif (strncmp(method,'tsvd',4) | strncmp(method,'tgsv',4))

  57.   eta = zeros(p,1); rho = eta;
  58.   eta(1) = abs(xi(1))^2;
  59.   for k=2:p, eta(k) = eta(k-1) + abs(xi(k))^2; end
  60.   eta = sqrt(eta);
  61.   if (m > n)
  62.     if (beta2 > 0), rho(p) = beta2; else rho(p) = eps^2; end
  63.   else
  64.     rho(p) = eps^2;
  65.   end
  66.   for k=p-1:-1:1, rho(k) = rho(k+1) + abs(beta(k+1))^2; end
  67.   rho = sqrt(rho);
  68.   reg_param = (1:p)'; marker = 'o';
  69.   if (ps==1)
  70.     U = U(:,1:p); txt = 'TSVD';
  71.   else
  72.     U = U(:,1:p); txt = 'TGSVD';
  73.   end

  74. elseif (strncmp(method,'dsvd',4) | strncmp(method,'dgsv',4))

  75.   eta = zeros(npoints,1); rho = eta; reg_param = eta;
  76.   reg_param(npoints) = max([s(p),s(1)*smin_ratio]);
  77.   ratio = (s(1)/reg_param(npoints))^(1/(npoints-1));
  78.   for i=npoints-1:-1:1, reg_param(i) = ratio*reg_param(i+1); end
  79.   for i=1:npoints
  80.     f = s./(s + reg_param(i));
  81.     eta(i) = norm(f.*xi);
  82.     rho(i) = norm((1-f).*beta(1:p));
  83.   end
  84.   if (m > n & beta2 > 0), rho = sqrt(rho.^2 + beta2); end
  85.   marker = ':';
  86.   if (ps==1), txt = 'DSVD'; else txt = 'DGSVD'; end

  87. elseif (strncmp(method,'mtsv',4))

  88.   if (nargin~=6)
  89.     error('The matrices L and V must also be specified')
  90.   end
  91.   [p,n] = size(L); rho = zeros(p,1); eta = rho;
  92.   [Q,R] = qr(L*V(:,n:-1:n-p),0);
  93.   for i=1:p
  94.     k = n-p+i;
  95.     Lxk = L*V(:,1:k)*xi(1:k);
  96.     zk = R(1:n-k,1:n-k)\(Q(:,1:n-k)'*Lxk); zk = zk(n-k:-1:1);
  97.     eta(i) = norm(Q(:,n-k+1:p)'*Lxk);
  98.     if (i < p)
  99.       rho(i) = norm(beta(k+1:n) + s(k+1:n).*zk);
  100.     else
  101.       rho(i) = eps;
  102.     end
  103.   end
  104.   if (m > n & beta2 > 0), rho = sqrt(rho.^2 + beta2); end
  105.   reg_param = (n-p+1:n)'; txt = 'MTSVD';
  106.   U = U(:,reg_param); sm = sm(reg_param);
  107.   marker = 'x'; ps = 2;  % General form regularization.

  108. else
  109.   error('Illegal method')
  110. end

  111. % Locate the "corner" of the L-curve, if required.
  112. if (locate)
  113.   [reg_corner,rho_c,eta_c] = l_corner(rho,eta,reg_param,U,sm,b,method);
  114. end

  115. % Make plot.
  116. plot_lc(rho,eta,marker,ps,reg_param);
  117. if locate
  118.   ax = axis;
  119.   HoldState = ishold; hold on;
  120.   loglog([min(rho)/100,rho_c],[eta_c,eta_c],':r',...
  121.          [rho_c,rho_c],[min(eta)/100,eta_c],':r')
  122.   title(['L-curve, ',txt,' corner at ',num2str(reg_corner)]);
  123.   axis(ax)
  124.   if (~HoldState), hold off; end
  125. end
复制代码

  1. function [x_k,rho,eta] = mtsvd(U,s,V,b,k,L)
  2. %MTSVD Modified truncated SVD regularization.
  3. %
  4. % [x_k,rho,eta] = mtsvd(U,s,V,b,k,L)
  5. %
  6. % Computes the modified TSVD solution:
  7. %    x_k = V*[ xi_k ] .
  8. %            [ xi_0 ]
  9. % Here, xi_k defines the usual TSVD solution
  10. %    xi_k = inv(diag(s(1:k)))*U(:,1:k)'*b ,
  11. % and xi_0 is chosen so as to minimize the seminorm || L x_k ||.
  12. % This leads to choosing xi_0 as follows:
  13. %    xi_0 = -pinv(L*V(:,k+1:n))*L*V(:,1:k)*xi_k .
  14. %
  15. % The truncation parameter must satisfy k > n-p.
  16. %
  17. % If k is a vector, then x_k is a matrix such that
  18. %     x_k = [ x_k(1), x_k(2), ... ] .
  19. %
  20. % The solution and residual norms are returned in eta and rho.

  21. % Reference: P. C. Hansen, T. Sekii & H. Shibahashi, "The modified
  22. % truncated-SVD method for regularization in general form", SIAM J.
  23. % Sci. Stat. Comput. 13 (1992), 1142-1150.

  24. % Per Christian Hansen, IMM, 12/22/95.

  25. % Initialization.
  26. m = size(U,1); [p,n] = size(L);
  27. lk = length(k); kmin = min(k);
  28. if (kmin<n-p+1 | max(k)>n)
  29.   error('Illegal truncation parameter k')
  30. end
  31. x_k = zeros(n,lk);
  32. beta = U(:,1:n)'*b; xi = beta./s;
  33. eta = zeros(lk,1); rho =zeros(lk,1);

  34. % Compute large enough QR factorization.
  35. [Q,R] = qr(L*V(:,n:-1:kmin+1),0);

  36. % Treat each k separately.
  37. for j=1:lk
  38.   kj = k(j); xtsvd = V(:,1:kj)*xi(1:kj);
  39.   if (kj==n)
  40.     x_k(:,j) = xtsvd;
  41.   else
  42.     z = R(1:n-kj,1:n-kj)\(Q(:,1:n-kj)'*(L*xtsvd));
  43.     z = z(n-kj:-1:1);
  44.     x_k(:,j) = xtsvd - V(:,kj+1:n)*z;
  45.   end
  46.   eta(j) = norm(x_k(:,j));
  47.   rho(j) = norm(beta(kj+1:n) + s(kj+1:n).*z);
  48. end

  49. if (nargout > 1 & m > n)
  50.   rho = sqrt(rho.^2 + norm(b - U(:,1:n)*beta)^2);
  51. end
复制代码

  1. function [x_k,rho,eta] = tsvd(U,s,V,b,k)
  2. %TSVD Truncated SVD regularization.
  3. %
  4. % [x_k,rho,eta] = tsvd(U,s,V,b,k)
  5. %
  6. % Computes the truncated SVD solution
  7. %    x_k = V(:,1:k)*inv(diag(s(1:k)))*U(:,1:k)'*b .
  8. % If k is a vector, then x_k is a matrix such that
  9. %    x_k = [ x_k(1), x_k(2), ... ] .
  10. %
  11. % The solution and residual norms are returned in eta and rho.

  12. % Per Christian Hansen, IMM, 12/21/97.

  13. % Initialization.
  14. [n,p] = size(V); lk = length(k);
  15. if (min(k)<0 | max(k)>p)
  16.   error('Illegal truncation parameter k')
  17. end
  18. x_k = zeros(n,lk);
  19. eta = zeros(lk,1); rho = zeros(lk,1);
  20. beta = U(:,1:p)'*b;
  21. xi = beta./s;

  22. % Treat each k separately.
  23. for j=1:lk
  24.   i = k(j);
  25.   if (i>0)
  26.     x_k(:,j) = V(:,1:i)*xi(1:i);
  27.     eta(j) = norm(xi(1:i));
  28.     rho(j) = norm(beta(i+1:p));
  29.   end
  30. end

  31. if (nargout > 1 & size(U,1) > p)
  32.   rho = sqrt(rho.^2 + norm(b - U(:,1:p)*beta)^2);
  33. end
复制代码
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-19 02:53 , Processed in 0.122894 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表