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

📄 fastkennardstone.m

📁 有监督自组织映射-偏最小二乘算法(A supervised self-organising map–partial least squares algorithm),可以用语多变量数据的回归分析
💻 M
字号:
function [model,test]=FastKennardStone(x,k,B)
% -------------------------------------------------------------------------
% Function:
% [model,test]=fastkenstone(x,k,B)  
% -------------------------------------------------------------------------
% Aim: 
% Selection of uniformly distributed subset with OptiSim algorithm
% (a fast version of Kennard and Stone algorithm)
% -------------------------------------------------------------------------
% Input: 
% x - matrix (n,p), predictor variables in columns
% k - number of objects to be selected
% B - number of objects in the random subset (optional)
% if not specified B = 10% of objects in the data
% -------------------------------------------------------------------------
% Output:
% model - indices of the selected objects to the model set
% test - indices of the objects to the test set objects
% -------------------------------------------------------------------------
% References:
% [1] R.D. Clark, OptiSim: An extended dissimilarity selection method
% for finding diverse representative subsets, 
% J. Chem. Inf. Comput. Sci 37 (1997) 1181-1188
% [2] M. Daszykowski, B. Walczak, D.L. Massart, Representative subset selection,
% Analytica Chimica Acta 468 (2002) 91-103
% -------------------------------------------------------------------------
% Example:
% x=randn(300,2);
% [model,test]=fastkenstone(x,50,30) 
% -------------------------------------------------------------------------
% 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);option=2;

if nargin<3
    B=round(m*0.1);
end

range=(max(x)-min(x));
V=prod(range);
Vs=(1/k)*V;
R=(Vs/(sqrt(pi.^n)/gamma(n/2+1))).^(1/n);

if option==1;
    r=randperm(m);r=r(1); 
else
    mx=mean(x);
    d=sum(((x-ones(m,1)*mx).^2)');
    [i r]=min(d);
end

model=[r];
A=[1:m]';
A(r)=[];
recycling=[];
mS=1;
ma=length(A);

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

while mS<k
    r=randperm(ma);
  
    if B<ma
        r=r(1:B);
    else
        r=r(1:ma);
    end

    odleglosc=fastdist(x(model,:),x(A(r),:));

    if mS>1
        odleglosc=min(odleglosc,[],2);
    end
    
    remove=find(odleglosc<R);      
    [i1 i2]=max(odleglosc);	
    model=[model A(r(i2))];
    
    if ~isempty(remove),
        A(r(remove))=[];
    end   
    
    r(i2)=[];
    recycling=[recycling r];

    if isempty(A)
        A=unique(recycling);
    end
    
    ma=length(A);
    mS=length(model);
    h=waitbar(mS/k,h);
end  

close(h);
test=1:m;
test(model)=[];

% ---> 

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 + -