function [wf,MAE,RMSE,MRE]=SubclustKMeanRBFSamExtRegTimeCPerr( ) clc; close all; clear; data=xlsread('trainingdata.xlsx','processed data'); A=xlsread('trainingdata.xlsx','sample selection'); B=xlsread('trainingdata.xlsx','test sample number'); SamTrainNum=A(:,1); SamTestNum=B(:,1); %-----------数据归一化------------% data1=[data(:,1:4) data(:,6)]'; [data2,PS]=mapminmax(data1,0,1); data=data2'; %-----------------------------------% %选择训练样本和测试样本% % Z=randperm(61); % Trrand=Z(1:51); % Terand=Z(52:61); train=data(SamTrainNum,:); test=data(SamTestNum,:); %-----------------------------------% [Clust]=subclust(train,0.45);%减聚类,确定节点数及中心 [A B]=size(Clust); SamNum=51; %训练样本个数 TestSamNum=10; %测试样本个数 Overlap=1; % %输入输出矩阵 %训练数据 SamIn=train(:,1:4)'; SamOut=train(:,5)'; %预测数据 TestSamIn=test(:,1:4)'; TestSamOut=test(:,5)'; %节点数 InDim=4; %输入节点 ClusterNum=A; %隐含节点 %K-均值聚类 [IDX,C,sumd,D]=kmeans(SamIn',A,'start',Clust(:,1:4)) %sumd是在一个聚类内部,所有点到中心的聚类和 %D所有点到k个聚类中心的距离 %计算各隐层结点的扩展常数 Centers=C'; AllDistances=dist(Centers',Centers); Maximun=max(max(sumd)); for i=1:ClusterNum AllDistances(i,i)=Maximun+1; end Spreads=Overlap*min(AllDistances)'; %用最小二乘法得到权值 Distance=dist(Centers',SamIn); SpreadsMat=repmat(Spreads,1,SamNum); HiddenUnitOut=radbas(Distance./SpreadsMat); HiddenUnitOutEx=[HiddenUnitOut' ones(SamNum,1)]'; W2Ex=SamOut*pinv(HiddenUnitOutEx); W2=W2Ex(:,1:ClusterNum); B2=W2Ex(:,ClusterNum+1); %预测数据输出 TestDistance=dist(Centers',TestSamIn); TestSpreadsMat=repmat(Spreads,1,TestSamNum); TestHiddenUnitOut=radbas(TestDistance./TestSpreadsMat); %高斯函数,距离除以宽度,使用的是指数转移函数 [n2,m2]=size(TestSamIn); for i=1:m2 TestNNOut(:,i)=W2*TestHiddenUnitOut(:,i)+B2; end %反归一化 ReMapTest=mapminmax('reverse',[ TestSamIn TestNNOut ],PS); TestNNOut=ReMapTest( 5, : ); ReMapSam=mapminmax('reverse',[ TestSamIn TestSamOut ],PS); TestSamOut=ReMapSam( 5, : ); %平均绝对误差 Y=[TestNNOut -TestSamOut]; Ycha=sum(Y); MAE=mean (abs(Ycha)) %误差均方根 RMSE=sqrt(mean(Ycha.^2)) %平均相对误差 MRE=mean(abs(Ycha./TestSamOut)) R=corrcoef(TestNNOut,TestSamOut) A=sum(abs(TestNNOut-mean(TestNNOut))+abs(TestSamOut-mean(TestNNOut))).^2 WIA=1-mean(sum(TestNNOut-TestSamOut).^2)/A % PE=RMSE./mean(TestSamOut) f=figure('Visible','on'); plot(TestNNOut,'-r*'); hold on plot(TestSamOut,':go'); legend('模拟预测值','真实值') hold off wf=webfigure(f); end %---------------------------------------以上------------------------%