MATLAB: Questions about the regularization (Modified Performance Function) of neural network

validation curve regularization

Hello, everyone. I tried to find out the best regularization ratio for a very simple problem from Matlab, using the function trainbgf for a shallow neural network. Then I plotted a validation curve. The problem is that the curve didn't make any sense. I just followed the contents from the official document as follows:
Here are my codes.
*******************************************
regularization_term = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
m = size(regularization_term,2);
[x,t] = simplefit_dataset;
x_train = x(1:70);
t_train = t(1:70);
x_test = x(71:94);
t_test = t(71:94);
trainPerformance = zeros(50,11);
testPerformance = zeros(50,11);
for j = 1:50
for i = 1:m
net = feedforwardnet(10,'trainbfg');
net.divideFcn = '';
net.trainParam.epochs = 300;
net.trainParam.goal = 1e-5;
net.performParam.regularization = regularization_term(i);
net = train(net,x_train,t_train);
y_train = net(x_train);
trainPerformance(j,i) = sqrt(perform(net,t_train,y_train));
y_test = net(x_test);
testPerformance(j,i) = sqrt(perform(net,t_test,y_test));
end
end
plot(regularization_term, mean(trainPerformance),regularization_term,mean(testPerformance))
legend('trainperformance-RMSE','testperformacne-RMSE','best')
xlabel('Regularization Ratio')
ylabel('RMSE')
************************************************
Here is the learning curve I plotted.
I think that the RMSE of the training data should increase as the regularization ratio increases and the RMSE of the test data should decrease at first and at a certain point start to increase as the regularization ratio increases. I'm not sure where I made a mistake, can anyone give me advice? Thank you in advance!

Best Answer

Oh! … O.K.
The simplefit_dataset is smooth with 4 interior local extrema. Therefore, you probably only need H = 4 hidden nodes.
More than H = 4 hidden nodes can be considered overfitting. So, if you use the default H = 10, you will have an overfit net and should implement a mitigation to
PREVENT OVERTRAINING AN OVERFIT NET.
The most common mitigations are
1. DO NOT OVERFIT
A. No. of unknown weights <= No. of training equations:
Nw <= Ntrneq
AND/OR
B. Minimize weighted sum of SQUARED ERRORS AND SQUARED WEIGHTS
MSE + gamma * MSW
2. DO NOT OVERTRAIN:
Use a validation subset to implement EARLY STOPPING
Hope this helps.
Greg