From: <jen...@us...> - 2009-06-26 14:11:49
|
Revision: 1810 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1810&view=rev Author: jenslehmann Date: 2009-06-26 14:11:46 +0000 (Fri, 26 Jun 2009) Log Message: ----------- practical tests and enhancements Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2009-06-25 16:56:18 UTC (rev 1809) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2009-06-26 14:11:46 UTC (rev 1810) @@ -45,6 +45,7 @@ import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.refinementoperators.ELDown2; +import org.dllearner.utilities.owl.DescriptionMinimizer; /** * A learning algorithm for EL, which will based on an @@ -79,6 +80,7 @@ Map<String,String> prefixes; private ELDown2 operator; + private DescriptionMinimizer minimizer; private boolean isRunning = false; private boolean stop = false; @@ -101,6 +103,8 @@ private SearchTreeNode bestCurrentNode; private double bestCurrentScore = 0; private long treeStartTime; + // minimum score a tree must have to be part of the solution + private double minimumTreeScore = -8; public ELLearningAlgorithmDisjunctive(PosNegLP problem, ReasonerComponent reasoner) { super(problem, reasoner); @@ -151,6 +155,8 @@ baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); + + minimizer = new DescriptionMinimizer(reasoner); } @Override @@ -198,37 +204,41 @@ // System.out.println("=="); } - // we found a tree (partial solution) - currentSolution.add(bestCurrentNode.getDescriptionTree()); - Description bestDescription = bestCurrentNode.getDescriptionTree().transformToDescription(); - // form union of trees found so far with - if(treeCount==0) { - bestEvaluatedDescription = learningProblem.evaluate(bestDescription); - } else { - Union union = new Union(bestEvaluatedDescription.getDescription(), bestDescription); - bestEvaluatedDescription = learningProblem.evaluate(union); - } - - // remove already covered examples - Iterator<Individual> it = currentPosExamples.iterator(); - int posCov = 0; - while(it.hasNext()) { - Individual ind = it.next(); - if(reasoner.hasType(bestDescription, ind)) { - it.remove(); - posCov++; + if(bestCurrentScore > minimumTreeScore) { + // we found a tree (partial solution) + currentSolution.add(bestCurrentNode.getDescriptionTree()); + Description bestDescription = bestCurrentNode.getDescriptionTree().transformToDescription(); + // form union of trees found so far with + if(treeCount==0) { + bestEvaluatedDescription = learningProblem.evaluate(bestDescription); + } else { + Union union = new Union(bestEvaluatedDescription.getDescription(), bestDescription); + bestEvaluatedDescription = learningProblem.evaluate(union); } - } - it = currentNegExamples.iterator(); - int negCov = 0; - while(it.hasNext()) { - Individual ind = it.next(); - if(reasoner.hasType(bestDescription, ind)) { - it.remove(); - negCov++; + + // remove already covered examples + Iterator<Individual> it = currentPosExamples.iterator(); + int posCov = 0; + while(it.hasNext()) { + Individual ind = it.next(); + if(reasoner.hasType(bestDescription, ind)) { + it.remove(); + posCov++; + } } + it = currentNegExamples.iterator(); + int negCov = 0; + while(it.hasNext()) { + Individual ind = it.next(); + if(reasoner.hasType(bestDescription, ind)) { + it.remove(); + negCov++; + } + } + logger.info("tree found: " + bestDescription.toManchesterSyntaxString(baseURI, prefixes) + " (" + posCov + " pos covered, " + currentPosExamples.size() + " remaining, " + negCov + " neg covered, " + currentNegExamples.size() + " remaining, score: " + bestCurrentNode.getScore() + ")"); + } else { + logger.info("no tree found, which satisfies the minimum criteria - the best was: " + bestCurrentNode.getDescriptionTree().transformToDescription().toManchesterSyntaxString(baseURI, prefixes) + " with score " + bestCurrentNode.getScore()); } - logger.info("tree found: " + bestDescription.toManchesterSyntaxString(baseURI, prefixes) + " (" + posCov + " pos covered, " + currentPosExamples.size() + " remaining, " + negCov + " neg covered, " + currentNegExamples.size() + " remaining, score: " + bestCurrentNode.getScore() + ")"); // reset temporary variables candidates.clear(); @@ -236,6 +246,10 @@ treeCount++; } + // simplify solution (in particular necessary when start class is specified) + Description niceDescription = minimizer.minimizeClone(bestEvaluatedDescription.getDescription()); + bestEvaluatedDescription = learningProblem.evaluate(niceDescription); + // print solution logger.info("solution : " + bestEvaluatedDescription.getDescription().toManchesterSyntaxString(baseURI, prefixes) + "(acc: " + bestEvaluatedDescription.getAccuracy() + ")"); @@ -324,8 +338,9 @@ private boolean treeCriteriaSatisfied() { long runTime = System.nanoTime() - treeStartTime; - // more than one second has passed - if(runTime / (double) 1000000000 >= 10) { + double runTimeSeconds = runTime / (double) 1000000000; + + if(runTimeSeconds >= 10) { return true; } else { return false; @@ -337,8 +352,16 @@ // SearchTreeNode bestNode = candidates.last(); // return (bestNode.getCoveredNegatives() == 0); - // stop whan all positive examples have been covered - return (currentPosExamples.size()==0); + // we stop when the score of the last tree added is too low + // (indicating that the algorithm could not find anything appropriate + // in the timeframe set) + if(bestCurrentScore < minimumTreeScore) { + return true; + } + + // stop when almost all positive examples have been covered + int maxPosRemaining = (int) Math.ceil(startPosExamplesSize * 0.05d); + return (currentPosExamples.size()<=maxPosRemaining); } private void reset() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |