matlab/myNeuralNetworkFunction.m
function [y1] = myNeuralNetworkFunction(x1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 11-Jul-2015 13:41:39.
% 
% [y1] = myNeuralNetworkFunction(x1) takes these arguments:
%   x = 2xQ matrix, input #1
% and returns:
%   y = 1xQ matrix, output #1
% where Q is the number of samples.

%#ok<*RPMT0>

  % ===== NEURAL NETWORK CONSTANTS =====
  
  % Input 1
  x1_step1_xoffset = [-0.29021135;-0.78823662];
  x1_step1_gain = [1.9826979663695;1.11842022338185];
  x1_step1_ymin = -1;
  
  % Layer 1
  b1 = [-1.2522117859338435;0.4967565180494472;0.68619404332689171;-0.30033335846468623;-4.2015999639224724;0.60942699202867956;1.6571600574129681;1.3859044949948669;-3.8163842697962971;1.9156380756689737];
  IW1_1 = [2.9170543783616889 -0.52830128582677205;0.011130398279790645 1.8430411446592063;2.2304352377480252 -3.5804412419555387;-0.92978289791909952 1.531693550587786;1.6047337371656967 4.5656461961825201;2.6211436655104268 -4.6894871037696761;-17.657407266986468 10.059432468602694;-3.025502336584124 1.2541005935686866;2.1448927964398177 4.0094365585556631;-20.169377124550742 11.86690542902943];
  
  % Layer 2
  b2 = 0.59989155821132045;
  LW2_1 = [-3.1959592657421334 -0.92202632779648563 2.7219584531218159 3.2756136431351064 -4.8896329739892321 -1.5643091450871234 -2.6650648326799988 -3.4265413725881495 4.8603179006644748 2.4417594015759798];
  
  % Output 1
  y1_step1_ymin = -1;
  y1_step1_gain = 8.34039570908494;
  y1_step1_xoffset = -0.118081269120729;
  
  % ===== SIMULATION ========
  
  % Dimensions
  Q = size(x1,2); % samples
  
  % Input 1
  xp1 = mapminmax_apply(x1,x1_step1_gain,x1_step1_xoffset,x1_step1_ymin);
  
  % Layer 1
  a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);
  
  % Layer 2
  a2 = repmat(b2,1,Q) + LW2_1*a1;
  
  % Output 1
  y1 = mapminmax_reverse(a2,y1_step1_gain,y1_step1_xoffset,y1_step1_ymin);
end

% ===== MODULE FUNCTIONS ========

% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings_gain,settings_xoffset,settings_ymin)
  y = bsxfun(@minus,x,settings_xoffset);
  y = bsxfun(@times,y,settings_gain);
  y = bsxfun(@plus,y,settings_ymin);
end

% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n)
  a = 2 ./ (1 + exp(-2*n)) - 1;
end

% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings_gain,settings_xoffset,settings_ymin)
  x = bsxfun(@minus,y,settings_ymin);
  x = bsxfun(@rdivide,x,settings_gain);
  x = bsxfun(@plus,x,settings_xoffset);
end
