double logLikelihood = Double.NEGATIVE_INFINITY, prevLogLikelihood;
for (int iter = 0; iter < numIterations; iter++) {
prevLogLikelihood = logLikelihood;
logLikelihood = 0;
for (Instance inst : trainingSet) {
FeatureSequence input = (FeatureSequence) inst.getData();
FeatureSequence output = (FeatureSequence) inst.getTarget();
double obsLikelihood = new SumLatticeDefault(hmm, input,
output, hmm.new Incrementor()).getTotalWeight();
logLikelihood += obsLikelihood;
}
logger.info("getValue() (observed log-likelihood) = "
+ logLikelihood);
if (unlabeledSet != null) {
int numEx = 0;
for (Instance inst : unlabeledSet) {
numEx++;
if (numEx % 100 == 0) {
System.err.print(numEx + ". ");
System.err.flush();
}
FeatureSequence input = (FeatureSequence) inst.getData();
double hiddenLikelihood = new SumLatticeDefault(hmm, input,
null, hmm.new Incrementor()).getTotalWeight();
logLikelihood += hiddenLikelihood;
}
System.err.println();