LSTM in App Designer: predictAndUpdateState Error

for i = 1:app.count
net = networks{i};
temp = dataStandardized{i};
XTrain = temp(1:app.Timer.TasksExecuted-2);
YTrain = temp(2:app.Timer.TasksExecuted-1);
net = predictAndUpdateState(net,XTrain);
[net,YPred] = predictAndUpdateState(net,YTrain(end));
[net,YPred(:,app.Timer.TasksExecuted)] = predictAndUpdateState(net,YPred(:,app.Timer.TasksExecuted-1),'ExecutionEnvironment','cpu');
%Unstandardize the predictions
YPred = app.sig{app.idxFailDs(i)}.*YPred + app.mu{app.idxFailDs(i)};
app.C(app.idxFailDs(i)) = YPred;
app.EditField.Value = "Predicted for "+ app.count +".";
app.Lamp.Color = [1 1 0];
end
I have trained several LSTM networks stored in a cell array and being called in the loop, one at a time.
However the code is not running as I want to and the Command Window says to the effect that the function predictAndUpdateState is not defined for type double arguments.
But the arguments of type double arrays in the network were tested by me in a separate live script; working perfectly fine.
Please suggest a solution for using my LSTM networks in App Designer.

 Accepted Answer

The error doens't necessarily mean it cannot work with double type parameters. I may also be that it cannot find the function. Make sure the function def file is in the same directory as the app you are creating in app designer. You may check visibility of the file using which()
>> which predictAndUpdateState

14 Comments

Thanks @cr. I copied the folder named '@DAGNetwork' from my installation directory to the same folder as the app, but now the Command Window says ''Unrecognized method, property, or field ''predictAndUpdateState' for class 'AppName'.
PS: I had these networks predicting just fine in live script without the need of copying the functions' folder into my root directory. The problem is just coming app for the app implementation ...
Not sure what @DAGNetwork contains, but presuming it has predictAndUpdateState. If it is not on path it explains the problem. Can't comment on the behaviour without seeing the live script and app programme.
@cr, yes '@DAGNetwork' contains the predictAndUpdateState function (.m file). As I stated earlier, I have copied the folder to the current path (same folder as my app), but a new error prompt, as stated earlier, is showing up.
@cr As for the live script, it's identical to that given in this example. I adapted this for multiple networks using for loops and cell arrays...
My app code is in OP.
What is the output of which() as asked earlier?
It was the path to the @DAGNetwork folder in my C drive (where MATLAB's installed).
for i = 1:length(idxFailDs)
YPred =[];
net = networks{i};
temp = dataStandardized{i};
dataBF = temp(1:timeStepfail(i)-1);
dataAF = temp(timeStepfail(i):end);
XBF = dataBF(1:end-1);
YBF = dataBF(2:end);
XAF = dataAF(1:end-1);
net = predictAndUpdateState(net,XBF);
[net,YPred] = predictAndUpdateState(net,YBF(end));
[net,YPred] = predictAndUpdateState(net,XAF(1));
numTimeStepsTest = numel(XAF);
for j = 2:numTimeStepsTest
[net,YPred(:,j)] = predictAndUpdateState(net,YPred(:,j-1),'ExecutionEnvironment','cpu');
end
%Unstandardize the predictions
YPred = sig{idxFailDs(i)}.*YPred + mu{idxFailDs(i)};
C(idxFailDs(i), timeStepfail(i)+1:180) = YPred;
end
This is the code that runs perfectly fine in my live script. However, now when implementing in the app (without using timer) I am getting these errors:
Error using nnet.internal.cnn.util.PredictionDataErrorThrower/throwXIsNotValidSequenceInput
Invalid prediction data. Predictors must be a N-by-1 cell array of sequences, where N is the number of sequences. All
sequences must have the same feature dimension and at least one time step.
Error in nnet.internal.cnn.data.SequenceInputDataValidator/assertValidSequenceInput (line 53)
errorStrategy.throwXIsNotValidSequenceInput()
Error in nnet.internal.cnn.data.SequenceInputDataValidator/validateArrayOrCell (line 48)
this.assertValidSequenceInput(X,inputSize,errorStrategy);
Error in nnet.internal.cnn.data.SequenceInputDataValidator/validateArray (line 22)
this.validateArrayOrCell(x,errorStrategy);
Error in nnet.internal.cnn.data.ArrayValidator/validatePredictionDataAndNetwork (line 35)
inputLayerValidator{1}.validateArray(X,this.ErrorStrategy);
Error in nnet.internal.cnn.data.validatePredictionData>iValidateData (line 62)
dataValidator.validatePredictionDataAndNetwork(X,inputLayerValidator);
Error in nnet.internal.cnn.data.validatePredictionData (line 45)
iValidateData(X,errorStrategy,inputLayerValidator);
Error in DAGNetwork/predictAndUpdateState (line 151)
nnet.internal.cnn.data.validatePredictionData(X,this.PrivateNetwork.InputLayers);
Error in SeriesNetwork/predictAndUpdateState (line 444)
[this.UnderlyingDAGNetwork, Y] = this.UnderlyingDAGNetwork.predictAndUpdateState(X, varargin{:});
Looks like your error of "function not defined" is now resolved.
It looks like your data is not consistent with expectations of the function. It's sometimes confusing when the training data should be Nx1 or 1xN. Try transposing it and see if that was the problem. Can't really tell where the problem lies without having a way to reproduce the problem.
The strange thing's that the same data used in a live script gives no issues. Only the app implementation ensues errors...
Think I will have to go without showcasing in an app : ( ...
Transposing didn't help. Errors still coming up in the app...
Turn the script into a function and see if calling/running it results in errors. If it does, I'm guessing some variables are getting overwritten incorrectly or not ovewritten correctly in the app while it happens in script. Or perhaps some data is not available inside app. Did you initialise/load all data in the app? Are there any global variables in your workflow?
I used the refactor option to convert the working live script to a function. It is working fine as well.
Calling the function in the app is working out. Can you please post that as an answer so that I can acknowledge you.
cr
cr on 19 Nov 2022
Edited: cr on 19 Nov 2022
Cool. You may just accept this answer. Thanks for confirming.

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 13 Nov 2022

Edited:

cr
on 19 Nov 2022

Community Treasure Hunt

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

Start Hunting!