• 大小: 407KB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2024-02-01
  • 语言: Matlab
  • 标签: CARS_V1.50  

资源简介

CARS-PLS 用于光谱数据或色谱数据变量选择的matlab 源码

资源截图

代码片段和文件信息

function F=carspls(XyAfoldmethodnum) 
%+++ CARS: Competitive Adaptive Reweighted Sampling method for variable selection.
%+++ X: The data matrix of size m x p
%+++ y: The reponse vector of size m x 1
%+++ A: the maximal principle to extract.
%+++ fold: the group number for cross validation.
%+++ num: the  number of Monte Carlo Sampling runs.
%+++ method: pretreatment method.
%+++ Hongdong Li Dec.15 2008.
%+++ Advisor: Yizeng Liang yizeng_liang@263.net
%+++ lhdcsu@gmail.com
%+++ Ref:  Hongdong Li Yizeng Liang Qingsong Xu Dongsheng Cao Key
%    wavelengths screening using competitive adaptive reweighted sampling 
%    method for multivariate calibration Anal Chim Acta 2009 648(1):77-84


tic;
%+++ Initial settings.
if nargin<6;num=50;end;
if nargin<5;method=‘center‘;end;
if nargin<4;fold=5;end;
if nargin<3;A=2;end;

%+++ Initial settings.
[MxNx]=size(X);
A=min([Mx Nx A]);
index=1:Nx;
ratio=0.9;
r0=1;
r1=2/Nx;
Vsel=1:Nx;
Q=floor(Mx*ratio);
W=zeros(Nxnum);
Ratio=zeros(1num);

%+++ Parameter of exponentially decreasing function. 
b=log(r0/r1)/(num-1);  a=r0*exp(b);

%+++ Main Loop
for iter=1:num
     
     perm=randperm(Mx);   
     Xcal=X(perm(1:Q):); ycal=y(perm(1:Q));   %+++ Monte-Carlo Sampling.
     
     PLS=pls(Xcal(:Vsel)ycalAmethod);    %+++ PLS model
     w=zeros(Nx1);coef=PLS.coef_origin(1:end-1end);
     w(Vsel)=coef;W(:iter)=w; 
     w=abs(w);                                  %+++ weights
     [wsindexw]=sort(-w);                      %+++ sort weights
     
     ratio=a*exp(-b*(iter+1));                      %+++ Ratio of retained variables.
     Ratio(iter)=ratio;
     K=round(Nx*ratio);  
     
     
     w(indexw(K+1:end))=0;                      %+++ Eliminate some variables with small coefficients.  
     
     Vsel=randsample(NxNxtruew);                 %+++ Reweighted Sampling from the pool of retained variables.                 
     Vsel=unique(Vsel);              
     fprintf(‘The %dth variable sampling finished.\n‘iter);    %+++ Screen output.
 end

%+++  Cross-Validation to choose an optimal subset;
RMSEP=zeros(1num);
Q2_max=zeros(1num);
Rpc=zeros(1num);
for i=1:num
   vsel=find(W(:i)~=0);
 
   CV=plscvfold(X(:vsel)yAfoldmethod0);  
   RMSEP(i)=CV.RMSECV;
   Q2_max(i)=CV.Q2_max;   
   
   Rpc(i)=CV.optPC;
   fprintf(‘The %d/%dth subset finished.\n‘inum);
end
[RminindexOPT]=min(RMSEP);
Q2_max=max(Q2_max);




%+++ save results;
time=toc;
%+++ output
F.W=W;
F.time=time;
F.cv=RMSEP;
F.Q2_max=Q2_max;
F.minRMSECV=Rmin;
F.iterOPT=indexOPT;
F.optPC=Rpc(indexOPT);
Ft.ratio=Ratio;
F.vsel=find(W(:indexOPT)~=0)‘;



function sel=weightsampling_in(w)
%Bootstrap sampling
%2007.9.6H.D. Li.

w=w/sum(w);
N1=length(w);
min_sec(1)=0; max_sec(1)=w(1);
for j=2:N1
   max_sec(j)=sum(w(1:j));
   min_sec(j)=sum(w(1:j-1));
end
% figure;plot(max_sec‘r‘);hold on;plot(min_sec);
      
for i=1:N1
  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-03-30 21:57  CARS\
     文件       53760  2010-05-20 16:23  CARS\CARS_manual.doc
     文件         776  2011-01-14 16:44  CARS\CIP2pred.m
     文件       46264  2010-04-10 10:35  CARS\LOGO_CARS.JPG
     文件        1132  2010-05-20 10:31  CARS\Manne_bi.m
     文件         236  2016-12-15 13:43  CARS\Read me.txt
     文件        3399  2011-05-21 15:53  CARS\carspls.m
     文件         920  2010-08-13 10:51  CARS\classplot2.m
     文件         429  2011-05-21 10:28  CARS\compute_T2DM_data.asv
     文件      448880  2010-02-12 14:42  CARS\corn_m51.mat
     文件         278  2010-03-30 14:20  CARS\csvd.m
     文件         540  2011-04-21 09:49  CARS\databin.m
     文件        1102  2000-10-13 00:00  CARS\dosc.M
     文件         506  2010-04-16 15:52  CARS\example_nir.m
     文件         465  2008-04-20 16:25  CARS\expred1.m
     文件         736  2008-06-24 11:37  CARS\expred2.m
     文件         812  2009-05-08 15:26  CARS\ks.m
     文件         966  2010-04-12 11:10  CARS\lsreg.m
     文件        3031  2011-01-28 04:09  CARS\mcs.m
     文件        1217  2010-04-12 16:08  CARS\mcuvepls.m
     文件         976  2008-12-10 08:58  CARS\mwpls.m
     文件        3013  2009-04-14 15:38  CARS\oscplscv.m
     文件         835  2010-04-19 08:30  CARS\plotcars.m
     文件         592  2010-03-08 19:07  CARS\plotmcs.m
     文件        1953  2010-02-14 23:57  CARS\pls.m
     文件        1788  2010-09-07 17:11  CARS\pls_nipals.m
     文件        2639  2011-01-08 18:20  CARS\plscvfold.m
     文件        1955  2009-12-16 11:14  CARS\plsdcv.m
     文件        2977  2010-04-16 15:21  CARS\plsmccv.m
     文件        1734  2009-10-27 08:37  CARS\plsnipals.m
     文件        2179  2010-06-30 11:14  CARS\plsrdcv.m
............此处省略13个文件信息

评论

共有 条评论

相关资源