在多属性综合评价问题中,为了消除量纲差异带来指标不可公度性问题,往往需要对原始评价矩阵进行标准化处理,通过将不同量纲进行变换,变为无量纲的标准化指标。考虑到原始评价矩阵可能同时有多种类型的指标,比如,某个评价问题中可能同时有正向指标(越大越好)、逆向指标(越小越好)和中性指标(最优值为给定区间),故以下程序只针对某个指标值的列向量进行标准化处理;如果要处理整个评价矩阵,则根据指标类型分别对各个指标单独处理,然后再组成成一个标准评价矩阵,如:标准评价矩阵S=[std_1, std_2, …, std_n],其中,std_1,std_2,…,std_n为各指标的标准化数值。
(一)向量归一化法,转换到区间[0,1]
function std_attrValues= vecStd(attrValues)
if iscolumn(attrValues)~=1%如果不是指标数据列向量,则提示错误
warndlg('输入数据必需为列向量,数据标准化处理失败,返回空值!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
m=length(attrValues); %列向量长度
std_attrValues=ones(m,1); %初始化标准化属性值,与属性值一样是个m×1的列向量
sqAttr=attrValues.^2; %原数据每个值的平方
sqSumByAttr=sum(sqAttr,1); %列向量的平方和
sqrtByAttr=sqrt(sqSumByAttr); %对平方和开根号
if sqSumByAttr==0
warndlg('指标值全为0,不能采用向量归一化法进行标准化处理,返回空值,请选择其他方法!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
for i=1:m
std_attrValues(i,1)=attrValues(i,1)/sqrtByAttr;%计算标准化属性值
end
disp('数据标准化处理成功!');
end
end
end
(二)线性比例变换法,分正向型和反向型分别转换到区间[0,1]
function std_attrValues=linearStd(attrValues,attrType)
if nargin<2
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标类型,1为正向指标,2为逆向指标。','失败!');
std_attrValues=[]; %调用错误时返回空值
else
if iscolumn(attrValues)~=1%如果不是指标数据列向量,则提示错误
warndlg('输入数据必需为列向量,数据标准化处理失败,返回空值!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
m=length(attrValues); %列向量长度
std_attrValues=ones(m,1); %初始化标准化属性值,与属性值一样是个m×1的列向量
maxByAttr=max(attrValues); %列向量的最大值
minByAttr=min(attrValues);%列向量的最小值
switch(attrType)
case1 %正向指标
if maxByAttr==0
warndlg('正向指标最大值为0,不能采用线性比例变换法进行标准化处理,返回空值,请选择其他方法!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
for i=1:m
std_attrValues(i,1)=attrValues(i,1)/maxByAttr;%计算标准化属性值
end
disp('数据标准化处理成功!');
end
case2 %逆向指标
zeroFlag=0;%是否存在0的标记
for i=1:m
if attrValues(i,1)==0
zeroFlag=1; %遇到0就设为1
break; %只要遇到0就退出循环
else
zeroFlag=0;
end
end
if zeroFlag==1
warndlg('逆向指标存在0值,不能采用线性比例变换法进行标准化处理,返回空值,请选择其他方法!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
for i=1:m
std_attrValues(i,1)=minByAttr/attrValues(i,1);%计算标准化属性值
end
disp('数据标准化处理成功!');
end
otherwise
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标类型,1为正向指标,2为逆向指标。','失败!');
std_attrValues=[]; %调用错误时返回空值
end
end
end
end
(三)极差变换法(标准0-1变换),分正向型和反向型分别转换到区间[0,1]
function std_attrValues=minmaxStd(attrValues,attrType)
if nargin<2
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标类型,1为正向指标,2为逆向指标。','失败!');
std_attrValues=[]; %调用错误时返回空值
else
if iscolumn(attrValues)~=1%如果不是指标数据列向量,则提示错误
warndlg('输入数据必需为列向量,数据标准化处理失败,返回空值!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
m=length(attrValues); %列向量长度
std_attrValues=ones(m,1); %初始化标准化属性值,与属性值一样是个m×1的列向量
maxByAttr=max(attrValues); %列向量的最大值
minByAttr=min(attrValues); %列向量的最小值
if maxByAttr-minByAttr==0
warndlg('指标最大值和最小值相等,不能采用标准0-1变换进行标准化处理,返回空值!请选择其他方法!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
switch(attrType)
case 1 %正向指标
for i=1:m
std_attrValues(i,1)=(attrValues(i,1)-minByAttr)./(maxByAttr-minByAttr);%计算标准化属性值
end
disp('数据标准化处理成功!');
case 2 %逆向指标
for i=1:m
std_attrValues(i,1)=(maxByAttr-attrValues(i,1))./(maxByAttr-minByAttr);%计算标准化属性值
end
disp('数据标准化处理成功!');
otherwise
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标类型,1为正向指标,2为逆向指标。','失败!');
std_attrValues=[]; %调用错误时返回空值
end
end
end
end
end
(四)最优值为给定数值的标准化,转换到区间[0,1]
function std_attrValues =optValue(attrValues,opt,lowLmt,upLmt)
if nargin<4
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标最优值及上下极限(下极限
std_attrValues=[];%调用错误时返回空值
else
if iscolumn(attrValues)~=1%如果不是指标数据列向量,则提示错误
warndlg('输入数据必需为列向量,数据标准化处理失败,返回空值!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
m=length(attrValues); %列向量长度
std_attrValues=ones(m,1); %初始化标准化属性值,与属性值一样是个m×1的列向量
if (lowLmt
for i=1:m
if (attrValues(i,1)<=lowLmt) || (attrValues(i,1)>=upLmt)
std_attrValues(i,1)=0;
elseif (lowLmt
std_attrValues(i,1)=1-(opt-attrValues(i,1))/(opt-lowLmt);
elseif (attrValues(i,1)) == opt
std_attrValues(i,1)=1;
else
std_attrValues(i,1)=1-(attrValues(i,1)-opt)/(upLmt-opt);
end
end
disp('数据标准化处理成功!');
else
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标最优值及上下极限(下极限
std_attrValues=[];%调用错误时返回空值
end
end
end
end
(五)最优值为给定区间的标准化,转换到区间[0,1]
function std_attrValues =optInterval(attrValues,lowLmt,upLmt,optLow,optUp)
if nargin<5
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标上下极限及最优值区间(下极限
std_attrValues=[];%调用错误时返回空值
else
if iscolumn(attrValues)~=1%如果不是指标数据列向量,则提示错误
warndlg('输入数据必需为列向量,数据标准化处理失败,返回空值!','失败!');
std_attrValues=[]; %调用错误时返回空值
else
m=length(attrValues); %列向量长度
std_attrValues=ones(m,1); %初始化标准化属性值,与属性值一样是个m×1的列向量
if (lowLmt
for i=1:m
if (attrValues(i,1)<=lowLmt) || (attrValues(i,1)>=upLmt)
std_attrValues(i,1)=0;
elseif (lowLmt
std_attrValues(i,1)=1-(optLow-attrValues(i,1))/(optLow-lowLmt);
elseif (optLow<=attrValues(i,1)) && (attrValues(i,1)<=optUp)
std_attrValues(i,1)=1;
else
std_attrValues(i,1)=1-(attrValues(i,1)-optUp)/(upLmt-optUp);
end
end
disp('数据标准化处理成功!');
else
warndlg('函数调用错误,数据标准化处理失败,返回空值!请正确设置指标上下极限及最优值区间(下极限
std_attrValues=[];%调用错误时返回空值
end
end
end
end