[X1, X2] = meshgrid(-2:.2:2, -2:.2:2);
Y = X1 .* exp(-X1.^2 - X2.^2);
Ntrain = 500;
X_train = (4 * rand(2, Ntrain) - 2).';
Y_train = X_train(:, 1) .* exp(-X_train(:, 1).^2 - X_train(:, 2).^2);
lgraph = layerGraph();
tempLayers = [
sequenceInputLayer([1 500 2],"Name","sequence")
sequenceFoldingLayer("Name","seqfold")
sequenceUnfoldingLayer("Name","sequnfold")
fullyConnectedLayer(4,"Name","fc_1")
tanhLayer("Name","tanh_1")
fullyConnectedLayer(3,"Name","fc_2")
tanhLayer("Name","tanh_2")
fullyConnectedLayer(1,"Name","fc_3")
regressionLayer("Name","regressionoutput")];
lgraph = addLayers(lgraph,tempLayers);
lgraph = connectLayers(lgraph,"seqfold/miniBatchSize","sequnfold/miniBatchSize");
clear tempLayers;
plot(lgraph);
options = trainingOptions('sgdm', ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.2, ...
'LearnRateDropPeriod',5, ...
'MaxEpochs',20, ...
'MiniBatchSize',50, ...
'Plots','training-progress');
net = trainNetwork(X_train, Y_train, layers, options);