public void testLSH() {
System.setProperty("model.lsh.sampleRatio", "0.1");
System.setProperty("model.lsh.numHashes", "20");
RandomGenerator random = RandomManager.getRandom();
Mean avgPercentTopRecsConsidered = new Mean();
Mean avgNDCG = new Mean();
Mean avgPercentAllItemsConsidered= new Mean();
for (int iteration = 0; iteration < ITERATIONS; iteration++) {
FastByIDMap<float[]> Y = new FastByIDMap<float[]>();
for (int i = 0; i < NUM_ITEMS; i++) {
Y.put(i, RandomUtils.randomUnitVector(NUM_FEATURES, random));
}
float[] userVec = RandomUtils.randomUnitVector(NUM_FEATURES, random);
double[] results = doTestRandomVecs(Y, userVec);
double percentTopRecsConsidered = results[0];
double ndcg = results[1];
double percentAllItemsConsidered = results[2];
log.info("Considered {}% of all candidates, {} nDCG, got {}% recommendations correct",
100 * percentAllItemsConsidered,
ndcg,
100 * percentTopRecsConsidered);
avgPercentTopRecsConsidered.increment(percentTopRecsConsidered);
avgNDCG.increment(ndcg);
avgPercentAllItemsConsidered.increment(percentAllItemsConsidered);
}
log.info("{}", avgPercentTopRecsConsidered.getResult());
log.info("{}", avgNDCG.getResult());
log.info("{}", avgPercentAllItemsConsidered.getResult());
assertTrue(avgPercentTopRecsConsidered.getResult() > 0.55);
assertTrue(avgNDCG.getResult() > 0.55);
assertTrue(avgPercentAllItemsConsidered.getResult() < 0.075);
}