note able to run this program

1 view (last 30 days)
Chiranth N  Raj
Chiranth N Raj on 14 Nov 2022
Edited: Chiranth N Raj on 14 Nov 2022
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 14-Nov-2022 14:03:04.
%
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
%
% X = 1xTS cell, 1 inputs over TS timesteps
% Each X{1,ts} = 6xQ matrix, input #1 at timestep ts.
%
% and returns:
% Y = 1xTS cell of 1 outputs over TS timesteps.
% Each Y{1,ts} = 1xQ matrix, output #1 at timestep ts.
%
% where Q is number of samples (or series) and TS is the number of timesteps.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1.xoffset = [0;0;0;0;0;0];
x1_step1.gain = [2;2;2;2;2;2];
x1_step1.ymin = -1;
% Layer 1
b1 = [-1.5405239961044094876;-1.5273808353399593862;1.3260615608441381763;-1.5672656908495641304;-0.52463531414582453838;-0.28562547291621864787;-0.92600523410297119753;0.94836491891548213573;0.60413286072586980247;1.3812775835551660553;-0.98746545414147057773;1.8537659554345575774];
IW1_1 = [0.694735700484934382 1.0822554083725968166 0.58162355947880228779 -0.03182512671079117117 -0.35594714793451137647 -0.42115056541279694002;1.7126774333679974927 0.38541323476327671305 0.79165816668606570072 -0.58420613872381599307 0.47446011946542465676 -0.77321888761387003175;-0.47022972931769457805 1.3575902664213252979 -0.022964776251181699684 0.98954132183856580163 -1.3141641243687507412 0.26303920875519415379;0.50570618121209287565 -0.021764214642695456359 -0.17241505384885658092 -1.6282392397915912419 0.35958459771516887438 0.65811302429996787478;0.61453749200090124205 -0.58597896420739203904 0.628444680629517749 0.10933592079163188815 0.64514255935658848529 1.6220061225237449865;-0.93738364435824672594 0.32630035707491461539 -0.99320598793569225826 0.62830932212865575615 -1.1012636140809652918 1.2068758779914174895;-0.36250296717830537974 0.94937094400320753973 0.99760130900678023469 0.70186338551042104505 -1.1900576806232499028 -0.210153503141659731;-0.075593817872469382113 0.24277422296966821857 -1.0955800396372881167 1.2464066543147362953 -0.2124800541687666966 -0.78058215295044663939;0.62073106044722403674 0.12362028693823426395 -0.098384844666925347356 -0.63298401375966018012 0.15725136244761661608 -0.11174225226285876278;0.97877205494941077468 -0.49569157152645215714 -1.7661741788009719389 0.76245089960480827429 -0.875109689249058742 -0.47742261438667982221;-0.50331411621013577573 0.87483246760882549253 -1.2072547488793210491 -0.91121672594314229165 0.77339529988332500476 1.6743937944334255086;1.1929761368367524099 0.99724807116224178927 0.72139890919897775579 0.76024416241570236252 -1.2847855749809071746 -0.19326786300070347702];
% Layer 2
b2 = 0.23670804816455365271;
LW2_1 = [0.16518424966462744163 0.060203722234422205051 0.094778695751439587247 0.48904037181873094564 0.027025074991859011214 -0.042606777963060948888 0.23347377085036169486 0.063412372907630298879 0.41374384009683085051 -0.25859598579246850791 0.034358285747008235345 0.12452529500120101957];
% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 435.824798431031;
y1_step1.xoffset = 0.010163;
% ===== 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
Error message
myNeuralNetworkFunction(X, ~, ~)
myNeuralNetworkFunction(X, ~, ~)
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.
myNeuralNetworkFunction1
Not enough input arguments.
Error in myNeuralNetworkFunction1 (line 42)
isCellX = iscell(X);

Answers (1)

Jan
Jan on 14 Nov 2022
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
This means, that the 2nd and 3rd input are ignored. But you cannot call this function as:
[Y,Xf,Af] = myNeuralNetworkFunction(X,~,~) % Failing
but either use 1 input argument only or insert dummy variables:
[Y,Xf,Af] = myNeuralNetworkFunction(X)

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!