/** {@inheritDoc} */ @Override public int getDocumentLength(int docid) { return docids2lengths.get(docid); }
public IDSorter[] getSortedTopicWords(int topic) { IDSorter[] sortedTypes = new IDSorter[ numTypes ]; for (int type = 0; type < numTypes; type++) sortedTypes[type] = new IDSorter(type, typeTopicCounts[type].get(topic)); Arrays.sort(sortedTypes); return sortedTypes; }
public int get (int featureIndex) { if (featureIndex < 0 || featureIndex > alphabet.size()) throw new IllegalArgumentException ("featureIndex "+featureIndex+" out of range"); return featureCounts.get (featureIndex); }
/** Unlike increment(Object), this method does not add the entry to the Alphabet if it is not there already. */ public int get (Object entry) { int fi = alphabet.lookupIndex(entry, false); if (fi == -1) return 0; else return featureCounts.get (fi); }
public final void setValue (int index, double value) { if (index2location == null) setIndex2Location (); int location = index2location.get(index); if (index2location.contains (index)) values[location] = value; else throw new IllegalArgumentException ("Trying to set value that isn't present in HashedSparseVector"); }
public void columnPlusEquals (int index, double value) { if (index2location == null) setIndex2Location (); int location = index2location.get(index); if (index2location.contains (index)) values[location] += value; else throw new IllegalArgumentException ("Trying to set value that isn't present in HashedSparseVector"); }
public void columnPlusEquals (int index, double value) { if (index2location == null) setIndex2Location (); int location = index2location.get(index); if (index2location.contains (index)) values[location] += value; else throw new IllegalArgumentException ("Trying to set value that isn't present in HashedSparseVector"); }
public FeatureVector toFeatureVector () { int[] indices = featureCounts.keys(); double[] values = new double[indices.length]; for (int i = 0; i < indices.length; i++) values[i] = featureCounts.get(indices[i]); return new FeatureVector (alphabet, indices, values); }
public RankedFeatureVector toRankedFeatureVector () { int[] indices = featureCounts.keys(); double[] values = new double[indices.length]; for (int i = 0; i < indices.length; i++) values[i] = featureCounts.get(indices[i]); return new RankedFeatureVector (alphabet, indices, values); }
public void remove1(int key) { int key2 = _map1.get(key); _map1.remove(key); _map2.remove(key2); }
public void getExpectations(double[] expectations) { assert(expectations.length == numDimensions()); for (int fi : constraintIndices.keys()) { int ci = constraintIndices.get(fi); OneLabelPRConstraint constraint = constraints.get(fi); for (int li = 0; li < constraint.expectation.length; li++) { expectations[ci + li * constraints.size()] = constraint.expectation[li]; } } }
public void getExpectations(double[] expectations) { assert(expectations.length == numDimensions()); for (int fi : constraintIndices.keys()) { int ci = constraintIndices.get(fi); OneLabelPRConstraint constraint = constraints.get(fi); for (int li = 0; li < constraint.expectation.length; li++) { expectations[ci + li * constraints.size()] = constraint.expectation[li]; } } }
public void addExpectations(double[] expectations) { assert(expectations.length == numDimensions()); for (int fi : constraintIndices.keys()) { int ci = constraintIndices.get(fi); OneLabelPRConstraint constraint = constraints.get(fi); for (int li = 0; li < constraint.expectation.length; li++) { constraint.expectation[li] += expectations[ci + li * constraints.size()]; } } }
public void addExpectations(double[] expectations) { assert(expectations.length == numDimensions()); for (int fi : constraintIndices.keys()) { int ci = constraintIndices.get(fi); OneLabelPRConstraint constraint = constraints.get(fi); for (int li = 0; li < constraint.expectation.length; li++) { constraint.expectation[li] += expectations[ci + li * constraints.size()]; } } }
public double getAuxiliaryValueContribution(double[] parameters) { double value = 0; for (int fi : constraints.keys()) { int ci = constraintIndices.get(fi); for (int li = 0; li < map.getNumLabels(); li++) { double param = parameters[ci + li * constraints.size()]; value += constraints.get(fi).target[li] * param - (param * param) / (2 * constraints.get(fi).weight); } } return value; }
public double getAuxiliaryValueContribution(double[] parameters) { double value = 0; for (int fi : constraints.keys()) { int ci = constraintIndices.get(fi); for (int li = 0; li < map.getNumLabels(); li++) { double param = parameters[ci + li * constraints.size()]; value += constraints.get(fi).target[li] * param - (param * param) / (2 * constraints.get(fi).weight); } } return value; }
public void preProcess(FeatureVector fv) { cache.resetQuick(); int fi; for (int loc = 0; loc < fv.numLocations(); loc++) { fi = fv.indexAtLocation(loc); if (constraintsMap.containsKey(fi)) { cache.add(constraintsMap.get(fi)); } } }
public double getAuxiliaryValueContribution(double[] parameters) { double value = 0; for (int fi : constraints.keys()) { int ci = constraintIndices.get(fi); for (int li = 0; li < map.getNumLabels(); li++) { double param = parameters[ci + li * constraints.size()]; value += constraints.get(fi).target[li] * param - (param * param) / (2 * constraints.get(fi).weight); } } return value; }
public void preProcess(FeatureVector fv) { cache.resetQuick(); int fi; for (int loc = 0; loc < fv.numLocations(); loc++) { fi = fv.indexAtLocation(loc); if (constraintsMap.containsKey(fi)) { cache.add(constraintsMap.get(fi)); } } }
public void preProcess(FeatureVector fv) { cache.resetQuick(); int fi; for (int loc = 0; loc < fv.numLocations(); loc++) { fi = fv.indexAtLocation(loc); if (constraintsMap.containsKey(fi)) { cache.add(constraintsMap.get(fi)); } } }