From: <jen...@us...> - 2008-06-27 14:28:52
|
Revision: 986 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=986&view=rev Author: jenslehmann Date: 2008-06-27 07:28:48 -0700 (Fri, 27 Jun 2008) Log Message: ----------- extension of abstract LearningAlgorithm class and many subsequent (possibly code-breaking) changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/core/Score.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-06-27 14:28:48 UTC (rev 986) @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -277,8 +278,13 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return bestDefinition; + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(bestDefinition,bestScore); } @Override @@ -286,4 +292,22 @@ stop = true; } + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#pause() + */ + @Override + public void pause() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#resume() + */ + @Override + public void resume() { + // TODO Auto-generated method stub + + } + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-27 14:28:48 UTC (rev 986) @@ -24,6 +24,7 @@ import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -145,12 +146,35 @@ } @Override - public Description getBestSolution() { - return learner.getBestSolution(); + public Description getCurrentlyBestDescription() { + return learner.getCurrentlyBestDescription(); + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return learner.getCurrentlyBestEvaluatedDescription(); } @Override public Score getSolutionScore() { return learner.getSolutionScore(); } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#pause() + */ + @Override + public void pause() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#resume() + */ + @Override + public void resume() { + // TODO Auto-generated method stub + + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-06-27 14:28:48 UTC (rev 986) @@ -25,6 +25,7 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -117,8 +118,13 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return bestDefinition; + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(bestDefinition,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,9 +1,8 @@ package org.dllearner.algorithms; -import java.util.Set; -import java.util.List; import java.util.*; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -25,9 +24,14 @@ //this.learningProblem = learningProblem; } - public Description getBestSolution() + public Description getCurrentlyBestDescription() { return bestSollution; + } + + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() + { + return new EvaluatedDescription(bestSollution, solutionScore); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-06-27 14:28:48 UTC (rev 986) @@ -30,6 +30,7 @@ import java.util.Map.Entry; import org.dllearner.algorithms.hybridgp.Psi; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -948,9 +949,14 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { + return bestConcept; + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { // return fittestIndividual.getTree(); - return bestConcept; + return new EvaluatedDescription(bestConcept,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-06-27 14:28:48 UTC (rev 986) @@ -25,9 +25,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.SortedSet; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -391,21 +393,24 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return algorithm.getBestSolution(); } @Override - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { - return algorithm.getBestSolutions(nrOfSolutions); + public synchronized SortedSet<Description> getCurrentlyBestDescriptions() { + return algorithm.getCurrentlyBestDescriptions(); } @Override - public synchronized List<Description> getGoodSolutions() { - return algorithm.getGoodSolutions(); + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(algorithm.getBestSolution(),algorithm.getSolutionScore()); } - + @Override + public synchronized SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + return algorithm.getCurrentlyBestEvaluatedDescriptions(); + } @Override public void stop() { @@ -415,14 +420,15 @@ public ExampleBasedNode getStartNode() { return algorithm.getStartNode(); } + + @Override + public void pause() { + // TODO: not implemented + } + + @Override + public void resume() { + // TODO: not implemented + } - - /*public void printBestSolutions(int nrOfSolutions){ - - algorithm.printBestSolutions(nrOfSolutions); - }*/ - - - - } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-06-27 14:28:48 UTC (rev 986) @@ -33,6 +33,7 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -455,8 +456,7 @@ String KBSyntax="KBSyntax:\n"; for(Description c : solutions) { logger.info(show+": " + c.toString(baseURI,null) + " (length " + c.getLength() +", depth " + c.getDepth() + ")"); - // watch for String.replace Quick hack - manchester+=show+": "+c.toManchesterSyntaxString(baseURI, new HashMap<String,String>()).replace("\"", "")+"\n"; + manchester+=show+": "+c.toManchesterSyntaxString(baseURI, new HashMap<String,String>())+"\n"; KBSyntax+=show+": " + c.toKBSyntaxString()+"\n"; if(show>=5){break;} show++; } @@ -1059,43 +1059,34 @@ return candidatesStable.last().getConcept(); } - - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { - List<Description> best = new LinkedList<Description>(); + public SortedSet<Description> getCurrentlyBestDescriptions() { + SortedSet<Description> best = new TreeSet<Description>(); int i=0; + int nrOfSolutions = 200; for(ExampleBasedNode n : candidatesStable.descendingSet()) { - - best.add(n.getConcept()); - if(i==nrOfSolutions) - return best; + best.add(n.getConcept()); + if(i==nrOfSolutions) + return best; i++; } return best; } - - /** - * returns the solutions, that have at least a certain quality - * either accuracy = 100% full solutions - * or accuracy > 100% - noise; - * @return - */ - public synchronized List<Description> getGoodSolutions() { - List<Description> best = new LinkedList<Description>(); - - for(ExampleBasedNode n : candidatesStable.descendingSet()) { - if(n.getAccuracy(nrOfPositiveExamples, nrOfNegativeExamples)<(1-noise)) - return best; - best.add(n.getConcept()); - + public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + int count = 0; + SortedSet<ExampleBasedNode> rev = candidatesStable.descendingSet(); + SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(); + for(ExampleBasedNode eb : rev) { + cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept()))); + // return a maximum of 200 elements (we need a maximum, because the + // candidate set can be very large) + if(count > 200) + return cbd; + count++; } - return best; + return cbd; } - - - - public void printBestSolutions(int nrOfSolutions, boolean showOrderedSolutions){ //QUALITY: could be optimized if(!logger.isTraceEnabled()) @@ -1136,6 +1127,13 @@ return learningProblem.computeScore(getBestSolution()); } + private Score getScore(Description d) { + if(posOnly) + return posOnlyLearningProblem.computeScore(d); + else + return learningProblem.computeScore(d); + } + public ExampleBasedNode getStartNode() { return startNode; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-27 14:28:48 UTC (rev 986) @@ -14,6 +14,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -1033,8 +1034,13 @@ } @Override - public Description getBestSolution() { + public Description getCurrentlyBestDescription() { return candidatesStable.last().getConcept(); + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore()); } public void printBestSolutions(int nrOfSolutions){ @@ -1050,7 +1056,7 @@ } @Override - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { + public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfSolutions) { List<Description> best = new LinkedList<Description>(); int i=0; for(Node n : candidatesStable.descendingSet()) { @@ -1065,9 +1071,9 @@ @Override public Score getSolutionScore() { if(posOnly) - return posOnlyLearningProblem.computeScore(getBestSolution()); + return posOnlyLearningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); else - return learningProblem.computeScore(getBestSolution()); + return learningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); } Added: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-27 14:28:48 UTC (rev 986) @@ -0,0 +1,108 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.Set; + +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.ScoreTwoValued; + +/** + * This represents a class description, which has been + * evaluated by the learning algorithm, i.e. it has been checked + * which examples it covers. It can be used as return value for + * learning algorithms to make it easier for applications to + * assess how good an offered class description is and how it + * classifies particular examples. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescription { + + private Description description; + private Score score; + + public EvaluatedDescription(Description description, Score score) { + this.description = description; + this.score = score; + } + + public EvaluatedDescription(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { + this.description = description; + // usually core methods should not depend on methods outside of the core package (except utilities) + // in this case, this is just a convenience constructor + score = new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg); + } + + public Description getDescription() { + return description; + } + + public int getDescriptionLength() { + return description.getLength(); + } + + public int getDescriptionDepth() { + return description.getDepth(); + } + + /** + * @return + * @see org.dllearner.core.Score#getAccuracy() + */ + public double getAccuracy() { + return score.getAccuracy(); + } + + /** + * @return + * @see org.dllearner.core.Score#getCoveredNegatives() + */ + public Set<Individual> getCoveredNegatives() { + return score.getCoveredNegatives(); + } + + /** + * @return + * @see org.dllearner.core.Score#getCoveredPositives() + */ + public Set<Individual> getCoveredPositives() { + return score.getCoveredPositives(); + } + + /** + * @return + * @see org.dllearner.core.Score#getNotCoveredNegatives() + */ + public Set<Individual> getNotCoveredNegatives() { + return score.getNotCoveredNegatives(); + } + + /** + * @return + * @see org.dllearner.core.Score#getNotCoveredPositives() + */ + public Set<Individual> getNotCoveredPositives() { + return score.getNotCoveredPositives(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -22,73 +22,188 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.owl.Description; +import org.dllearner.utilities.owl.ConceptTransformation; /** + * Abstract superclass of all learning algorithm implementations. + * Includes support for anytime learning algorithms and resumable + * learning algorithms. Provides methods for filtering the best + * descriptions found by the algorithm. As results of the algorithm, + * you can either get only descriptions or evaluated descriptions. + * Evaluated descriptions have information about accuracy and + * example coverage associated with them. However, retrieving those + * may require addition reasoner queries, because the learning + * algorithms usually use but do not necessarily store this information. + * * @author Jens Lehmann * */ public abstract class LearningAlgorithm extends Component { /** - * Starts the algorithm. - * + * Starts the algorithm. It runs until paused, stopped, or + * a termination criterion has been reached. */ public abstract void start(); - /** - * Stops the algorithm gracefully. - * + * Pauses the algorithm (not all algorithms need to implement + * this operation). */ + public void pause() { }; + + /** + * Resumes the algorithm (not all algorithms need to implement + * this operation). You can use this method to continue + * an algorithm run even after a termination criterion has been + * reached. It will run until paused, stopped, or terminated + * again. + */ + public void resume() { }; + + /** + * Stops the algorithm gracefully. A stopped algorithm cannot be resumed anymore. + * Use this method for cleanup and freeing memory. + */ public abstract void stop(); - + /** * Every algorithm must be able to return the score of the * best solution found. + * * @return Best score. */ + @Deprecated public abstract Score getSolutionScore(); /** - * Returns the best solutions obtained so far. - * @return Best solution. + * @see #getCurrentlyBestEvaluatedDescription() */ - public abstract Description getBestSolution(); + public abstract Description getCurrentlyBestDescription(); + /** + * @see #getCurrentlyBestEvaluatedDescriptions() + */ + public SortedSet<Description> getCurrentlyBestDescriptions() { + TreeSet<Description> ds = new TreeSet<Description>(); + ds.add(getCurrentlyBestDescription()); + return ds; + } + /** + * @see #getCurrentlyBestEvaluatedDescriptions(int) + */ + public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { + return getCurrentlyBestDescriptions(nrOfDescriptions, false); + } /** - * returns the best nrOfSolutions solutions - * regardless of quality, just depends on input int - * @param nrOfSolutions - * @return List<Description> + * @see #getCurrentlyBestEvaluatedDescriptions(int,double,boolean) */ - public synchronized List<Description> getBestSolutions(int nrOfSolutions) { - List<Description> single = new LinkedList<Description>(); - single.add(getBestSolution()); - return single; + public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions, boolean filterNonMinimalDescriptions) { + SortedSet<Description> currentlyBest = getCurrentlyBestDescriptions(); + List<Description> returnList = new LinkedList<Description>(); + int count = 0; + for(Description ed : currentlyBest) { + // return if we have sufficiently many descriptions + if(count >= nrOfDescriptions) + return returnList; + + if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed)) + returnList.add(ed); + + count++; + } + return returnList; + } + + /** + * Returns the best descriptions obtained so far. + * @return Best class description found so far. + */ + public abstract EvaluatedDescription getCurrentlyBestEvaluatedDescription(); + + /** + * Returns a sorted set of the best descriptions found so far. We + * assume that they are ordered such that the best ones come in + * first. + * @return Best class descriptions found so far. + */ + public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + TreeSet<EvaluatedDescription> ds = new TreeSet<EvaluatedDescription>(); + ds.add(getCurrentlyBestEvaluatedDescription()); + return ds; } /** - * returns the solutions, that have at least a certain quality - * either accuracy = 100%, i.e. full solutions - * or accuracy > 100% - noise; - * @return + * Returns a filtered list of currently best class descriptions. + * + * @param nrOfDescriptions Maximum number of restrictions. Use Integer.MAX_VALUE + * if you do not want this filter to be active. + * + * @param accuracyThreshold Minimum accuracy. All class descriptions with lower + * accuracy are disregarded. Specify a value between 0.0 and 1.0. Use 0.0 if + * you do not want this filter to be active. + * + * @param filterNonMinimalDescriptions If true, non-minimal descriptions are + * filtered, e.g. ALL r.TOP (being equivalent to TOP), male AND male (can be + * shortened to male). Currently, non-minimal descriptions are just skipped, + * i.e. they are completely omitted from the return list. Later, implementation + * might be changed to return shortened versions of those descriptions. + * + * @return A list of currently best class descriptions. */ - public synchronized List<Description> getGoodSolutions() { - List<Description> single = new LinkedList<Description>(); - single.add(getBestSolution()); - return single; + public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) { + SortedSet<EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions(); + List<EvaluatedDescription> returnList = new LinkedList<EvaluatedDescription>(); + int count = 0; + for(EvaluatedDescription ed : currentlyBest) { + // once we hit a description with a below threshold accuracy, we simply return + // because learning algorithms are advised to order descriptions by accuracy, + // so we won't find any concept with higher accuracy in the remaining list + if(ed.getAccuracy() < accuracyThreshold) + return returnList; + + // return if we have sufficiently many descriptions + if(count >= nrOfDescriptions) + return returnList; + + if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed.getDescription())) + returnList.add(ed); + + count++; + } + return returnList; } + /** + * Return the best currently found concepts up to some maximum + * count (no minimality filter used). + * @param nrOfDescriptions Maximum number of descriptions returned. + * @return Return value is getCurrentlyBestDescriptions(nrOfDescriptions, 0.0, false). + */ + public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions) { + return getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions, 0.0, false); + } /** + * Returns a fraction of class descriptions with sufficiently high accuracy. + * @param accuracyThreshold Only return solutions with this accuracy or higher. + * @return Return value is getCurrentlyBestDescriptions(Integer.MAX_VALUE, accuracyThreshold, false). + */ + public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) { + return getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, accuracyThreshold, false); + } + + /** * Returns all learning problems supported by this component. */ public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { return new LinkedList<Class<? extends LearningProblem>>(); } - + } Modified: trunk/src/dl-learner/org/dllearner/core/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Score.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/core/Score.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.core; import java.util.Set; @@ -4,9 +24,26 @@ import org.dllearner.core.owl.Individual; +/** + * The score class is used to store how well a class description did + * on a learning problem. + * + * @author Jens Lehmann + * + */ public abstract class Score { + + // accuracy + public abstract double getAccuracy(); + + // example coverage + public abstract Set<Individual> getCoveredPositives(); + public abstract Set<Individual> getCoveredNegatives(); + public abstract Set<Individual> getNotCoveredPositives(); + public abstract Set<Individual> getNotCoveredNegatives(); + + // older methods (not frequently used anymore) public abstract double getScore(); - /** * The score of a concept depends on how good it classifies the * examples of a learning problem and the length of the concept @@ -20,9 +57,4 @@ */ public abstract Score getModifiedLengthScore(int newLength); - public abstract Set<Individual> getCoveredPositives(); - public abstract Set<Individual> getCoveredNegatives(); - public abstract Set<Individual> getNotCoveredPositives(); - - // public abstract int getNrOfMiss } Modified: trunk/src/dl-learner/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-06-27 14:28:48 UTC (rev 986) @@ -284,7 +284,7 @@ //System.out.println("best"+la.getBestSolution()); }catch (Exception e) {e.printStackTrace();} - return la.getBestSolution(); + return la.getCurrentlyBestDescription(); } static KB getKB(SortedSet<Integer> lines){ Modified: trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-06-27 14:28:48 UTC (rev 986) @@ -198,7 +198,7 @@ // wait for a solution (note that not all learning problems have a // solution (100% accuracy), so one usually has to run the algorithm in its own // thread, such that it can be aborted after some time - Description solution = la.getBestSolution(); + Description solution = la.getCurrentlyBestDescription(); solutionDisplay.setText(solution.toString()); } } Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-06-27 14:28:48 UTC (rev 986) @@ -172,9 +172,9 @@ infoArea.setText(""); // best solutions - if (config.getLearningAlgorithm().getBestSolutions(5) != null) { + if (config.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(5) != null) { infoArea.append("Best solutions: \n\n" - + listToString(config.getLearningAlgorithm().getBestSolutions(10)) + "\n"); + + listToString(config.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(10)) + "\n"); } // solution score // if (config.getLearningAlgorithm().getSolutionScore() != null) @@ -257,7 +257,7 @@ if (millis > 0) time += millis + "ms "; if (false) - time += mikros + "\xB5s "; + time += mikros + "�s "; if (false) time += nanos + "ns "; return time; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2008-06-27 14:28:48 UTC (rev 986) @@ -233,6 +233,22 @@ @Override public Score getModifiedLengthScore(int newLength) { return new ScoreThreeValued(newLength, accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, posClassified, neutClassified, negClassified, posExamples, neutExamples, negExamples); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Score#getAccuracy() + */ + @Override + public double getAccuracy() { + return accuracy; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Score#getNotCoveredNegatives() + */ + @Override + public Set<Individual> getNotCoveredNegatives() { + return negAsNeg; } } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + package org.dllearner.learningproblems; import java.util.Set; @@ -6,10 +26,15 @@ import org.dllearner.core.owl.Individual; /** + * Calculates accuracy and score (with respect to some length penalty) of + * a class description. * - * TODO: accuracy-Berechnung (positive+negative Beispiele muessen dafuer bekannt sein) + * TODO: In fact, a score value influencing a learning algorithm + * should not be calculated here, but rather in a separate heuristic + * as there are many methods to calculate such a value. This class + * should only be used for computing example coverage, accuracy etc. * - * @author jl + * @author Jens Lehmann * */ public class ScoreTwoValued extends Score { @@ -19,11 +44,15 @@ private Set<Individual> negAsPos; private Set<Individual> negAsNeg; private double score; - private double classificationScore; + private double accuracy; private int nrOfExamples; private int conceptLength; private double percentPerLengthUnit; + public ScoreTwoValued(Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { + this(0,0,posAsPos,posAsNeg,negAsPos,posAsPos); + } + public ScoreTwoValued(int conceptLength, double percentPerLengthUnit, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { this.conceptLength = conceptLength; this.percentPerLengthUnit = percentPerLengthUnit; @@ -36,15 +65,22 @@ } private void computeScore() { - // - Anzahl falscher Klassifikationen - classificationScore = - posAsNeg.size() - negAsPos.size(); - // Anteil falscher Klassifikationen (Zahl zwischen -1 und 0) - classificationScore = classificationScore / (double) nrOfExamples; - // Berücksichtigung des Längenfaktors - score = classificationScore - percentPerLengthUnit * conceptLength; + // compute accuracy + accuracy = posAsPos.size() + negAsNeg.size(); + accuracy = accuracy / (double) nrOfExamples; + // compute score + score = accuracy - 1 - percentPerLengthUnit * conceptLength; } @Override + public double getAccuracy() { + return accuracy; + } + + /** + * score = accuracy - 1 - length * length penalty + */ + @Override public double getScore() { return score; } @@ -53,7 +89,7 @@ public String toString() { String str = ""; str += "score: " + score + "\n"; - str += "accuracy: " + (1 + classificationScore) + "\n"; + str += "accuracy: " + accuracy + "\n"; str += "posAsPos (" + posAsPos.size() + "): " + posAsPos + "\n"; str += "positive examples classified as negative (" + posAsNeg.size() + "): " + posAsNeg + "\n"; str += "negative examples classified as positive (" + negAsPos.size() + "): " + negAsPos + "\n"; @@ -74,16 +110,15 @@ public Set<Individual> getNotCoveredPositives() { return posAsNeg; } - - /* + @Override - public double getModifiedLengthScore(int newLength) { - return classificationScore - Config.percentPerLengthUnit * newLength; - } - */ + public Set<Individual> getNotCoveredNegatives() { + return negAsNeg; + } @Override public Score getModifiedLengthScore(int newLength) { return new ScoreTwoValued(newLength, percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); - } + } + } Modified: trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java 2008-06-27 14:28:48 UTC (rev 986) @@ -222,7 +222,7 @@ long algorithmDuration = System.nanoTime() - algorithmStartTime; runtime.addNumber(algorithmDuration/(double)1000000000); - Description concept = la.getBestSolution(); + Description concept = la.getCurrentlyBestDescription(); ReasoningService rs = start.getReasoningService(); Set<Individual> tmp = rs.instanceCheck(concept, testSetsPos.get(currFold)); Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-06-27 14:28:48 UTC (rev 986) @@ -89,7 +89,7 @@ s.makeExamples(prim, percentOfSKOSSet, negfactor, sparqlResultSize); - List<Description> conceptresults = s.learn(); + SortedSet<Description> conceptresults = s.learn(); logger.debug("found nr of concepts: "+conceptresults.size()); System.out.println(conceptresults); @@ -249,7 +249,7 @@ logger.debug(fullPosSetWithoutPosExamples); } - public List<Description> learn(){ + public SortedSet<Description> learn(){ SortedSet<String> instances = new TreeSet<String>(); instances.addAll(this.posExamples); @@ -330,7 +330,7 @@ //Statistics.addTimeLearning(sc.getTime()); - return la.getGoodSolutions(); + return la.getCurrentlyBestDescriptions(); }catch (Exception e) {e.printStackTrace();} return null; Modified: trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java 2008-06-27 14:28:48 UTC (rev 986) @@ -57,7 +57,7 @@ Start start = new Start(new File(filenameTrain)); start.start(false); - Description solution = start.getLearningAlgorithm().getBestSolution(); + Description solution = start.getLearningAlgorithm().getCurrentlyBestDescription(); logger.setLevel(Level.WARN); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-27 14:28:48 UTC (rev 986) @@ -308,7 +308,7 @@ public String learn(int id, String format) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); - Description solution = state.getLearningAlgorithm().getBestSolution(); + Description solution = state.getLearningAlgorithm().getCurrentlyBestDescription(); if(format.equals("manchester")) return solution.toManchesterSyntaxString(state.getReasoningService().getBaseURI(), new HashMap<String,String>()); else if(format.equals("kb")) @@ -342,13 +342,13 @@ @WebMethod public String getCurrentlyBestConcept(int id) throws ClientNotKnownException { ClientState state = getState(id); - return state.getLearningAlgorithm().getBestSolution().toString(); + return state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescription().toString(); } @WebMethod public String[] getCurrentlyBestConcepts(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); - List<Description> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); + List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); List<String> conc=new LinkedList<String>(); Iterator<Description> iter=bestConcepts.iterator(); while (iter.hasNext()) @@ -612,7 +612,7 @@ @WebMethod public int[] getConceptDepth(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); - List<Description> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); + List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); Iterator<Description> iter=bestConcepts.iterator(); int[] length=new int[bestConcepts.size()]; int i=0; @@ -626,7 +626,7 @@ @WebMethod public int[] getConceptArity(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); - List<Description> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); + List<Description> bestConcepts = state.getLearningAlgorithm().getCurrentlyBestDescriptions(nrOfConcepts); Iterator<Description> iter=bestConcepts.iterator(); int[] arity=new int[bestConcepts.size()]; int i=0; Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-27 14:28:48 UTC (rev 986) @@ -97,7 +97,7 @@ // start the algorithm and print the best concept found la.start(); - System.out.println(la.getBestSolution()); + System.out.println(la.getCurrentlyBestEvaluatedDescription()); } } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-06-27 14:28:48 UTC (rev 986) @@ -69,7 +69,7 @@ la = getWizardModel().getOre().start();//started endlosen Algorithmus - publish(la.getBestSolutions(10)); + publish(la.getCurrentlyBestDescriptions(10)); List<Description> result = getWizardModel().getOre().getLearningResults(100); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-06-27 14:28:48 UTC (rev 986) @@ -177,15 +177,15 @@ } public Description getLearningResult(){ - return la.getBestSolution(); + return la.getCurrentlyBestDescription(); } - public List<Description> getSolutions(){ - return la.getGoodSolutions(); - } +// public List<Description> getSolutions(){ +// return la.getCurrentlyBestDescriptions(); +// } public List<Description> getLearningResults(int anzahl){ - return la.getBestSolutions(anzahl); + return la.getCurrentlyBestDescriptions(anzahl); } /** Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-06-27 14:28:48 UTC (rev 986) @@ -224,9 +224,9 @@ */ private void addToListModel() { - for(int j = 0;j<la.getBestSolutions(anzahl).size();j++) + for(int j = 0;j<la.getCurrentlyBestEvaluatedDescriptions(anzahl).size();j++) { - suggestModel.add(j,la.getBestSolutions(anzahl).get(j)); + suggestModel.add(j,la.getCurrentlyBestEvaluatedDescriptions(anzahl).get(j)); } } @@ -352,7 +352,7 @@ error = "Learning succesful"; // start the algorithm and print the best concept found la.start(); - description = new Description[la.getBestSolutions(anzahl).size()]; + description = new Description[la.getCurrentlyBestEvaluatedDescriptions(anzahl).size()]; addToListModel(); view.renderErrorMessage(error); view.getRunButton().setEnabled(true); Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-06-27 13:44:33 UTC (rev 985) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-06-27 14:28:48 UTC (rev 986) @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ package org.dllearner.utilities.owl; import java.util.Collections; @@ -21,8 +40,11 @@ import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.Thing; -// ev. kann man diese Klasse später in ein anderes Paket ziehen, da sie nicht direkt mit -// refinement zu tun hat +/** + * Concept transformation and concept checking methods. + * + * @author Jens Lehmann + */ public class ConceptTransformation { public static long cleaningTimeNs = 0; @@ -386,4 +408,39 @@ return concept; } + /** + * Method to determine, whether a class description is minimal, + * e.g. \forall r.\top (\equiv \top) or male \sqcup male are not + * minimal. This method performs heuristic sanity checks (it will + * not try to find semantically equivalent shorter descriptions). + * @param description Input description. + * @return True if a superfluous construct has been found. + */ + public static boolean isDescriptionMinimal(Description description) { + ConceptComparator cc = new ConceptComparator(); + int length = description.getLength(); + int length2 = ConceptTransformation.getShortConcept(description, cc).getLength(); + if(length2 < length) + return false; + if(ConceptTransformation.findEquivalences(description)) + return false; + return true; + } + + private static boolean findEquivalences(Description description) { + // \exists r.\bot \equiv \bot + if(description instanceof ObjectSomeRestriction && description.getChild(0) instanceof Nothing) + return true; + // \forall r.\top \equiv \top + if(description instanceof ObjectAllRestriction && description.getChild(0) instanceof Thing) + return true; + // check children + for(Description child : description.getChildren()) { + if(findEquivalences(child)) + return true; + } + // false if none of the checks was successful + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |