double[][] scores = new double[trainingList.size()][numLabels];
double[] constraintValue = new double[numLabels];
// pass 1: calculate model distribution
for (int ii = 0; ii < trainingList.size(); ii++) {
Instance instance = trainingList.get(ii);
double instanceWeight = trainingList.getInstanceWeight(instance);
// skip if labeled
if (instance.getTarget() != null) {
continue;
}
FeatureVector fv = (FeatureVector) instance.getData();
classifier.getClassificationScoresWithTemperature(instance, temperature, scores[ii]);
for (MaxEntGEConstraint constraint : constraints) {
constraint.computeExpectations(fv,scores[ii],instanceWeight);
}
}
// compute value
double value = 0;
for (MaxEntGEConstraint constraint : constraints) {
value += constraint.getValue();
}
value *= objWeight;
// pass 2: determine per example gradient
for (int ii = 0; ii < trainingList.size(); ii++) {
Instance instance = trainingList.get(ii);
// skip if labeled
if (instance.getTarget() != null) {
continue;
}
Arrays.fill(constraintValue,0);
double instanceExpectation = 0;
double instanceWeight = trainingList.getInstanceWeight(instance);
FeatureVector fv = (FeatureVector) instance.getData();
for (MaxEntGEConstraint constraint : constraints) {
constraint.preProcess(fv);
for (int label = 0; label < numLabels; label++) {
double val = constraint.getCompositeConstraintFeatureValue(fv, label);