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

es.ucm.fdi.gaia.jcolibri.method.reuse.classification.UnanimousVotingMethod Maven / Gradle / Ivy

Go to download

jCOLIBRI is a java framework for the development of Case-Based Reasoning systems.

There is a newer version: 3.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy