资源简介
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代码
相关资源
- Pattern Recognition and Machine Learning(高清
- MATLAB 编程 第二版 Stephen J. Chapman 著
- 均值滤波和FFT频谱分析Matlab代码
- 《MATLAB扩展编程》代码
- HDB3码、AMI码的MATLAB实现
- 3点GPS定位MATLAB仿真
- MATLAB数字信号处理85个实用案例精讲入
- matlab从入门到精通pdf94795
- 欧拉放大论文及matlab代码
- 跳一跳辅助_matlab版本
- 全面详解LTE MATLAB建模、仿真与实现
- MIMO-OFDM无线通信技术及MATLAB实现_孙锴
- MATLAB Programming for Engineers 4th - Chapman
- matlab 各种谱分析对比
- 分数阶chen混沌matlab程序
- 基于粒子群算法的非合作博弈的matl
- MATLAB车流仿真 包括跟驰、延误
- matlab空间桁架计算程序
- 基于MATLAB的图像特征点匹配和筛选
- DMA-TVP-FAVAR
- GPS信号的码捕获matlab代码.7z
- 一维光子晶体MATLAB仿真代码吸收率折
- newmark法源程序
- 传统关联成像、计算鬼成像matlab
- pri传统分选算法
- 摆动滚子推杆盘形凸轮设计
- 医学图像重建作业matlab源码
- Matlab实现混沌系统的控制
- 检测疲劳驾驶
- Matlab锁相环仿真-Phase Locked Loop.rar
评论
共有 条评论