public SparseMatrix(){ vector = new TLongFloatHashMap(100,0.8f); }
public SparseMatrix clone(){ SparseMatrix mat = new SparseMatrix(); mat.dim = this.dim; mat.vector = new TLongFloatHashMap(vector); return mat; }
public static TLongFloatMap intMap2LongMap(TIntFloatMap map) { if (map == null) { return null; } final TLongFloatMap result = new TLongFloatHashMap(); map.forEachEntry(new TIntFloatProcedure() { @Override public boolean execute(int k, float v) { result.put(k, v); return true; } }); return result; } }
private void loadCache(DistanceParser parser, File matrixfile) throws IOException { InputStream in = new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(matrixfile))); cache = new TLongFloatHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1L, Float.POSITIVE_INFINITY); min = Integer.MAX_VALUE; max = Integer.MIN_VALUE; parser.parse(in, new DistanceCacheWriter() { @Override public void put(int id1, int id2, double distance) { if(id1 < id2) { min = id1 < min ? id1 : min; max = id2 > max ? id2 : max; } else { min = id2 < min ? id2 : min; max = id1 > max ? id1 : max; } cache.put(makeKey(id1, id2), (float) distance); } @Override public boolean containsKey(int id1, int id2) { return cache.containsKey(makeKey(id1, id2)); } }); if(min != 0) { LOG.verbose("Distance matrix is supposed to be 0-indexed. Choosing offset " + min + " to compensate."); } }
@Override public TLongFloatMap getVector(String phrase) { final TLongFloatMap vector = new TLongFloatHashMap(); for (int i = 0; i < metrics.length; i++) { try { TIntFloatMap v = PhraseUtils.getPhraseVector(metrics[i], phrase); if (v == null) continue; final int finalI = i; v.forEachEntry(new TIntFloatProcedure() { @Override public boolean execute(int key, float value) { long id = ((long) finalI) * Integer.MAX_VALUE + key; vector.put(id, (float) (value * coefficients[finalI])); return true; } }); } catch (Exception e) { LOGGER.info("SR call for " + phrase + ", metric " + metrics[i].getName() + " failed", e); } } return vector; }
return; } else if (db == null) { this.cache = new TLongFloatHashMap(); // build cache later return; TLongFloatMap cache = new TLongFloatHashMap(); Iterator<Pair<String, Double>> iter = db.iterator(); TLongSet subgrams = new TLongHashSet();
TLongFloatMap initialRanks = new TLongFloatHashMap(); degrees.forEachKey(k -> { initialRanks.putIfAbsent(k, initialRank); for (int iteration = 0; iteration < this.getNumIterations(); iteration++) { TLongFloatMap newRanks = new TLongFloatHashMap(currentRanks.size()); degrees.forEachKey(k -> { newRanks.putIfAbsent(k, dampingRank);