public void init( RankingSample sample, double[] scores, int beginIdx, int endIdx, TieBreaker tieBreaker) { this.sample = sample; this.beginIdx = beginIdx; this.endIdx = endIdx; comparator.labels = sample.targets; comparator.scores = scores; comparator.tieBreaker = tieBreaker; Arrays.fill(result, 0); }
@Override public void run() { for (int q = beginIdx; q < endIdx; q++) { int begin = sample.queryBoundaries[q]; int numDocs = sample.queryBoundaries[q + 1] - begin; comparator.offset = begin; for (int d = 0; d < numDocs; d++) { permutation[d] = d; } ArraysUtil.sort(permutation, numDocs, comparator); try { int numRelevant = 0; for (int pos = 0; pos < Math.min(numDocs, maxLevels); pos++) { if (sample.targets[begin + permutation[pos]] >= relevancyThreshold) { numRelevant++; } result[pos] += ((double) numRelevant / (pos + 1)); } } catch (Exception e) { e.printStackTrace(); } } }