int numInfWeight = 0;
// Calculate the value of each instance, and also fill in expectations
double unlabeledWeight, labeledWeight, weight;
for (int ii = 0; ii < trainingSet.size(); ii++) {
Instance instance = trainingSet.get(ii);
double instanceWeight = trainingSet.getInstanceWeight(instance);
FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
FeatureSequence output = (FeatureSequence) instance.getTarget();
labeledWeight = new SumLatticeDefault (this.crf, input, output, (Transducer.Incrementor)null).getTotalWeight();
String instanceName = instance.getName() == null ? "instance#"+ii : instance.getName().toString();
//System.out.println ("labeledWeight = "+labeledWeight);
if (Double.isInfinite (labeledWeight)) {
++numInfLabeledWeight;
logger.warning (instanceName + " has -infinite labeled weight.\n"+(instance.getSource() != null ? instance.getSource() : ""));
}
Transducer.Incrementor incrementor = instanceWeight == 1.0 ? expectations.new Incrementor() : expectations.new WeightedIncrementor (instanceWeight);
unlabeledWeight = new SumLatticeDefault (this.crf, input, null, incrementor).getTotalWeight();
//System.out.println ("unlabeledWeight = "+unlabeledWeight);
if (Double.isInfinite (unlabeledWeight)) {
++numInfUnlabeledWeight;
logger.warning (instance.getName().toString() + " has -infinite unlabeled weight.\n"+(instance.getSource() != null ? instance.getSource() : ""));
}
// Here weight is log(conditional probability correct label sequence)
weight = labeledWeight - unlabeledWeight;
//System.out.println ("Instance "+ii+" CRF.MaximizableCRF.getWeight = "+weight);