摘自:神经网络理论与MATLAB7实现
Elman网络设计
- p1 = sin(1:20);
- p2 = sin(1:20)*2;
- t1 = ones(1,20);
- t2 = ones(1,20)*2;
- %产生训练样本p和t
- 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=300;
- net=train(net,Pseq,Tseq);
- y=sim(net,Pseq);
- figure;
- plot(t5,cat(2,y{:}),t5,cat(2,Tseq{:}),'b--');
- %利用新的信号来测试网络
- p3 = sin(1:20)*1.6;
- t3 = ones(1,20)*1.6;
- p4 = sin(1:20)*1.2;
- t4 = ones(1,20)*1.2;
- %产生测试样本pg和tg
- pg = [p3 p4 p3 p4];
- tg = [t3 t4 t3 t4];
- pgseq = con2seq(pg);
- a = sim(net,pgseq);
- figure;
- plot(t5,cat(2,a{:}),t5,tg,'b--');
复制代码
[ 本帖最后由 frogfish 于 2007-6-25 03:20 编辑 ]本文内容由 frogfish 提供 |