ciir.umass.edu.metric.ERRScorer Maven / Gradle / Ivy
/*===============================================================================
* Copyright (c) 2010-2012 University of Massachusetts. All Rights Reserved.
*
* Use of the RankLib package is subject to the terms of the software license set
* forth in the LICENSE file included with this software, and also available at
* http://people.cs.umass.edu/~vdang/ranklib_license.html
*===============================================================================
*/
package ciir.umass.edu.metric;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import ciir.umass.edu.learning.RankList;
/**
*
* @author Van Dang
* Expected Reciprocal Rank
*/
public class ERRScorer extends MetricScorer {
public static double MAX = 16;//by default, we assume the relevance scale of {0, 1, 2, 3, 4} => g_max = 4 => 2^g_max = 16
public ERRScorer()
{
this.k = 10;
}
public ERRScorer(int k)
{
this.k = k;
}
public ERRScorer copy()
{
return new ERRScorer();
}
/**
* Compute ERR at k. NDCG(k) = DCG(k) / DCG_{perfect}(k). Note that the "perfect ranking" must be computed based on the whole list,
* not just top-k portion of the list.
*/
public double score(RankList rl)
{
int size = k;
if(k > rl.size() || k <= 0)
size = rl.size();
List rel = new ArrayList();
for(int i=0;i k) ? k : rl.size();
int[] labels = new int[rl.size()];
double[] R = new double[rl.size()];
double[] np = new double[rl.size()];//p[i] = (1 - p[0])(1 - p[1])...(1-p[i-1])
double p = 1.0;
//for(int i=0;i