/** * Selects the next element of the permutation that maximizes the * objective function. * * @param remainingI positions of the original recommendation that have * not been selected yet. * @param list the list of item-score pairs of the input recommendation * @return the next element of the permutation that maximizes the * objective function. */ protected int selectItem(IntSortedSet remainingI, List<Tuple2od<I>> list) { double[] max = new double[]{Double.NEGATIVE_INFINITY}; int[] bestI = new int[]{remainingI.firstInt()}; remainingI.forEach(i -> { double value = value(list.get(i)); if (isNaN(value)) { return; } if (value > max[0] || (value == max[0] && i < bestI[0])) { max[0] = value; bestI[0] = i; } }); return bestI[0]; }
/** * Will crawl the weak hash maps and make sure we always have the latest * information on the availability of messages. * * This method is only intended to be used from within * {@link LogWatchStorageSweeper}. * * @return ID of the very first message that is reachable by any follower in * this logWatch. -1 when there are no reachable messages. */ protected synchronized int getFirstReachableMessageId() { final boolean followersRunning = !this.runningFollowerStartMarks.isEmpty(); if (!followersRunning && this.terminatedFollowerRanges.isEmpty()) { // no followers present; no reachable messages return -1; } final IntSortedSet set = new IntAVLTreeSet(this.runningFollowerStartMarks.values()); if (!set.isEmpty()) { final int first = this.messages.getFirstPosition(); if (set.firstInt() <= first) { /* * cannot go below first position; any other calculation * unnecessary */ return first; } } set.addAll(this.terminatedFollowerRanges.values().stream().map(pair -> pair[0]).collect(Collectors.toList())); return set.firstInt(); }
@Override protected int selectItem(IntSortedSet remainingI, List<Tuple2od<I>> list) { novMap = new Object2DoubleOpenHashMap<>(); relStats = new Stats(); novStats = new Stats(); remainingI.forEach(i -> { Tuple2od<I> itemValue = list.get(i); double nov = nov(itemValue); novMap.put(itemValue.v1, nov); relStats.accept(itemValue.v2); novStats.accept(nov); }); return super.selectItem(remainingI, list); }