SHARE
TWEET

Untitled

a guest May 12th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [networkHistory trReport] = ann_training(learningRate, noHiddenNeurons, noEpochs)
  2.  
  3. [tvec tlab tstv tstl] = readSets();
  4. tlab += 1;
  5. tstl += 1;
  6.  
  7. rand();
  8. %rndstate = rand("state");
  9. %save rndstate.txt rndstate;
  10. load rndstate.txt;
  11. rand("state", rndstate);
  12.  
  13. network = crann([columns(tvec) noHiddenNeurons numel(unique(tlab))]);
  14. trainCorrect = zeros(1, noEpochs);
  15. testCorrect = zeros(1, noEpochs);
  16. trReport = [];
  17. for epoch=1:noEpochs
  18.     tic();
  19.     terr = 0;
  20.     for i=1:rows(tvec)
  21.         [network terrN] = backprop(tvec(i, :), tlab(i, :), network, learningRate);
  22.         terr += terrN;
  23.     end
  24.     terr /= rows(tvec);
  25.     clsRes = anncls(tvec, network);
  26.     cfmx = confMx(tlab, clsRes);
  27.     errcf = compErrors(cfmx);
  28.     trainCorrect(epoch) = 1-errcf(2);
  29.  
  30.     clsRes = anncls(tstv, network);
  31.     cfmx = confMx(tstl, clsRes);
  32.     errcf2 = compErrors(cfmx);
  33.     testCorrect(epoch) = 1-errcf2(2);
  34.     epochTime = toc();
  35.     disp([epoch epochTime terr trainCorrect(epoch) testCorrect(epoch)])
  36.     trReport = [trReport; epoch epochTime terr trainCorrect(epoch) testCorrect(epoch)];
  37.     fflush(stdout);
  38.   networkHistory{epoch} = network;
  39.     %learningRate = learningRate / epoch;
  40. endfor
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top