jeffheaton / encog-java-core

http://www.heatonresearch.com/encog
Other
744 stars 268 forks source link

Iteration counts not increasing when using CrossValidationKFold training #211

Closed samcic closed 7 years ago

samcic commented 9 years ago

In the method CmdTrain.performTraining, training is continued until a stop condition. That condition could either be that a stop command has been issued, the training is done, the error is satisfactory or the current iteration is greater than or equal to a specified max iteration.

I'm using k-fold cross validation and have set a maxIteration. When I do this, the training continues indefinitely (assuming none of the other stop conditions are reached).

I debugged this to find out why. The class CrossValidationKFold uses its OWN private train object to do the "real" training. When it runs an iteration (method 'iteration'), it calls 'iteration' on its private train object. The iteration count is hence increased on this private train object, but the 'iteration' variable in the superclass BasicTraining is NOT increased. It is this variable that is essentially queried in the stop condition in CmdTrain.performTraining (i.e. it will only ever see an iteration count of 0).

Suggested solution: override the getIteration method in CrossValidationKFold class, so that it returns the iteration count from the private train object, or make sure to call 'setIteration' on 'this' at an appropriate place in CrossValidationKFold.iteration().

jeffheaton commented 7 years ago

Good point, thank you for the information. I've added it to 3.4.