optLikelihood = new ThreadedOptimizable(likelihood,trainingSet,crf.getParameters().getNumFactors(),
new CRFCacheStaleIndicator(crf));
likelihood.setGaussianPriorVariance(gpv);
}
CRFOptimizableByGE ge = new CRFOptimizableByGE(crf,constraints,unlabeledSet,map,numThreads,geWeight);
// turn off the prior... it already appears above!
ge.setGaussianPriorVariance(Double.POSITIVE_INFINITY);
CRFOptimizableByGradientValues opt =
new CRFOptimizableByGradientValues(crf,new Optimizable.ByGradientValue[] { optLikelihood, ge });
LimitedMemoryBFGS optimizer = new LimitedMemoryBFGS(opt);
try {
converged = optimizer.optimize(numIterations);
}
catch (Exception e) {
e.printStackTrace();
}
optimizer.reset();
try {
converged = optimizer.optimize(numIterations);
}
catch (Exception e) {
e.printStackTrace();
}
if (numThreads > 1) {
((ThreadedOptimizable)optLikelihood).shutdown();
ge.shutdown();
}
return converged;
}