public double getDouble(long row, long column) { return Arrays.binarySearch(featureVector.getIndices(), (int) column) >= 0 ? 1.0 : 0.0; }
public double getDouble(int row, int column) { return Arrays.binarySearch(featureVector.getIndices(), column) >= 0 ? 1.0 : 0.0; }
protected static String getText( @SuppressWarnings("rawtypes") Sequence input, int j) { FeatureVector fv = (FeatureVector) input.get(j); for (int idx : fv.getIndices()) { Object ooo = fv.getAlphabet().lookupObject(idx); if (ooo.toString().startsWith("text=") && !ooo.toString().matches("^.+?\\/[-\\+]\\d$")) { return ooo.toString().substring(5); } } return ""; } }
protected static String getText( @SuppressWarnings("rawtypes") Sequence input, int j) { FeatureVector fv = (FeatureVector) input.get(j); for (int idx : fv.getIndices()) { Object ooo = fv.getAlphabet().lookupObject(idx); if (ooo.toString().startsWith("text=") && !ooo.toString().matches("^.+?\\/[-\\+]\\d$")) { return ooo.toString().substring(5); } } return ""; } }
/** Serializes a single object without metadata * @param out * @param object * @throws IOException */ private void serializeObject (ObjectOutputStream out, Object obj) throws IOException { if (obj instanceof FeatureVector) { FeatureVector features = (FeatureVector) obj; out.writeChar (TYPE_FEATURE_VECTOR); out.writeObject (features.getIndices ()); out.writeObject (features.getValues ()); } else if (obj instanceof Label) { out.writeChar (TYPE_LABEL); out.writeObject (((Label) obj).toString ()); } else { out.writeChar (TYPE_OBJECT); out.writeObject (obj); } }
/** Serializes a single object without metadata * @param out * @param object * @throws IOException */ private void serializeObject (ObjectOutputStream out, Object obj) throws IOException { if (obj instanceof FeatureVector) { FeatureVector features = (FeatureVector) obj; out.writeChar (TYPE_FEATURE_VECTOR); out.writeObject (features.getIndices ()); out.writeObject (features.getValues ()); } else if (obj instanceof Label) { out.writeChar (TYPE_LABEL); out.writeObject (((Label) obj).toString ()); } else { out.writeChar (TYPE_OBJECT); out.writeObject (obj); } }
/** Serializes a single object without metadata * @param out * @param object * @throws IOException */ private void serializeObject (ObjectOutputStream out, Object obj) throws IOException { if (obj instanceof FeatureVector) { FeatureVector features = (FeatureVector) obj; out.writeChar (TYPE_FEATURE_VECTOR); out.writeObject (features.getIndices ()); out.writeObject (features.getValues ()); } else if (obj instanceof Label) { out.writeChar (TYPE_LABEL); out.writeObject (((Label) obj).toString ()); } else { out.writeChar (TYPE_OBJECT); out.writeObject (obj); } }
int pos = 0; int[] indices = fv.getIndices(); int lastIdx = -1; for (int idx = 0; idx < size; idx++) {
RankedFeatureVector rfv = new RankedFeatureVector (crf.inputAlphabet, input.getIndices (), absVals); for (int rank = 0; rank < absVals.length; rank++) { int fidx = rfv.getIndexAtRank (rank);
RankedFeatureVector rfv = new RankedFeatureVector (crf.inputAlphabet, input.getIndices (), absVals); for (int rank = 0; rank < absVals.length; rank++) { int fidx = rfv.getIndexAtRank (rank);
RankedFeatureVector rfv = new RankedFeatureVector (crf.inputAlphabet, input.getIndices (), absVals); for (int rank = 0; rank < absVals.length; rank++) { int fidx = rfv.getIndexAtRank (rank);
for (int index : fv.getIndices()) { if (isPos) truePositives[index]++;
"has NaN value."); for (int label: multinomialValues.getIndices()) { logger.fine ("log(scores)= " + Math.log(scores[label]) + " scores = " + scores[label]);
FeatureSequence topicSequence) { int[] possibleTopics = labels.getIndices(); int numLabels = labels.numLocations();
FeatureSequence topicSequence) { int[] possibleTopics = labels.getIndices(); int numLabels = labels.numLocations();
FeatureSequence topicSequence) { int[] possibleTopics = labels.getIndices(); int numLabels = labels.numLocations();
public Instance2Sample(Instance instance, int index) { this.instance = instance; this.index = index; Object data = instance.getData(); if (data instanceof FeatureVectorSequence) { FeatureVectorSequence fvs = (FeatureVectorSequence) data; put(INPUT, new MalletInputMatrix(fvs.getFeatureVector(index))); } LabelSequence labelSequence = (LabelSequence) instance.getTarget(); put(Sample.TARGET, new MalletOutputMatrix(labelSequence, index)); if (data instanceof FeatureVectorSequence) { FeatureVectorSequence fvs = (FeatureVectorSequence) data; FeatureVector fv = fvs.getFeatureVector(index); for (int i = fv.numLocations() - 1; i != -1; i--) { String word = (String) fv.getAlphabet().lookupObject(fv.getIndices()[i]); if (word.startsWith("W=")) { if (!word.matches(".*[0-9]$")) { setLabel(word.substring(2)); } } } } }
/** * * @param inst input instance, with FeatureVectorSequence as data. * @param alphabetsPipe a Noop pipe containing the data and target alphabets for * the resulting InstanceList and AugmentableFeatureVectors * @return list of instances, each with one AugmentableFeatureVector as data */ public static InstanceList convert(Instance inst, Noop alphabetsPipe) { InstanceList ret = new InstanceList(alphabetsPipe); Object obj = inst.getData(); assert(obj instanceof FeatureVectorSequence); FeatureVectorSequence fvs = (FeatureVectorSequence) obj; LabelSequence ls = (LabelSequence) inst.getTarget(); assert(fvs.size() == ls.size()); Object instName = (inst.getName() == null ? "NONAME" : inst.getName()); for (int j = 0; j < fvs.size(); j++) { FeatureVector fv = fvs.getFeatureVector(j); int[] indices = fv.getIndices(); FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(), indices, fv.getValues(), indices.length); Labeling target = ls.getLabelAtPosition(j); String name = instName.toString() + "_@_POS_" + (j + 1); Object source = inst.getSource(); Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source)); ret.add(toAdd); } return ret; }
/** * * @param inst input instance, with FeatureVectorSequence as data. * @param alphabetsPipe a Noop pipe containing the data and target alphabets for * the resulting InstanceList and AugmentableFeatureVectors * @return list of instances, each with one AugmentableFeatureVector as data */ public static InstanceList convert(Instance inst, Noop alphabetsPipe) { InstanceList ret = new InstanceList(alphabetsPipe); Object obj = inst.getData(); assert(obj instanceof FeatureVectorSequence); FeatureVectorSequence fvs = (FeatureVectorSequence) obj; LabelSequence ls = (LabelSequence) inst.getTarget(); assert(fvs.size() == ls.size()); Object instName = (inst.getName() == null ? "NONAME" : inst.getName()); for (int j = 0; j < fvs.size(); j++) { FeatureVector fv = fvs.getFeatureVector(j); int[] indices = fv.getIndices(); FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(), indices, fv.getValues(), indices.length); Labeling target = ls.getLabelAtPosition(j); String name = instName.toString() + "_@_POS_" + (j + 1); Object source = inst.getSource(); Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source)); ret.add(toAdd); } return ret; }
/** * * @param inst input instance, with FeatureVectorSequence as data. * @param alphabetsPipe a Noop pipe containing the data and target alphabets for * the resulting InstanceList and AugmentableFeatureVectors * @return list of instances, each with one AugmentableFeatureVector as data */ public static InstanceList convert(Instance inst, Noop alphabetsPipe) { InstanceList ret = new InstanceList(alphabetsPipe); Object obj = inst.getData(); assert(obj instanceof FeatureVectorSequence); FeatureVectorSequence fvs = (FeatureVectorSequence) obj; LabelSequence ls = (LabelSequence) inst.getTarget(); assert(fvs.size() == ls.size()); Object instName = (inst.getName() == null ? "NONAME" : inst.getName()); for (int j = 0; j < fvs.size(); j++) { FeatureVector fv = fvs.getFeatureVector(j); int[] indices = fv.getIndices(); FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(), indices, fv.getValues(), indices.length); Labeling target = ls.getLabelAtPosition(j); String name = instName.toString() + "_@_POS_" + (j + 1); Object source = inst.getSource(); Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source)); ret.add(toAdd); } return ret; }