From: <jen...@us...> - 2008-01-26 19:25:36
|
Revision: 429 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=429&view=rev Author: jenslehmann Date: 2008-01-26 11:25:33 -0800 (Sat, 26 Jan 2008) Log Message: ----------- algorithm fixes and beautification Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-01-26 01:51:11 UTC (rev 428) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-01-26 19:25:33 UTC (rev 429) @@ -287,6 +287,7 @@ // options to it algorithm = new ExampleBasedROLearner( learningProblem, + rs, operator, algHeuristic, // usedConcepts, @@ -305,7 +306,7 @@ } public static String getName() { - return "example driven refinement operator based learning algorithm [not working]"; + return "example driven refinement operator based learning algorithm"; } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-01-26 01:51:11 UTC (rev 428) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-01-26 19:25:33 UTC (rev 429) @@ -148,6 +148,7 @@ public ExampleBasedROLearner( LearningProblem learningProblem, + ReasoningService rs, RefinementOperator operator, ExampleBasedHeuristic heuristic, // Set<AtomicConcept> allowedConcepts, @@ -167,27 +168,29 @@ this.posOnlyLearningProblem = (PosOnlyDefinitionLP) learningProblem; posOnly = true; } - - // this.heuristic = heuristic; - // candidate sets entsprechend der gewählten Heuristik initialisieren + this.rs = rs; + this.operator = (RhoDown) operator; + // initialise candidate set with heuristic as ordering candidates = new TreeSet<ExampleBasedNode>(heuristic); - // newCandidates = new TreeSet<Node>(nodeComparator); + // this.noisePercentage ... + this.writeSearchTree = writeSearchTree; + this.replaceSearchTree = replaceSearchTree; + this.searchTreeFile = searchTreeFile; + this.useTooWeakList = useTooWeakList; + this.useOverlyGeneralList = useOverlyGeneralList; + this.useShortConceptConstruction = useShortConceptConstruction; } public void start() { - // Suche wird mit Top-Konzept gestartet + // start search with most general concept Top top = new Top(); ExampleBasedNode topNode = new ExampleBasedNode(top); - // int coveredNegativeExamples = learningProblem.coveredNegativeExamplesOrTooWeak(top); - // aus Top folgen immer alle negativen Beispiele, d.h. es ist nur eine Lösung, wenn - // es keine negativen Beispiele gibt + // top covers all negatives int coveredNegativeExamples = getNumberOfNegatives(); topNode.setCoveredNegativeExamples(coveredNegativeExamples); - // topNode.setHorizontalExpansion(1); // die 0 ist eigentlich richtig, da keine Refinements - // der Länge 1 untersucht wurden candidates.add(topNode); candidatesStable.add(topNode); - // Abbruchvariable => beachten, dass bereits TOP eine Lösung sein kann + // note that TOP may already be a solution solutionFound = (coveredNegativeExamples == 0); solutions = new LinkedList<Concept>(); if(solutionFound) @@ -690,7 +693,7 @@ } public void stop() { - + stop = true; } public Concept getBestSolution() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-07 17:36:37
|
Revision: 515 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=515&view=rev Author: jenslehmann Date: 2008-02-07 09:36:33 -0800 (Thu, 07 Feb 2008) Log Message: ----------- started better example and noise handling Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-02-07 17:11:15 UTC (rev 514) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-02-07 17:36:33 UTC (rev 515) @@ -39,9 +39,9 @@ */ public class ExampleBasedNode { - // TODO: add example based variables here - @SuppressWarnings({"unused"}) + // example based variables here private Set<Individual> coveredPositives; + private Set<Individual> coveredNegatives; // TOP ist einfach das TOP-Konzept, also das einzige welches nicht evaluiert wird public enum QualityEvaluationMethod { TOP, REASONER, TOO_WEAK_LIST, OVERLY_GENERAL_LIST }; @@ -190,5 +190,21 @@ public void setQualityEvaluationMethod(QualityEvaluationMethod qualityEvaluationMethod) { this.qualityEvaluationMethod = qualityEvaluationMethod; } + + public Set<Individual> getCoveredPositives() { + return coveredPositives; + } + + public void setCoveredPositives(Set<Individual> coveredPositives) { + this.coveredPositives = coveredPositives; + } + + public Set<Individual> getCoveredNegatives() { + return coveredNegatives; + } + + public void setCoveredNegatives(Set<Individual> coveredNegatives) { + this.coveredNegatives = coveredNegatives; + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-07 17:11:15 UTC (rev 514) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-07 17:36:33 UTC (rev 515) @@ -250,6 +250,7 @@ Helper.checkConcepts(rs, allowedConcepts); usedConcepts = allowedConcepts; } else if(ignoredConcepts != null) { + System.out.println(ignoredConcepts); usedConcepts = Helper.computeConceptsUsingIgnoreList(rs, ignoredConcepts); } else { usedConcepts = Helper.computeConcepts(rs); @@ -292,7 +293,7 @@ algHeuristic, // usedConcepts, // usedRoles, - noisePercentage, + noisePercentage/(double)100, writeSearchTree, replaceSearchTree, searchTreeFile, Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-07 17:11:15 UTC (rev 514) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-07 17:36:33 UTC (rev 515) @@ -21,6 +21,7 @@ import java.io.File; import java.text.DecimalFormat; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -28,6 +29,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.algorithms.refinement.RhoDown; @@ -35,6 +37,7 @@ import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Top; @@ -56,6 +59,15 @@ * can be misclassified (everything above is considered a too weak * concept wrt. the noise percentage). * + * TODO: Solve subsumption problems. It is easy to implement approximate fast + * instance checks. However, subsumption is difficult to optimise. It should by + * analysed whether it is reasonable to perform instance comparisions instead + * of subsumption checks, e.g. a concept is only included in the search tree + * when it covers strictly less examples than its parent. Note, that this does + * not mean that concepts not bearing an advantage in classification are thrown + * away. They are just handled like improper refinements. [TODO: How does this + * differ from not checking subsumption at all?] + * * @author Jens Lehmann * */ @@ -68,8 +80,15 @@ private ReasoningService rs; private PosNegLP learningProblem; private PosOnlyDefinitionLP posOnlyLearningProblem; - private boolean posOnly = false; + private boolean posOnly = false; + private int nrOfExamples; + private int nrOfPositiveExamples; + private int nrOfNegativeExamples; + // noise regulates how many positives can be misclassified and when the algorithm terminates + private double noise = 0.0; + private int allowedMisclassifications = 0; + // search tree options private boolean writeSearchTree; private File searchTreeFile; @@ -153,7 +172,7 @@ ExampleBasedHeuristic heuristic, // Set<AtomicConcept> allowedConcepts, // Set<AtomicRole> allowedRoles, - double noisePercentage, + double noise, boolean writeSearchTree, boolean replaceSearchTree, File searchTreeFile, @@ -162,39 +181,56 @@ boolean useShortConceptConstruction ) { if(learningProblem instanceof PosNegLP) { - this.learningProblem = (PosNegLP) learningProblem; + PosNegLP lp = (PosNegLP) learningProblem; + this.learningProblem = lp; posOnly = false; + nrOfPositiveExamples = lp.getPositiveExamples().size(); + nrOfNegativeExamples = lp.getNegativeExamples().size(); } else if(learningProblem instanceof PosOnlyDefinitionLP) { - this.posOnlyLearningProblem = (PosOnlyDefinitionLP) learningProblem; + PosOnlyDefinitionLP lp = (PosOnlyDefinitionLP) learningProblem; + this.posOnlyLearningProblem = lp; posOnly = true; + nrOfPositiveExamples = lp.getPositiveExamples().size(); + nrOfNegativeExamples = lp.getPseudoNegatives().size(); } + nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; this.rs = rs; this.operator = (RhoDown) operator; // initialise candidate set with heuristic as ordering candidates = new TreeSet<ExampleBasedNode>(heuristic); - // this.noisePercentage ... + this.noise = noise; this.writeSearchTree = writeSearchTree; this.replaceSearchTree = replaceSearchTree; this.searchTreeFile = searchTreeFile; this.useTooWeakList = useTooWeakList; this.useOverlyGeneralList = useOverlyGeneralList; this.useShortConceptConstruction = useShortConceptConstruction; + + logger.setLevel(Level.DEBUG); } public void start() { + + // calculate quality threshold required for a solution + allowedMisclassifications = (int) Math.round(noise * nrOfExamples); + // start search with most general concept Top top = new Top(); ExampleBasedNode topNode = new ExampleBasedNode(top); // top covers all negatives int coveredNegativeExamples = getNumberOfNegatives(); topNode.setCoveredNegativeExamples(coveredNegativeExamples); + topNode.setCoveredPositives(learningProblem.getPositiveExamples()); + topNode.setCoveredNegatives(learningProblem.getNegativeExamples()); candidates.add(topNode); candidatesStable.add(topNode); + // note that TOP may already be a solution - solutionFound = (coveredNegativeExamples == 0); - solutions = new LinkedList<Concept>(); - if(solutionFound) - solutions.add(top); + ExampleBasedNode bestNode = topNode; +// solutionFound = (coveredNegativeExamples == 0); +// solutions = new LinkedList<Concept>(); +// if(solutionFound) +// solutions.add(top); int loop = 0; @@ -202,14 +238,17 @@ while(!solutionFound && !stop) { - // besten Knoten nach Heuristik auswählen - ExampleBasedNode bestNode = candidates.last(); - // besten Knoten erweitern - // newCandidates = new TreeSet<Node>(nodeComparator); + printStatistics(false); + + // chose best node according to heuristics + bestNode = candidates.last(); + // extend best node newCandidates.clear(); + // TODO: why is the best node tempoariliy removed from the candidates set? candidates.remove(bestNode); extendNodeProper(bestNode, bestNode.getHorizontalExpansion()+1); candidates.add(bestNode); + // newCandidates has been filled during node expansion candidates.addAll(newCandidates); candidatesStable.addAll(newCandidates); @@ -373,7 +412,7 @@ propernessTestsAvoidedByTooWeakList++; conceptTestsTooWeakList++; propernessDetected = true; - tooWeakList.add(refinement); + // tooWeakList.add(refinement); // Knoten wird direkt erzeugt (es ist buganfällig zwei Plätze // zu haben, an denen Knoten erzeugt werden, aber es erscheint @@ -436,40 +475,12 @@ // schon existiert if(nonRedundant) { - // Knoten erzeugen + // newly created node ExampleBasedNode newNode = new ExampleBasedNode(refinement); // die -1 ist wichtig, da sonst keine gleich langen Refinements // für den neuen Knoten erlaubt wären z.B. person => male newNode.setHorizontalExpansion(refinement.getLength()-1); - - // hier finden Tests statt, die Retrieval-Anfrage vermeiden sollen - /* - Integer n = evaluationCache.get(concept); - // Konzept gefunden - if(n!=null) { - // Knoten erzeugen - Node newNode = new Node(refinement); - newNode.setHorizontalExpansion(refinement.getLength()-1); - node.addChild(newNode); - - // too weak - if(n==-1) { - newNode.setTooWeak(true); - // nicht too weak - } else { - // feststellen, ob proper => geht so nicht - // gleiche covered negatives bedeutet nicht improper - boolean proper = (n==node.getCoveredNegativeExamples()); - newNode.setCoveredNegativeExamples(n); - - } - // Konzept nicht gefunden => muss ausgewertet werden - } else { - toEvaluateConcepts.add(refinement); - } - */ - boolean qualityKnown = false; int quality = -2; @@ -487,9 +498,59 @@ if(!qualityKnown) { long propCalcReasoningStart2 = System.nanoTime(); conceptTestsReasoner++; - quality = coveredNegativesOrTooWeak(refinement); + + // quality = coveredNegativesOrTooWeak(refinement); + + // determine individuals which have not been covered yet (more efficient than full retrieval) + Set<Individual> coveredPositives = node.getCoveredPositives(); + Set<Individual> newlyCoveredPositives = new HashSet<Individual>(); + + // calculate how many pos. examples are not covered by the + // parent node of the refinement + int misclassifications = nrOfPositiveExamples - coveredPositives.size(); + + // iterate through all covered examples (examples which are not + // covered do not need to be tested, because they remain uncovered) + // TODO: DIG will be slow if we send each reasoner request individually + // (however if we send everything in one request, too many instance checks + // are performed => rely on fast instance checker [still to implement]) + for(Individual i : coveredPositives) { + // TODO: move code to a separate function + if(quality != -1) { + boolean covered = rs.instanceCheck(refinement, i); + if(!covered) + misclassifications++; + else + newlyCoveredPositives.add(i); + + if(misclassifications > allowedMisclassifications) + quality = -1; + + } + } + + Set<Individual> newlyCoveredNegatives = null; + if(quality != -1) { + Set<Individual> coveredNegatives = node.getCoveredNegatives(); + newlyCoveredNegatives = new HashSet<Individual>(); + + for(Individual i : coveredNegatives) { + boolean covered = rs.instanceCheck(refinement, i); + if(covered) + newlyCoveredNegatives.add(i); + } + } + propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart2; newNode.setQualityEvaluationMethod(ExampleBasedNode.QualityEvaluationMethod.REASONER); + if(quality != -1) { + // quality is the number of misclassifications (if it is not too weak) + quality = (nrOfPositiveExamples - newlyCoveredPositives.size()) + + newlyCoveredNegatives.size(); + newNode.setCoveredNegatives(newlyCoveredNegatives); + newNode.setCoveredPositives(newlyCoveredPositives); + } + } if(quality == -1) { @@ -520,66 +581,6 @@ } - /* - Iterator<Concept> it = refinements.iterator(); - while(it.hasNext()) { - Concept refinement = it.next(); - if(refinement.getLength()>node.getHorizontalExpansion()) { - // Test auf properness - long propCalcReasoningStart = System.nanoTime(); - boolean isProper = !learningProblem.getReasoningService().subsumes(refinement, concept); - propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; - - if(isProper) { - long redundancyCheckTimeNsStart = System.nanoTime(); - boolean nonRedundant = properRefinements.add(refinement); - redundancyCheckTimeNs += System.nanoTime() - redundancyCheckTimeNsStart; - - if(!nonRedundant) - redundantConcepts++; - - // es wird nur ein neuer Knoten erzeugt, falls das Konzept nicht - // schon existiert - if(nonRedundant) { - - // Knoten erzeugen - Node newNode = new Node(refinement); - // die -1 ist wichtig, da sonst keine gleich langen Refinements - // für den neuen Knoten erlaubt wären z.B. person => male - newNode.setHorizontalExpansion(refinement.getLength()-1); - node.addChild(newNode); - - // Qualität des Knotens auswerten - long propCalcReasoningStart2 = System.nanoTime(); - int quality = learningProblem.coveredNegativeExamplesOrTooWeak(refinement); - propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart2; - - if(quality == -1) { - newNode.setTooWeak(true); - } else { - // Lösung gefunden - if(quality == 0) { - solutionFound = true; - solutions.add(refinement); - } - - newNode.setCoveredNegativeExamples(quality); - newCandidates.add(newNode); - - // System.out.print("."); - } - } - - // jedes proper Refinement wird gelöscht - it.remove(); - - } - } - } - */ - - - // es sind jetzt noch alle Konzepte übrig, die improper refinements sind // auf jedem dieser Konzepte wird die Funktion erneut aufgerufen, da sich // proper refinements ergeben könnten @@ -662,6 +663,7 @@ + conceptTestsTooWeakList + "/" + conceptTestsOverlyGeneralList + "/" + redundantConcepts); } + @SuppressWarnings({"unused"}) private int coveredNegativesOrTooWeak(Concept concept) { if(posOnly) return posOnlyLearningProblem.coveredPseudoNegativeExamplesOrTooWeak(concept); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-03-03 20:07:34
|
Revision: 678 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=678&view=rev Author: jenslehmann Date: 2008-03-03 12:06:17 -0800 (Mon, 03 Mar 2008) Log Message: ----------- added support for specifying a start class (the search starts from there instead of owl:Thing) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-03-03 19:38:48 UTC (rev 677) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-03-03 20:06:17 UTC (rev 678) @@ -299,6 +299,7 @@ rs, operator, algHeuristic, + startClass, // usedConcepts, // usedRoles, noisePercentage/(double)100, Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-03 19:38:48 UTC (rev 677) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-03 20:06:17 UTC (rev 678) @@ -80,6 +80,7 @@ private ReasoningService rs; private PosNegLP learningProblem; private PosOnlyDefinitionLP posOnlyLearningProblem; + private Description startDescription; private boolean posOnly = false; private int nrOfExamples; private int nrOfPositiveExamples; @@ -171,6 +172,7 @@ ReasoningService rs, RefinementOperator operator, ExampleBasedHeuristic heuristic, + Description startDescription, // Set<AtomicConcept> allowedConcepts, // Set<AtomicRole> allowedRoles, double noise, @@ -197,6 +199,7 @@ nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; this.rs = rs; this.operator = (RhoDRDown) operator; + this.startDescription = startDescription; // initialise candidate set with heuristic as ordering candidates = new TreeSet<ExampleBasedNode>(heuristic); this.noise = noise; @@ -216,19 +219,28 @@ // calculate quality threshold required for a solution allowedMisclassifications = (int) Math.round(noise * nrOfExamples); - // start search with most general concept - Thing top = new Thing(); - ExampleBasedNode topNode = new ExampleBasedNode(top); - // top covers all negatives - int coveredNegativeExamples = getNumberOfNegatives(); - topNode.setCoveredNegativeExamples(coveredNegativeExamples); - topNode.setCoveredPositives(learningProblem.getPositiveExamples()); - topNode.setCoveredNegatives(learningProblem.getNegativeExamples()); - candidates.add(topNode); - candidatesStable.add(topNode); + // start search with start class + ExampleBasedNode startNode; + if(startDescription == null) { + Thing top = new Thing(); + startNode = new ExampleBasedNode(top); + // top covers all negatives + int coveredNegativeExamples = getNumberOfNegatives(); + startNode.setCoveredNegativeExamples(coveredNegativeExamples); + startNode.setCoveredPositives(learningProblem.getPositiveExamples()); + startNode.setCoveredNegatives(learningProblem.getNegativeExamples()); + } else { + startNode = new ExampleBasedNode(startDescription); + Set<Individual> coveredNegatives = rs.instanceCheck(startDescription, learningProblem.getNegativeExamples()); + startNode.setCoveredPositives(rs.instanceCheck(startDescription, learningProblem.getPositiveExamples())); + startNode.setCoveredNegatives(coveredNegatives); + startNode.setCoveredNegativeExamples(coveredNegatives.size()); + } + candidates.add(startNode); + candidatesStable.add(startNode); // note that TOP may already be a solution - ExampleBasedNode bestNode = topNode; + ExampleBasedNode bestNode = startNode; // solutionFound = (coveredNegativeExamples == 0); // solutions = new LinkedList<Concept>(); // if(solutionFound) @@ -272,7 +284,7 @@ } } expandedNodes.clear(); - treeString += topNode.getTreeString(); + treeString += startNode.getTreeString(); treeString += "\n"; if(replaceSearchTree) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-05-13 13:23:47
|
Revision: 833 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=833&view=rev Author: JensLehmann Date: 2008-05-13 06:23:45 -0700 (Tue, 13 May 2008) Log Message: ----------- started new comparator for ordering solutions Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-05-13 11:11:07 UTC (rev 832) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-05-13 13:23:45 UTC (rev 833) @@ -22,6 +22,7 @@ import java.text.DecimalFormat; import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; import org.dllearner.core.owl.Description; @@ -64,9 +65,9 @@ // link to parent in search tree private ExampleBasedNode parent = null; - private Set<ExampleBasedNode> children = new TreeSet<ExampleBasedNode>(nodeComparator); + private SortedSet<ExampleBasedNode> children = new TreeSet<ExampleBasedNode>(nodeComparator); // apart from the child nodes, we also keep child concepts - private Set<Description> childConcepts = new TreeSet<Description>(conceptComparator); + private SortedSet<Description> childConcepts = new TreeSet<Description>(conceptComparator); public ExampleBasedNode(Description concept) { this.concept = concept; @@ -210,11 +211,11 @@ return coveredNegatives; } - public Set<ExampleBasedNode> getChildren() { + public SortedSet<ExampleBasedNode> getChildren() { return children; } - public Set<Description> getChildConcepts() { + public SortedSet<Description> getChildConcepts() { return childConcepts; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-05-13 11:11:07 UTC (rev 832) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-05-13 13:23:45 UTC (rev 833) @@ -96,6 +96,12 @@ private double noise = 0.0; private int allowedMisclassifications = 0; + // positive only learning options: + // if no negatives are given, then one possible strategy is to find a very special concept still entailing all positive examples; + // this is realised by changing the termination criterion: a concept is a solution if it has been expanded x times (x is + // configurable) but no more special concept is found (all are either equivalent or too weak) + private int maxPosOnlyExpansion = 3; + // search tree options private boolean writeSearchTree; private File searchTreeFile; @@ -118,7 +124,7 @@ // but the disadvantage of properness testing are additional reasoner // queries and a search bias towards ALL r.something because // ALL r.TOP is improper and automatically expanded further - private boolean testProperness = false; + private boolean testProperness = true; // tree traversal means to run through the most promising concepts // and connect them in an intersection to find a solution @@ -402,6 +408,23 @@ Files.appendFile(searchTreeFile, treeString); } + // special situation for positive only learning: the expanded node can become a solution (see explanations + // for maxPosOnlyExpansion above) + if(posOnly && (bestNode.getHorizontalExpansion() - bestNode.getConcept().getLength() >= maxPosOnlyExpansion)) { + // check whether there are any child concept, which are not too weak (we only need to check whether the best concept + // is too weak) + ExampleBasedNode bestChild = null; + if(bestNode.getChildren().size() > 0) + bestChild = bestNode.getChildren().last(); + if(bestNode.getChildren().size() == 0 || bestChild.isTooWeak()) { + solutions.add(bestNode.getConcept()); + System.out.println("solution: " + bestNode.getConcept()); + System.out.println("TODO: needs to be integrated with other stopping criteria"); + System.exit(0); + } + } + + // handle termination criteria handleStoppingConditions(); //logger.info(minExecutionTimeReached()+"aaaaaaa "+solutions.size()+"::"+guaranteeXgoodDescriptions); @@ -716,7 +739,7 @@ tooWeakList.add(refinement); } else { // Lösung gefunden - if(quality >= 0 && quality<=allowedMisclassifications) { + if(quality >= 0 && quality<=allowedMisclassifications && !posOnly) { solutionFound = true; solutions.add(refinement); } Added: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java 2008-05-13 13:23:45 UTC (rev 833) @@ -0,0 +1,32 @@ +package org.dllearner.algorithms.refexamples; + +import java.util.Comparator; + +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Description; + +public class SubsumptionComparator implements Comparator<ExampleBasedNode> { + + public ReasoningService rs; + + public SubsumptionComparator(ReasoningService rs) { + this.rs = rs; + } + + public int compare(ExampleBasedNode arg0, ExampleBasedNode arg1) { + Description concept1 = arg0.getConcept(); + Description concept2 = arg1.getConcept(); + // return true if concept1 is a super concept of concept2 + boolean value1 = rs.subsumes(concept1, concept2); + if(value1) + return 1; + + boolean value2 = rs.subsumes(concept2, concept1); + if(value2) + return -1; + + // both concepts are equal + return 0; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-05-19 14:12:17
|
Revision: 903 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=903&view=rev Author: kurzum Date: 2008-05-19 07:12:01 -0700 (Mon, 19 May 2008) Log Message: ----------- some more claenup Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-05-19 14:03:09 UTC (rev 902) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-05-19 14:12:01 UTC (rev 903) @@ -290,10 +290,7 @@ Helper.checkConcepts(rs, allowedConcepts); usedConcepts = allowedConcepts; } else if(ignoredConcepts != null) { - //System.out.println(ignoredConcepts); usedConcepts = Helper.computeConceptsUsingIgnoreList(rs, ignoredConcepts); - //RBC - //System.out.println(usedConcepts); } else { usedConcepts = Helper.computeConcepts(rs); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-05-19 14:03:09 UTC (rev 902) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-05-19 14:12:01 UTC (rev 903) @@ -279,8 +279,6 @@ public void start() { runtime=System.currentTimeMillis(); - //RBC many comments can be removed - //SimpleClock sc =new SimpleClock(); // TODO: write a JUnit test for this problem (long-lasting or infinite loops because // redundant children of a node are called recursively after when the node is extended // twice) @@ -361,16 +359,12 @@ lastPrintTime = currentTime; logger.debug("--- loop " + loop + " started ---"); } - //RBC - //logger.debug("--- loop " + loop + " started ---"); - //printStatistics(false); - //sc.printAndSet("before Traverse"); + // traverse the current search tree to find a solution if(useTreeTraversal && (currentTime - lastTreeTraversalTime > traversalInterval)) { traverseTree(); lastTreeTraversalTime = System.nanoTime(); } - //sc.printAndSet("Traverse"); // reduce candidates to focus on promising concepts if(useCandidateReduction && (currentTime - lastReductionTime > reductionInterval)) { @@ -379,7 +373,7 @@ // Logger.getRootLogger().setLevel(Level.TRACE); } - //sc.printAndSet("candidates"); + // System.out.println("next expanded: " + candidates.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); // chose best node according to heuristics bestNode = candidates.last(); @@ -394,7 +388,7 @@ candidates.addAll(newCandidates); candidatesStable.addAll(newCandidates); - //sc.printAndSet("after candidates"); + // System.out.println("done"); if(writeSearchTree) { @@ -415,7 +409,7 @@ else Files.appendFile(searchTreeFile, treeString); } - //sc.printAndSet("before posonly"); + // special situation for positive only learning: the expanded node can become a solution (see explanations // for maxPosOnlyExpansion above) if(posOnly && (bestNode.getHorizontalExpansion() - bestNode.getConcept().getLength() >= maxPosOnlyExpansion)) { @@ -432,15 +426,10 @@ } } - //sc.printAndSet("before stopping"); + // handle termination criteria handleStoppingConditions(); - //sc.printAndSet("after stopping"); - //logger.info(minExecutionTimeReached()+"aaaaaaa "+solutions.size()+"::"+guaranteeXgoodDescriptions); - //logger.info(solutionFound+"aaaaaaa "+stop); - - // Anzahl Schleifendurchläufe loop++; @@ -1118,6 +1107,7 @@ public void printBestSolutions(int nrOfSolutions, boolean showOrderedSolutions){ + //QUALITY if(!logger.isTraceEnabled()) return; //if(!logger.getLevel().toString().equalsIgnoreCase("TRACE"))return; @@ -1132,19 +1122,8 @@ i++; } - if(nrOfSolutions==0) - nrOfSolutions=solutions.size(); - int a=0; - for(;a<nrOfSolutions && a < solutions.size();a++) { - - logger.trace("nnn: "+solutions.get(a)); - if(a==nrOfSolutions) - break ; - - } - if(showOrderedSolutions) { logger.trace("ordered by generality (most special solutions first):"); SubsumptionComparator sc = new SubsumptionComparator(rs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |