* @param foldNum The current fold.
* @param fold The current fold.
*/
private void fitFold(int k, int foldNum, DataFold fold) {
MLMethod method = this.createMethod();
MLTrain train = this.createTrainer(method, fold.getTraining());
if (train.getImplementationType() == TrainingImplementationType.Iterative) {
SimpleEarlyStoppingStrategy earlyStop = new SimpleEarlyStoppingStrategy(
fold.getValidation());
train.addStrategy(earlyStop);
StringBuilder line = new StringBuilder();
while (!train.isTrainingDone()) {
train.iteration();
line.setLength(0);
line.append("Fold #");
line.append(foldNum);
line.append("/");
line.append(k);
line.append(": Iteration #");
line.append(train.getIteration());
line.append(", Training Error: ");
line.append(Format.formatDouble(train.getError(), 8));
line.append(", Validation Error: ");
line.append(Format.formatDouble(earlyStop.getValidationError(),
8));
report.report(k, foldNum, line.toString());
}
fold.setScore(earlyStop.getValidationError());
fold.setMethod(method);
} else if (train.getImplementationType() == TrainingImplementationType.OnePass) {
train.iteration();
double validationError = calculateError(method,
fold.getValidation());
this.report.report(k, k,
"Trained, Training Error: " + train.getError()
+ ", Validatoin Error: " + validationError);
fold.setScore(validationError);
fold.setMethod(method);
} else {
throw new EncogError("Unsupported training type for EncogModel: "
+ train.getImplementationType());
}
}