Advertisement
Guest User

Untitled

a guest
Mar 17th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. W1=net.IW{1,1};
  2. W2=net.LW{2,1};
  3. b1=net.b{1,1};
  4. b2=net.b{2,1};
  5.  
  6. % Solve a Pattern Recognition Problem with a Neural Network
  7. % Script generated by NPRTOOL
  8. % Created Tue May 22 22:05:57 CEST 2012
  9. %
  10. % This script assumes these variables are defined:
  11. %
  12. % input - input data.
  13. % target - target data.
  14. inputs = input;
  15. targets = target;
  16.  
  17. % Create a Pattern Recognition Network
  18. hiddenLayerSize = 10;
  19. net = patternnet(hiddenLayerSize);
  20.  
  21. % Choose Input and Output Pre/Post-Processing Functions
  22. % For a list of all processing functions type: help nnprocess
  23. net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
  24. net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
  25.  
  26.  
  27. % Setup Division of Data for Training, Validation, Testing
  28. % For a list of all data division functions type: help nndivide
  29. net.divideFcn = 'dividerand'; % Divide data randomly
  30. net.divideMode = 'sample'; % Divide up every sample
  31. net.divideParam.trainRatio = 70/100;
  32. net.divideParam.valRatio = 15/100;
  33. net.divideParam.testRatio = 15/100;
  34.  
  35. % For help on training function 'trainlm' type: help trainlm
  36. % For a list of all training functions type: help nntrain
  37. net.trainFcn = 'trainlm'; % Levenberg-Marquardt
  38.  
  39. % Choose a Performance Function
  40. % For a list of all performance functions type: help nnperformance
  41. net.performFcn = 'mse'; % Mean squared error
  42.  
  43. % Choose Plot Functions
  44. % For a list of all plot functions type: help nnplot
  45. net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
  46. 'plotregression', 'plotfit'};
  47.  
  48.  
  49. % Train the Network
  50. [net,tr] = train(net,inputs,targets);
  51.  
  52. % Test the Network
  53. outputs = net(inputs);
  54. errors = gsubtract(targets,outputs);
  55. performance = perform(net,targets,outputs)
  56.  
  57. % Recalculate Training, Validation and Test Performance
  58. trainTargets = targets .* tr.trainMask{1};
  59. valTargets = targets .* tr.valMask{1};
  60. testTargets = targets .* tr.testMask{1};
  61. trainPerformance = perform(net,trainTargets,outputs)
  62. valPerformance = perform(net,valTargets,outputs)
  63. testPerformance = perform(net,testTargets,outputs)
  64.  
  65. % View the Network
  66. view(net)
  67.  
  68. % Plots
  69. % Uncomment these lines to enable various plots.
  70. %figure, plotperform(tr)
  71. %figure, plottrainstate(tr)
  72. %figure, plotconfusion(targets,outputs)
  73. %figure, ploterrhist(errors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement