声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4547|回复: 9

[人工智能] 反馈型神经网络理论及MATLAB实现的几个程序

[复制链接]
发表于 2007-6-25 03:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
摘自:神经网络理论与MATLAB7实现

Elman网络设计
  1. p1 = sin(1:20);
  2. p2 = sin(1:20)*2;
  3. t1 = ones(1,20);
  4. t2 = ones(1,20)*2;
  5. %产生训练样本p和t
  6. p = [p1 p2 p1 p2];
  7. t = [t1 t2 t1 t2];
  8. Pseq = con2seq(p);
  9. Tseq = con2seq(t);
  10. R = 1; % 输入元素的数目为1
  11. S2 = 1; % 输出层的神经元个数为1
  12. S1 = 10; %中间层有10个神经元
  13. net=newelm([-2,2],[S1,S2],{'tansig','purelin'});
  14. %设定网络训练次数
  15. net.trainParam.epochs=300;
  16. net=train(net,Pseq,Tseq);
  17. y=sim(net,Pseq);
  18. figure;
  19. plot(t5,cat(2,y{:}),t5,cat(2,Tseq{:}),'b--');
  20. %利用新的信号来测试网络
  21. p3 = sin(1:20)*1.6;
  22. t3 = ones(1,20)*1.6;
  23. p4 = sin(1:20)*1.2;
  24. t4 = ones(1,20)*1.2;
  25. %产生测试样本pg和tg
  26. pg = [p3 p4 p3 p4];
  27. tg = [t3 t4 t3 t4];
  28. pgseq = con2seq(pg);
  29. a = sim(net,pgseq);
  30. figure;
  31. plot(t5,cat(2,a{:}),t5,tg,'b--');
复制代码

[ 本帖最后由 frogfish 于 2007-6-25 03:20 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2007-6-25 03:16 | 显示全部楼层
  1. P=[0.4413 0.4707 0.6953 0.8133 0.4379 0.4677 0.6981 0.8002 0.4517 0.4725 0.7006 0.8201;
  2. 0.4379 0.4677 0.6981 0.8002 0.4517 0.4725 0.7006 0.8201 0.4557 0.4790 0.7019 0.8211;
  3. 0.4517 0.4725 0.7006 0.8201 0.4557 0.4790 0.7019 0.8211 0.4601 0.4811 0.7101 0.8298;]'
  4. T=[0.4557 0.4790 0.7019 0.8211;
  5. 0.4601 0.4811 0.7101 0.8298;
  6. 0.4612 0.4845 0.7188 0.8312]';
  7. 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];
  8. a=[11 17 23];
  9. for i=1:3
  10.     net=newelm(threshold,[a(i),4],{'tansig','purelin'});
  11.     net.trainParam.epochs=1000;
  12.     net=init(net);
  13.     net=train(net,P,T);
  14.     y=sim(net,p_test);
  15.     error(i,:)=y'-t;
  16. end
  17. hold off;
  18. plot(1:4,error(1,:));
  19. hold on;
  20. plot(1:4,error(2,:),'-.');
  21. hold on;
  22. plot(1:4,error(3,:),'--');
  23. hold off;
复制代码
 楼主| 发表于 2007-6-25 03:16 | 显示全部楼层
  1. one=[-1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1  -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1];
  2. two=[1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1];
  3. T=[one;two]';
  4. net=newhop(T);
  5. no2={[1 1 1 -1 1 1 -1 1 -1 -1  1 1 1 1 1 1 1 1 -1 -1  -1 1 -1 1 -1 -1 1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1  1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 -1 1 1 1 1 -1 -1 1 1 -1 1 1 1 1 1 -1 -1]'};
  6. tu2=sim(net,{1,5},{},no2);
  7. tu2{3}'
复制代码
 楼主| 发表于 2007-6-25 03:16 | 显示全部楼层
  1. function c=bsb(x,beta,multi)

  2. % function c=bsb(x,beta)
  3. %
  4. %  This m-file duplicates the Brain State in a Box Experiment.
  5. %    x     - input vector
  6. %    beta  - feedback factor
  7. %    c     - number of iterations required for convergence
  8. %   
  9. % Hugh Pasika 1997

  10. hold on
  11. flag=0;   x=x(:);   c=2; %c is a general purpose counter
  12. W=[.035 -.005; -.005 .035];

  13. set(gca,'YLim',[-1 1]);      set(gca,'XLim',[-1 1])    % set axes

  14. plot(x(1),x(2),'ob')         % plot first point   
  15. orig=x';
  16. plot([0,0],[1,-1],'-');      plot([1,-1],[0,0],'-')     % plot center lines
  17. set(gca,'YTick',[-1  1 ]);   set(gca,'XTick',[-1  1 ])  % label plot

  18. while flag < 1,
  19. y=x+beta*W*x;
  20. x=(y(:,:) < -1 )*(-1) + (y(:,:)>1) + (y(:,:) > -1 & y(:,:) < 1).*y;
  21. u(c,:)=x';
  22. c=c+1;
  23. if u(c-1,:) == u(c-2,:),
  24.    flag=10;
  25.    c=c-3;
  26. end
  27. end
  28. u=u(2:c+1,:);
  29. orig
  30. plot([orig(1,1) u(1,1)], [orig(1,2) u(1,2)],'-b')
  31. plot(u(:,1), u(:,2),'ob')
  32. plot(u(:,1), u(:,2),'-b')
  33. drawnow
  34. fprintf(1,'It took %g iteration for a stable point to be reached.\n\n',c);
  35. set(gca,'Box','on')
  36. hold off
复制代码
发表于 2007-7-1 13:22 | 显示全部楼层
谢谢~~:loveliness:
发表于 2009-3-17 20:34 | 显示全部楼层
楼主辛苦:handshake
发表于 2009-3-18 22:29 | 显示全部楼层
请问第一个程序的t5变量在哪定义的?
发表于 2009-3-29 16:59 | 显示全部楼层
谢谢了!楼主辛苦了!
发表于 2009-5-12 16:57 | 显示全部楼层
发表于 2012-7-30 11:38 | 显示全部楼层
为什么该程序一运行就显示“??? Error using ==> feedback at 72
Not enough input arguments. ”
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-6 02:01 , Processed in 0.073782 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表