当前位置:文档之家› 灰色关联度matlab源程序(完整版)

灰色关联度matlab源程序(完整版)

灰色关联度matlab源程序(完整版)最近几天一直在写算法,其实网上可以下到这些算法的源程序的,但是为了搞懂,搞清楚,还是自己一个一个的看了,写了,作为自身的积累,而且自己的的矩阵计算类库也迅速得到补充,以后关于算法方面,基本的矩阵运算不用再重复写了,挺好的,是种积累,下面把灰关联的matlab程序与大家分享。

灰色关联度分析法是将研究对象及影响因素的因子值视为一条线上的点,与待识别对象及影响因素的因子值所绘制的曲线进行比较,比较它们之间的贴近度,并分别量化,计算出研究对象与待识别对象各影响因素之间的贴近程度的关联度,通过比较各关联度的大小来判断待识别对象对研究对象的影响程度。

简言之,灰色关联度分析的意义是指在系统发展过程中,如果两个因素变化的态势是一致的,即同步变化程度较高,则可以认为两者关联较大;反之,则两者关联度较小。

因此,灰色关联度分析对于一个系统发展变化态势提供了量化的度量,非常适合动态(Dynamic)的历程分析。

灰色关联度可分成“局部性灰色关联度”与“整体性灰色关联度”两类。

主要的差别在于局部性灰色关联度有一参考序列,而整体性灰色关联度是任一序列均可为参考序列。

关联度分析是基于灰色系统的灰色过程, 进行因素间时间序列的比较来确定哪些是影响大的主导因素, 是一种动态过程的研究。

关联度计算的预处理,一般初值化或者均值化,根据我的实际需要,本程序中使用的是比较序列与参考序列组成的矩阵除以参考序列的列均值等到的,当然也可以是其他方法。

%注意:由于需要,均值化方法采用各组值除以样本的各列平均值clear;clc;yangben=[47.924375 25.168125 827.4105438 330.08875 1045.164375 261.37437516.3372 6.62 940.2824 709.2752 962.1284 84.87455.69666667 30.80333333 885.21 275.8066667 1052.42 435.81]; %样本数据fangzhen=[36.27 14.59 836.15 420.41 1011.83 189.5464.73 35.63 755.45 331.32 978.5 257.8742.44 23.07 846 348.05 1025.4 296.6959.34 39.7 794.31 334.63 1016.4 317.2752.91 17.14 821.79 306.92 1141.94 122.044.21 4.86 1815.52 2584.68 963.61 0.006.01 2.43 1791.61 2338.17 1278.08 30.873.01 1.58 1220.54 956.14 1244.75 3.9125.65 7.42 790.17 328.88 1026.01 92.82115.80 27 926.5 350.93 1079.49 544.3812.63 8.75 1055.50 1379.00 875.10 1.65]; %待判数据[rows,cols]=size(fangzhen);p=0.5; %分辨系数[m,n]=size(yangben);R=[];for irow=1:rowsyy=fangzhen(irow,:);data=[yy;yangben];data_gyh1=mean(yangben)for i=1:m+1for j=1:ndata_gyh(i,j)=data(i,j)/data_gyh1(j);endendfor i=2:m+1for j=1:nDij(i-1,j)=abs(data_gyh(1,j)-data_gyh(i,j));endendDijmax=max(max(Dij));Dijmin=min(min(Dij));for i=1:mfor j=1:nLij(i,j)=(Dijmin+p*Dijmax)/(Dij(i,j)+p*Dijmax);endendLijRowSum=sum(Lij');for i=1:mRij(i)=LijRowSum(i)/n;endR=[R;Rij];endRmatlab求灰色关联度矩阵源代码2010-12-11 22:57function greyrelationaldegree(X,c)%GRAYRELATIONALDEGREE this function is used for calculating the gery %relation between squence%rememeber that the first column of the input matrix is the desicion %attribution squences.what we want to calculate is the grey ralational degree between%it and other attributions%X is the squence matrix, c is the parameter used in the function%in most of the time, the value of c is 0.5firstrow = X(1,:);reci_firstrow = 1./firstrow;reci_convert = diag(reci_firstrow);initialMIRROR = X*reci_convert;% find the initial value mirror of the sequce matrixA = initialMIRROR'[nrow,ncolumn] = size(A);for (i=2:nrow)C = A(i,:)-A(1,:)D=abs(C);eval(['B' num2str(i) '=D']);amax = max(eval(['B' num2str(i)]))amin = min(eval(['B' num2str(i)]))maxarray(i-1)=amaxminarray(i-1)=aminend %find the difference squence and the max value and min value of each squencemaxmax = max(maxarray)minmin = min(minarray)for(i=2:nrow)for(j=1:ncolumn)eval(['greyrelationdegree' num2str(i)'(j)=(minmin+c*maxmax)/(B' num2str(i) '(j)+c*maxmax)'])endend % calculate the greyralational degree of each datafor(i=2:nrow)eval(['greyrelatioanaldegree_value' num2str(i) '= mean (greyrelationdegree' num2str(i) ')' ])end基于matlab灰色关联度计算的实现2006年07月28日星期五上午 11:06function r=incident_degree(x0,x1)%compute the incident degree for grey model.%Designed by NIXIUHUI,Dalian Fisher University.%17 August,2004,Last modified by NXH at 21 August,2004%数据初值化处理x0_initial=x0./x0(1);temp=size(x1);b=repmat(x1(:,1),[1 temp(2)]);x1_initial=x1./b;%分辨系数选择K=0.1;disp('The grey interconnect degree is: ');x0_ext=repmat(x0_initial,[temp(1) 1]);contrast_mat=abs(x0_ext-x1_initial);delta_min=min(min(contrast_mat));%delta_min在数据初值化后实际为零delta_max=max(max(contrast_mat));a=delta_min+K*delta_max;incidence_coefficient=a./(contrast_mat+K*delta_max);%得到关联系数r=(sum(incidence_coefficient'))'/temp(2); %得到邓氏面积关联度我们根据图1的步骤和图2的数据进行编程实现,程序如下:%清除内存空间等clear;close all;clc;%载入源数据%其实这里可以载入execl表格的n=15; %参与评价的人数m=4; %参与评价的指标个数X_0=zeros(n,m); % 数据矩阵X_2=zeros(n,m); %偏差结果的求取矩阵X_3=zeros(n,m); % 相关系数计算矩阵a1_0=[13 18 17 18 17 17 18 17 13 17 18 13 18 13 18];a2_0=[18 18 17 17 18 13 17 13 18 13 17 13 13 17 17];a3_0=[48.67 43.33 43.56 41.89 39.47 43.44 37.97 41.14 39.67 39.8334.11 40.58 34.19 30.75 21.22];a4_0=[10 10.7 3 5.4 5.4 0.7 4.2 0.5 9.3 0.85 2.9 5.45 4.2 2.7 6]; %指标数X_1=[a1_0',a2_0',a3_0',a4_0']; %最后使用到的数据矩阵%1 寻找参考列x0=[max(a1_0),max(a2_0),max(a3_0),max(a4_0)]; %取每列的最大值(指标的最大值)%2 计算偏差结果i=1;while(i~=m+1) %为什么这个地方会出问题呢for j=1:1:nX_2(j,i)=abs(X_1(j,i)-x0(i));end;i=i+1;end%3 确定偏差的最值error_min=min(min(X_2));error_max=max(max(X_2));%4 计算相关系数i=1;p=0.5;while(i~=m+1)for j=1:1:nX_3(j,i)=(error_min+p*error_max)/(X_2(j,i)+p*error_max);end;i=i+1;end%X_3 %可以在此观察关联矩阵%5 计算各个学生的关连序a=zeros(1,n);for j=1:1:nfor i=1:1:ma(j)=a(j)+X_3(j,i); %%%%其实可以直接用sumend;a(j)=a(j)/m; %%%%%%%%%可以改进%%%%%%%%%%1 2 3 下一页%end%a %在此可以观测各个学生的序%改进:如果各个指标的所占权重不一样的话,可以添加相应的权系数%6 排序b=a';[c,s]=sort(b);for i=1:1:nd(i)=i;endd=d';result=[d b c s]%7 将结果显示出来figure(1);plot(a);figure(2)bar(a); %柱状图最后所得到的结果如图3到图5所示。

相关主题