连续投影算法.zip

  • K7_772806
    了解作者
  • matlab
    开发工具
  • 97.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-02-21 17:17
    上传日期
连续投影算法spa的 matlab程序源代码压缩文件,用于可见-近红外光谱数据的特征波长提取,内含8个文件,可以下载试试,还不错。
连续投影算法.zip
  • 连续投影算法
  • gui_spa.p
    51.7KB
  • spa.m
    4.4KB
  • statistical_prediction_error.m
    988B
  • projections_qr.m
    803B
  • ~$structions.doc
    162B
  • spa2.fig
    9.3KB
  • validation.m
    1.1KB
  • validation_metrics.m
    1.2KB
  • guiLibrary1c.p
    55.9KB
内容介绍
function [var_sel,var_sel_phase2] = spa(Xcal,ycal,Xval,yval,m_min,m_max,autoscaling) % [var_sel,var_sel_phase2] = spa(Xcal,ycal,Xval,yval,m_min,m_max,autoscaling) --> Validation with a separate set % [var_sel,var_sel_phase2] = spa(Xcal,ycal,[],[],m_min,m_max,autoscaling) --> Cross-validation % % If m_min = [], the default value m_min = 1 is employed % If m_max = [], the default values m_max = min(N-1,K) (validation with a separate set) % or min(N-2,K) (cross-validation) are employed. % autoscaling --> 1 (yes) or 0 (no) autoscaling if ((autoscaling ~= 1) & (autoscaling ~= 0)) error('Please choose whether or not to use autoscaling.') end N = size(Xcal,1); % Number of calibration objects K = size(Xcal,2); % Total number of variables if length(m_min) == 0, m_min = 1; end if length(m_max) == 0, if size(Xval,1) > 0 m_max = min(N-1,K); else m_max = min(N-2,K); end end if m_max > min(N-1,K) error('m_max is too large !'); end % Phase 1: Projection operations for the selection of candidate subsets % The projections are applied to the columns of Xcal after % mean-centering and (optional) autoscaling if autoscaling == 1 normalization_factor = std(Xcal); else normalization_factor = ones(1,K); end for k = 1:K x = Xcal(:,k); Xcaln(:,k) = (x - mean(x)) / normalization_factor(k); end SEL = zeros(m_max,K); h = waitbar(0,'Phase 1 (Projections). Please wait...'); loopStart = now; for k = 1:K SEL(:,k) = projections_qr(Xcaln,k,m_max); loopEnd = loopStart + (now-loopStart)*K/k; waitbar(k/K,h,['Phase 1 ETC: ' datestr(loopEnd)]); end close(h); disp('Phase 1 (projections) completed !') % Phase 2: Evaluation of the candidate subsets according to the PRESS criterion PRESS = Inf*ones(m_max,K); h = waitbar(0,'Phase 2 (Evaluation of variable subsets). Please wait...'); warning off MATLAB:singularMatrix warning off MATLAB:nearlySingularMatrix loopStart = now; for k = 1:K for m = m_min:m_max var_sel = SEL(1:m,k); [yhat,e] = validation(Xcal,ycal,Xval,yval,var_sel); PRESS(m,k) = e'*e; end loopEnd = loopStart + (now-loopStart)*K/k; waitbar(k/K,h,['Phase 2 ETC: ' datestr(loopEnd)]); end close(h); warning on MATLAB:singularMatrix warning on MATLAB:nearlySingularMatrix [PRESSmin,m_sel] = min(PRESS); [dummy,k_sel] = min(PRESSmin); var_sel_phase2 = SEL(1:m_sel(k_sel),k_sel); disp('Phase 2 (evaluation of variable subsets) completed !') % Phase 3: Final elimination of variables % Step 3.1: Calculation of the relevance index Xcal2 = [ones(N,1) Xcal(:,var_sel_phase2)]; b = Xcal2\ycal; % MLR with intercept term std_deviation = std(Xcal2); relev = abs(b.*std_deviation'); relev = relev(2:end); % The intercept term is always included % Sorts the selected variables in decreasing order of "relevance" [dummy,index_increasing_relev] = sort(relev); % Increasing order index_decreasing_relev = index_increasing_relev(end:-1:1); % Decreasing order % Step 3.2: Calculation of PRESS values for i = 1:length(var_sel_phase2) [yhat,e] = validation(Xcal,ycal,Xval,yval,var_sel_phase2(index_decreasing_relev(1:i)) ); PRESS_scree(i) = e'*e; end RMSEP_scree = sqrt(PRESS_scree/length(e)); figure, grid, hold on plot(RMSEP_scree) xlabel('Number of variables included in the model'),ylabel('RMSE') % Step 3.3: F-test criterion PRESS_scree_min = min(PRESS_scree); alpha = 0.25; dof = length(e); % Number of degrees of freedom fcrit = finv(1-alpha,dof,dof); % Critical F-value PRESS_crit = PRESS_scree_min*fcrit; % Finds the minimum number of variables for which PRESS_scree % is not significantly larger than PRESS_scree_min i_crit = min(find(PRESS_scree < PRESS_crit)); i_crit = max(m_min,i_crit); % The number of selected variables must be at least m_min var_sel = var_sel_phase2( index_decreasing_relev(1:i_crit) ); title(['Final number of selected variables: ' num2str(length(var_sel)) ' (RMSE = ' num2str(RMSEP_scree(i_crit)) ')']) % Indicates the selected point on the scree plot plot(i_crit,RMSEP_scree(i_crit),'s') disp('Phase 3 (final elimination of variables) completed !') % Presents the selected variables % in the first object of the calibration set figure,plot(Xcal(1,:));hold,grid plot(var_sel,Xcal(1,var_sel),'s') legend('First calibration object','Selected variables') xlabel('Variable index')
评论
    相关推荐
    • Matlab合集
      冈萨雷斯数字图像处理MATLAB版.中文版+数字图像处理第二版中文版(冈萨雷斯)+MATLAB-R2014a完全自学一本通+MATLAB R2016a完全自学一本通 素材文件+[模式识别与智能计算:MATLAB技术实现(第2版)].杨淑莹.扫描版
    • MATLAB教程
      MATLAB教程MATLAB教程MATLAB教程MATLAB教程MATLAB教程MATLAB教程
    • MATLAB
      MATLAB 该项目是在matlab上完成的,涉及创建和移动宇宙飞船和机器人。 太空飞船和机器人是使用Matlab中的简单几何形状创建的,并通过连续变换矩阵进行移动。 这个项目教我如何使用变换矩阵(旋转,平移等)的概念...
    • MATLAB基础
      一本学习matlab的一本好书
    • MATLAB编译器
      基于MATLAB 2018b版本介绍MATLAB编译器。介绍如何利用编译器将MATLAB代码编译为独立应用程序或组件,并在没有安装MATLAB的计算机上进行部署。
    • matlabruntime
      通过奇点容器运行您的matlab项目 可以在没有MATLAB的容器中运行matlab代码。 为此,我们首先需要通过Matlab编译器在本地构建相应的Matlab代码的独立应用程序,然后使用具有Matlab运行时( 的容器)运行该应用程序 )...
    • matlab实现
      matlab实现 matlab实现matlab实现matlab实现matlab实现
    • matlab 教程
      matlab 信号处理资料,里面包含信号处理pdf文档,一些杂乱的程序和命令等
    • matlab教程
      matlab教程,PPT格式,包含 matlab基本知识、matlab入门、matlab作图、线性规划、无约束优化、非线性规划、统计工具箱、差值、微分方程等多项知识点,并且每个知识点独立成为PPT,内还含有matlab信号处理详解等文档...
    • matlab简介
      1.MATLAB 开发环境 1.1 MATLAB 的视窗环境 进入MATLAB之后,会看到一个视窗MATLAB Command Window称为指令视窗,它是你键入指令的地方同时 MATLAB也将计算结果显示在此。 1.2 简易计算 我们先从MATLAB的...