trainbr returns best network by performance not the best regularized
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Using trainbr in R2022b for a feedforwardnet should return the network with the best regularization. However, it seems that the best network by performance is returned. The performance in the following example is lowest in epoch 2 (as indicated by tr.best_epoch) and the returned net seem to be from this epoch (when I set net.trainParam.epochs=2 the same net results). This network is not very much regularized and the optimization process continues for another 998 epochs and ends with a "Effective # of Parameters" of roughly 4 which the result returned does not reflect at all.
If I set net.trainParam.max_fail=5; I can get train to return the net from epoch 19 which is nuch more regularized.
Long story short, I think trainbr is buggy and returns the wrong net.
rng(0)
% load data
[X, T_] = simplefit_dataset;
% resample data and apply noise
X= X(1:3:end);
T_= T_(1:3:end);
T= T_ + randn(size(T_));
% network with too many neurons
net= feedforwardnet(30, 'trainbr');
% net.trainParam.epochs=2;
% net.trainParam.max_fail=5;
[net, tr] = train(net, X, T);
% display results
Y = sim(net, X);
figure(1)
clf
hold on
plot(X, T_, 'DisplayName', 'real')
plot(X, Y, 'DisplayName', 'model')
plot(X(tr.trainInd), T(tr.trainInd), '.', 'DisplayName', 'Training')
plot(X(tr.valInd), T(tr.valInd), 'o', 'DisplayName', 'Validation')
plot(X(tr.testInd), T(tr.testInd), '*', 'DisplayName', 'Test')
hold off
grid on
legend
0 commentaires
Réponses (1)
Akshat
le 15 Déc 2023
Hi Jens,
As per my understanding of your question, you need an explanation of why the “trainbr” function is not giving the optimum results without enabling the “net.trainParam.max_fail”.
I ran your code on my end and found out that when “net.trainParam.max_fail” is not enabled, there is no validation set for checking for the early stopping. PFA the images for the two cases, one where it is enabled and one where it isn’t.
To check these graphs, press the performance button after running the code.
Case 1 (no early stopping):
Case 2 (early stopping):
Upon further research, I found out the reason why this is the case. Please refer to this MATLAB Answer to get more idea of the same: https://www.mathworks.com/matlabcentral/answers/405727-why-does-the-trainbr-function-not-require-a-validation-dataset
Hope this helps.
Regards
Akshat
2 commentaires
Ben Hinkle
le 16 Oct 2024
Modifié(e) : Ben Hinkle
le 16 Oct 2024
Interestingly for this example the "best" regularization metric still happens very early, and results in an almost linear approximation (i.e. very regular, but terrible MSE value).
Given how the current system defaults to the "performFcn" being "mse" and the plot saying "Mean Squared Error", the most consistent behavior is to continue to record MSE as the performance metric. In the future we will consider an enhancement to design an additional API to allow for "regularized MSE" to be used as a performance metric.
Voir également
Catégories
En savoir plus sur Sequence and Numeric Feature Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!