ajdyj距离分类器的Matlab实现ajdyj距离分类器是贝叶斯分类器的退化版本,在样本满足一定条件下成立。
代码是下一个:
function cls=mahalanobisclassifier [ vararg in ] [ x,m,sigma ]=parse inputs [ vararg in { : } ]; %分析输入的变量dis=Zeros(size(m,1 ),1 ); %ajdyj距离cls=Zeros(size(x,1 ); %每个样品所属的类别forI=1:size(x,1 ) )分类for j=1:size(m ) m,1 ) dis ) j )=) x ) I, )-m ) j,33: ) end function [x,m,sigma]=parseinputs(varargin ) %用于分析输入变量的函数narginchk(2) 2,inf ) validate attributes (x=ifnargin==2validate attributes (vararg in )、(numeric )、({'nonempty )、) nonsparse )、 (2d )、(ncols )、sigmm else if nargin==3validate attributes (vararg in )、((numeric )、)、{'nonempty )、(nonsparse )、…)、(ncols )。 {'numeric'}、{'nonempty '、' nonsparse '、 ' 2d '、' nrows '、size(varargin{2}、1 ) ncols )、size ) vargin Elsen=Length(varargin ); m=Zeros(n-2,size(x ) x,2 ); fork=2: n-1 validate attributes (vararg in (k )、(numeric )、({'nonempty )、) nonsparse )、) 2d、) nrows endvalidateattributes (vararg in (end )、(numeric )、({'nonempty )、) nonsparse )、 (2d )、(nrows )、size ) m 2 结束