From: <jen...@us...> - 2008-09-12 16:51:31
|
Revision: 1201 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1201&view=rev Author: jenslehmann Date: 2008-09-12 16:51:26 +0000 (Fri, 12 Sep 2008) Log Message: ----------- fixed tricky multi-threading issue when querying currently best class descriptions Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionSet.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-09-12 12:35:09 UTC (rev 1200) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-09-12 16:51:26 UTC (rev 1201) @@ -21,6 +21,7 @@ import java.io.File; import java.text.DecimalFormat; +import java.util.ConcurrentModificationException; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -30,9 +31,11 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.concurrent.ConcurrentSkipListSet; import org.apache.log4j.Logger; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -51,6 +54,7 @@ import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; +import org.dllearner.utilities.owl.EvaluatedDescriptionSet; import com.jamonapi.Monitor; @@ -160,9 +164,13 @@ // an ordering which does not change during the run of the algorithm private NodeComparatorStable nodeComparatorStable = new NodeComparatorStable(); // stable candidate set; it has no functional part in the algorithm, - // but is a list of the currently best concepts found - private TreeSet<ExampleBasedNode> candidatesStable = new TreeSet<ExampleBasedNode>( + // but is a list of the currently best concepts found; + // it is very important to use a concurrent set here as other threads will + // access it (usual iterating is likely to throw a ConcurrentModificationException) + private NavigableSet<ExampleBasedNode> candidatesStable = new ConcurrentSkipListSet<ExampleBasedNode>( nodeComparatorStable); + // evaluated descriptions +// private EvaluatedDescriptionSet evaluatedDescriptions = new EvaluatedDescriptionSet(LearningAlgorithm.MAX_NR_OF_RESULTS); // comparator used to create ordered sets of concepts private ConceptComparator conceptComparator = new ConceptComparator(); @@ -1191,12 +1199,13 @@ } return best; } - + public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + Iterator<ExampleBasedNode> it = candidatesStable.descendingIterator(); int count = 0; - SortedSet<ExampleBasedNode> rev = candidatesStable.descendingSet(); SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator); - for (ExampleBasedNode eb : rev) { + while(it.hasNext()) { + ExampleBasedNode eb = it.next(); cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept()))); // return a maximum of 200 elements (we need a maximum, because the // candidate set can be very large) Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-09-12 12:35:09 UTC (rev 1200) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-09-12 16:51:26 UTC (rev 1201) @@ -170,6 +170,7 @@ * Show Statistics. */ public void showStats() { + System.out.println("stat update " + System.currentTimeMillis()); Long algorithmRunTime = null; Long overallReasoningTime = null; Long instanceCheckReasoningTime = null; @@ -178,7 +179,7 @@ infoArea.setText(""); // best solutions - if (config.getLearningAlgorithm().getCurrentlyBestDescriptions() != null) { + if (config.getLearningAlgorithm().getCurrentlyBestDescription() != null) { infoArea.append("Best class descriptions in Manchester OWL Syntax: \n\n" + getSolutionString(config.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(10)) + "\n"); } Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-09-12 12:35:09 UTC (rev 1200) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-09-12 16:51:26 UTC (rev 1201) @@ -232,7 +232,7 @@ Logger logger = Logger.getRootLogger(); logger.removeAllAppenders(); logger.addAppender(consoleAppender); - logger.setLevel(Level.TRACE); + logger.setLevel(Level.DEBUG); File file = null; if (args.length > 0) Added: trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionSet.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/DescriptionSet.java 2008-09-12 16:51:26 UTC (rev 1201) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities.owl; + +import java.util.Collection; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.owl.Description; + +/** + * A set of descriptions, which is bound by a maximum + * size. Can be used by algorithms to store the most promising + * n class descriptions. + * + * @author Jens Lehmann + * + */ +public class DescriptionSet { + + private ConceptComparator comp = new ConceptComparator(); + + private SortedSet<Description> set = new TreeSet<Description>(comp); + + private int maxSize; + + public DescriptionSet(int maxSize) { + this.maxSize = maxSize; + } + + public void add(Description ed) { + set.add(ed); + if(set.size()>maxSize) { + Iterator<Description> it = set.iterator(); + it.next(); + it.remove(); + } + } + + public void addAll(Collection<Description> eds) { + for(Description ed : eds) { + add(ed); + } + } + + /** + * @return the set + */ + public SortedSet<Description> getSet() { + return set; + } + +} Added: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2008-09-12 16:51:26 UTC (rev 1201) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities.owl; + +import java.util.Collection; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.EvaluatedDescription; + +/** + * A set of evaluated descriptions, which is bound by a maximum + * size. Can be used by algorithms to store the most promising + * n class descriptions. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescriptionSet { + + private EvaluatedDescriptionComparator comp = new EvaluatedDescriptionComparator(); + + private SortedSet<EvaluatedDescription> set = new TreeSet<EvaluatedDescription>(comp); + + private int maxSize; + + public EvaluatedDescriptionSet(int maxSize) { + this.maxSize = maxSize; + } + + public void add(EvaluatedDescription ed) { + set.add(ed); + if(set.size()>maxSize) { + Iterator<EvaluatedDescription> it = set.iterator(); + it.next(); + it.remove(); + } + } + + public void addAll(Collection<EvaluatedDescription> eds) { + for(EvaluatedDescription ed : eds) { + add(ed); + } + } + + /** + * @return the set + */ + public SortedSet<EvaluatedDescription> getSet() { + return set; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |