您好,欢迎访问三七文档
clearall;x=[];T=[];x(1)=0.22;k=4;n=900;N=400;%产生logistic序列,前100个去除fori=1:nx(i+1)=k*x(i)*(1-x(i));endX(1:800)=x(101:900);%用X的前400个数据训练RBF神经网络forj=1:NP(1:8,j)=X(j:j+7)';endT=X(9:408);%目标数据net1=newrb(P,T,0.001,1);%训练RBF神经网络N1=300;%选取X的400—700个数据进行RBF神经网络检验forj=1:N1P1(1:8,j)=X(j+400:j+7+400)';endT1=X(409:708);%目标数据%仿真验证a=sim(net1,P1);%对检验数据的预测结果%sim是仿真该网络的意思e=T1-a;%一步预测误差mse=sqrt(e*e')/size(e,2)%均方误差MeanSquareError%画图描绘仿真结果figure(2)plot(X(1:200));axis([1200-0.11.1]);title('logistic混沌序列');xlabel('t');ylabel('magnitude');figure(3)plot(1:300,T1,'b',1:300,a,'r*');h=legend('混沌序列','RBF神经网络一步预测值');axis([1300-0.51.5]);holdontitle('混沌序列与一步预测值');xlabel('t');ylabel('magnitude');figure(4);plot(e,'b-');axis([1300-0.020.02]);title('预测误差e');xlabel('t');ylabel('magnitude');至于你要K均值聚类的话:%一个最基本的rbf算法,学习算法采用伪逆函数%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clearall;closeall;clc;%定义用到的变量r=1;%领域半径,人为设定nodenum=0;%隐层节点数,由实际数据与r共同决定inputdata=[];%输入矩阵inputpath='';%存储原始输入数据的路径nodeout=[];%隐层输入阵netout=[];%网络输出阵weight=[];%输出权值阵,也是唯一的权值inputnum=0;%输入维数outputnum=0;%输出维数center=[];%聚类中心numtrain=0;%学习样本的个数row=0;%学习样本的个数simrow=0;%全部样本的个数numtest=0;%泛化样本的个数strength=1;%归一化处理时用到的范围,一般为1yout=[];%输出的期望值%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%变量的初始化r=1;inputnum=9;inputpath='e:\yinjia\data\yearsun.dat';outputnum=1;simrow=290;source=load(inputpath);%保存一个source的副本,为反归一化做准备copysource=source;%归一化处理source=normalize(source,strength);yout=source(inputnum+1:simrow+inputnum);inputdata=phasespace(source,inputnum,simrow);row=250;numtrain=row;numtest=simrow-row;%把第一人输入变量定为初始的中心%中心的位置在初始化后,不会再变化center=inputdata(1,:)';%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%开始进行简单的聚类%其基本思想是:给定一个固定的邻域半径,在中心点邻域半径内的点就算作%是该邻域的点;半径外的点,取第一个不是半径内的点做为新的中心点%设计一个函数iscenter,来计算一个点是否为中心点。forstep=2:rowifiscenter(inputdata(step,:)',center,r)center=[centerinputdata(step,:)'];nodenum=nodenum+1;end%thisendforiscenter(inputdata(step,:))end%thisendforstep=2:row%聚类完成.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%准备进行神经网络的前向计算[centerrownodenum]=size(center);%网络的初始化nodeout=zeros(row,nodenum);netout=zeros(row,outputnum);weight=zeros(nodenum,outputnum);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%网络的计算forstep=1:rowforstep1=1:nodenumnodeout(step,step1)=GaussRadialBasisFunction(inputdata(step,:)',...center(:,step1),r);end%thisendforstep1=1:nodenumend%thisendforstep=1:row%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%用伪逆来计算权值搜索weight=pinv(nodeout)*yout(1:250);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%进行仿真forstep=1:simrowforstep1=1:nodenumnodeout(step,step1)=GaussRadialBasisFunction(inputdata(step,:)',...center(:,step1),r);end%thisendforstep1=1:nodenumend%thisendforstep=1:simrowmydata=nodeout*weight;%反归一化mydata=unnomal(mydata,copysource,strength);rldata=copysource(inputnum+1:inputnum+simrow);plot(rldata);holdon;plot(mydata,'r');%计算一个评价函数rmsetest=(norm(rldata(numtrain+1:simrow)-mydata(numtrain+1:simrow))...^2/(numtest-1))^0.5
本文标题:RBF预测的程序
链接地址:https://www.777doc.com/doc-5178686 .html