001 package jcolibri.method.maintenance.solvesFunctions; 002 003 import java.util.Collection; 004 import java.util.Iterator; 005 import java.util.LinkedList; 006 007 import jcolibri.cbrcore.CBRCase; 008 import jcolibri.extensions.classification.ClassificationSolution; 009 import jcolibri.method.maintenance.SolvesFunction; 010 import jcolibri.method.retrieve.RetrievalResult; 011 import jcolibri.method.retrieve.NNretrieval.NNScoringMethod; 012 import jcolibri.method.retrieve.selection.SelectCases; 013 import jcolibri.method.reuse.classification.KNNClassificationConfig; 014 import jcolibri.method.revise.classification.BasicClassificationOracle; 015 import jcolibri.method.revise.classification.ClassificationOracle; 016 017 /** 018 * Provides the ICF algorithm solves function which will 019 * decide which cases solve a query. 020 * 021 * @author Lisa Cummins 022 * @author Derek Bridge 023 * 22/05/07 024 */ 025 public class ICFSolvesFunction extends SolvesFunction 026 { 027 /** 028 * Sets the cases that both solve q or contribute to its 029 * misclassification. In the case of ICF we only record 030 * cases that solve q. According to the ICF definition, 031 * a case solves a query if it is of the same class as 032 * the query and if there are no classes more similar 033 * to the query with a different class. 034 * 035 * @param q the query 036 * @param cases from which to find the cases which solve 037 * and classify the query. These include the query itself. 038 * @param knnConfig the similarity configuration 039 */ 040 public void setCasesThatSolveAndMisclassifyQ(CBRCase q, Collection<CBRCase> cases, KNNClassificationConfig knnConfig) 041 { 042 solveQ = new LinkedList<CBRCase>(); 043 misclassifyQ = null; 044 045 knnConfig.setK(RetrievalResult.RETRIEVE_ALL); 046 Collection<RetrievalResult> orderedRetrievedCases = NNScoringMethod.evaluateSimilarity(cases, q, knnConfig); 047 orderedRetrievedCases = SelectCases.selectTopKRR(orderedRetrievedCases, knnConfig.getK()); 048 049 ClassificationOracle oracle = new BasicClassificationOracle(); 050 boolean disagreeingCaseFound = false; 051 Iterator<RetrievalResult> iter = orderedRetrievedCases.iterator(); 052 while(!disagreeingCaseFound && iter.hasNext()) 053 { CBRCase c = iter.next().get_case(); 054 ClassificationSolution cSol = (ClassificationSolution)c.getSolution(); 055 if(oracle.isCorrectPrediction(cSol, q)) 056 { solveQ.add(c); 057 } 058 else 059 { disagreeingCaseFound = true; 060 } 061 } 062 } 063 }