es.ucm.fdi.gaia.jcolibri.method.reuse.classification.UnanimousVotingMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jCOLIBRI Show documentation
Show all versions of jCOLIBRI Show documentation
jCOLIBRI is a java framework for the development of Case-Based Reasoning systems.
package es.ucm.fdi.gaia.jcolibri.method.reuse.classification;
import java.util.Collection;
import es.ucm.fdi.gaia.jcolibri.extensions.classification.ClassificationSolution;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult;
/**
* Provides the ability to classify a query by predicting its
* solution from supplied cases. Classification is done by
* unaimous voting respecting to a class. That class is
* configured using the constructor .
*
* @author Juan A. Recio Garcia
* 16/05/07
*/
public class UnanimousVotingMethod extends AbstractKNNClassificationMethod
{
private Object _class;
public UnanimousVotingMethod(Object classification)
{
_class = classification;
}
/**
* Predicts the class that has all the votes
* among the k most similar cases and is equal to the class configured
* using the constructor.
* If several classes receive the same highest vote, the class that
* has the lowest hash code is taken as the prediction.
* @param cases
* an ordered list of cases along with similarity scores.
* @return Returns the predicted solution.
*/
public ClassificationSolution getPredictedSolution(Collection cases)
{
ClassificationSolution solution = null;
for (RetrievalResult result: cases)
{
ClassificationSolution sol = (ClassificationSolution)result.get_case().getSolution();
Object classif = sol.getClassification();
if(classif.equals(_class))
solution = sol;
else
return sol;
}
return solution;
}
}