对向传播神经网络预测问题
我在应用对向传播神经网络(counter propagation network)预测信号时,常出现问题。比如当预测周期的正弦信号时,好像趋势比较好,但是当用衰减信号进行测试时,就没有衰减趋势,只能预测出等幅值的周期信号,不知是哪里出现错误了,请高手帮我看看。function =CPN_learn(inputdata,numhid,numout,outdata) %%进行数据的训练
=size(inputdata);
W=rands(numhid,numfeat)/2;
V=rands(numout,numhid)/2;
=size(outdata);
T=outdata;
T_out=T;
P=inputdata;
%设定学习步骤为1000
% epoch=1000;
%归一化输入向量P
for i=1:numsample
if P(i,:)==zeros(1,numfeat)
P(i,:)=P(i,:);
else
P(i,:)=P(i,:)/norm(P(i,:));
end
end
%开始训练
% while epoch>0
for epoch=1:1000
for j=1:numsample
%%归一化正向权值W
for i=1:numhid
W(i,:)=W(i,:)/norm(W(i,:));
s(1,i)=P(j,:)*W(i,:)';
end
%%求输出为最大的神经元,即为获胜的神经元
temp=max(s);
for i=1:numhid
if temp==s(i);
count=i;
end
end
%%%将所有竞争层神经元的输出置0
for i=1:numhid
s(i)=0;
end
%%将获胜神经元的输出置为1
s(count)=1;
alpha=1/((epoch+1)^2);
beita=1/((epoch+1)^2);
% alpha=0.1*(1-epoch/1000);
% beita=0.1*(1-epoch/1000);
%%权值调整
W(count,:)=W(count,:)+alpha*(P(j,:)-W(count,:));
W(count,:)=W(count,:)/norm(W(count,:));
V(:,count)=V(:,count)+beita*(T(j,:)'-T_out(j,:)');
%%计算网络输出
T_out(j,:)=V(:,count)';
end
delta=T(:,1)'-T_out(:,1)';
error=sqrt((sum(delta.^2)/numsample));
wucha(epoch,1)=error;
if error<10^-1
break;
end
end
hiddenweight=W;
outweight=V;
% numsampnode=numiter;
trainout=T_out;
err=wucha;
return;
%%
function predictdata=CPN_predict(W,V,data)%%进行数据的预测
%%网络输出
% Outc=0;
% countp=1;
=size(data);
%归一化输入向量P
for i=1:numsample
if data(i,:)==zeros(1,numfeat)
data(i,:)=data(i,:);
else
data(i,:)=data(i,:)/norm(data(i,:));
end
end
=size(W);
for j=1:numsample
for i=1:numhid
sc(i)=data(j,:)*W(i,:)';
end
tempc=max(sc);
for i=1:numhid
if tempc==sc(i)
countp=i;
end
sc(i)=0;
end
% posi=find(sc==tempc);
% countp=posi;
sc(countp)=1;
Outc=V(:,countp)';
end
predictdata=Outc;
%%
%%%对衰减信号进行预测的程序
t=0:0.001:1;
y=1.*exp(-0.02*150.*t).*sin(sqrt(0.9996)*150.*t+pi/2);%+...
% 2.*exp(-0.01*350.*t).*sin(sqrt(0.9999)*350.*t+pi/2);
figure(1)
subplot(2,1,1)
plot(y)
n=length(y);
y1=y(1:1000);
subplot(2,1,2)
plot(y1)
numFeat=11;numOut=1;
N=numFeat;
for i=1:1000-N*6
inputx(i,:)=y1(i:6:i+(N-1)*6);
inputy(i)=y1(i+N*6);
end
data=inputx(1:600,:);
supervisor=inputy(1:600)';
%%%未改进的
W = CPNkron_Learn(data,40);
=CPNgros_learn(data,W,1,supervisor);
% %%%进行数据的预测
% % predtest=y(400-N+1:400);
predtest=inputx(1:934,:);
% for i=1:400
% currentData=predtest;
% predictdata(1,i) = CPN_predict(W,V,predtest);
% predtest=;
% end
for i=1:934
predictdata(1,i)=CPN_predict(W,V,predtest(i,:));
end
%%测试结果进行比较
figure(2)
% plot(1:1000,y(1:1000));
plot(inputy)
hold on
% plot(401:800,predictdata,'r-.')
plot(1:934,predictdata,'r-.')
页:
[1]