public boolean predict(FeatureVector featureVector, SingleDecision decision) throws MaltChainedException { if (featureVector == null) { throw new LibException( "The learner cannot predict the next class, because the feature vector cannot be found. "); } final FeatureList featureList = new FeatureList(); final int size = featureVector.size(); for (int i = 1; i <= size; i++) { final FeatureValue featureValue = featureVector.getFeatureValue(i - 1); if (featureValue != null && !(excludeNullValues == true && featureValue.isNullValue())) { if (featureValue instanceof SingleFeatureValue) { SingleFeatureValue singleFeatureValue = (SingleFeatureValue) featureValue; int index = featureMap.getIndex(i, singleFeatureValue.getIndexCode()); if (index != -1 && singleFeatureValue.getValue() != 0) { featureList.add(index, singleFeatureValue.getValue()); } } else if (featureValue instanceof MultipleFeatureValue) { for (Integer value : ((MultipleFeatureValue) featureValue).getCodes()) { int v = featureMap.getIndex(i, value); if (v != -1) { featureList.add(v, 1); } } } } } try { decision.getKBestList().addList(model.predict(featureList.toArray())); // decision.getKBestList().addList(prediction(featureList)); } catch (OutOfMemoryError e) { throw new LibException("Out of memory. Please increase the Java heap size (-Xmx<size>). ", e); } return true; }
public int featureIndex(FeatureIdentifier fId) { return featureMap.getIndex(fId); }