simpls1.m

来自「偏最小二乘算法在MATLAB中的实现」· M 代码 · 共 50 行

M
50
字号
function b = simpls1(x,y,maxlv)
%SIMPLS1 minimum implementation of simpls for PLS1
%  Inputs are the matrix of predictor variables (x), vector
%  of predicted variables (y) and maximum number of latent 
%  variables to calculate (lv). The output is a matrix of
%  regression vectors (b) where each row corresponds to the
%  regression vector for the PLS model with corresponding number
%  of LVs. 
%
%  Note: This function is primarily used for fast cross-validation
%  since none of the PLS model parameters (weights, loadings,
%  etc.) are calculated. The SIMPLS algorithm developed by
%  Sijmen de Jong is used.
%
%  The I/O format is: b = simpls1(x,y,maxlv);

%  Copyright
%  Eigenvector Technologies
%  Barry M. Wise
%  May 1994

[m,n] = size(x);
s = x'*y;
rmat = zeros(n,maxlv);
tmat = zeros(m,maxlv);
vmat = zeros(n,maxlv);
qmat = zeros(1,maxlv);
for i = 1:maxlv
  r = s;
  t = x*r;
  normt = sqrt(t'*t);
  t = t/normt;
  r = r/normt;
  p = x'*t;
  q = y'*t;
  u = y*q;
  v = p;
  if i > 1
    v = v - vmat*(vmat'*p);
	u = u - tmat*(tmat'*u);
  end
  v = v/sqrt(v'*v);
  s = s - v*(v'*s);
  rmat(:,i) = r;
  tmat(:,i) = t;
  qmat(:,i) = q;
  vmat(:,i) = v;
end
b = cumsum((rmat*diag(qmat))');

⌨️ 快捷键说明

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