ciir.umass.edu.metric.ReciprocalRankScorer 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.Arrays;
import ciir.umass.edu.learning.RankList;
/**
* @author vdang
*/
public class ReciprocalRankScorer extends MetricScorer {
public ReciprocalRankScorer()
{
this.k = 0;//consider the whole list
}
public double score(RankList rl)
{
int size = (rl.size() > k) ? k : rl.size();
int firstRank = -1;
for(int i=0;i 0.0)//relevant
firstRank = i+1;
}
return (firstRank==-1)?0:(1.0f/firstRank);
}
public MetricScorer copy()
{
return new ReciprocalRankScorer();
}
public String name()
{
return "RR@"+k;
}
public double[][] swapChange(RankList rl)
{
int firstRank = -1;
int secondRank = -1;
int size = (rl.size() > k) ? k : rl.size();
for(int i=0;i 0.0)//relevant
{
if(firstRank==-1)
firstRank = i;
else if(secondRank == -1)
secondRank = i;
}
}
//compute the change in RR by swapping each pair
double[][] changes = new double[rl.size()][];
for(int i=0;i 0)
changes[i][j] = changes[j][i] = 1.0/(i+1) - rr;
}
}
return changes;
}
}