All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ciir.umass.edu.metric.PrecisionScorer 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 PrecisionScorer extends MetricScorer {

	public PrecisionScorer()
	{
		this.k = 10;
	}
	public PrecisionScorer(int k)
	{
		this.k = k;
	}
	public double score(RankList rl)
	{
		int count = 0;
		
		int size = k;
		if(k > rl.size() || k <= 0)
			size = rl.size();
		
		for(int i=0;i 0.0)//relevant
				count++;
		}
		return ((double)count)/size;
	}
	public MetricScorer copy()
	{
		return new PrecisionScorer();
	}
	public String name()
	{
		return "P@"+k;
	}
	public double[][] swapChange(RankList rl)
	{
		int size = (rl.size() > k) ? k : rl.size();
		/*int relCount = 0;
		for(int i=0;i 0.0)//relevant
				relCount++;*/
		
		double[][] changes = new double[rl.size()][];
		for(int i=0;i 0.0)
			return 1;
		return 0;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy