Advertisement
Guest User

aproximuj funkciu.m

a guest
Mar 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.90 KB | None | 0 0
  1. clc;
  2. clear;
  3. % Príklad na aproximáciu nelin. funkcie pomocou NS typu
  4. % MLP siet s 1 vstupom a 1 výstupom
  5. clear
  6. load datafun2
  7.  
  8. % vytvorenie štruktúry NS
  9. % 1 vstup - x suradnica
  10. % 1 skrytá vrstva s poctom neurónov 25 s funkciou 'tansig'
  11. % 1 výstup s funkciou 'purelin' - y suradnica
  12. % trénovacia metóda - Levenberg-Marquardt
  13. pocet_neuronov=20;
  14. net=fitnet(pocet_neuronov);
  15.  
  16. % % vyber rozdelenia
  17. net.divideFcn='dividerand'; % náhodné rozdelenie
  18.  
  19. % net.divideFcn='divideblock'; % blokove
  20.  
  21. % %net.divideFcn='divideint';  % kazdy n-ta vzorka
  22.  
  23. % net.divideFcn='dividetrain';  % iba trenovacie
  24.  
  25.  net.divideParam.trainRatio=0.65;
  26.  net.divideParam.valRatio=0.25;
  27.  net.divideParam.testRatio=0.15;
  28.  
  29.  
  30. % net.divideFcn='divideind';      % indexove
  31. % net.divideParam.trainInd=indx_train;
  32. % net.divideParam.valInd=[];
  33. % net.divideParam.testInd=indx_test;
  34.  
  35.  
  36. % Nastavenie parametrov trénovania
  37. net.trainParam.goal = 1e-100;     % Ukoncovacia podmienka na chybu
  38. net.trainParam.show = 10;        % Frekvencia zobrazovania priebehu chyby trénovania net.trainParam.epochs = 100;  % Max. po?et trénovacích cyklov.
  39. net.trainParam.epochs =1000;      % maximalny pocet trenovacich epoch.
  40. % Trénovanie NS
  41.  
  42. net=train(net,x,y);
  43. % Simulácia výstupu NS
  44. outnetsim = sim(net,x);
  45. outnetsim_train = sim(net,x(indx_train));
  46. outnetsim_test = sim(net,x(indx_test));
  47.  
  48. % vypocet chyby siete
  49.  
  50. SSE=sum((y-outnetsim).^2)
  51. MSE=SSE/length(y)
  52. MAE=mae(y-outnetsim)
  53.  
  54. SSE_train=sum((y(indx_train)-outnetsim_train).^2)
  55. MSE_train=SSE/length(y)
  56. MAE_train=mae(y(indx_train)-outnetsim_train)
  57.  
  58. SSE_test=sum((y(indx_test)-outnetsim_test).^2)
  59. MSE_test=SSE/length(y)
  60. MAE_test=mae(y(indx_test)-outnetsim_test)
  61.  
  62.  
  63. % Vykreslenie priebehov
  64. figure
  65. hold on
  66. plot(x,y,'b',x,outnetsim,'-or')
  67. % figure
  68. plot(x,y,'b',x(indx_test),outnetsim_test,'xgreen')
  69. % figure
  70. plot(x,y,'b',x(indx_train),outnetsim_train,'sblack')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement