Slightly updated program:
NumVars = 3;
NumInputs = 4;
TotRows = 2;
%% while hasdata(ds_1), read(ds_1), end
ds_1 = arrayDatastore(zeros(TotRows, NumVars));
ds_2 = arrayDatastore(zeros(TotRows, NumVars));
ds_3 = arrayDatastore(zeros(TotRows, NumVars));
ds_4 = arrayDatastore(zeros(TotRows, NumVars - 1));
TargetY = zeros(TotRows, 1);
ds_TargetY = arrayDatastore(TargetY);
dsTrain = combine(ds_1, ds_2, ds_3, ds_4, ds_TargetY);
%%
lgraph = layerGraph();
for i = 1 : NumInputs
if i == NumInputs
UsedVars = NumVars - 1;
else
UsedVars = NumVars;
end
NameStrIn = ['In_' num2str(i)];
inLayer = featureInputLayer(UsedVars, 'Name', NameStrIn);
lgraph = addLayers(lgraph, inLayer);
NameStrFC = ['FC_' num2str(i)];
fcLayer = fullyConnectedLayer(UsedVars, 'Name', NameStrFC);
lgraph = addLayers(lgraph, fcLayer);
lgraph = connectLayers(lgraph, ['In_' num2str(i)], ['FC_' num2str(i)]);
end
concatLayer = concatenationLayer(1, NumInputs, 'Name', 'Concat');
lgraph = addLayers(lgraph, concatLayer);
for CurIdx = 1 : NumInputs
lgraph = connectLayers(lgraph, ['FC_' num2str(CurIdx)], ['Concat' '/in' num2str(CurIdx)]);
end
Final_Layers = [
fullyConnectedLayer(2, 'Name', 'Final_Layers');
fullyConnectedLayer(1)
regressionLayer];
lgraph = addLayers(lgraph, Final_Layers);
lgraph = connectLayers(lgraph, 'Concat', 'Final_Layers');
analyzeNetwork(lgraph)
%%
options = trainingOptions("sgdm", ...
MaxEpochs=15, ...
InitialLearnRate=0.01, ...
Plots="training-progress", ...
Verbose=0);
net = trainNetwork(dsTrain, lgraph, options);