/** * Add the values in the given vector to * this vector and return this * @param vector the vector to add * @return this */ public SparseFloatArray addInplace(SparseFloatArray vector) { for (Entry e : vector.entries()) { increment(e.index, e.value); } return this; }
/** * Subtract the values in the given vector from * this array and return this * @param vector the vector to add * @return this */ public SparseFloatArray subtractInplace(SparseFloatArray vector) { for (Entry e : vector.entries()) { increment(e.index, (float)(-e.value)); } return this; }
private static SparseFloatFV loadVector(File f, List<String> vocab) throws IOException { final String str = FileUtils.readall(f); final String[] terms = str.split(",\\s*"); final SparseFloatFV fv = new SparseFloatFV(vocab.size()); for (String term : terms) { term = term.trim(); if (term.length() < 1) continue; int idx = vocab.indexOf(term); if (idx == -1) { idx = vocab.size(); vocab.add(term); fv.values.setLength(idx + 1); fv.values.set(idx, 1); } else { fv.values.increment(idx, 1); } } return fv; } }
private static SparseFloatFV loadVector(File f, List<String> vocab) throws IOException { final String str = FileUtils.readall(f); final String[] terms = str.split(",\\s*"); final SparseFloatFV fv = new SparseFloatFV(vocab.size()); for (String term : terms) { term = term.trim(); if (term.length() < 1) continue; int idx = vocab.indexOf(term); if (idx == -1) { idx = vocab.size(); vocab.add(term); fv.values.setLength(idx + 1); fv.values.set(idx, 1); } else { fv.values.increment(idx, 1); } } return fv; } }