
Which dimension(s) does trainingOptions shuffle apply to?
3 views (last 30 days)
Show older comments
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 Comments
Stephen23
on 20 Mar 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:
Accepted Answer
Matt J
on 18 Mar 2025
You can use analyzeNetwork to see which dimension is the batch dimension.However, I believe it will always be the last dimension.
3 Comments
Matt J
on 20 Mar 2025
Edited: Matt J
on 20 Mar 2025
I think so far my findings (see edit) are similar to the shuffleing of batches within the mini-batch.
I don't understand how your are using the terminology "batch" as distinct from "minibatch". The process of shuffling training samples and the process of dividing training samples into minibatches are entirely separate and independent (assuming you are not using a custom datastore). Both processes, however, operate along the (B) dimension of your data.
More Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!