Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear;
- % Príklad na aproximáciu nelin. funkcie pomocou NS typu
- % MLP siet s 1 vstupom a 1 výstupom
- clear
- load datafun2
- % vytvorenie štruktúry NS
- % 1 vstup - x suradnica
- % 1 skrytá vrstva s poctom neurónov 25 s funkciou 'tansig'
- % 1 výstup s funkciou 'purelin' - y suradnica
- % trénovacia metóda - Levenberg-Marquardt
- pocet_neuronov=20;
- net=fitnet(pocet_neuronov);
- % % vyber rozdelenia
- net.divideFcn='dividerand'; % náhodné rozdelenie
- % net.divideFcn='divideblock'; % blokove
- % %net.divideFcn='divideint'; % kazdy n-ta vzorka
- % net.divideFcn='dividetrain'; % iba trenovacie
- net.divideParam.trainRatio=0.65;
- net.divideParam.valRatio=0.25;
- net.divideParam.testRatio=0.15;
- % net.divideFcn='divideind'; % indexove
- % net.divideParam.trainInd=indx_train;
- % net.divideParam.valInd=[];
- % net.divideParam.testInd=indx_test;
- % Nastavenie parametrov trénovania
- net.trainParam.goal = 1e-100; % Ukoncovacia podmienka na chybu
- net.trainParam.show = 10; % Frekvencia zobrazovania priebehu chyby trénovania net.trainParam.epochs = 100; % Max. po?et trénovacích cyklov.
- net.trainParam.epochs =1000; % maximalny pocet trenovacich epoch.
- % Trénovanie NS
- net=train(net,x,y);
- % Simulácia výstupu NS
- outnetsim = sim(net,x);
- outnetsim_train = sim(net,x(indx_train));
- outnetsim_test = sim(net,x(indx_test));
- % vypocet chyby siete
- SSE=sum((y-outnetsim).^2)
- MSE=SSE/length(y)
- MAE=mae(y-outnetsim)
- SSE_train=sum((y(indx_train)-outnetsim_train).^2)
- MSE_train=SSE/length(y)
- MAE_train=mae(y(indx_train)-outnetsim_train)
- SSE_test=sum((y(indx_test)-outnetsim_test).^2)
- MSE_test=SSE/length(y)
- MAE_test=mae(y(indx_test)-outnetsim_test)
- % Vykreslenie priebehov
- figure
- hold on
- plot(x,y,'b',x,outnetsim,'-or')
- % figure
- plot(x,y,'b',x(indx_test),outnetsim_test,'xgreen')
- % figure
- plot(x,y,'b',x(indx_train),outnetsim_train,'sblack')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement