加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

灰色关联度matlab源程序

(2013-03-12 12:05:34)
标签:

灰色

灰色关联度

关联度

matlab

程序

休闲

分类: 学习历程

灰色关联度matlab源程序

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

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

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

%注意:由于需要,均值化方法采用各组值除以样本的各列平均值
clear;clc;
yangben=[
47.924375 25.168125 827.4105438 330.08875 1045.164375 261.374375
16.3372 6.62 940.2824 709.2752 962.1284 84.874
55.69666667 30.80333333 885.21 275.8066667 1052.42 435.81

]; %样本数据

fangzhen=[
36.27 14.59 836.15 420.41 1011.83 189.54
64.73 35.63 755.45 331.32 978.5 257.87
42.44 23.07 846 348.05 1025.4 296.69
59.34 39.7 794.31 334.63 1016.4 317.27
52.91 17.14 821.79 306.92 1141.94 122.04
4.21 4.86 1815.52 2584.68 963.61 0.00
6.01 2.43 1791.61 2338.17 1278.08 30.87
3.01 1.58 1220.54 956.14 1244.75 3.91
25.65 7.42 790.17 328.88 1026.01 92.82
115.80 27 926.5 350.93 1079.49 544.38
12.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:rows
     yy=fangzhen(irow,:);
     data=[yy;yangben];
     data_gyh1=mean(yangben)
     for i=1:m+1
         for j=1:n
             data_gyh(i,j)=data(i,j)/data_gyh1(j);
         end
     end
    
     for i=2:m+1
         for j=1:n
             Dij(i-1,j)=abs(data_gyh(1,j)-data_gyh(i,j));
         end
     end
     Dijmax=max(max(Dij));
     Dijmin=min(min(Dij));
    
     for i=1:m
         for j=1:n
             Lij(i,j)=(Dijmin+p*Dijmax)/(Dij(i,j)+p*Dijmax);
         end
     end
    
     LijRowSum=sum(Lij');
    
     for i=1:m
         Rij(i)=LijRowSum(i)/n;
     end
     R=[R;Rij];
end
R

 

 

 

 

matlab求灰色关联度矩阵源代码

2010-12-11 22:57

function 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.5

firstrow = X(1,:);
reci_firstrow = 1./firstrow;
reci_convert = diag(reci_firstrow);
initialMIRROR = X*reci_convert;% find the initial value mirror of the sequce matrix
A = initialMIRROR'
[nrow,ncolumn] = size(A);

for (i=2:nrow)
    C = A(i,:)-A(1,:)
    D=abs(C);
    eval_r(['B' num2str(i) '=D']);
    amax = max(eval_r(['B' num2str(i)]))
    amin = min(eval_r(['B' num2str(i)]))
    maxarray(i-1)=amax
    minarray(i-1)=amin
end %find the difference squence and the max value and min value of each squence

maxmax = max(maxarray)
minmin = min(minarray)

for(i=2:nrow)
    for(j=1:ncolumn)
        eval_r(['greyrelationdegree' num2str(i) '(j)=(minmin+c*maxmax)/(B' num2str(i) '(j)+c*maxmax)'])
    end
end % calculate the greyralational degree of each data

for(i=2:nrow)
   eval_r(['greyrelatioanaldegree_value' num2str(i) '= mean (greyrelationdegree' num2str(i) ')'  ])   
end

基于matlab灰色关联度计算的实现

20060728日 星期五 上午 11:06

function r=incident_degree(x0,x1)
%compute the incident degree for grey model.

�signed by NIXIUHUI,Dalian Fisher University.
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));�lta_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.83 34.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:n
        X_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:n
        X_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:n
    for i=1:1:m
     a(j)=a(j)+X_3(j,i);   %%%%
其实可以直接用sum
    end;
    a(j)=a(j)/m;           %%%%%%%%%
可以改进%%%%%%%%%%

%
end
%a      %
在此可以观测各个学生的序

%改进:如果各个指标的所占权重不一样的话,可以添加相应的权系数

%6 排序
b=a';
[c,s]=sort(b);
for i=1:1:n
    d(i)=i;
end
d=d';
result=[d b c s]

%7 将结果显示出来
figure(1);
plot(a);
figure(2)
bar(a);                  %
柱状图

    最后所得到的结果如图3到图5所示。

 

3 程序运行结果



4 曲线图



5 柱状图

    根据以上三图我们就可以判断出每个学生序列与参考序列(最大值)之间的关系,与最大值的关系越密切,那么其关联度越大。

根据以上的启示,我用matlab灰度关联分析的想法是:

1、参考序列我可以选择已知属于某一类神经元的统计数据,我选择平均值。

2、加入一个未知类的数据,与已有类中的数据一起计算他们与平均值的关联度。

3、计算出来的关联度我们可以有多种处理思路,如果未知类的关联度不是排在最末,可以认为它属于这一类,或者未知类的关联度大于计算出来的关联度平均值,我们可以认为它属于这一类。

    使用关联度进行分类,计算出来的关联度如何使用还是个问题,这个东西是我琢磨出来的,我还没有见到过相关的文献,估计应该可以用,期望以后的专家学者钻研了。

参考文献:

[1] 郝海燕,王斌.大学生综合素质测评的灰色关联分析法[J].承德石油高等专科学校学报,2009,11(2):57-59.

 

 

请教一下用MATLAB实现灰色关联分析的程序

初始矩阵为x=[1.14 1.49 1.69 2.12 2.43 4.32 5.92 6.07 7.85;3.30 3.47 3.61 3.80 4.00 4.19 4.42 4.61 4.80;6.00 6.00 6.00 7.50 7.50 7.50 9.00 9.00 9.00;1.20 1.20 1.80 1.80 1.80 2.40 2.70 3.60 4.00;4.87 5.89 6.76 7.97 8.84 10.05 11.31 12.25 11.64]

 

我写的程序如下:

x1=[1.14 1.49 1.69 2.12 2.43 4.32 5.92 6.07 7.85;3.30 3.47 3.61 3.80 4.00 4.19 4.42 4.61 4.80;6.00 6.00 6.00 7.50 7.50 7.50 9.00 9.00 9.00;1.20 1.20 1.80 1.80 1.80 2.40 2.70 3.60 4.00;4.87 5.89 6.76 7.97 8.84 10.05 11.31 12.25 11.64]%原始数据59

x1=x

for i=1:5

    for j=1:9

  x(i,j)=x(i,j)/x1(1,j)

 end

end

x1=x

for i=1:5

    for j=1:9

  x(i,j)=abs(x(i,j)-x1(i,1))

 end

end

max=x(1,1)

min=x(1,1)

for i=1:5

    for j=1:9

 if x(i,j)>=max

     max=x(i,j)

 end

  end

end

for i=1:5

    for j=1:9

 if x(i,j)<=min

     min=x(i,j)

  end

  end

end

k=0.5 %分辨系数取值

l=(min+k*max)./(x+k*max)%求关联系数矩阵

但是运算错误!!!!

请教一下高手

问题补充:

楼下回答的不对,那样虽不会运行错误,但得不到正确的答案

怎么没人再给我回答啊555555555

 

其他回答 1

4.00;4.87 5.89 6.76 7.97 8.84 10.05 11.31 12.25 11.64]%原始数据59

x1=x %有错,应该为 x=x1

for i=1:5

 

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有