if(actual_label.equals(missed_label)) {
throw new IllegalArgumentException("Actual label equals to missed label: "
+ actual_label);
}
PredictionModel model2add = label2model.get(actual_label);
if(model2add == null) {
model2add = createModel();
label2model.put(actual_label, model2add);
}
PredictionModel model2sub = null;
if(missed_label != null) {
model2sub = label2model.get(missed_label);
if(model2sub == null) {
model2sub = createModel();
label2model.put(missed_label, model2sub);
}
}
final ObjectInspector featureInspector = featureListOI.getListElementObjectInspector();
for(Object f : features) {// w[f] += y * x[f]
if(f == null) {
continue;
}
final Object k;
final float v;
if(parseFeature) {
FeatureValue fv = FeatureValue.parse(f);
k = fv.getFeature();
v = fv.getValue();
} else {
k = ObjectInspectorUtils.copyToStandardObject(f, featureInspector);
v = 1.f;
}
IWeightValue old_correctclass_w = model2add.get(k);
IWeightValue new_correctclass_w = getNewWeight(old_correctclass_w, v, alpha, beta, true);
model2add.set(k, new_correctclass_w);
if(model2sub != null) {
IWeightValue old_wrongclass_w = model2sub.get(k);
IWeightValue new_wrongclass_w = getNewWeight(old_wrongclass_w, v, alpha, beta, false);
model2sub.set(k, new_wrongclass_w);
}
}
}