From: <jen...@us...> - 2009-03-23 10:35:19
|
Revision: 1658 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1658&view=rev Author: jenslehmann Date: 2009-03-23 10:35:06 +0000 (Mon, 23 Mar 2009) Log Message: ----------- - continued implementation of new learning problem structure - extended CELOE to be able to also handle pos only + pos/neg learning problems - updated manual accordingly Modified Paths: -------------- trunk/doc/manual/manual.tex trunk/examples/family/father_posonly.conf trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java trunk/src/dl-learner/org/dllearner/core/LearningProblem.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLPStandard.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/scripts/DumbLPFinder.java trunk/src/dl-learner/org/dllearner/scripts/NewSample.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java trunk/src/dl-learner/org/dllearner/test/ClassCastExceptionTest.java trunk/src/dl-learner/org/dllearner/tools/ore/ColumnListCellRenderer.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/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanelHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionPosOnly.java trunk/src/dl-learner/org/dllearner/learningproblems/ScorePosOnly.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java Modified: trunk/doc/manual/manual.tex =================================================================== --- trunk/doc/manual/manual.tex 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/doc/manual/manual.tex 2009-03-23 10:35:06 UTC (rev 1658) @@ -182,8 +182,20 @@ \item[Class Expression Learning for Ontology Engineering (CELOE)] \todo{This algorithm is under construction.} \end{description} -Please note that while components are interchangeable, it is not possible to arbitrarily combine them. For instance, the newer learning algorithms do not work with the DIG interface, since it does not provide the necessary inference tasks. Furthermore, a learning algorithm can specify which learning problems it can solve, i.e.~we do not require it to be able to solve each learning problem. In later versions of this manual, we may include a compatibility matrix. In the meantime, you can easily verify whether a combination works by testing it in a conf file. +Please note that while components are interchangeable, it is not possible to arbitrarily combine them. For instance, the newer learning algorithms do not work with the DIG interface, since it does not provide the necessary inference tasks. Furthermore, a learning algorithm can specify which learning problems it can solve, i.e.~we do not require it to be able to solve each learning problem. Table \ref{tab:la_lp_comp} provides a compatibility matrix. Note that this can change in future releases, because algorithms may be extended to support new learning problems or drop support for them. +\begin{table}[htb] +\centering +\begin{tabular}{c|cccccc} +learning problem & BF & RG & GP & Ref & Ref II & CELOE \\\hline +pos only & x & x & & & & x \\ +pos neg & x & x & x & x & x & x \\ +class learning & x & x & & & & x +\end{tabular} +\caption{Learning problem - learning algorithm compatibility matrix in DL-Learner. Legend: BF = brute force, RG = random guesser, Ref = Refinement} +\label{tab:la_lp_comp} +\end{table} + \section{DL-Learner Interfaces} One interface you have already used in Section \ref{sec:start} is the command line. There are two executables, which can be used for starting DL-Learner on the commandline: \verb|dl-learner| and \verb|quickstart|. The first one takes a conf file as argument, whereas the latter one lists all conf files in the examples folder and allows you to select one of those. Modified: trunk/examples/family/father_posonly.conf =================================================================== --- trunk/examples/family/father_posonly.conf 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/examples/family/father_posonly.conf 2009-03-23 10:35:06 UTC (rev 1658) @@ -4,30 +4,16 @@ * possible solution: * male AND EXISTS hasChild.TOP * - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2009, Jens Lehmann */ /** settings **/ - - import("father.kb"); +problem = posOnlyLP; +algorithm = celoe; +celoe.maxExecutionTimeInSeconds = 1; -problem = posOnlyDefinitionLP; -reasoner = owlAPIReasoner; -algorithm = refexamples; -refexamples.usePropernessChecks = true; -refexamples.maxPosOnlyExpansion = 4; - -refexamples.writeSearchTree = false; -refexamples.searchTreeFile = "log/posonlytest.txt"; - /** examples **/ +stefan +markus +bernd -/* --heinz --anna --gabi --michelle -*/ Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -45,6 +45,7 @@ import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.ScorePosNeg; /** Deleted: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2007-2009, 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.algorithms; - -import java.util.Set; - -import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.learningproblems.ClassScore; - -/** - * An evaluated description for learning classes in ontologies. - * - * @author Jens Lehmann - * - */ -public class EvaluatedDescriptionClass extends EvaluatedDescription { - - private ClassScore classScore; - - /** - * Constructs an evaluated description for learning classes in ontologies. - * @param description Description. - * @param score Score of description. - */ - public EvaluatedDescriptionClass(Description description, ClassScore score) { - super(description, score); - classScore = score; - } - - /** - * @return The addition factor. - * @see org.dllearner.learningproblems.ClassScore#getAddition() - */ - public double getAddition() { - return classScore.getAddition(); - } - - /** - * @return The instances of the class description, which are not instances - * of the class to learn. - * @see org.dllearner.learningproblems.ClassScore#getAdditionalInstances() - */ - public Set<Individual> getAdditionalInstances() { - return classScore.getAdditionalInstances(); - } - - /** - * @return The coverage percentage. - * @see org.dllearner.learningproblems.ClassScore#getCoverage() - */ - public double getCoverage() { - return classScore.getCoverage(); - } - - /** - * - * @return The instances covered by the class description. - * @see org.dllearner.learningproblems.ClassScore#getCoveredInstances() - */ - public Set<Individual> getCoveredInstances() { - return classScore.getCoveredInstances(); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -1,168 +0,0 @@ -/** - * 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.algorithms; - -import java.util.Set; - -import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.learningproblems.ScorePosNeg; -import org.dllearner.learningproblems.ScoreTwoValued; -import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; -import org.dllearner.utilities.owl.OWLAPIRenderers; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.semanticweb.owl.model.OWLDescription; - -/** - * 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 EvaluatedDescriptionPosNeg extends EvaluatedDescription { - - private ScorePosNeg score2; - - /** - * Constructs an evaluated description using its score. - * @param description The description, which was evaluated. - * @param score The score of the description. - */ - public EvaluatedDescriptionPosNeg(Description description, ScorePosNeg score) { - super(description, score); - score2 = (ScorePosNeg) score; - } - - /** - * Constructs an evaluated description using example coverage. - * @param description The description, which was evaluated. - * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description. - * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description. - * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description. - * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description. - */ - public EvaluatedDescriptionPosNeg(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { - // usually core methods should not depend on methods outside of the core package (except utilities) - // in this case, this is just a convenience constructor - super(description, new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg)); - score2 = (ScorePosNeg) score; - } - - /** - * @see org.dllearner.learningproblems.ScorePosNeg#getAccuracy() - * @return Accuracy of the description. - */ - @Override - public double getAccuracy() { - return score2.getAccuracy(); - } - - /** - * Gets the score of this description. This can be used to get - * further statistical values. - * @see org.dllearner.learningproblems.ScorePosNeg - * @return The score object associated with this evaluated description. - */ - public ScorePosNeg getScore() { - return score2; - } - - /** - * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredNegatives() - * @return Negative examples covered by the description. - */ - public Set<Individual> getCoveredNegatives() { - return score2.getCoveredNegatives(); - } - - /** - * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredPositives() - * @return Positive examples covered by the description. - */ - public Set<Individual> getCoveredPositives() { - return score2.getCoveredPositives(); - } - - /** - * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredNegatives() - * @return Negative examples not covered by the description. - */ - public Set<Individual> getNotCoveredNegatives() { - return score2.getNotCoveredNegatives(); - } - - /** - * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredPositives() - * @return Positive examples not covered by the description. - */ - public Set<Individual> getNotCoveredPositives() { - return score2.getNotCoveredPositives(); - } - - /** - * This convenience method can be used to store and exchange evaluated - * descriptions by transforming them to a JSON string. - * @return A JSON representation of an evaluated description. - */ - @Override - public String asJSON() { - JSONObject object = new JSONObject(); - try { - object.put("descriptionManchesterSyntax", description.toManchesterSyntaxString(null, null)); - OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description); - object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d)); - object.put("descriptionKBSyntax", description.toKBSyntaxString()); - object.put("accuracy", score2.getAccuracy()); - object.put("coveredPositives", getJSONArray(score2.getCoveredPositives())); - object.put("coveredNegatives", getJSONArray(score2.getCoveredNegatives())); - object.put("notCoveredPositives", getJSONArray(score2.getNotCoveredPositives())); - object.put("notCoveredNegatives", getJSONArray(score2.getNotCoveredNegatives())); - return object.toString(3); - } catch (JSONException e) { - e.printStackTrace(); - return null; - } - } - - @Override - public String toString() { - return description.toString() + "(accuracy: " + getAccuracy() + ")"; - } - - // we need to use this method instead of the standard JSON array constructor, - // otherwise we'll get unexpected results (JSONArray does not take Individuals - // as arguments and does not use toString) - private static JSONArray getJSONArray(Set<Individual> individuals) { - JSONArray j = new JSONArray(); - for(Individual i : individuals) { - j.put(i.getName()); - } - return j; - } - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -34,6 +34,7 @@ import org.dllearner.core.options.IntegerConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.Description; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.ScorePosNeg; public class RandomGuesser extends LearningAlgorithm { Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -47,8 +47,11 @@ import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.ClassLearningProblem; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; +import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; import org.dllearner.utilities.owl.DescriptionMinimizer; @@ -94,13 +97,19 @@ private EvaluatedDescriptionSet bestEvaluatedDescriptions; private NamedClass classToDescribe; - private Set<Individual> classInstances; + // examples are either 1.) instances of the class to describe 2.) positive examples + // 3.) union of pos.+neg. examples depending on the learning problem at hand + private Set<Individual> examples; + + // CELOE was originally created for learning classes in ontologies, but also + // works for other learning problem types + private boolean isClassLearningProblem; private boolean isEquivalenceProblem; private long nanoStartTime; // important parameters - private double minAcc; + private double noise; private double maxDepth; // utility variables @@ -119,14 +128,14 @@ return configurator; } - public CELOE(ClassLearningProblem problem, ReasonerComponent reasoner) { + public CELOE(LearningProblem problem, ReasonerComponent reasoner) { super(problem, reasoner); configurator = new CELOEConfigurator(this); } - + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); - problems.add(ClassLearningProblem.class); + problems.add(LearningProblem.class); return problems; } @@ -155,43 +164,51 @@ @Override public void init() throws ComponentInitException { - ClassLearningProblem problem = (ClassLearningProblem) learningProblem; - classToDescribe = problem.getClassToDescribe(); - isEquivalenceProblem = problem.isEquivalenceProblem(); - // copy class hierarchy and modify it such that each class is only // reachable via a single path ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); - classHierarchy.thinOutSubsumptionHierarchy(); + classHierarchy.thinOutSubsumptionHierarchy(); - classInstances = reasoner.getIndividuals(classToDescribe); - minimizer = new DescriptionMinimizer(reasoner); - // start class: intersection of super classes for definitions (since it needs to - // capture all instances), but owl:Thing for learning subclasses (since it is - // superfluous to add super classes in this case) - if(isEquivalenceProblem) { - Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); - if(superClasses.size() > 1) { - startClass = new Intersection(new LinkedList<Description>(superClasses)); - } else { - startClass = (Description) superClasses.toArray()[0]; - } - } else { - startClass = Thing.instance; - } + startClass = Thing.instance; // create refinement operator operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); baseURI = reasoner.getBaseURI(); - prefixes = reasoner.getPrefixes(); + prefixes = reasoner.getPrefixes(); bestEvaluatedDescriptions = new EvaluatedDescriptionSet(configurator.getMaxNrOfResults()); - + // we put important parameters in class variables - minAcc = configurator.getNoisePercentage()/100d; - maxDepth = configurator.getMaxDepth(); + noise = configurator.getNoisePercentage()/100d; + maxDepth = configurator.getMaxDepth(); + + isClassLearningProblem = (learningProblem instanceof ClassLearningProblem); + // actions specific to ontology engineering + if(isClassLearningProblem) { + ClassLearningProblem problem = (ClassLearningProblem) learningProblem; + classToDescribe = problem.getClassToDescribe(); + isEquivalenceProblem = problem.isEquivalenceProblem(); + + examples = reasoner.getIndividuals(classToDescribe); + + // start class: intersection of super classes for definitions (since it needs to + // capture all instances), but owl:Thing for learning subclasses (since it is + // superfluous to add super classes in this case) + if(isEquivalenceProblem) { + Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); + if(superClasses.size() > 1) { + startClass = new Intersection(new LinkedList<Description>(superClasses)); + } else { + startClass = (Description) superClasses.toArray()[0]; + } + } + } else if(learningProblem instanceof PosOnlyLP) { + examples = ((PosOnlyLP)learningProblem).getPositiveExamples(); + } else if(learningProblem instanceof PosNegLP) { + examples = Helper.union(((PosNegLP)learningProblem).getPositiveExamples(),((PosNegLP)learningProblem).getNegativeExamples()); + } } @Override @@ -221,21 +238,6 @@ reset(); nanoStartTime = System.nanoTime(); - // test -// Description testD = null; -// try { -//// testD = KBParser.parseConcept("(\"EPC\" AND EXISTS hasModelElements.(\"Function\" AND ALL previousObjects.BOTTOM))", "http://localhost/aris/sap_model.owl#"); -// testD = KBParser.parseConcept("(\"EPC\" AND EXISTS hasModelElements.(\"Function\" AND ALL nextObject.BOTTOM))", "http://localhost/aris/sap_model.owl#"); -// } catch (ParseException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// double val = learningProblem.getAccuracyOrTooWeak(testD, minAcc); -// System.out.println(testD); -// System.out.println(val); -// System.out.println(testD.getDepth()); -// System.exit(0); - // highest accuracy so far double highestAccuracy = 0.0; OENode nextNode; @@ -244,8 +246,6 @@ int loop = 0; while (!terminationCriteriaSatisfied()) { - -// System.out.println(startNode.toTreeString(baseURI)); if(bestEvaluatedDescriptions.getBest().getAccuracy() > highestAccuracy) { highestAccuracy = bestEvaluatedDescriptions.getBest().getAccuracy(); @@ -271,7 +271,6 @@ if(length > horizExp && refinement.getDepth() <= maxDepth) { Monitor mon2 = MonitorFactory.start("addNode"); -// boolean added = addNode(refinement, nextNode); mon2.stop(); @@ -281,7 +280,6 @@ updateMinMaxHorizExp(nextNode); - // Anzahl Schleifendurchläufe loop++; } @@ -292,7 +290,6 @@ } // print solution(s) -// logger.info("solution : " + bestDescriptionToString()); logger.info("solutions:\n" + getSolutionString()); // System.out.println(startNode.toTreeString(baseURI)); @@ -302,7 +299,7 @@ private OENode getNextNodeToExpand() { // we expand the best node of those, which have not achieved 100% accuracy - // already and have a horizontal expansion equalling their length + // already and have a horizontal expansion equal to their length // (rationale: further extension is likely to add irrelevant syntactical constructs) Iterator<OENode> it = nodes.descendingIterator(); while(it.hasNext()) { @@ -321,7 +318,7 @@ private TreeSet<Description> refineNode(OENode node) { // we have to remove and add the node since its heuristic evaluation changes through the expansion // (you *must not* include any criteria in the heuristic which are modified outside of this method, - // otherwise you may see rarely occuring but critical false ordering in the nodes set) + // otherwise you may see rarely occurring but critical false ordering in the nodes set) nodes.remove(node); // System.out.println("refining: " + node); int horizExp = node.getHorizontalExpansion(); @@ -348,7 +345,7 @@ } // quality of description (return if too weak) - double accuracy = learningProblem.getAccuracyOrTooWeak(description, minAcc); + double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); descriptionTests++; // System.out.println(description + " " + accuracy); if(accuracy == -1) { @@ -402,23 +399,25 @@ // checks whether the description is allowed private boolean isDescriptionAllowed(Description description, OENode parentNode) { - if(isEquivalenceProblem) { - // the class to learn must not appear on the outermost property level - if(occursOnFirstLevel(description, classToDescribe)) { - return false; - } - } else { - // none of the superclasses of the class to learn must appear on the - // outermost property level - TreeSet<Description> toTest = new TreeSet<Description>(); - toTest.add(classToDescribe); - while(!toTest.isEmpty()) { - Description d = toTest.pollFirst(); - if(occursOnFirstLevel(description, d)) { + if(isClassLearningProblem) { + if(isEquivalenceProblem) { + // the class to learn must not appear on the outermost property level + if(occursOnFirstLevel(description, classToDescribe)) { return false; } - toTest.addAll(reasoner.getClassHierarchy().getSuperClasses(d)); - } + } else { + // none of the superclasses of the class to learn must appear on the + // outermost property level + TreeSet<Description> toTest = new TreeSet<Description>(); + toTest.add(classToDescribe); + while(!toTest.isEmpty()) { + Description d = toTest.pollFirst(); + if(occursOnFirstLevel(description, d)) { + return false; + } + toTest.addAll(reasoner.getClassHierarchy().getSuperClasses(d)); + } + } } // perform forall sanity tests @@ -437,7 +436,7 @@ // transform [r,s] to \exists r.\exists s.\top Description existentialContext = context.toExistentialContext(); boolean fillerFound = false; - for(Individual instance : classInstances) { + for(Individual instance : examples) { if(reasoner.hasType(existentialContext, instance)) { // System.out.println(instance + " " + existentialContext); fillerFound = true; Deleted: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristic.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -1,32 +0,0 @@ -/** - * Copyright (C) 2007-2009, 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.algorithms.celoe; - -import java.util.Comparator; - -/** - * Marker interface for heurist comparators over nodes in the search tree. - * - * @author Jens Lehmann - * - */ -public interface OEHeuristic extends Comparator<OENode> { - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -19,6 +19,8 @@ */ package org.dllearner.algorithms.celoe; +import java.util.Comparator; + import org.dllearner.utilities.owl.ConceptComparator; /** @@ -29,7 +31,7 @@ * @author Jens Lehmann * */ -public class OEHeuristicRuntime implements OEHeuristic { +public class OEHeuristicRuntime implements Comparator<OENode>{ // strong penalty for long descriptions private double expansionPenaltyFactor = 0.1; Deleted: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OEHeuristicStable.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2007-2009, 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.algorithms.celoe; - -/** - * @author Jens Lehmann - * - */ -public class OEHeuristicStable implements OEHeuristic { - - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - @Override - public int compare(OENode o1, OENode o2) { - // TODO Auto-generated method stub - return 0; - } - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -26,7 +26,6 @@ import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; @@ -36,6 +35,7 @@ import org.dllearner.core.configurators.ELLearningAlgorithmConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.ELDown2; Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -29,7 +29,6 @@ import java.util.Set; import java.util.Map.Entry; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.algorithms.hybridgp.Psi; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; @@ -44,6 +43,7 @@ import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -14,7 +14,6 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; @@ -33,8 +32,8 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.Files; @@ -111,8 +110,6 @@ DecimalFormat df = new DecimalFormat(); private PosNegLP learningProblem; - private PosOnlyLP posOnlyLearningProblem; - private boolean posOnly = false; // Menge von Kandidaten für Refinement // (wird für Direktzugriff auf Baumknoten verwendet) @@ -198,23 +195,13 @@ super(learningProblem, reasoningService); this.learningProblem = learningProblem; this.configurator = new ROLearnerConfigurator(this); - posOnly=false; baseURI = reasoningService.getBaseURI(); } - public ROLearner(PosOnlyLP learningProblem, ReasonerComponent reasoningService) { - super(learningProblem, reasoningService); - this.posOnlyLearningProblem = learningProblem; - this.configurator = new ROLearnerConfigurator(this); - posOnly=true; - baseURI = reasoningService.getBaseURI(); - } - public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); - problems.add(PosOnlyLP.class); return problems; } @@ -334,12 +321,9 @@ Files.clearFile(searchTreeFile); // adjust heuristic - if(heuristic == Heuristic.LEXICOGRAPHIC) + if(heuristic == Heuristic.LEXICOGRAPHIC) { nodeComparator = new NodeComparator(); - else { - if(posOnly) { - throw new RuntimeException("does not work with positive examples only yet"); - } + } else { nodeComparator = new NodeComparator2(learningProblem.getNegativeExamples().size(), learningProblem.getPercentPerLengthUnit()); } @@ -383,17 +367,11 @@ } private int coveredNegativesOrTooWeak(Description concept) { - if(posOnly) - return posOnlyLearningProblem.coveredPseudoNegativeExamplesOrTooWeak(concept); - else - return learningProblem.coveredNegativeExamplesOrTooWeak(concept); + return learningProblem.coveredNegativeExamplesOrTooWeak(concept); } private int getNumberOfNegatives() { - if(posOnly) - return posOnlyLearningProblem.getPseudoNegatives().size(); - else - return learningProblem.getNegativeExamples().size(); + return learningProblem.getNegativeExamples().size(); } // Kernalgorithmus @@ -1101,18 +1079,12 @@ // @Override public ScorePosNeg getSolutionScore() { - if(posOnly) - return (ScorePosNeg) posOnlyLearningProblem.computeScore(getCurrentlyBestDescription()); - else - return (ScorePosNeg) learningProblem.computeScore(getCurrentlyBestDescription()); + return (ScorePosNeg) learningProblem.computeScore(getCurrentlyBestDescription()); } public ScorePosNeg getSolutionScore(Description d) { - if(posOnly) - return (ScorePosNeg) posOnlyLearningProblem.computeScore(d); - else - return (ScorePosNeg) learningProblem.computeScore(d); + return (ScorePosNeg) learningProblem.computeScore(d); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLComponent2.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -29,7 +29,6 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; @@ -48,6 +47,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.learningproblems.ScorePosNeg; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement2/ROLearner2.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -33,7 +33,6 @@ import java.util.concurrent.ConcurrentSkipListSet; import org.apache.log4j.Logger; -import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.ROLComponent2Configurator; @@ -42,8 +41,8 @@ import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; @@ -72,9 +71,7 @@ // often the learning problems needn't be accessed directly; instead // use the example sets below and the posonly variable private PosNegLP learningProblem; - private PosOnlyLP posOnlyLearningProblem; private Description startDescription; - private boolean posOnly = false; private int nrOfExamples; private int nrOfPositiveExamples; private Set<Individual> positiveExamples; @@ -238,10 +235,9 @@ int maxPosOnlyExpansion, int maxExecutionTimeInSeconds, int minExecutionTimeInSeconds, int guaranteeXgoodDescriptions, int maxClassDescriptionTests, boolean forceRefinementLengthIncrease) { - if (learningProblem instanceof PosNegLP) { + PosNegLP lp = (PosNegLP) learningProblem; this.learningProblem = lp; - posOnly = false; positiveExamples = lp.getPositiveExamples(); negativeExamples = lp.getNegativeExamples(); nrOfPositiveExamples = positiveExamples.size(); @@ -251,16 +247,6 @@ // System.out.println(nrOfNegativeExamples); // System.exit(0); - } else if (learningProblem instanceof PosOnlyLP) { - PosOnlyLP lp = (PosOnlyLP) learningProblem; - this.posOnlyLearningProblem = lp; - posOnly = true; - positiveExamples = lp.getPositiveExamples(); - negativeExamples = new TreeSet<Individual>(); - nrOfPositiveExamples = lp.getPositiveExamples().size(); - // nrOfNegativeExamples = lp.getPseudoNegatives().size(); - nrOfNegativeExamples = 0; - } this.configurator = configurator; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; this.rs = rs; @@ -482,7 +468,9 @@ // special situation for positive only learning: the expanded node // can become a solution (see explanations // for maxPosOnlyExpansion above) - if (posOnly + + // DEPRECATED CODE + if (false && bestNode.isPosOnlyCandidate() && (bestNode.getHorizontalExpansion() - bestNode.getConcept().getLength() >= maxPosOnlyExpansion)) { @@ -855,7 +843,7 @@ tooWeakList.add(refinement); } else { // Lösung gefunden - if (quality >= 0 && quality <= allowedMisclassifications && !posOnly) { + if (quality >= 0 && quality <= allowedMisclassifications) { solutions.add(newNode); } @@ -1300,17 +1288,11 @@ } public ScorePosNeg getSolutionScore() { - if (posOnly) - return (ScorePosNeg) posOnlyLearningProblem.computeScore(getBestSolution()); - else - return (ScorePosNeg) learningProblem.computeScore(getBestSolution()); + return (ScorePosNeg) learningProblem.computeScore(getBestSolution()); } private ScorePosNeg getScore(Description d) { - if (posOnly) - return (ScorePosNeg) posOnlyLearningProblem.computeScore(d); - else - return (ScorePosNeg) learningProblem.computeScore(d); + return (ScorePosNeg) learningProblem.computeScore(d); } public ExampleBasedNode getStartNode() { Modified: trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -42,6 +42,7 @@ import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosNegLPStrict; +import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.FastRetrievalReasoner; @@ -82,9 +83,10 @@ reasonerMapping.put("owlAPIReasoner", OWLAPIReasoner.class); reasonerMapping.put("fastInstanceChecker", FastInstanceChecker.class); reasonerMapping.put("fastRetrievalReasoner", FastRetrievalReasoner.class); - learningProblemMapping.put("posNegDefinitionLP", PosNegLPStandard.class); - learningProblemMapping.put("posNegDefinitionLPStrict", PosNegLPStrict.class); + learningProblemMapping.put("posNegLPStandard", PosNegLPStandard.class); + learningProblemMapping.put("posNegLPStrict", PosNegLPStrict.class); learningProblemMapping.put("classLearning", ClassLearningProblem.class); + learningProblemMapping.put("posOnlyLP", PosOnlyLP.class); learningAlgorithmMapping.put("random", RandomGuesser.class); learningAlgorithmMapping.put("bruteForce", BruteForceLearner.class); learningAlgorithmMapping.put("gp", GP.class); Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -109,5 +109,5 @@ * @return A value between 0 and 1 indicating the quality (of a class description) * or -1 as described above. */ - public abstract double getAccuracyOrTooWeak(Description description, double minAccuracy); + public abstract double getAccuracyOrTooWeak(Description description, double noise); } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-20 14:15:15 UTC (rev 1657) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -27,9 +27,7 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.algorithms.EvaluatedDescriptionClass; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.ClassLearningProblemConfigurator; @@ -38,10 +36,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; -import org.dllearner.utilities.Helper; -import com.jamonapi.MonitorFactory; - /** * The problem of learning the description of an existing class * in an OWL ontology. @@ -52,9 +47,11 @@ public class ClassLearningProblem extends LearningProblem { private NamedClass classToDescribe; - private Set<Individual> classInstances; + private List<Individual> classInstances; private boolean equivalence = true; private ClassLearningProblemConfigurator configurator; + // approximation of accuracy +- 0.05 % + private static final double approx = 0.05; // factor for higher weight on coverage (needed for subclass learning) private double coverageFactor; @@ -92,7 +89,7 @@ throw new ComponentInitException("The class \"" + configurator.getClassToDescribe() + "\" does not exist. Make sure you spelled it correctly."); } - classInstances = reasoner.getIndividuals(classToDescribe); + classInstances = new LinkedList<Individual>(reasoner.getIndividuals(classToDescribe)); equivalence = (configurator.getType().equals("equivalence")); if(equivalence) { @@ -113,6 +110,7 @@ // any bias through URI names, so we shuffle the list once pseudo-randomly superClassInstances = new LinkedList<Individual>(superClassInstancesTmp); Random rand = new Random(1); + Collections.shuffle(classInstances, rand); Collections.shuffle(superClassInstances, rand); } @@ -134,25 +132,25 @@ @Override public ClassScore computeScore(Description description) { - Set<Individual> retrieval = reasoner.getIndividuals(description); + // overhang + Set<Individual> additionalInstances = new TreeSet<Individual>(); + for(Individual ind : superClassInstances) { + if(reasoner.hasType(description, ind)) { + additionalInstances.add(ind); + } + } + // coverage Set<Individual> coveredInstances = new TreeSet<Individual>(); - - int instancesCovered = 0; - for(Individual ind : classInstances) { - if(retrieval.contains(ind)) { - instancesCovered++; + if(reasoner.hasType(description, ind)) { coveredInstances.add(ind); } } - Set<Individual> additionalInstances = Helper.difference(retrieval, coveredInstances); + double coverage = coveredInstances.size()/(double)classInstances.size(); + double protusion = additionalInstances.size() == 0 ? 0 : coveredInstances.size()/(double)(coveredInstances.size()+additionalInstances.size()); - double coverage = instancesCovered/(double)classInstances.size(); - double protusion = retrieval.size() == 0 ? 0 : instancesCovered/(double)retrieval.size(); -// double accuracy = coverage + Math.sqrt(protusion); - return new ClassScore(coveredInstances, coverage, additionalInstances, protusion, getAccuracy(coverage, protusion)); } @@ -165,31 +163,36 @@ */ @Override public double getAccuracy(Description description) { - Set<Individual> retrieval = reasoner.getIndividuals(description); - int instancesCovered = 0; + // overhang + int additionalInstances = 0; + for(Individual ind : superClassInstances) { + if(reasoner.hasType(description, ind)) { + additionalInstances++; + } + } + + // coverage + int coveredInstances = 0; for(Individual ind : classInstances) { - if(retrieval.contains(ind)) { - instancesCovered++; + if(reasoner.hasType(description, ind)) { + coveredInstances++; } } - double coverage = instancesCovered/(double)classInstances.size(); -// double protusion = instancesCovered/(double)retrieval.size(); - double protusion = retrieval.size() == 0 ? 0 : instancesCovered/(double)retrieval.size(); -// + double coverage = coveredInstances/(double)classInstances.size(); + double protusion = additionalInstances == 0 ? 0 : coveredInstances/(double)(coveredInstances+additionalInstances); -// return (coverageFactor * coverage + protusion) / (coverageFactor + 1); return getAccuracy(coverage, protusion); } @Override - public double getAccuracyOrTooWeak(Description description, double minAccuracy) { + public double getAccuracyOrTooWeak(Description description, double noise) { // instead of using the standard operation, we use optimisation // and approximation here // we abort when there are too many uncovered positives - int maxNotCovered = (int) Math.ceil(minAccuracy*classInstances.size()); + int maxNotCovered = (int) Math.ceil(noise*classInstances.size()); int instancesCovered = 0; int instancesNotCovered = 0; int total = 0; @@ -220,7 +223,7 @@ upperBorderA = Math.min(1, p1 + p2); double size = upperBorderA - lowerBorderA; // if the interval has a size smaller than 10%, we can be confident - if(size < 0.1) { + if(size < 2 * approx) { // we have to distinguish the cases that the accuracy limit is // below, within, or above the limit and that the mean is below // or above the limit @@ -229,7 +232,7 @@ // if the mean is greater than the required minimum, we can accept; // we also accept if the interval is small and close to the minimum // (worst case is to accept a few inaccurate descriptions) - if(mean > minAccuracy || (upperBorderA > mean && size < 0.03)) { + if(mean > noise || (upperBorderA > mean && size < 0.03)) { instancesCovered = (int) (instancesCovered/(double)total * classInstances.size()); upperEstimateA = (int) (upperBorderA * classInstances.size()); lowerEstimateA = (int) (lowerBorderA * classInstances.size()); @@ -239,7 +242,7 @@ // reject only if the upper border is far away (we are very // certain not to lose a potential solution) - if(upperBorderA + 0.1 < minAccuracy) { + if(upperBorderA + 0.1 < noise) { return -1; } } @@ -315,9 +318,7 @@ return getAccuracy(coverage, protusion); } - /* (non-Javadoc) - * @see org.dllearner.core.LearningProblem#getAccuracyOrTooWeak(org.dllearner.core.owl.Description, double) - */ + @Deprecated public double getAccuracyOrTooWeakStandard(Description description, double minAccuracy) { // since we have to perform a retrieval operation anyway, we cannot easily // get a benefit from the accuracy limit @@ -362,7 +363,7 @@ * @see org.dllearner.core.LearningProblem#evaluate(org.dllearner.core.owl.Description) */ @Override - public EvaluatedDescription evaluate(Description description) { + public EvaluatedDescriptionClass evaluate(Description description) { ClassScore score = computeScore(description); return new EvaluatedDescriptionClass(description, score); } Copied: trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java (from rev 1657, trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionClass.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -0,0 +1,82 @@ +/** + * Copyright (C) 2007-2009, 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; + +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; + +/** + * An evaluated description for learning classes in ontologies. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescriptionClass extends EvaluatedDescription { + + private ClassScore classScore; + + /** + * Constructs an evaluated description for learning classes in ontologies. + * @param description Description. + * @param score Score of description. + */ + public EvaluatedDescriptionClass(Description description, ClassScore score) { + super(description, score); + classScore = score; + } + + /** + * @return The addition factor. + * @see org.dllearner.learningproblems.ClassScore#getAddition() + */ + public double getAddition() { + return classScore.getAddition(); + } + + /** + * @return The instances of the class description, which are not instances + * of the class to learn. + * @see org.dllearner.learningproblems.ClassScore#getAdditionalInstances() + */ + public Set<Individual> getAdditionalInstances() { + return classScore.getAdditionalInstances(); + } + + /** + * @return The coverage percentage. + * @see org.dllearner.learningproblems.ClassScore#getCoverage() + */ + public double getCoverage() { + return classScore.getCoverage(); + } + + /** + * + * @return The instances covered by the class description. + * @see org.dllearner.learningproblems.ClassScore#getCoveredInstances() + */ + public Set<Individual> getCoveredInstances() { + return classScore.getCoveredInstances(); + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java (from rev 1657, trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java 2009-03-23 10:35:06 UTC (rev 1658) @@ -0,0 +1,166 @@ +/** + * 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; + +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIRenderers; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.semanticweb.owl.model.OWLDescription; + +/** + * 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 EvaluatedDescriptionPosNeg extends EvaluatedDescription { + + private ScorePosNeg score2; + + /** + * Constructs an evaluated description using its score. + * @param description The description, which was evaluated. + * @param score The score of the description. + */ + public EvaluatedDescriptionPosNeg(Description description, ScorePosNeg score) { + super(description, score); + score2 = (ScorePosNeg) score; + } + + /** + * Constructs an evaluated description using example coverage. + * @param description The description, which was evaluated. + * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description. + * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description. + * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description. + * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description. + */ + public EvaluatedDescriptionPosNeg(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { + // usually core methods should not depend on methods outside of the core package (except utilities) + // in this case, this is just a convenience constructor + super(description, new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg)); + score2 = (ScorePosNeg) score; + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getAccuracy() + * @return Accuracy of the description. + */ + @Override + public double getAccuracy() { + return score2.getAccuracy(); + } + + /** + * Gets the score of this description. This can be used to get + * further statistical values. + * @see org.dllearner.learningproblems.ScorePosNeg + * @return The score object associated with this evaluated description. + */ + public ScorePosNeg getScore() { + return score2; + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredNegatives() + * @return Negative examples covered by the description. + */ + public Set<Individual> getCoveredNegatives() { + return score2.getCoveredNegatives(); + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredPositives() + * @return Positive examples covered by the description. + */ + public Set<Individual> getCoveredPositives() { + return score2.getCoveredPositives(); + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredNegatives() + * @r... [truncated message content] |