Advertisement
desdemona

nauka sieci

Apr 15th, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.45 KB | None | 0 0
  1. n = -5:0.1:5;
  2.  
  3. %plot(n, hardlim(n));
  4.  
  5. %n = -5:0.1:5;
  6. %plot(n, purelin(n));
  7. %plot(n, tansig(n));
  8.  
  9. %n = -5:0.1:5;
  10. %plot(n, logsig(n));
  11.  
  12. %pojedynczy neuron, 2 wejscia
  13. % + jedno wejscie jest stale
  14.  
  15. %argumenty newp:
  16. %zakresy danych wejsciowych
  17. %ilosc neuronow
  18. %funkcja
  19. %net = newp([-2 2; -2 2 ], 1, 'hardlim');
  20. %net = newp([-2 2; -2 2 ], 1, 'logsig');
  21. %net = newp([-2 2; -2 2 ], 1, 'purelin');
  22. %net = newp([-2 2; -2 2 ], 1, 'tansig');
  23.  
  24. %net = newp([-2 2; -2 2 ], 1, 'hardlim');
  25. %net.IW{1, 1} = [ 1 1 ];
  26. %IW input wieght
  27. %pierwsza warstwa 4 neurony, druga 1
  28. %net=newff([0 3; 0 3 ], [ 4, 1 ], {'hardlim', 'hardlim'});
  29. net=newff([0 5; 0 5 ], [ 3, 1 ], {'hardlim', 'hardlim'});
  30. net.IW{1,1}= [-1 -3;-1 1; 3 1];
  31. net.b{1}=[13; 1; -7];
  32. net.LW{2,1}=[1,1,1];
  33. %druga warstwa waga
  34. net.b{2}=[-2.5];
  35. %net.b{1} = -1;
  36. %podanie wagi dla wejscia stalego (wyraz wolny)
  37. [ X Y ] = meshgrid(0:0.1:5);
  38. Z = X;
  39. %2 argumenty, siec i dane wejsciowe
  40. Z(:) = sim(net, [X(:)'; Y(:)']);
  41. surf(X,Y,Z);
  42.  
  43. %za po moca pojedynczego neurona mozna zroibc linowy podzial przestrzeni
  44.  
  45. %dzielmy tak, zeby kwadrat mial 1 a reszta plaszczyzny 0
  46.  
  47. x=-1:0.05:1;
  48. x2=-1:0.01:1;
  49. y=sin(3*pi*x).^(2).*sin(pi*x);
  50. y2=sin(3*pi*x2).^(2).*sin(pi*x2);
  51.  
  52. net=newff([-1 1],[30 1], {'tansig' 'purelin'}, 'trainlm');
  53. net.trainParam.epochs=500;
  54. net.trainParam.show=50;
  55. net.trainParam.goal=0.0000001;
  56. net=init(net);
  57. net=train(net, x, y);
  58. z = sim(net, x2);
  59. plot(x2, y2, 'r', x ,y, 'gO', x2, z, 'b');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement