Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.65 KB | None | 0 0
  1. %%%%%% LOAD DATA %%%%%%%
  2. matrix = (load('podaci_564.mat').data)';
  3. input = matrix(:, 1:2);
  4. output = matrix(:,3);
  5.  
  6. negative = input(find(output == 0),:);
  7. positive = input(find(output == 1),:);
  8.  
  9. %a - visualize data classes
  10.  
  11. figure('Name', 'Data classes');
  12. %0 - red crosses
  13. plot(negative(:,1), negative(:,2),'r+');
  14. hold on;
  15. %1 - blue circles
  16. plot(positive(:,1), positive(:,2),'bo');
  17. %pause;
  18. hold off;
  19.  
  20. %NOTE - first 450 data samples are class 0 , next 114 are class 1,
  21. %for test randomize data - shuffle
  22. %b  - make test dataset (20% of original size)
  23.  
  24. shuffled_array = randperm(int32((length(input) * 0.2)));
  25. test_input = input(shuffled_array, :);
  26. test_output = output(shuffled_array, :);
  27.  
  28.  
  29. %neural nwtwork creation
  30. first_input_col = input(:,1)';
  31. second_input_col = input(:,2)';
  32. Pr = min_max([first_input_col;second_input_col]);
  33. Ni_1 = [2 3 ];
  34. Ni_2 = [2 3 1];
  35. %output layer is considered as part of hidden layer
  36. %trainlm can produce maximum memory usage problem. Possible solutions:
  37.  
  38. %1.Slow trainlm training, but reduce memory requirements by setting net.trainParam.mem_reduc to 2 or more. (See help trainlm.)
  39. %2.Use trainbfg, which is slower but more memory-efficient than trainlm.-not available
  40. %3.Use trainrp, which is slower but more memory-efficient than trainbfg. -not available
  41.  
  42. net = newff(Pr, Ni_2, {"tansig","purelin","logsig"}, "trainlm", "learngdm", "mse");
  43. net.trainParam.mem_reduc = 2;
  44. net.trainParam.Mu = 0.0001;
  45.  
  46. %Y = sim(net,input');
  47.  
  48. %plot(input,output);
  49. %,input',Y,'o')
  50. %disp(net.inputs.size);
  51. net.trainParam.epochs = 50;
  52. net = train(net,input',output');
  53. #{Y = sim(net,input);
  54. plot(input,output,input,Y,'o')
  55. #}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement