@Override public int[] rerankPermutation(Recommendation<U, I> recommendation, int maxLength) { List<Tuple2od<I>> items = recommendation.getItems(); int M = items.size(); int N = min(maxLength, M); IntDoubleTopN topN = new IntDoubleTopN(N); for (int i = 0; i < M; i++) { topN.add(M - i, likelihood(items.get(i)) * prior(items.get(i).v1)); } topN.sort(); return topN.reverseStream() .mapToInt(e -> M - e.v1) .toArray(); }
@Override public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) { if (maxLength == 0) { maxLength = numItems(); } IntDoubleTopN topN = new IntDoubleTopN(maxLength); getAllIidx() .filter(filter) .forEach(iidx -> topN.add(iidx, fm.predict(uidx, new IdxPref(iidx, NaN)))); topN.sort(); List<Tuple2id> items = topN.reverseStream() .collect(toList()); return new FastRecommendation(uidx, items); }
@Override public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) { IntDoubleTopN topN = new IntDoubleTopN(min(maxLength, numItems())); for (int iidx = 0; iidx < numItems(); iidx++) { if (filter.test(iidx)) { topN.add(iidx, score(topicModel, uidx, iidx)); } } topN.sort(); List<Tuple2id> items = topN.reverseStream() .collect(toList()); return new FastRecommendation(uidx, items); }
@Override public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) { if (uidx == -1) { return new FastRecommendation(uidx, new ArrayList<>(0)); } Int2DoubleMap scoresMap = getScoresMap(uidx); final IntDoubleTopN topN = new IntDoubleTopN(min(maxLength, scoresMap.size())); scoresMap.int2DoubleEntrySet().forEach(e -> { int iidx = e.getIntKey(); double score = e.getDoubleValue(); if (filter.test(iidx)) { topN.add(iidx, score); } }); topN.sort(); List<Tuple2id> items = topN.reverseStream() .collect(toList()); return new FastRecommendation(uidx, items); }
@Override public FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter) { DoubleMatrix1D pu; pu = factorization.getUserVector(uidx2user(uidx)); if (pu == null) { return new FastRecommendation(uidx, new ArrayList<>()); } IntDoubleTopN topN = new IntDoubleTopN(min(maxLength, factorization.numItems())); DoubleMatrix1D r = factorization.getItemMatrix().zMult(pu, null); for (int iidx = 0; iidx < r.size(); iidx++) { if (filter.test(iidx)) { topN.add(iidx, r.getQuick(iidx)); } } topN.sort(); List<Tuple2id> items = topN.reverseStream() .collect(toList()); return new FastRecommendation(uidx, items); }
return topN.reverseStream() .mapToInt(e -> M - e.v1) .toArray();