From: <jen...@us...> - 2011-01-31 22:38:54
|
Revision: 2638 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2638&view=rev Author: jenslehmann Date: 2011-01-31 22:38:48 +0000 (Mon, 31 Jan 2011) Log Message: ----------- continued unit tests and fixed a bug Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreTwoValued.java trunk/components-core/src/test/java/org/dllearner/test/junit/HeuristicTests.java trunk/test/pdb/pdb.conf Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-01-31 19:41:38 UTC (rev 2637) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-01-31 22:38:48 UTC (rev 2638) @@ -89,9 +89,9 @@ options.add(new StringSetConfigOption("negativeExamples", "negative examples",null, true, false)); options.add(new BooleanConfigOption("useRetrievalForClassficiation", - "Specifies whether to use retrieval or instance checks for testing a concept.", false)); + "Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.", false)); options.add(CommonConfigOptions.getPercentPerLenghtUnitOption(0.05)); - StringConfigOption multiInstanceChecks = new StringConfigOption("useMultiInstanceChecks", "See UseMultiInstanceChecks enum.","twoChecks"); + StringConfigOption multiInstanceChecks = new StringConfigOption("useMultiInstanceChecks", "See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.","twoChecks"); multiInstanceChecks.setAllowedValues(new String[] {"never", "twoChecks", "oneCheck"}); options.add(multiInstanceChecks); return options; Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-01-31 19:41:38 UTC (rev 2637) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-01-31 22:38:48 UTC (rev 2638) @@ -61,6 +61,7 @@ private double approxDelta = 0.05; private boolean useApproximations; // private boolean useFMeasure; + private boolean useOldDIGOptions = false; private HeuristicType heuristic = HeuristicType.PRED_ACC; @@ -218,6 +219,9 @@ * to implement TWO_CHECKS in this function, because we have to test all * examples to create a score object anyway). * + * NOTE: The options above are no longer supported, because of interface changes (the options + * are more or less only relevant in combination with DIG). + * * @see org.dllearner.learningproblems.PosNegLP.UseMultiInstanceChecks * @param concept * The concept to test. @@ -225,63 +229,92 @@ */ @Override public ScorePosNeg computeScore(Description concept) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + if(useOldDIGOptions) { + if (useRetrievalForClassification) { + SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); + SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - // piecewise set construction - for (Individual posExample : positiveExamples) { - if (!posClassified.contains(posExample)) - posAsNeg.add(posExample); + // piecewise set construction + for (Individual posExample : positiveExamples) { + if (!posClassified.contains(posExample)) + posAsNeg.add(posExample); + } + SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + for (Individual negExample : negativeExamples) { + if (!posClassified.contains(negExample)) + negAsNeg.add(negExample); + } + return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); + // instance checks for classification + } else { + SortedSet<Individual> posAsPos = new TreeSet<Individual>(); + SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); + SortedSet<Individual> negAsPos = new TreeSet<Individual>(); + SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + SortedSet<Individual> posClassified = reasoner.hasType(concept, + allExamples); + SortedSet<Individual> negClassified = Helper.difference(allExamples, + posClassified); + posAsPos = Helper.intersection(positiveExamples, posClassified); + posAsNeg = Helper.intersection(positiveExamples, negClassified); + negAsPos = Helper.intersection(negativeExamples, posClassified); + negAsNeg = Helper.intersection(negativeExamples, negClassified); + + // System.out.println("pos classified: " + posClassified); + + return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + negAsNeg); + } else { + + for (Individual example : positiveExamples) { + if (reasoner.hasType(concept, example)) { + posAsPos.add(example); + } else { + posAsNeg.add(example); + } + } + for (Individual example : negativeExamples) { + if (reasoner.hasType(concept, example)) + negAsPos.add(example); + else + negAsNeg.add(example); + } + return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + negAsNeg); + } } - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - for (Individual negExample : negativeExamples) { - if (!posClassified.contains(negExample)) - negAsNeg.add(negExample); - } - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); - // instance checks for classification - } else { + } else { + SortedSet<Individual> posAsPos = new TreeSet<Individual>(); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); SortedSet<Individual> negAsPos = new TreeSet<Individual>(); SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - SortedSet<Individual> posClassified = reasoner.hasType(concept, - allExamples); - SortedSet<Individual> negClassified = Helper.difference(allExamples, - posClassified); - posAsPos = Helper.intersection(positiveExamples, posClassified); - posAsNeg = Helper.intersection(positiveExamples, negClassified); - negAsPos = Helper.intersection(negativeExamples, posClassified); - negAsNeg = Helper.intersection(negativeExamples, negClassified); - - // System.out.println("pos classified: " + posClassified); - - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, - negAsNeg); - } else { - - for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { - posAsPos.add(example); - } else { - posAsNeg.add(example); - } + for (Individual example : positiveExamples) { + if (reasoner.hasType(concept, example)) { + posAsPos.add(example); + } else { + posAsNeg.add(example); } - for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) - negAsPos.add(example); - else - negAsNeg.add(example); - } - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, - negAsNeg); } + for (Individual example : negativeExamples) { + if (reasoner.hasType(concept, example)) + negAsPos.add(example); + else + negAsNeg.add(example); + } + + // TODO: this computes accuracy twice - more elegant method should be implemented + double accuracy = getAccuracyOrTooWeakExact(concept,1); + + return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + negAsNeg, accuracy); } + } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreTwoValued.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreTwoValued.java 2011-01-31 19:41:38 UTC (rev 2637) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreTwoValued.java 2011-01-31 22:38:48 UTC (rev 2638) @@ -54,6 +54,7 @@ this(0,0,posAsPos,posAsNeg,negAsPos,negAsNeg); } + @Deprecated public ScoreTwoValued(int conceptLength, double percentPerLengthUnit, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { this.conceptLength = conceptLength; this.percentPerLengthUnit = percentPerLengthUnit; @@ -65,6 +66,21 @@ computeScore(); } + public ScoreTwoValued(int conceptLength, double percentPerLengthUnit, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg, double accuracy) { + this.conceptLength = conceptLength; + this.percentPerLengthUnit = percentPerLengthUnit; + this.posAsPos = posAsPos; + this.posAsNeg = posAsNeg; + this.negAsPos = negAsPos; + this.negAsNeg = negAsNeg; + nrOfExamples = posAsPos.size()+posAsNeg.size()+negAsPos.size()+negAsNeg.size(); + this.accuracy = accuracy; + score = accuracy - 1 - percentPerLengthUnit * conceptLength; + } + + // score should not be computed within this class anymore, but directly within learning problem (to support + // different functions like predictive accuracy, F-measure etc.) + @Deprecated private void computeScore() { // compute accuracy accuracy = posAsPos.size() + negAsNeg.size(); Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/HeuristicTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/HeuristicTests.java 2011-01-31 19:41:38 UTC (rev 2637) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/HeuristicTests.java 2011-01-31 22:38:48 UTC (rev 2638) @@ -183,26 +183,17 @@ kb.addAxiom(new ClassAssertionAxiom(Thing.instance,ind[i])); } - // A0 has 20 instances (i0 to i19) - for(int i=0; i<20; i++) { - kb.addAxiom(new ClassAssertionAxiom(nc[0],ind[i])); - } + // A0 + kb.addAxiom(new ClassAssertionAxiom(nc[0],ind[0])); + kb.addAxiom(new ClassAssertionAxiom(nc[0],ind[1])); + kb.addAxiom(new ClassAssertionAxiom(nc[0],ind[5])); - // A1 has 20 instances (i10 to i29) - for(int i=10; i<30; i++) { - kb.addAxiom(new ClassAssertionAxiom(nc[1],ind[i])); - } + // A1 + kb.addAxiom(new ClassAssertionAxiom(nc[1],ind[0])); + kb.addAxiom(new ClassAssertionAxiom(nc[1],ind[1])); + kb.addAxiom(new ClassAssertionAxiom(nc[1],ind[2])); + kb.addAxiom(new ClassAssertionAxiom(nc[1],ind[5])); - // A2 has 40 instances (i10 to i49) - for(int i=10; i<50; i++) { - kb.addAxiom(new ClassAssertionAxiom(nc[2],ind[i])); - } - - // A3 has 5 instances (i8 to i12) - for(int i=8; i<13; i++) { - kb.addAxiom(new ClassAssertionAxiom(nc[3],ind[i])); - } - ComponentManager cm = ComponentManager.getInstance(); KnowledgeSource ks = new KBFile(kb); ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, ks); @@ -210,11 +201,22 @@ ks.init(); reasoner.init(); - Individual[] pos1 = new Individual[] {ind[1], ind[2]}; - Individual[] neg1 = new Individual[] {ind[3], ind[4]}; + Individual[] pos1 = new Individual[] {ind[0], ind[1], ind[2], ind[3], ind[4]}; + Individual[] neg1 = new Individual[] {ind[5], ind[6], ind[7], ind[8], ind[9]}; + + // F-Measure and no approximations HeuristicTests.configurePosNegStandardLP(problem, pos1, neg1, "fmeasure", false); - // TODO: continue + assertEqualsPosNegLPStandard(problem, nc[0], 0.5); // precision 2/3, recall 2/5 + assertEqualsPosNegLPStandard(problem, nc[1], 2/3d); // precision 3/4, recall 3/5 +// System.out.println(problem.getFMeasureOrTooWeakExact(nc[0], 1)); +// System.out.println(problem.getFMeasureOrTooWeakExact(nc[1], 1)); + + // F-Measure and approximations + HeuristicTests.configurePosNegStandardLP(problem, pos1, neg1, "fmeasure", true); + + assertEqualsPosNegLPStandard(problem, nc[0], 0.5); // precision 2/3, recall 2/5 + assertEqualsPosNegLPStandard(problem, nc[1], 2/3d); // precision 3/4, recall 3/5 } @@ -260,6 +262,13 @@ assertEquals(accuracy, problem.evaluate(description).getAccuracy(), delta); } + private static void assertEqualsPosNegLPStandard(PosNegLPStandard problem, Description description, double accuracy) { + assertEquals(accuracy, problem.getAccuracy(description), delta); + assertEquals(accuracy, problem.getAccuracyOrTooWeak(description, 1.0), delta); + assertEquals(accuracy, problem.computeScore(description).getAccuracy(), delta); + assertEquals(accuracy, problem.evaluate(description).getAccuracy(), delta); + } + // convencience method to set the learning problem to a desired configuration (approximations disabled) private static void configureClassLP(ClassLearningProblem problem, NamedClass classToDescribe, String accuracyMethod) throws ComponentInitException { try { Modified: trunk/test/pdb/pdb.conf =================================================================== --- trunk/test/pdb/pdb.conf 2011-01-31 19:41:38 UTC (rev 2637) +++ trunk/test/pdb/pdb.conf 2011-01-31 22:38:48 UTC (rev 2638) @@ -5,6 +5,10 @@ celoe.terminateOnNoiseReached = false; celoe.noisePercentage = 20; celoe.maxExecutionTimeInSeconds = 100; +// set this to true and look in interfaces/log/searchTree.txt to see which concepts +// are explored by DL-Learner - turn this feature off if you do not need logging, +// since it slows the learning algorithm down +celoe.writeSearchTree = false; learningProblems = posNegLPStandard; posNegLPStandard.accuracyMethod = fmeasure; posNegLPStandard.useApproximations = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |