Which dimension(s) does trainingOptions shuffle apply to?
Ältere Kommentare anzeigen
Hi all,
How do I know which dimension(s) the trainingOptions shuffle shuffles or how could I figure it out? The wiki does not state it sadly.
My assumption would be for e.g. TxCxB data that is shuffles the batches.
Side question, I would assume that it would keep input-output pairs intact, including for multi-task learning models?
Thanks in advance!
Edit:
I made the following code to try to understand what is going on. If you set a breakpoint at the end of the loss function you can inspect variable b. Assuming that reshape does not alter the data, the first and second dimension of b are not altered compared to A. Therefor, only the batches have been shuffled. However, I do not know and haven't been able to figure out if it always shuffles the batches or that some other thing is playing a part.
close all
clear all
clc
% Generate simple input and output data
A = reshape(1:210, [7,5,6]); % Example input data
% % Convert to table for trainnet compatibility
% trainData = array2table(A, 'VariableNames', {'Input'});
% trainLabels = array2table(A, 'VariableNames', {'Output'});
% Define a simple feedforward network
layers = [
sequenceInputLayer(5)
fullyConnectedLayer(5)
];
% Set training options with shuffle 'every-epoch'
MLoptions = trainingOptions('adam', ...
'MaxEpochs', 5, ...
'Shuffle', 'every-epoch', ...
'Verbose', true,...
'InputDataFormats','TCB');
% Train the network with a custom loss function
net = trainnet(A, A, layers, @customLossFunction, MLoptions);
% ----------------------------
% Inline Custom Loss Function
% ----------------------------
function loss = customLossFunction(Y,T)
% Example custom loss: Mean Squared Error (MSE)
loss = mean((Y - T).^2, 'all');
b=permute(extractdata(T), [3,1,2]);
end
4 Kommentare
According to an AI tool that I asked, the shuffle parameter in trainingOptions for MATLAB's Deep Learning Toolbox shuffles the observations (samples) in your training data before each training epoch. It affects how data is presented to the network during training but doesn't change the structure of individual samples. But AI is not very reliable.
In any case, the documentation should be clearer, so give a rating at the bottom of the documentation page. Make sure to leave a comment which clearly explains which information is lacking and how it could be improved.

Matt J
am 18 Mär. 2025
For TxCxB data: It shuffles the observations within each mini-batch, not the batches themselves. Your batches are still processed in sequence.
That sounds doubtful to me.
Corné Dijkstra
am 20 Mär. 2025
Stephen23
am 20 Mär. 2025
"... if it has not been stated before on the web which it hasn't according to my quick search."
Then please do make a documentation enhancement suggestion here:
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Data Workflows finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!