@Ignore @Test public void benchmark() { int numOuter = 100; int numInner = 10000; long before = System.currentTimeMillis(); double sum = 0; Random random = new Random(); for (int i = 0; i < numOuter; i++) { int overlap[] = new int[10]; for (int j = 0; j < overlap.length; j++) { overlap[j] = random.nextInt(Integer.MAX_VALUE / 10); } SparseMatrixRow row1 = makeRow(100, overlap); SparseMatrixRow row2 = makeRow(100, overlap); CosineSimilarity sim = new CosineSimilarity(); for (int j = 0; j < numInner; j++) { sum += sim.similarity(row1, row2); } } long after = System.currentTimeMillis(); System.out.println("elapsed is " + (after - before) + " sim is " + (sum / (numOuter * numInner))); }
@Override public double similarity(MatrixRow a, MatrixRow b) { return SimUtils.cosineSimilarity(a, b); }
CosineSimilarity implements VectorSimilarity { @Override public double similarity(MatrixRow a, MatrixRow b) { return SimUtils.cosineSimilarity(a, b); } }
CosineSimilarity implements VectorSimilarity { @Override public double similarity(MatrixRow a, MatrixRow b) { return SimUtils.cosineSimilarity(a, b); }  }
CosineSimilarity implements VectorSimilarity { @Override public double similarity(MatrixRow a, MatrixRow b) { return SimUtils.cosineSimilarity(a, b); }  @Override synchronized void setMatrices(SparseMatrix features, SparseMatrix transpose, File dataDir); @Override double similarity(MatrixRow a, MatrixRow b); @Override double similarity(TIntFloatMap vector1, TIntFloatMap vector2); @Override SRResultList mostSimilar(TIntFloatMap query, int maxResults, TIntSet validIds); @Override double getMinValue(); @Override double getMaxValue(); }
CosineSimilarity implements VectorSimilarity { @Override public double similarity(MatrixRow a, MatrixRow b) { return SimUtils.cosineSimilarity(a, b); }  @Override synchronized void setMatrices(SparseMatrix features, SparseMatrix transpose, File dataDir); @Override double similarity(MatrixRow a, MatrixRow b); @Override double similarity(TIntFloatMap vector1, TIntFloatMap vector2); @Override SRResultList mostSimilar(TIntFloatMap query, int maxResults, TIntSet validIds); @Override double getMinValue(); @Override double getMaxValue();  }