From: <jen...@us...> - 2007-08-29 13:42:18
|
Revision: 106 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=106&view=rev Author: jenslehmann Date: 2007-08-29 06:40:11 -0700 (Wed, 29 Aug 2007) Log Message: ----------- statistics script (working version) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java trunk/src/dl-learner/org/dllearner/parser/dllearner.jj trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java trunk/src/dl-learner/org/dllearner/utilities/Stat.java Modified: trunk/src/dl-learner/org/dllearner/parser/DLLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/parser/DLLearner.java 2007-08-29 13:40:11 UTC (rev 106) @@ -148,6 +148,13 @@ } public static void parseFile(String filename) { + + positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + confOptions = new LinkedList<ConfigurationOption>(); + functionCalls = new LinkedList<List<String>>(); + kb = new KB(); + try { if(constructorCalled) DLLearner.ReInit(new FileInputStream(filename)); @@ -1577,25 +1584,6 @@ finally { jj_save(11, xla); } } - static final private boolean jj_3R_18() { - if (jj_3R_12()) return true; - return false; - } - - static final private boolean jj_3R_35() { - if (jj_3R_49()) return true; - if (jj_3R_22()) return true; - if (jj_3R_17()) return true; - if (jj_scan_token(COMMAND_END)) return true; - if (jj_3R_14()) return true; - return false; - } - - static final private boolean jj_3R_26() { - if (jj_3R_4()) return true; - return false; - } - static final private boolean jj_3R_34() { if (jj_3R_39()) return true; if (jj_3R_14()) return true; @@ -2028,6 +2016,25 @@ return false; } + static final private boolean jj_3R_18() { + if (jj_3R_12()) return true; + return false; + } + + static final private boolean jj_3R_35() { + if (jj_3R_49()) return true; + if (jj_3R_22()) return true; + if (jj_3R_17()) return true; + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_14()) return true; + return false; + } + + static final private boolean jj_3R_26() { + if (jj_3R_4()) return true; + return false; + } + static private boolean jj_initialized_once = false; static public DLLearnerTokenManager token_source; static SimpleCharStream jj_input_stream; Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jj 2007-08-29 13:40:11 UTC (rev 106) @@ -166,6 +166,13 @@ } public static void parseFile(String filename) { + + positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + confOptions = new LinkedList<ConfigurationOption>(); + functionCalls = new LinkedList<List<String>>(); + kb = new KB(); + try { if(constructorCalled) DLLearner.ReInit(new FileInputStream(filename)); Modified: trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/parser/dllearner.jjt 2007-08-29 13:40:11 UTC (rev 106) @@ -162,6 +162,13 @@ } public static void parseFile(String filename) { + + positiveExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + negativeExamples = new TreeMap<AtomicConcept,SortedSet<Individual>>(conceptComparator); + confOptions = new LinkedList<ConfigurationOption>(); + functionCalls = new LinkedList<List<String>>(); + kb = new KB(); + try { if(constructorCalled) DLLearner.ReInit(new FileInputStream(filename)); Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-08-29 13:40:11 UTC (rev 106) @@ -99,11 +99,13 @@ String gnuplotBaseDir = "log/gnuplot/"; String statBaseDir = "log/stat/"; - File[] confFiles = new File[1]; - confFiles[0] = new File(exampleBaseDir + "trains", "trains_owl.conf"); + File[] confFiles = new File[2]; + confFiles[0] = new File(exampleBaseDir + "trains", "trains_owl.conf"); + confFiles[1] = new File(exampleBaseDir, "father2.conf"); - String[] examples = new String[1]; + String[] examples = new String[2]; examples[0] = "trains"; + examples[1] = "father"; String[] algorithms = new String[3]; algorithms[0] = "refinement"; @@ -151,77 +153,89 @@ statString += "example: " + examples[exampleNr] + "\n\n"; for(int algorithmNr=0; algorithmNr < algorithms.length; algorithmNr++) { - - // create reasoner (this has to be done in this inner loop to - // ensure that none of the algorithm benefits from e.g. caching - // of previous reasoning requests - Reasoner reasoner = Main.createReasoner(new KB(), imports); - ReasoningService rs = new ReasoningService(reasoner); + + Stat classification = new Stat(); + Stat length = new Stat(); + Stat runtime = new Stat(); - // prepare reasoner for using subsumption and role hierarchy - // TODO: currently, it is a small unfairness that each algorithm - // uses the same reasoning object (e.g. the second algorithm may - // have a small advantage if the reasoner cached reasoning requests - // of the first algorithm) - Main.autoDetectConceptsAndRoles(rs); - try { - reasoner.prepareSubsumptionHierarchy(); - reasoner.prepareRoleHierarchy(); - // improving the subsumption hierarchy makes only sense - // for the refinement based algorithm - if(algorithmNr==0) - reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - e.printStackTrace(); - } + for(int runNr=0; runNr < algorithmRuns[algorithmNr]; runNr++) { + + // create reasoner (this has to be done in this inner loop to + // ensure that none of the algorithm benefits from e.g. caching + // of previous reasoning requests + Reasoner reasoner = Main.createReasoner(new KB(), imports); + ReasoningService rs = new ReasoningService(reasoner); + + // prepare reasoner for using subsumption and role hierarchy + // TODO: currently, it is a small unfairness that each algorithm + // uses the same reasoning object (e.g. the second algorithm may + // have a small advantage if the reasoner cached reasoning requests + // of the first algorithm) + Main.autoDetectConceptsAndRoles(rs); + try { + reasoner.prepareSubsumptionHierarchy(); + reasoner.prepareRoleHierarchy(); + // improving the subsumption hierarchy makes only sense + // for the refinement based algorithm + if(algorithmNr==0) + reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + e.printStackTrace(); + } + + // create learning problem + LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + + LearningAlgorithm learningAlgorithm = null; + if(algorithmNr==0) { + Config.algorithm = Algorithm.REFINEMENT; + learningAlgorithm = new ROLearner(learningProblem); + } else if(algorithmNr==1) { + Config.algorithm = Algorithm.GP; + Config.GP.numberOfIndividuals = 21; + Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; + Config.GP.refinementProbability = 0; + Config.GP.mutationProbability = 0.02; + Config.GP.crossoverProbability = 0.8; + Config.GP.hillClimbingProbability = 0; + learningAlgorithm = new GP(learningProblem); + } else if(algorithmNr==2) { + Config.algorithm = Algorithm.HYBRID_GP; + Config.GP.numberOfIndividuals = 11; + Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; + Config.GP.refinementProbability = 0.65; + Config.GP.mutationProbability = 0.02; + Config.GP.crossoverProbability = 0.2; + Config.GP.hillClimbingProbability = 0; + learningAlgorithm = new GP(learningProblem); + } + + rs.resetStatistics(); + long algorithmStartTime = System.nanoTime(); + learningAlgorithm.start(); + long algorithmTime = System.nanoTime() - algorithmStartTime; + // long algorithmTimeSeconds = algorithmTime / 1000000000; + + int conceptLength = learningAlgorithm.getBestSolution().getLength(); + Score bestScore = learningAlgorithm.getSolutionScore(); + int misClassifications = bestScore.getCoveredNegatives().size() + + bestScore.getNotCoveredPositives().size(); + double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); + + classification.addNumber(classificationRatePercent); + length.addNumber(conceptLength); + runtime.addNumber(algorithmTime); + + // free knowledge base to avoid memory leaks + ((DIGReasoner) reasoner).releaseKB(); - // create learning problem - LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + } - LearningAlgorithm learningAlgorithm = null; - if(algorithmNr==0) { - Config.algorithm = Algorithm.REFINEMENT; - learningAlgorithm = new ROLearner(learningProblem); - } else if(algorithmNr==1) { - Config.algorithm = Algorithm.GP; - Config.GP.numberOfIndividuals = 21; - Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; - Config.GP.refinementProbability = 0; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.8; - Config.GP.hillClimbingProbability = 0; - learningAlgorithm = new GP(learningProblem); - } else if(algorithmNr==2) { - Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = 11; - Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; - Config.GP.refinementProbability = 0.65; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.2; - Config.GP.hillClimbingProbability = 0; - learningAlgorithm = new GP(learningProblem); - } - - rs.resetStatistics(); - long algorithmStartTime = System.nanoTime(); - learningAlgorithm.start(); - long algorithmTime = System.nanoTime() - algorithmStartTime; - // long algorithmTimeSeconds = algorithmTime / 1000000000; - - int conceptLength = learningAlgorithm.getBestSolution().getLength(); - Score bestScore = learningAlgorithm.getSolutionScore(); - int misClassifications = bestScore.getCoveredNegatives().size() - + bestScore.getNotCoveredPositives().size(); - double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); - - statString += "algorithm: " + algorithms[algorithmNr] + "\n"; - statString += "classification: " + classificationRatePercent + "%\n"; - statString += "concept length: " + conceptLength + "\n"; - statString += "runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime) + "s\n\n"; + statString += "algorithm: " + algorithms[algorithmNr] + " (runs: " + algorithmRuns[algorithmNr] + ")\n"; + statString += "classification: " + classification.getMean() + "% (standard deviation: " + classification.getStandardDeviation() + "%)\n"; + statString += "concept length: " + length.getMean() + " (standard deviation: " + length.getStandardDeviation() + ")\n"; + statString += "runtime: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getMean())) + " (standard deviation: " + Helper.prettyPrintNanoSeconds(Math.round(runtime.getStandardDeviation())) + ")\n\n"; - // free knowledge base to avoid memory leaks - ((DIGReasoner) reasoner).releaseKB(); - } } Modified: trunk/src/dl-learner/org/dllearner/utilities/Stat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Stat.java 2007-08-29 13:38:23 UTC (rev 105) +++ trunk/src/dl-learner/org/dllearner/utilities/Stat.java 2007-08-29 13:40:11 UTC (rev 106) @@ -1,3 +1,23 @@ +/** + * Copyright (C) 2007, 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; /** @@ -57,20 +77,21 @@ * * @return The stanard deviation of all numbers. */ - public double getStandardDeviation() { - // TODO: Standardabweichung ist anscheinend nicht korrekt, siehe - // http://de.wikipedia.org/wiki/Standardabweichung. Es muss N-1 verwendet - // werden. - /* - double mean = getMean(); - double tmp = squareSum / count - mean * mean; - if(tmp==0) - return 0; - else - return Math.sqrt(tmp); - */ - // korrekter Code nach http://de.wikipedia.org/wiki/Standardabweichung - return Math.sqrt((count*squareSum-sum*sum)/(count*(count-1))); + public double getStandardDeviation() { + if(count <= 1) + return 0.0; + + // formula from http://de.wikipedia.org/wiki/Standardabweichung + double val = (count*squareSum-sum*sum)/(count*(count-1)); + double root = Math.sqrt(val); + + // due to rounding errors it can happen that "val" is negative + // this means that the real value is 0 (or very close to it), so + // we return 0 + if(Double.isNaN(root)) + return 0.0; + else + return root; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |