gainFactory = new ExpGain.Factory (lvs, gaussianPriorVariance);
else if (gainName.equals("grad"))
gainFactory = new GradientGain.Factory (lvs);
else if (gainName.equals("info"))
gainFactory = new InfoGain.Factory ();
klfi[i][j] = new FeatureInducer (gainFactory,
clusteredErrorInstances[i][j],
numFeaturesPerFeatureInduction,
2*numFeaturesPerFeatureInduction,
2*numFeaturesPerFeatureInduction);
crf.featureInducers.add(klfi[i][j]);
}
}
for (int i = 0; i < numLabels; i++) {
for (int j = 0; j < numLabels; j++) {
logger.info ("Adding new induced features for "+
crf.outputAlphabet.lookupObject(i)+" -> "+crf.outputAlphabet.lookupObject(j));
if (klfi[i][j] == null) {
logger.info ("...skipping because no features induced.");
continue;
}
// Note that this adds features globally, but not on a per-transition basis
klfi[i][j].induceFeaturesFor (trainingData, false, false);
if (testingData != null) klfi[i][j].induceFeaturesFor (testingData, false, false);
}
}
klfi = null;
} else {
int s = errorLabelVectors.size();
LabelVector[] lvs = new LabelVector[s];
for (int i = 0; i < s; i++)
lvs[i] = (LabelVector) errorLabelVectors.get(i);
RankedFeatureVector.Factory gainFactory = null;
if (gainName.equals ("exp"))
gainFactory = new ExpGain.Factory (lvs, gaussianPriorVariance);
else if (gainName.equals("grad"))
gainFactory = new GradientGain.Factory (lvs);
else if (gainName.equals("info"))
gainFactory = new InfoGain.Factory ();
FeatureInducer klfi =
new FeatureInducer (gainFactory,
errorInstances,
numFeaturesPerFeatureInduction,
2*numFeaturesPerFeatureInduction,
2*numFeaturesPerFeatureInduction);
crf.featureInducers.add(klfi);
// Note that this adds features globally, but not on a per-transition basis
klfi.induceFeaturesFor (trainingData, false, false);
if (testingData != null) klfi.induceFeaturesFor (testingData, false, false);
logger.info ("CRF4 FeatureSelection now includes "+crf.globalFeatureSelection.cardinality()+" features");
klfi = null;
}
// This is done in CRF4.train() anyway
//this.setWeightsDimensionAsIn (trainingData);