怎样在matlab中建立elman神经网络?

2025-04-25 10:24:16
推荐回答(2个)
回答1:

t=1:20;
p1=sin(t);
p2=sin(t)*2;
plot(t,p1,'r');
hold on
plot(t,p2,'b--');
hold on
t1=ones(1,20);t2=ones(1,20)*2;%产生两组向量,分别为这两波形幅值,作为输出向量
p=[p1 p2 p1 p2];
t=[t1 t2 t1 t2];
Pseq=con2seq(p);%将矩阵形式的训练样本转换为序列的形式
Tseq=con2seq(t);
R=1;%输入元素的数目为1
S2=1;%输出曾的神经元个数为1
S1=10;%中间层有10个神经元
net=newelm([-2,2],[S1,S2],{'tansig','purelin'});
net.trainParam.epochs=100;%设定次数
net=train(net,Pseq,Tseq);
y=sim(net,Pseq);
%预测
P=randn(12,2);T=randn(12,2);
threshold=[0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1];
a=[11 17 23];
for i=1:3
net=newelm(threshold,[a(i),4],{'tansig','purelin'});
net.trainParam.epochs=1000;
net=init(net);
net=train(net,P,T);
y=sim(net,p_test);
error(i,:)=y'-t;
end
hold off;
plot(1:4,error(1,:));
hold on;
plot(1:4,error(2,:),'-.');
hold on;
plot(1:4,error(3,:),'--');
hold off;

回答2:

123