From: <jen...@us...> - 2009-01-11 07:56:48
|
Revision: 1573 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1573&view=rev Author: jenslehmann Date: 2009-01-11 07:56:41 +0000 (Sun, 11 Jan 2009) Log Message: ----------- EL monitoring Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java trunk/src/dl-learner/org/dllearner/utilities/Files.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-09 15:55:33 UTC (rev 1572) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-11 07:56:41 UTC (rev 1573) @@ -465,7 +465,7 @@ @Override @SuppressWarnings("unchecked") public ELDescriptionTree clone() { - Monitor mon = MonitorFactory.start("EL tree clone"); + Monitor mon = MonitorFactory.start("tree clone"); // clone "global" tree ELDescriptionTree treeClone = new ELDescriptionTree(rs); @@ -598,4 +598,16 @@ public int getDepth() { return maxLevel; } + + /** + * size of tree = number of nodes + sum of cardinality of node labels + * @return The tree size. + */ + public int getSize() { + int size = nodes.size(); + for(ELDescriptionNode node : nodes) { + size += node.getLabel().size(); + } + return size; + } } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-09 15:55:33 UTC (rev 1572) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-11 07:56:41 UTC (rev 1573) @@ -145,7 +145,7 @@ // the position of the node within the tree (needed for getting // the corresponding node in a cloned tree) int[] position = v.getCurrentPosition(); - logger.trace(" at position " + Helper.arrayContent(position)); +// logger.trace(" at position " + Helper.arrayContent(position)); // perform operations refinements.addAll(extendLabel(tree, v, position)); @@ -311,7 +311,9 @@ // System.out.println(mergedTree.toSimulationString()); // we check equivalence by a minimality test (TODO: can we still do this?) - if(mergedTree.isMinimal()) { + boolean minimal = mergedTree.isMinimal(); + MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0); + if(minimal) { logger.trace("Merged tree is minimal, i.e. not equivalent."); // it is not equivalent, i.e. we found a refinement refinements.add(mergedTree); @@ -320,6 +322,7 @@ // perform complex check in merged tree boolean check = asCheck(wClone); logger.trace("Result of complex check: " + check); + MonitorFactory.add("as.check", "boolean", check ? 1 : 0); if(check) { // refine property Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-09 15:55:33 UTC (rev 1572) +++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-11 07:56:41 UTC (rev 1573) @@ -20,9 +20,16 @@ package org.dllearner.scripts.evaluation; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.Random; import java.util.Set; @@ -39,8 +46,12 @@ import org.dllearner.kb.OWLFile; import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.refinementoperators.ELDown2; +import org.dllearner.utilities.Files; import org.dllearner.utilities.statistics.Stat; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + /** * An evaluation of the EL refinement operator {@link ELDown2}. It creates * a set of artificial ontologies with varying complexity and performs @@ -52,6 +63,7 @@ public class ELOperatorBenchmark { private static Random rand = new Random(1); + private static DecimalFormat df = new DecimalFormat(); public static void main(String[] args) throws ComponentInitException, IOException { @@ -62,8 +74,14 @@ // logger.removeAllAppenders(); // logger.addAppender(app); - String example = "/home/jl/ontologien/galen2.owl"; - testOntology(example); + // create a directory for log files + Date dt = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss"); + String dir = "log/el/" + df.format(dt) + "/"; + new File(dir).mkdir(); + + String example = "/home/jl/promotion/ontologien/galen2.owl"; + testOntology(dir, example, 100, 15); System.exit(0); /* TEST ON ARTIFICIAL ONTOLOGIES @@ -119,30 +137,36 @@ // ELDown2 operator = new ELDown2(); } - private static void testOntology(String ont) throws MalformedURLException, ComponentInitException { + private static void testOntology(String statDir, String ont, int nrOfChains, int chainLength) throws ComponentInitException, IOException { System.out.print("Reading in " + ont + " ... "); ComponentManager cm = ComponentManager.getInstance(); // reading ontology into a reasoner KnowledgeSource source = cm.knowledgeSource(OWLFile.class); - cm.applyConfigEntry(source, "url", new File(ont).toURI().toURL()); + File ontFile = new File(ont); + cm.applyConfigEntry(source, "url", ontFile.toURI().toURL()); source.init(); ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source); reasoner.init(); System.out.println("done."); System.out.println(); - int outerLoops = 1000; - for(int loop = 0; loop < outerLoops; loop++) { + // log file name + String name = ontFile.getName(); + String statFileName = name.substring(0, name.lastIndexOf(".")) + ".txt"; + File statFile = new File(statDir + statFileName); + String statString = ""; + MonitorFactory.reset(); + for(int loop = 0; loop < nrOfChains; loop++) { + // application of operator and statistics recording - int nrOfApplications = 15; ELDescriptionTree currTree = new ELDescriptionTree(reasoner, Thing.instance); ELDown2 operator = new ELDown2(reasoner); Stat runtime = new Stat(); Stat runtimePerRefinement = new Stat(); - System.out.println("Testing operator (applying it " + nrOfApplications + " times):"); - for(int i=0; i < nrOfApplications; i++) { + System.out.println("Testing operator (applying it " + chainLength + " times):"); + for(int i=0; i < chainLength; i++) { // System.out.println(currTree.transformToDescription().toKBSyntaxString()); System.out.print("current concept: " + currTree.transformToDescription().toString(reasoner.getBaseURI(), reasoner.getPrefixes())); // apply operator on current description @@ -151,16 +175,66 @@ long time = System.nanoTime() - start; runtime.addNumber(time/1000000d); runtimePerRefinement.addNumber(time/1000000d/refinements.size()); + MonitorFactory.add("operator application time", "ms.", time/1000000d); + MonitorFactory.add("operator application time per refinement", "ms.", time/1000000d/refinements.size()); + MonitorFactory.add("refinement count", "count", refinements.size()); + + int sizeSum = 0; + for(ELDescriptionTree tree : refinements) { + sizeSum += tree.getSize(); + } + + MonitorFactory.add("refinement size", "count", sizeSum/(double)refinements.size()); + MonitorFactory.add("refinement size increase", "count", (sizeSum-refinements.size()*currTree.getSize())/(double)refinements.size()); + System.out.println(" [has " + refinements.size() + " refinements]"); // pick a refinement randomly (which is kind of slow for a set, but // this does not matter here) int index = rand.nextInt(refinements.size()); currTree = new ArrayList<ELDescriptionTree>(refinements).get(index); + MonitorFactory.add("picked refinement size", "count", currTree.getSize()); } System.out.println("operator time: " + runtime.prettyPrint("ms")); System.out.println("operator time per refinement: " + runtimePerRefinement.prettyPrint("ms")); System.out.println(); } + + statString += "file: " + name + "\n"; + statString += "nr of refinement chains: " + nrOfChains + "\n"; + statString += "refinement chain length: " + chainLength + "\n\n"; + + statString += getMonitorData(MonitorFactory.getMonitor("operator application time", "ms.")); + statString += getMonitorData(MonitorFactory.getMonitor("operator application time per refinement", "ms.")); + statString += "\n"; + + statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement count", "count")); + statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement size", "count")); + statString += getMonitorDataCount(MonitorFactory.getMonitor("picked refinement size", "count")); + statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement size increase", "count")); + statString += "\n"; + + statString += getMonitorData(MonitorFactory.getMonitor("extend label", "ms.")); + statString += getMonitorData(MonitorFactory.getMonitor("refine label", "ms.")); + statString += getMonitorData(MonitorFactory.getMonitor("refine edge", "ms.")); + statString += getMonitorData(MonitorFactory.getMonitor("attach tree", "ms.")); + statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.minimal", "boolean")); + statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.check", "boolean")); + statString += getMonitorData(MonitorFactory.getMonitor("tree clone", "ms.")); + statString += getMonitorData(MonitorFactory.getMonitor("simulation update", "ms.")); + + Files.createFile(statFile, statString); } + + private static String getMonitorData(Monitor mon) { + return mon.getLabel() + ": av " + df.format(mon.getAvg()) + "ms (stddev " + df.format(mon.getStdDev()) + "ms, min " + df.format(mon.getMin()) + "ms, max " + df.format(mon.getMax()) + "ms, " + df.format(mon.getTotal()/1000) + "s total, " + (int)mon.getHits() + " hits)\n"; + } + + private static String getMonitorDataCount(Monitor mon) { + return mon.getLabel() + ": av " + df.format(mon.getAvg()) + " (stddev " + df.format(mon.getStdDev()) + ", min " + df.format(mon.getMin()) + ", max " + df.format(mon.getMax()) + ", " + df.format(mon.getTotal()) + " total, " + (int)mon.getHits() + " hits)\n"; + } + + private static String getMonitorDataBoolean(Monitor mon) { + return mon.getLabel() + ": " + df.format(mon.getAvg()*100) + "%\n"; + } } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-09 15:55:33 UTC (rev 1572) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-11 07:56:41 UTC (rev 1573) @@ -196,7 +196,8 @@ reasoner.init(); System.out.println("Galen loaded."); - Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))"); +// Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))"); + Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#10.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#DomainAttribute\".(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#6.0\" AND \"http://www.co-ode.org/ontologies/galen#TopCategory\")) AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#TopCategory\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".TOP)))))"); ConceptTransformation.cleanConcept(input); ELDown2 operator = new ELDown2(reasoner); Modified: trunk/src/dl-learner/org/dllearner/utilities/Files.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Files.java 2009-01-09 15:55:33 UTC (rev 1572) +++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2009-01-11 07:56:41 UTC (rev 1573) @@ -178,7 +178,7 @@ if(debug){System.exit(0);} } } - + public static void clearFile(File file) { try{ createFile(file, ""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |