amroamroamro

simulateStandaloneNet.m

Aug 5th, 2014
1,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.96 KB | None | 0 0
  1. function [y1] = simulateStandaloneNet(x1)
  2. %SIMULATESTANDALONENET neural network simulation function.
  3. %
  4. % Generated by Neural Network Toolbox function genFunction.
  5. %
  6. % [y1] = simulateStandaloneNet(x1) takes these arguments:
  7. %   x = 1xQ matrix, input #1
  8. % and returns:
  9. %   y = 1xQ matrix, output #1
  10. % where Q is the number of samples.
  11.  
  12. %#ok<*RPMT0>
  13.  
  14.   % ===== NEURAL NETWORK CONSTANTS =====
  15.  
  16.   % Input 1
  17.   x1_step1_xoffset = 0;
  18.   x1_step1_gain = 0.200475452649894;
  19.   x1_step1_ymin = -1;
  20.  
  21.   % Layer 1
  22.   b1 = [6.0358701949520981;2.725693924978148;0.58426771719145909;-5.1615078566382975];
  23.   IW1_1 = [-14.001919491063946;4.90641117353245;-15.228280764533135;-5.264207948688032];
  24.  
  25.   % Layer 2
  26.   b2 = -0.75620725148640833;
  27.   LW2_1 = [0.5484626432316061 -0.43580234386123884 -0.085111261420612969 -1.1367922825337915];
  28.  
  29.   % Output 1
  30.   y1_step1_ymin = -1;
  31.   y1_step1_gain = 0.2;
  32.   y1_step1_xoffset = 0;
  33.  
  34.   % ===== SIMULATION ========
  35.  
  36.   % Dimensions
  37.   Q = size(x1,2); % samples
  38.  
  39.   % Input 1
  40.   xp1 = mapminmax_apply(x1,x1_step1_gain,x1_step1_xoffset,x1_step1_ymin);
  41.  
  42.   % Layer 1
  43.   a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);
  44.  
  45.   % Layer 2
  46.   a2 = repmat(b2,1,Q) + LW2_1*a1;
  47.  
  48.   % Output 1
  49.   y1 = mapminmax_reverse(a2,y1_step1_gain,y1_step1_xoffset,y1_step1_ymin);
  50. end
  51.  
  52. % ===== MODULE FUNCTIONS ========
  53.  
  54. % Map Minimum and Maximum Input Processing Function
  55. function y = mapminmax_apply(x,settings_gain,settings_xoffset,settings_ymin)
  56.   y = bsxfun(@minus,x,settings_xoffset);
  57.   y = bsxfun(@times,y,settings_gain);
  58.   y = bsxfun(@plus,y,settings_ymin);
  59. end
  60.  
  61. % Sigmoid Symmetric Transfer Function
  62. function a = tansig_apply(n)
  63.   a = 2 ./ (1 + exp(-2*n)) - 1;
  64. end
  65.  
  66. % Map Minimum and Maximum Output Reverse-Processing Function
  67. function x = mapminmax_reverse(y,settings_gain,settings_xoffset,settings_ymin)
  68.   x = bsxfun(@minus,y,settings_ymin);
  69.   x = bsxfun(@rdivide,x,settings_gain);
  70.   x = bsxfun(@plus,x,settings_xoffset);
  71. end
Advertisement
Add Comment
Please, Sign In to add comment