MATLAB - How to change "Validation Check" count

6.3k Views Asked by At

How can I change "Validation Checks" value from 6 to higher or lower values using code?

I have following code:

% Create a Pattern Recognition Network
hiddenLayerSize = ns;

net = patternnet(hiddenLayerSize);

net.divideParam.trainRatio = trRa/100;
net.divideParam.valRatio = vaRa/100;
net.divideParam.testRatio = teRa/100;

% Train the Network
[net,tr] = train(net,inputs,targets);

% Test the Network
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);

% Recalculate Training, Validation and Test Performance
trainTargets = targets .* tr.trainMask{1};
valTargets = targets  .* tr.valMask{1};
testTargets = targets  .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs);
valPerformance = perform(net,valTargets,outputs);
testPerformance = perform(net,testTargets,outputs);

enter image description here

I could not find a clue at http://www.mathworks.com/help/nnet/ug/train-and-apply-multilayer-neural-networks.html

1

There are 1 best solutions below

1
On BEST ANSWER

TL;DL: net.trainParam.max_fail = 8;


I've used the example provided in the page you linked to get a working instance of nntraintool.

When you open nntraintool.m you see a small piece of documentation that says (among else):

% net.<a href="matlab:doc nnproperty.net_trainParam">trainParam</a>.<a href="matlab:doc nnparam.showWindow">showWindow</a> = false;

This hinted that some properties are stored within net.trainParam. When querying it to see what it holds you get:

ans = 


    Function Parameters for 'trainlm'

    Show Training Window Feedback   showWindow: true
    Show Command Line Feedback showCommandLine: false
    Command Line Frequency                show: 25
    Maximum Epochs                      epochs: 1000
    Maximum Training Time                 time: Inf
    Performance Goal                      goal: 0
    Minimum Gradient                  min_grad: 1e-07
    Maximum Validation Checks         max_fail: 6
    Mu                                      mu: 0.001
    Mu Decrease Ratio                   mu_dec: 0.1
    Mu Increase Ratio                   mu_inc: 10
    Maximum mu                          mu_max: 10000000000

Here you can see how the Maximum Validation Checks is stored: in a field named max_fail. Now it was only a case of testing if it was a read-only field or not, which could easily be tested using net.trainParam.max_fail = 8; train(net,...); - which correctly changed the default value from 6 to 8.