// Initialize the constraints, using only the constraints from
// the "positive" instance
Iterator<Instance> iter = trainingList.iterator ();
logger.fine("Number of instances in training list = " + trainingList.size());
while (iter.hasNext()) {
Instance instance = iter.next();
double instanceWeight = trainingList.getInstanceWeight(instance);
FeatureVectorSequence fvs = (FeatureVectorSequence) instance.getData();
// label of best instance in subList
Object target = instance.getTarget();
Label label = null;
if (target instanceof Labels)
label = ((Labels)target).get(0);
else label = (Label)target;
int positiveIndex =
Integer.valueOf(label.getBestLabel().getEntry().toString()).intValue();
if (positiveIndex == -1) { // invalid instance
logger.warning("True label is -1. Skipping...");
continue;
}
FeatureVector fv = (FeatureVector)fvs.get(positiveIndex);
Alphabet fdict = fv.getAlphabet();
assert (fv.getAlphabet() == fd);
// xxx ensure dimensionality of constraints correct
MatrixOps.rowPlusEquals (constraints, numFeatures, 0, fv, instanceWeight);
// For the default feature, whose weight is 1.0
assert(!Double.isNaN(instanceWeight)) : "instanceWeight is NaN";
//assert(!Double.isNaN(li)) : "bestIndex is NaN";
boolean hasNaN = false;
for(int i = 0; i < fv.numLocations(); i++) {
if(Double.isNaN(fv.valueAtLocation(i))) {
logger.info("NaN for feature " + fdict.lookupObject(fv.indexAtLocation(i)).toString());
hasNaN = true;
}
}
if(hasNaN)
logger.info("NaN in instance: " + instance.getName());
// default constraints for positive instances xxx
constraints[0*numFeatures + defaultFeatureIndex] += 1.0 * instanceWeight;
}
//TestMaximizable.testValueAndGradientCurrentParameters (this);