11.m
上传用户:yetwld
上传日期:2010-01-26
资源大小:82k
文件大小:3k
- data=[-0.22914 -0.059577 -0.88853 -0.25353 -0.28422 0.096958;
- -0.48264 0.63645 0.025257 -0.36327 0.47082 -0.087841;
- -0.4228 0.28586 0.34107 0.048845 -0.76611 0.18407;
- -0.38717 -0.46772 0.14487 -0.23132 -0.089108 -0.74088;
- -0.40248 -0.5382 0.19561 -0.22917 0.24525 0.63041;
- -0.47317 -0.035252 -0.18518 0.83387 0.20625 -0.051838];
- x=data(:,1:5);t=data(:,6);
- c1=x(1:3,:); %初值
- %第一次分类
- for i=1:1:6
- for j=1:1:3
- d1(i,j)=(x(i,:)-c1(j,:))*((x(i,:)-c1(j,:))');
- end
- end
- % x1 d1=[0 1.9658 1.9924;
- % x2 1.9658 0 1.9261;
- % x3 1.9924 1.9261 0
- % x4 1.298 1.5735 1.1445
- % x5 1.7154 1.4841 1.8008
- % x6 1.9779 1.9987 1.9443]
- %类1(x1)
- %类2(x2,x5)
- %类3(x3,x4,x6)
- %中心c1=[-0.22914 -0.059577 -0.88853 -0.25353 -0.28422
- % -0.48264 0.63645 0.025257 -0.36327 0.47082
- % -0.4228 0.28586 0.34107 0.048845 -0.76611]
- %第二次聚类
- %新的中心c
- c2=[x(1,:);0.5*(x(2,:)+x(5,:));(x(3,:)+x(4,:)+x(6,:))./3];
- %c2=[ -0.22914 -0.059577 -0.88853 -0.25353 -0.28422
- % -0.44256 0.049124 0.11043 -0.29622 0.35803
- % -0.42772 -0.072373 0.10025 0.21713 -0.21632]
- %求d2
- for i=1:1:6
- for j=1:1:3
- d2(i,j)=(x(i,:)-c2(j,:))*((x(i,:)-c2(j,:))');
- end
- end
- %x1 d2=[0 1.4696 1.2434
- %x2 1.9658 0.37103 1.3201
- %x3 1.9924 1.4924 0.51694
- %x4 1.298 0.47553 0.37723
- %x5 1.7154 0.37103 0.63896
- %x6 1.9779 1.3956 0.64385]
- %聚类结果
- %类1(x1)
- %类2(x2,x5)
- %类3(x3,x4,x6)
- %
- %可知,c不再变化,故,分类结束
- %
- %最后的结果:c=[ -0.22914 -0.059577 -0.88853 -0.25353 -0.28422
- % -0.44256 0.049124 0.11043 -0.29622 0.35803
- % -0.42772 -0.072373 0.10025 0.21713 -0.21632]
- % 求RBF基函数的宽度delta
- dd2=d2';
- dsum=sum(dd2);
- delta=[dsum(1) 0.5*(dsum(2)+dsum(5)) (dsum(2)+dsum(4)+dsum(6))./3];
- %delta=[2.713 3.1912 3.275]
- %据上述可知,隐含层数(采用高斯核函数)为3,输出层为线性输出
- for j=1:1:3
- for i=1:1:6
- a(j,i)=((x(i,:)-c2(j,:)))*((x(i,:)-c2(j,:))');
- a(j,i)=(-a(j,i)./delta(j));
- end
- end
- P=1:1:6;
- T=t;
- %figure;subplot(2,2,1);plot(P,t);title('待逼近的函数样本点');
- %axis([1,6,-1,1])
- p=a;
- r=radbas(p);
- err_goal=0.99;
- sc=1;
- net=newrb(p,T',err_goal,sc);
- %NEWRB, neurons = 0, SSE = 0.999213
- Y=sim(net,p);
- %axis([1,6,-0.4,0.4]);
- figure;
- plot(P,T,'r');
- hold on;
- plot(P,Y,':*');
- title('RBF网络拟合曲线图11');
- legend('化验值','估计值');
- ylabel('淀粉利用率(%)');
- xlabel('样本个数');
- axis([1,6,-1,1]);