资源简介
ols,正交最小二乘法的matlab代码,在曲线拟合中可以使用到,有注释。
代码片段和文件信息
function [x ind r_act A_o x_o] = ols(Abrthreshold)
% OLS Orthogonal Least Quares.
%
% [x ind] = OLS(Abr) gives the solution to the least squares problem
% using only the best r regressors chosen from the ones present in matrix A.
% This function also returns in the vector ind the indexes of the
% best r regressors (i.e. the best columns of A to use).
%
% If r is equal to n the solution x given by OLS is the same as the solution
% given by A\b but in ind we still have the regressors sorted by their
% importance. % This means that one can perform a feature selection by taking
% the first k entries in ind (k %
% THEORETICAL BACKGROUND
% Let us consider the Linear Least Squares Problem:
%
% min (A*x-b)‘*(A*x-b)
%
% where A is a m-by-n matrix b an m-dimentional vector and x the unknown
% an n-dimentional vector. The problem is well posed when m>n.
% A can be viewed as a set of columns usually called regressors while b typically
% is the vector of desired outputs.
% The solution to this problem can be computed in Matlab through the function
% MLDIVIDE as follows:
%
% x = A\b
%
% Although this function is very powerful it does not give any information on which
% regressor is better than others.
% On the other hand Orthogonal Least Squares (OLS) can extract this information.
% It is mainly based on the Gram-Schmidt orthogonalization algorithm.
%
% In pattern recognition problems usually a training matrix A_tr is given
% associated with the vector of desired outputs b_tr plus a test set pair (A_ts b_ts)
% where the system has to be tested. In such cases the OLS function can be
% used as follows with a value of r chosen by the user:
%
% [x ind] = OLS(A_tr b_tr r);
%
% err_tr = (A_tr*x-b_tr)‘ *(A_tr*x-b_tr)/length(b_tr); % Mean Squared Error on training set.
% err_ts = (A_ts*x-b_ts)‘ *(A_ts*x-b_ts)/length(b_ts); % Mean Squared Error on test set.
% While a large value for r will probably give a low error on the training set
% it could happen that a lower value of it would give a lower error on the test set.
% In such cases the value of r which minimizes the error on the test set should be chosen.
%
% ALTERNATIVE SYNTAX
%
% [x ind r_act] = OLS(Ab[] threshold) is another way to call the OLS function.
% This call requires a threshold in place of the number of regressors r.
% The threshold which has to be a decimal number in the interval [01]
% indicates the maximum relative error allowed between the approximated output b_r
% and the desired output b when the number of regressors used is r.
% The provided output r_act gives the number of regressors actually used which
% are necessary to reduce the error untill the desired value of the threshold.
% Please not that r_act is also equal to the length of the vector ind.
% The pseudocode for this call is the following:
%
% for r=1:n
% x_r = OLS(Abr);
% b_r = A*x_r;
%
- 上一篇:一个批量剪裁图像的matlab程序
- 下一篇:GUI人脸识别MATLAB代码
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论