* @return True if training has converged.
*/
public boolean train(InstanceList labeled, InstanceList unlabeled, int numIterations) {
if (iteration == 0) {
// train with log-likelihood only first
CRFOptimizableByLabelLikelihood likelihood =
new CRFOptimizableByLabelLikelihood(crf, labeled);
likelihood.setGaussianPriorVariance(gaussianPriorVariance);
this.bfgs = new LimitedMemoryBFGS(likelihood);
logger.info ("CRF about to train with "+numIterations+" iterations");
for (int i = 0; i < numIterations; i++) {
try {
converged = bfgs.optimize(1);
iteration++;
logger.info ("CRF finished one iteration of maximizer, i="+i);
runEvaluators();
} catch (IllegalArgumentException e) {
e.printStackTrace();
logger.info ("Catching exception; saying converged.");
converged = true;
} catch (Exception e) {
e.printStackTrace();
logger.info("Catching exception; saying converged.");
converged = true;
}
if (converged) {
logger.info ("CRF training has converged, i="+i);
break;
}
}
iteration = 0;
}
// train with log-likelihood + entropy regularization
CRFOptimizableByLabelLikelihood likelihood = new CRFOptimizableByLabelLikelihood(crf, labeled);
likelihood.setGaussianPriorVariance(gaussianPriorVariance);
CRFOptimizableByEntropyRegularization regularization = new CRFOptimizableByEntropyRegularization(crf, unlabeled);
regularization.setScalingFactor(this.entRegScalingFactor);
CRFOptimizableByGradientValues regLikelihood = new CRFOptimizableByGradientValues(crf,
new Optimizable.ByGradientValue[] { likelihood, regularization} );