@Test public void testNdgc() { double ndgc = ( (0.80 + 0.00 / Math.log(2+1) + 0.95 / Math.log(4+1) + 0.91 / Math.log(7+1)) / (0.95 + 0.91 / Math.log(2+1) + 0.80 / Math.log(4+1) + 0.00 / Math.log(7+1))); assertEquals(ndgc, guess.getNDGC(), 0.001); }
public double getNDGC() { if (observations.isEmpty()) { return 0.0; } TIntDoubleMap actual = new TIntDoubleHashMap(); for (KnownSim ks : known.getMostSimilar()) { actual.put(ks.wpId2, ks.similarity); } int ranks[] = new int[observations.size()]; double scores[] = new double[observations.size()]; double s = 0.0; for (int i = 0; i < observations.size(); i++) { Observation o = observations.get(i); double k = (o.rank == 1) ? 1 : Math.log(o.rank + 1); s += actual.get(o.id) / k; scores[i] = actual.get(o.id); ranks[i] = o.rank; } Arrays.sort(ranks); Arrays.sort(scores); ArrayUtils.reverse(scores); double t = 0; for (int i = 0; i < scores.length; i++) { double k = (ranks[i] == 1) ? 1 : Math.log(ranks[i] + 1); t += scores[i] / k; } return s / t; }
MostSimilarGuess { public double getNDGC() { if (observations.isEmpty()) { return 0.0; } TIntDoubleMap actual = new TIntDoubleHashMap(); for (KnownSim ks : known.getMostSimilar()) { actual.put(ks.wpId2, ks.similarity); } int ranks[] = new int[observations.size()]; double scores[] = new double[observations.size()]; double s = 0.0; for (int i = 0; i < observations.size(); i++) { Observation o = observations.get(i); double k = (o.rank == 1) ? 1 : Math.log(o.rank + 1); s += actual.get(o.id) / k; scores[i] = actual.get(o.id); ranks[i] = o.rank; } Arrays.sort(ranks); Arrays.sort(scores); ArrayUtils.reverse(scores); double t = 0; for (int i = 0; i < scores.length; i++) { double k = (ranks[i] == 1) ? 1 : Math.log(ranks[i] + 1); t += scores[i] / k; } return s / t; } }
MostSimilarGuess { public double getNDGC() { if (observations.isEmpty()) { return 0.0; } TIntDoubleMap actual = new TIntDoubleHashMap(); for (KnownSim ks : known.getMostSimilar()) { actual.put(ks.wpId2, ks.similarity); } int ranks[] = new int[observations.size()]; double scores[] = new double[observations.size()]; double s = 0.0; for (int i = 0; i < observations.size(); i++) { Observation o = observations.get(i); double k = (o.rank == 1) ? 1 : Math.log(o.rank + 1); s += actual.get(o.id) / k; scores[i] = actual.get(o.id); ranks[i] = o.rank; } Arrays.sort(ranks); Arrays.sort(scores); ArrayUtils.reverse(scores); double t = 0; for (int i = 0; i < scores.length; i++) { double k = (ranks[i] == 1) ? 1 : Math.log(ranks[i] + 1); t += scores[i] / k; } return s / t; } MostSimilarGuess(KnownMostSim known, String str);  MostSimilarGuess(KnownMostSim known, SRResultList guess); }
MostSimilarGuess { public double getNDGC() { if (observations.isEmpty()) { return 0.0; } TIntDoubleMap actual = new TIntDoubleHashMap(); for (KnownSim ks : known.getMostSimilar()) { actual.put(ks.wpId2, ks.similarity); } int ranks[] = new int[observations.size()]; double scores[] = new double[observations.size()]; double s = 0.0; for (int i = 0; i < observations.size(); i++) { Observation o = observations.get(i); double k = (o.rank == 1) ? 1 : Math.log(o.rank + 1); s += actual.get(o.id) / k; scores[i] = actual.get(o.id); ranks[i] = o.rank; } Arrays.sort(ranks); Arrays.sort(scores); ArrayUtils.reverse(scores); double t = 0; for (int i = 0; i < scores.length; i++) { double k = (ranks[i] == 1) ? 1 : Math.log(ranks[i] + 1); t += scores[i] / k; } return s / t; } MostSimilarGuess(KnownMostSim known, String str);  MostSimilarGuess(KnownMostSim known, SRResultList guess); String toString(); List<Observation> getObservations(); int getLength(); KnownMostSim getKnown(); double getNDGC(); double getPenalizedNDGC(); PrecisionRecallAccumulator getPrecisionRecall(int n, double threshold); }
MostSimilarGuess { public double getNDGC() { if (observations.isEmpty()) { return 0.0; } TIntDoubleMap actual = new TIntDoubleHashMap(); for (KnownSim ks : known.getMostSimilar()) { actual.put(ks.wpId2, ks.similarity); } int ranks[] = new int[observations.size()]; double scores[] = new double[observations.size()]; double s = 0.0; for (int i = 0; i < observations.size(); i++) { Observation o = observations.get(i); double k = (o.rank == 1) ? 1 : Math.log(o.rank + 1); s += actual.get(o.id) / k; scores[i] = actual.get(o.id); ranks[i] = o.rank; } Arrays.sort(ranks); Arrays.sort(scores); ArrayUtils.reverse(scores); double t = 0; for (int i = 0; i < scores.length; i++) { double k = (ranks[i] == 1) ? 1 : Math.log(ranks[i] + 1); t += scores[i] / k; } return s / t; } MostSimilarGuess(KnownMostSim known, String str);  MostSimilarGuess(KnownMostSim known, SRResultList guess); String toString(); List<Observation> getObservations(); int getLength(); KnownMostSim getKnown(); double getNDGC(); double getPenalizedNDGC(); PrecisionRecallAccumulator getPrecisionRecall(int n, double threshold);  }