⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ridgeg.m

📁 偏最小二乘算法在MATLAB中的实现
💻 M
字号:
function [b,theta] = ridgeg(xblock,yblock,tmaxm,divs,tf,gui,action);
%RIDGEG Ridge regression by Hoerl-Kennard-Baldwin for MODLGUI

%  Copyright
%  Eigenvector Technologies 1995
%  Graphics modified November 1993
global theta b tmaxm divs split thetamin incr
handl = get(gui,'UserData');
[m,n] = size(xblock);
if strcmp(action,'crval')
  incr = tmaxm/divs;
  dfs  = m - n - 1;
  b    = zeros(n,divs+1);
  b(:,1) = xblock\yblock;
  ridi = diag(diag(xblock'*xblock));
  dif  = xblock*b(:,1)-yblock;
  ssqerr = dif'*dif;
  theta = n*(ssqerr/dfs)/sum((ridi.^0.5*b(:,1)).^2);
  for i = 1:divs
    b(:,i+1) = inv(xblock'*xblock + ridi*i*incr)*xblock'*yblock;
  end
  figure(handl(1,1))
  plot(0:incr:tmaxm,b'); hold on; 
  ax = axis;
  plot([theta theta],[ax(3) ax(4)],'-g');
  hold off; title('Values of Regression Coefficients as a Function of theta');
  xlabel('Value of theta');
  ylabel('Regression Coefficients');
  xcoord = floor(divs/10);
  if xcoord == 0
    xcoord = 2;
  end
  for i = 1:n
    t = sprintf('%g',i);
    text(xcoord*incr,b(i,xcoord+1),t);
  end
  if nargin == 4
    tf = 0;
  end
  t = sprintf('theta = %g',theta);
  if tf == 0  
    text(.6*tmaxm,.8*(ax(4)-ax(3))+ax(3),'Vertical line shows');
    text(.6*tmaxm,.75*(ax(4)-ax(3))+ax(3),'best guess for theta');
    text(.6*tmaxm,.7*(ax(4)-ax(3))+ax(3),t);
  else
    gtext('Vertical line shows best guess for theta')
    gtext(t)
  end  
  b = inv(xblock'*xblock + ridi*theta)*xblock'*yblock;
  figure(gui)
  set(handl(3,3),'UserData',4);
  set(handl(4,12),'Visible','On');
  set(handl(2,4),'String',['Click RESUME to Continue']);
end 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -