55 views (last 30 days)
Show older comments
massimo giannini on 10 Aug 2024 at 12:00
Commented: massimo giannini on 12 Aug 2024 at 13:31
Accepted Answer: Jaimin
- dati_net.mat
Open in MATLAB Online
I need help!
I am managing Experiment Manager with a very simple exercise. I use data stocks for one-step ahead of the close price with a simple LSTM net. The net works well with trainnest(XTest,YTest,layers,options). I want to calibrate the Epochs parameters with Experiment Manager. I followed any suggestions and tutorials on the web but I can not do it. Xtest is an array with 6 cols (open, close, volum etc.) and 2401 (time steps) rows for a given stock. The reponse is a single 2401 vector containing one-time shifted of the close price. As said. I have no problem with trainnet and the net performs well.
I put data, layers and options in the script for Experiment Manager. Here is my code:
function [XTrain_N,YTrain_N,layers,options] = Experiment1_setup1(params)
load dati_net.mat XTrain_N YTrain_N
num_features = 6;
num_responses = 1;
num_hidden_units = 350;
layers = [
featureInputLayer(6);
lstmLayer(num_hidden_units, 'OutputMode','last')
fullyConnectedLayer(num_responses)
];
%Training Options
options = trainingOptions("adam", ...
MaxEpochs=params.MaxEpochs, ...
SequencePaddingDirection="left",...
InitialLearnRate=0.001,...
Shuffle="every-epoch", ...
ValidationFrequency=50, ...
GradientThreshold=.93, ...
L2Regularization=0.00001, ...
Verbose=false, ...
Metrics="rmse", ...
Plots="training-progress");
end
But when I run the experiment I always get:
The following errors occurred while running the experiment:
Errors occurred while validating the setup function: Caused by: Invalid output arguments from setup function. Third-from-last output of setup function must be a layer array or dlnetwork object, but a value of type 'double' was detected.
I tried dozens of trials but I am able to escape the problem. I attach also my data
Thanks in Advance!
2 Comments Show NoneHide None
Show NoneHide None
dpb on 10 Aug 2024 at 16:39
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2144389-troubles-with-experiment-manager-setup-for-lstm-regression#comment_3234689
The function as shown doesn't return any of the return variables...
massimo giannini on 11 Aug 2024 at 11:44
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2144389-troubles-with-experiment-manager-setup-for-lstm-regression#comment_3234954
Ok so how can I fix it?
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Jaimin on 12 Aug 2024 at 10:37
Edited: Jaimin on 12 Aug 2024 at 10:49
Open in MATLAB Online
Hi @massimo giannini,
According to the issue description, you are able to train your model using the“trainnet”function. However, when attempting to tune the epoch hyperparameter value using MATLAB's Experiment Manager app, you encounter an error.
One workaround I found is to use“trainNetwork”instead of“trainnet”in Experiment Manager. To do this
- Click on "New" -> "Project" -> "Blank Project"
- Select the 'Built-In Training' experiment from the 'Blank Built-In trainNetwork Experiment' as shown in the image below.
- After selecting that, configure the parameters as shown in the image below.
- Set all other parameters according to requirements.
Additionally, there is a modification in"Experiment1_setup1". Here is the updated code.
function [XTrain_N, YTrain_N, layers, options] = SequenceRegressionExperiment_setup2(params)
load dati_net.mat XTrain_N YTrain_N
num_features = 6;
num_responses = 1;
num_hidden_units = 350;
layers = [
featureInputLayer(6);
lstmLayer(num_hidden_units, 'OutputMode','last')
fullyConnectedLayer(num_responses)
regressionLayer
];
%Training Options
options = trainingOptions("adam", ...
MaxEpochs=params.MaxEpochs, ...
SequencePaddingDirection="left",...
InitialLearnRate=0.001,...
Shuffle="every-epoch", ...
ValidationFrequency=50, ...
GradientThreshold=.93, ...
L2Regularization=0.00001, ...
Verbose=false, ...
Plots="training-progress");
end
I have attached some resources that will be helpful to you.
Difference between “trainnet” and “trainNetwork”: https://www.mathworks.com/matlabcentral/answers/2060029-difference-between-trainnet-and-trainnetwork
Experiment Manager: https://www.mathworks.com/help/deeplearning/ref/experimentmanager-app.html#mw_92d8f99c-f283-4bc5-a5d7-7d779c4831f7
Training Configurations for LSTM: https://www.mathworks.com/help/deeplearning/ug/experiment-with-training-configurations-for-sequence-regression.html
I hope this helps!
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
massimo giannini on 12 Aug 2024 at 13:31
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2144389-troubles-with-experiment-manager-setup-for-lstm-regression#comment_3235369
Open in MATLAB Online
Great! Thank you!!
I found a second working alternative yesterday by "try and guess". I converted XTrain_N YTrain_N to a datastore:
load dati_net.mat XTrain_N YTrain_N
adsXTrain = arrayDatastore(XTrain_N);
adsYTrain = arrayDatastore(YTrain_N);
cdsTrain = combine(adsXTrain,adsYTrain);
, erased Metrics from the options and used this string for the function:
function [cdsTrain,layers,lossFcn,options] = Experiment1_setup1(params)
lossFcn="mse";
and now Experiment Manager works.
Anyway thanks for your valuable help
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Categories
MATLABData Import and AnalysisData Import and ExportStandard File Formats
Find more on Standard File Formats in Help Center and File Exchange
Tags
- experiment manager
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office