11.m
上传用户: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)=(-a(j,i)./delta(j));
  65. end
  66. end
  67. P=1:1:6;
  68. T=t;
  69. %figure;subplot(2,2,1);plot(P,t);title('待逼近的函数样本点');
  70. %axis([1,6,-1,1])
  71.   p=a;
  72.  r=radbas(p);
  73.  err_goal=0.99;
  74.  sc=1;
  75.  net=newrb(p,T',err_goal,sc);
  76. %NEWRB, neurons = 0, SSE = 0.999213
  77. Y=sim(net,p);
  78. %axis([1,6,-0.4,0.4]);
  79. figure;
  80. plot(P,T,'r');
  81. hold on;
  82. plot(P,Y,':*');
  83. title('RBF网络拟合曲线图11');
  84. legend('化验值','估计值');
  85. ylabel('淀粉利用率(%)');
  86. xlabel('样本个数');
  87. axis([1,6,-1,1]);