function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 01-Apr-2023 00:29:40.
%
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
%
% X = 1xTS cell, 1 inputs over TS timesteps
% Each X{1,ts} = 4xQ matrix, input #1 at timestep ts.
%
% and returns:
% Y = 1xTS cell of 1 outputs over TS timesteps.
% Each Y{1,ts} = 3xQ matrix, output #1 at timestep ts.
%
% where Q is number of samples (or series) and TS is the number of timesteps.
%#ok
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1.xoffset = [40;20;40;10];
x1_step1.gain = [0.0666666666666667;0.05;0.05;0.1];
x1_step1.ymin = -1;
% Layer 1
b1 = [-2.6491297155389195161;1.760336089106702584;1.6398067063960171108;0.9177075806031128602;-1.4761983536611926748;0.275159870040095067;-1.4879060682820477446;1.9696257706183293301;2.1817650132807728802;3.2407541052221184863];
IW1_1 = [2.9107116995306858698 0.020045809688666926807 -0.7213288732558067462 -0.35355014987443855734;-0.78415290885139299348 2.1620717371802546936 1.9986262152483760257 0.73394638161677838717;-0.60332577542935628134 0.36919294585372963713 0.56789908295376712033 1.8886814261468365395;-0.41372698158378440336 2.07991713220274832 1.8392164942687596607 -0.4149439342002693154;1.8251305698269497668 -1.8100060978190763983 2.1253806758662587839 -0.20297346905145868812;0.72769678044808427941 -0.42294970520998020902 2.5696556898352245213 1.5025226478733253455;-0.54990739957004919347 -1.7497697640971152655 -0.8273354757144428806 0.39315970363298796686;-0.30945750294905238764 -1.8019228954213091232 -2.5111243875575213202 0.079001418949672830294;-1.0691388657257299144 -0.2208636798185789063 1.2120058130665820606 -1.8443207419376965728;2.0156371100772290106 -0.48638781398035080272 -1.0416631454405287371 -1.3136601408706976013];
% Layer 2
b2 = [0.054184247339965789514;-0.28156322626833285572;0.38465049209181595424];
LW2_1 = [0.4627288718431851744 0.41902162291665384641 0.45104963674116588246 -0.18001103631971338004 0.0096271504669345545069 -0.015977183622564644638 0.21048187961321102035 0.21569590240416905425 0.14039680976530213852 -0.1345008801790371078;0.49153199309846229426 0.56057695095383930362 0.020144865726856753252 -0.33262306066701291529 -0.21806490196903238754 0.39032319271931259497 -0.31495042266468115111 0.23252227186432056216 0.056638683994068461658 -0.50313305668003216464;-0.67602621676039309495 -1.5188191954465772859 0.36008657058699833353 1.1291743399777320889 -0.48788206787418042509 0.35182774397824312373 0.56106769711464088424 -0.36218101294025317749 -0.50495893464108454474 0.85467807305577270238];
% Output 1
y1_step1.ymin = -1;
y1_step1.gain = [0.00171526586620926;0.00823045267489712;0.0263157894736842];
y1_step1.xoffset = [890;67;5];
% ===== SIMULATION ========
% Format Input Arguments
isCellX = iscell(X);
if ~isCellX
X = {X};
end
% Dimensions
TS = size(X,2); % timesteps
if ~isempty(X)
Q = size(X{1},2); % samples/series
else
Q = 0;
end
% Allocate Outputs
Y = cell(1,TS);
% Time loop
for ts=1:TS
% Input 1
Xp1 = mapminmax_apply(X{1,ts},x1_step1);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);
% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;
% Output 1
Y{1,ts} = mapminmax_reverse(a2,y1_step1);
end
% Final Delay States
Xf = cell(1,0);
Af = cell(2,0);
% Format Output Arguments
if ~isCellX
Y = cell2mat(Y);
end
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
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)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end