建模1.asv
上传用户:yetwld
上传日期:2010-01-26
资源大小:82k
文件大小:3k
源码类别:

TAPI编程

开发平台:

Matlab

  1. data=[-0.22914 -0.059577 -0.88853 -0.25353 -0.28422 0.096958;
  2. -0.48264 0.63645 0.025257 -0.36327 0.47082 -0.087841;
  3. -0.4228 0.28586 0.34107 0.048845 -0.76611 0.18407;
  4. -0.38717 -0.46772 0.14487 -0.23132 -0.089108 -0.74088;
  5. -0.40248 -0.5382 0.19561 -0.22917 0.24525 0.63041;
  6. -0.47317 -0.035252 -0.18518 0.83387 0.20625 -0.051838];
  7. x=data(:,1:5);t=data(:,6);
  8. c1=x(1:3,:);  %初值
  9. %第一次分类
  10. for i=1:1:6
  11.      for j=1:1:3
  12.     d1(i,j)=(x(i,:)-c1(j,:))*((x(i,:)-c1(j,:))');
  13. end
  14. end
  15. % x1   d1=[0    1.9658  1.9924;     
  16.  % x2    1.9658 0      1.9261;
  17.  % x3    1.9924 1.9261   0
  18.  % x4    1.298 1.5735  1.1445
  19.  % x5    1.7154 1.4841  1.8008
  20.  % x6    1.9779 1.9987  1.9443]     
  21. %类1(x1)
  22. %类2(x2,x5)
  23. %类3(x3,x4,x6)
  24. %中心c1=[-0.22914  -0.059577  -0.88853  -0.25353  -0.28422
  25. %       -0.48264 0.63645    0.025257    -0.36327    0.47082
  26. %       -0.4228     0.28586    0.34107    0.048845    -0.76611]
  27. %第二次聚类
  28. %新的中心c
  29. c2=[x(1,:);0.5*(x(2,:)+x(5,:));(x(3,:)+x(4,:)+x(6,:))./3];
  30. %c2=[ -0.22914   -0.059577  -0.88853  -0.25353  -0.28422
  31. %     -0.44256   0.049124  0.11043     -0.29622   0.35803
  32. %    -0.42772   -0.072373   0.10025   0.21713 -0.21632]
  33. %求d2
  34. for i=1:1:6
  35.      for j=1:1:3
  36.     d2(i,j)=(x(i,:)-c2(j,:))*((x(i,:)-c2(j,:))');
  37. end
  38. end
  39. %x1      d2=[0     1.4696   1.2434
  40. %x2          1.9658 0.37103   1.3201
  41. %x3          1.9924 1.4924   0.51694
  42. %x4          1.298 0.47553   0.37723
  43. %x5          1.7154 0.37103   0.63896
  44. %x6          1.9779 1.3956   0.64385]
  45. %聚类结果
  46. %类1(x1)
  47. %类2(x2,x5)
  48. %类3(x3,x4,x6)
  49. %
  50. %可知,c不再变化,故,分类结束
  51. %
  52. %最后的结果:c=[ -0.22914   -0.059577  -0.88853  -0.25353  -0.28422
  53. %                -0.44256   0.049124  0.11043     -0.29622   0.35803
  54. %                -0.42772   -0.072373   0.10025   0.21713 -0.21632]
  55. %  求RBF基函数的宽度delta
  56. dd2=d2';
  57. dsum=sum(dd2);
  58. delta=[dsum(1) 0.5*(dsum(2)+dsum(5)) (dsum(2)+dsum(4)+dsum(6))./3];
  59. %delta=[2.713 3.1912 3.275]
  60. %据上述可知,隐含层数(采用高斯核函数)为3,输出层为线性输出
  61. for j=1:1:3
  62. for i=1:1:6
  63. a(j,i)=((x(i,:)-c2(j,:)))*((x(i,:)-c2(j,:))');
  64.     a(j,i)=exp(-a(j,i)./delta(j));
  65. end
  66. end
  67. %
  68. lr=0.001;max_epoch=500;err_goal=0.99;
  69. w=0.5*rands(3,1);
  70. y=a'*w;
  71. E=t-y;
  72. SSE=sumsqr(E);
  73. for epoch=1:1:max_epoch
  74.     if SSE<err_goal,epoch=epoch-1;break,end
  75.     w=w+lr*a*E;
  76.     y=a'*w;
  77.     E=t-y;
  78.     SSE=sumsqr(E);
  79. end
  80. y=a'*w;
  81. %标准化处理
  82. %ymax=max(y);
  83. %ymin=min(y);
  84. %i=ones(6,1);
  85. %y=0.9*i-0.8*(i*ymax-y)./(i*(ymax-ymin));
  86. %
  87. figure;
  88. plot(t,'r');
  89. hold on;
  90. plot(y,':*');
  91. title('RBF网络拟合曲线图');
  92. legend('化验值','估计值');
  93. ylabel('淀粉利用率(%)');
  94. xlabel('样本个数');
  95. axis([1,6,-1,1]);