es.ucm.fdi.gaia.jcolibri.method.maintenance.solvesFunctions.ICFSolvesFunction 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.maintenance.solvesFunctions;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase;
import es.ucm.fdi.gaia.jcolibri.extensions.classification.ClassificationSolution;
import es.ucm.fdi.gaia.jcolibri.method.maintenance.SolvesFunction;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.NNScoringMethod;
import es.ucm.fdi.gaia.jcolibri.method.retrieve.selection.SelectCases;
import es.ucm.fdi.gaia.jcolibri.method.reuse.classification.KNNClassificationConfig;
import es.ucm.fdi.gaia.jcolibri.method.revise.classification.BasicClassificationOracle;
import es.ucm.fdi.gaia.jcolibri.method.revise.classification.ClassificationOracle;
/**
* Provides the ICF algorithm solves function which will
* decide which cases solve a query.
*
* @author Lisa Cummins
* @author Derek Bridge
* 22/05/07
*/
public class ICFSolvesFunction extends SolvesFunction
{
/**
* Sets the cases that both solve q or contribute to its
* misclassification. In the case of ICF we only record
* cases that solve q. According to the ICF definition,
* a case solves a query if it is of the same class as
* the query and if there are no classes more similar
* to the query with a different class.
*
* @param q the query
* @param cases from which to find the cases which solve
* and classify the query. These include the query itself.
* @param knnConfig the similarity configuration
*/
public void setCasesThatSolveAndMisclassifyQ(CBRCase q, Collection cases, KNNClassificationConfig knnConfig)
{
solveQ = new LinkedList();
misclassifyQ = null;
knnConfig.setK(RetrievalResult.RETRIEVE_ALL);
Collection orderedRetrievedCases = NNScoringMethod.evaluateSimilarity(cases, q, knnConfig);
orderedRetrievedCases = SelectCases.selectTopKRR(orderedRetrievedCases, knnConfig.getK());
ClassificationOracle oracle = new BasicClassificationOracle();
boolean disagreeingCaseFound = false;
Iterator iter = orderedRetrievedCases.iterator();
while(!disagreeingCaseFound && iter.hasNext())
{ CBRCase c = iter.next().get_case();
ClassificationSolution cSol = (ClassificationSolution)c.getSolution();
if(oracle.isCorrectPrediction(cSol, q))
{ solveQ.add(c);
}
else
{ disagreeingCaseFound = true;
}
}
}
}