From: <jen...@us...> - 2009-03-19 17:31:42
|
Revision: 1654 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1654&view=rev Author: jenslehmann Date: 2009-03-19 17:31:22 +0000 (Thu, 19 Mar 2009) Log Message: ----------- fix for possible division by zero Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-17 14:56:12 UTC (rev 1653) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-03-19 17:31:22 UTC (rev 1654) @@ -122,8 +122,6 @@ public CELOE(ClassLearningProblem problem, ReasonerComponent reasoner) { super(problem, reasoner); configurator = new CELOEConfigurator(this); - classToDescribe = problem.getClassToDescribe(); - isEquivalenceProblem = problem.isEquivalenceProblem(); } public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { @@ -157,6 +155,10 @@ @Override public void init() throws ComponentInitException { + ClassLearningProblem problem = (ClassLearningProblem) learningProblem; + classToDescribe = problem.getClassToDescribe(); + isEquivalenceProblem = problem.isEquivalenceProblem(); + // copy class hierarchy and modify it such that each class is only // reachable via a single path ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); @@ -175,8 +177,7 @@ startClass = new Intersection(new LinkedList<Description>(superClasses)); } else { startClass = (Description) superClasses.toArray()[0]; - } - + } } else { startClass = Thing.instance; } @@ -186,7 +187,7 @@ baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); - bestEvaluatedDescriptions = new EvaluatedDescriptionSet(configurator.getMaxNrOfResults()); + bestEvaluatedDescriptions = new EvaluatedDescriptionSet(configurator.getMaxNrOfResults()); // we put important parameters in class variables minAcc = configurator.getNoisePercentage()/100d; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-17 14:56:12 UTC (rev 1653) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-03-19 17:31:22 UTC (rev 1654) @@ -73,8 +73,8 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("classToDescribe", "class of which a description should be learned", null, true, false)); - StringConfigOption type = new StringConfigOption("type", "Whether to learn an equivalence class or super class axiom.","equivalence"); - type.setAllowedValues(new String[] {"equivalence", "superClass"}); + StringConfigOption type = new StringConfigOption("type", "Whether to learn an equivalence class or super class axiom or domain/range of a property.","equivalence"); + type.setAllowedValues(new String[] {"equivalence", "superClass", "domain", "range"}); options.add(type); return options; } @@ -148,9 +148,10 @@ Set<Individual> additionalInstances = Helper.difference(retrieval, coveredInstances); double coverage = instancesCovered/(double)classInstances.size(); - double protusion = instancesCovered/(double)retrieval.size(); + double protusion = retrieval.size() == 0 ? 0 : instancesCovered/(double)retrieval.size(); +// double accuracy = coverage + Math.sqrt(protusion); - return new ClassScore(coveredInstances, coverage, additionalInstances, protusion); + return new ClassScore(coveredInstances, coverage, additionalInstances, protusion, getAccuracy(coverage, protusion)); } public boolean isEquivalenceProblem() { @@ -172,9 +173,12 @@ } double coverage = instancesCovered/(double)classInstances.size(); - double protusion = instancesCovered/(double)retrieval.size(); +// double protusion = instancesCovered/(double)retrieval.size(); + double protusion = retrieval.size() == 0 ? 0 : instancesCovered/(double)retrieval.size(); +// - return (coverageFactor * coverage + protusion) / (coverageFactor + 1); +// return (coverageFactor * coverage + protusion) / (coverageFactor + 1); + return getAccuracy(coverage, protusion); } @Override @@ -243,16 +247,19 @@ // since we measured/estimated accuracy only on instances outside A (superClassInstances // does not include instances of A), we need to add it in the denominator double protusion = instancesCovered/(double)(instancesDescription+instancesCovered); + if(instancesCovered + instancesDescription == 0) { + protusion = 0; + } // System.out.println(description); // System.out.println(instancesDescription); // System.out.println("prot: " + protusion); - double acc = (coverageFactor * coverage + protusion) / (coverageFactor + 1); +// double acc = (coverageFactor * coverage + protusion) / (coverageFactor + 1); // System.out.println("acc: " + acc); - return acc; + return getAccuracy(coverage, protusion); } /* (non-Javadoc) @@ -269,6 +276,10 @@ } } + private double getAccuracy(double coverage, double protusion) { + return (coverageFactor * coverage + Math.sqrt(protusion)) / (coverageFactor + 1); + } + /** * @return the classToDescribe */ Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-03-17 14:56:12 UTC (rev 1653) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java 2009-03-19 17:31:22 UTC (rev 1654) @@ -37,12 +37,14 @@ private double coverage; private double addition; + private double accuracy; - public ClassScore(Set<Individual> coveredInstances, double coverage, Set<Individual> additionalInstances, double protusion) { + public ClassScore(Set<Individual> coveredInstances, double coverage, Set<Individual> additionalInstances, double protusion, double accuracy) { this.coveredInstances = coveredInstances; this.additionalInstances = additionalInstances; this.coverage = coverage; this.addition = protusion; + this.accuracy = accuracy; } /** @@ -67,7 +69,8 @@ */ @Override public double getAccuracy() { - return 0.5 * (coverage + addition); +// return 0.5 * (coverage + addition); + return accuracy; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |