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

📄 kennardstone.m

📁 有监督自组织映射-偏最小二乘算法(A supervised self-organising map–partial least squares algorithm),可以用语多变量数据的回归分析
💻 M
字号:
function [model,test]=KennardStone(X,k)

% -------------------------------------------------------------------------
% Function:
% [model,test]=kenstone(X,k) 
% -------------------------------------------------------------------------
% Aim:
% Subset selection with Kennard and Stone algorithm
% -------------------------------------------------------------------------
% Input:
% X, matrix (n,p), predictor variables in columns
% k, number of objects to be selected to the model set
% -------------------------------------------------------------------------
% Output:
% model, vector (k,1), list of objects selected to model set
% test, vector (n-k,1), list of objects selected to test set (optionally)
% -----------------------------------------------------------------------
% Example: 
% x=randn(300,2);
% [model,test]=kenstone(X,10)
% [model]=kenstone(X,10)
% -----------------------------------------------------------------------
% Reference:
% R.W. Kennard, L.A. Stone, Computer aided design of experiments, 
% Technometrics 11 (1969) 137-148
% -------------------------------------------------------------------------
% Written by Michal Daszykowski
% Department of Chemometrics, Institute of Chemistry, 
% The University of Silesia
% December 2004
% http://www.chemometria.us.edu.pl

[m,n]=size(X);
if k>=m | k<=0  
    h=errordlg('Wrongly specified number of objects to be selected to model set.','Error');
    model=[];
    if nargout==2
        test=[];
    end
    waitfor(h)
    return
end

x=[[1:size(X,1)]' X];
n=size(x,2);
[i1,ind1]=min(fastdist(mean(x(:,2:n)),x(:,2:n)));
model(1)=x(ind1,1);
x(ind1,:)=[];

[i2,ind2]=max(fastdist(X(model(1),:),x(:,2:n)));
model(2)=x(ind2,1);
x(ind2,:)=[];

%h=waitbar(0,'Please wait ...'); 
%h=waitbar(0/k,h);

for d=3:k
    [ii,ww]=max(min(fastdist(x(:,2:n),X(model,:))));
	model(d)=x(ww,1);
	x(ww,:)=[];
    %h=waitbar(d/k,h);
end

if nargout==2
    test=1:size(X,1);
    test(model)=[];
end

%close(h);

% ---> 

function D=fastdist(x,y)

% Calculated Euclideam distances between two sets of objetcs

D=((sum(y'.^2))'*ones(1,size(x,1)))+(ones(size(y,1),1)*(sum(x'.^2)))-2*(y*x');

⌨️ 快捷键说明

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