From: <jen...@us...> - 2009-02-16 17:09:37
|
Revision: 1606 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1606&view=rev Author: jenslehmann Date: 2009-02-16 17:09:30 +0000 (Mon, 16 Feb 2009) Log Message: ----------- continued ontology engineering algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Added Paths: ----------- trunk/examples/family/father_oe.conf trunk/examples/family/father_oe.owl Added: trunk/examples/family/father_oe.conf =================================================================== --- trunk/examples/family/father_oe.conf (rev 0) +++ trunk/examples/family/father_oe.conf 2009-02-16 17:09:30 UTC (rev 1606) @@ -0,0 +1,7 @@ + +import("father_oe.owl"); + +problem = classLearning; +classLearning.classToDescribe = "http://example.com/father#father"; + +algorithm = celoe; Added: trunk/examples/family/father_oe.owl =================================================================== --- trunk/examples/family/father_oe.owl (rev 0) +++ trunk/examples/family/father_oe.owl 2009-02-16 17:09:30 UTC (rev 1606) @@ -0,0 +1,136 @@ +<?xml version="1.0"?> + + +<!DOCTYPE rdf:RDF [ + <!ENTITY father "http://example.com/father#" > + <!ENTITY owl "http://www.w3.org/2002/07/owl#" > + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" > + <!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" > + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > +]> + + +<rdf:RDF xmlns="http://example.com/father#" + xml:base="http://example.com/father" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:father="http://example.com/father#"> + <owl:Ontology rdf:about=""/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Object Properties + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://example.com/father#hasChild --> + + <owl:ObjectProperty rdf:about="#hasChild"/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Classes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://example.com/father#father --> + + <owl:Class rdf:about="#father"> + <rdfs:subClassOf rdf:resource="#male"/> + </owl:Class> + + + + <!-- http://example.com/father#female --> + + <owl:Class rdf:about="#female"> + <owl:disjointWith rdf:resource="#male"/> + </owl:Class> + + + + <!-- http://example.com/father#male --> + + <owl:Class rdf:about="#male"/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Individuals + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://example.com/father#anna --> + + <female rdf:about="#anna"> + <hasChild rdf:resource="#heinz"/> + </female> + + + + <!-- http://example.com/father#heinz --> + + <male rdf:about="#heinz"/> + + + + <!-- http://example.com/father#markus --> + + <male rdf:about="#markus"> + <rdf:type rdf:resource="#father"/> + <hasChild rdf:resource="#anna"/> + </male> + + + + <!-- http://example.com/father#martin --> + + <male rdf:about="#martin"> + <rdf:type rdf:resource="#father"/> + <hasChild rdf:resource="#heinz"/> + </male> + + + + <!-- http://example.com/father#michelle --> + + <female rdf:about="#michelle"/> + + + + <!-- http://example.com/father#stefan --> + + <father rdf:about="#stefan"> + <rdf:type rdf:resource="#male"/> + <hasChild rdf:resource="#markus"/> + </father> +</rdf:RDF> + + + +<!-- Generated by the OWL API (version 2.2.1.974) http://owlapi.sourceforge.net --> + Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -19,9 +19,11 @@ */ package org.dllearner.algorithms.celoe; +import java.text.DecimalFormat; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -85,7 +87,13 @@ // important parameters private double minAcc; + private double maxDepth; + // utility variables + private String baseURI; + private Map<String, String> prefixes; + DecimalFormat dfPercent = new DecimalFormat("0.00%"); + @Override public Configurator getConfigurator() { return configurator; @@ -93,6 +101,7 @@ public CELOE(ClassLearningProblem problem, ReasonerComponent reasoner) { super(problem, reasoner); + configurator = new CELOEConfigurator(this); classToDescribe = problem.getClassToDescribe(); isEquivalenceProblem = problem.isEquivalenceProblem(); } @@ -114,8 +123,9 @@ options.add(CommonConfigOptions.useNegation()); options.add(CommonConfigOptions.useBooleanDatatypes()); options.add(CommonConfigOptions.useDoubleDatatypes()); - options.add(CommonConfigOptions.maxExecutionTimeInSeconds()); + options.add(CommonConfigOptions.maxExecutionTimeInSeconds(10)); options.add(CommonConfigOptions.getNoisePercentage()); + options.add(CommonConfigOptions.getMaxDepth(4)); return options; } @@ -135,6 +145,7 @@ // we put important parameters in class variables minAcc = configurator.getNoisePercentage()/100d; + maxDepth = configurator.getMaxDepth(); } @Override @@ -164,6 +175,10 @@ reset(); nanoStartTime = System.nanoTime(); + // highest accuracy so far + double highestAccuracy = 0.0; + OENode bestNode; + // start class: intersection of super classes for definitions (since it needs to // capture all instances), but owl:Thing for learning subclasses (since it is // superfluous to add super classes in this case) @@ -176,16 +191,67 @@ } addNode(startClass, null); + int loop = 0; + while (!terminationCriteriaSatisfied()) { + + if(bestEvaluatedDescriptions.getBest().getAccuracy() > highestAccuracy) { + highestAccuracy = bestEvaluatedDescriptions.getBest().getAccuracy(); + logger.info("more accurate (" + dfPercent.format(100*highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); + } + + // chose best node according to heuristics + bestNode = nodes.last(); + int horizExp = bestNode.getHorizontalExpansion(); + + // apply operator + TreeSet<Description> refinements = refineNode(bestNode); + + while(refinements.size() != 0) { + // pick element from set + Description refinement = refinements.pollFirst(); + int length = refinement.getLength(); + + // we ignore all refinements with lower length and too high depth + if(length >= horizExp && refinement.getDepth() <= maxDepth) { + boolean added = addNode(refinement, bestNode); + + // if refinements have the same length, we apply the operator again + // (descending the subsumption hierarchy) + if(added && length == horizExp) { + // ... refine node (first check whether we need this as there will + // the penalty for longer descriptions will be quite hard anyway) + } + + } + + } + + // Anzahl Schleifendurchläufe + loop++; + } + + if (stop) { + logger.info("Algorithm stopped.\n"); + } else { + logger.info("Algorithm terminated succesfully.\n"); + } + // print solution(s) - logger.info("solution : " + bestEvaluatedDescriptions.getBest()); + logger.info("solution : " + bestDescriptionToString()); isRunning = false; } // expand node horizontically - private void expandNode(OENode node) { - + private TreeSet<Description> refineNode(OENode node) { + // we have to remove and add the node since its heuristic evaluation changes through the expansion + nodes.remove(node); + int horizExp = node.getHorizontalExpansion(); + TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); + node.incHorizontalExpansion(); + nodes.add(node); + return refinements; } // add node to search tree if it is not too weak @@ -212,9 +278,13 @@ } else { parentNode.addChild(node); } + + nodes.add(node); // maybe add to best descriptions (method keeps set size fixed) - bestEvaluatedDescriptions.add(description, accuracy, learningProblem); + if(checkNode(node)) { + bestEvaluatedDescriptions.add(description, accuracy, learningProblem); + } return true; } @@ -222,11 +292,16 @@ // check whether the node is a potential solution candidate // (sufficient accuracy; minimal; rewriting steps?) private boolean checkNode(OENode node) { + + // what to do if super class occurs? either return false, but then it + // does not make sense to expand it further; or rewrite but then we have to + // take care of double occurrences + return true; } private boolean terminationCriteriaSatisfied() { - return !stop && (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()/1000000)); + return stop || (System.nanoTime() - nanoStartTime >= (configurator.getMaxExecutionTimeInSeconds()*1000000)); } private void reset() { @@ -248,4 +323,17 @@ stop = true; } + public OENode getSearchTreeRoot() { + return startNode; + } + + // central function for printing description + private String descriptionToString(Description description) { + return description.toManchesterSyntaxString(baseURI, prefixes); + } + + private String bestDescriptionToString() { + EvaluatedDescription best = bestEvaluatedDescriptions.getBest(); + return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()*100) + ")"; + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/OENode.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -44,6 +44,8 @@ private double accuracy; + private int horizontalExpansion; + private OENode parent; private List<OENode> children; @@ -51,12 +53,17 @@ this.parent = parentNode; this.description = description; this.accuracy = accuracy; + horizontalExpansion = 0; } public void addChild(OENode node) { children.add(node); } + public void incHorizontalExpansion() { + horizontalExpansion++; + } + /** * @return the description */ @@ -84,5 +91,12 @@ public List<OENode> getChildren() { return children; } + + /** + * @return the horizontalExpansion + */ + public int getHorizontalExpansion() { + return horizontalExpansion; + } } Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -294,11 +294,14 @@ lpClass = PosNegLPStandard.class; } lp = cm.learningProblem(lpClass, rc); - SortedSet<String> posExamples = parser.getPositiveExamples(); - SortedSet<String> negExamples = parser.getNegativeExamples(); - cm.applyConfigEntry(lp, "positiveExamples", posExamples); - if (lpClass != PosOnlyLP.class) + if(lpClass == PosNegLPStandard.class || lpClass == PosOnlyLP.class) { + SortedSet<String> posExamples = parser.getPositiveExamples(); + cm.applyConfigEntry(lp, "positiveExamples", posExamples); + } + if(lpClass == PosNegLPStandard.class) { + SortedSet<String> negExamples = parser.getNegativeExamples(); cm.applyConfigEntry(lp, "negativeExamples", negExamples); + } configureComponent(cm, lp, parser); initComponent(cm, lp); lpMonitor.stop(); Modified: trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/core/configurators/CELOEConfigurator.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -155,6 +155,15 @@ public double getNoisePercentage() { return (Double) ComponentManager.getInstance().getConfigOptionValue(cELOE, "noisePercentage") ; } +/** +* maxDepth maximum depth of description. +* mandatory: false| reinit necessary: true +* default value: 3 +* @return int +**/ +public int getMaxDepth() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(cELOE, "maxDepth") ; +} /** * @param useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm. @@ -255,6 +264,15 @@ ComponentManager.getInstance().applyConfigEntry(cELOE, "noisePercentage", noisePercentage); reinitNecessary = true; } +/** +* @param maxDepth maximum depth of description. +* mandatory: false| reinit necessary: true +* default value: 3 +**/ +public void setMaxDepth(int maxDepth) { +ComponentManager.getInstance().applyConfigEntry(cELOE, "maxDepth", maxDepth); +reinitNecessary = true; +} /** * true, if this component needs reinitializsation. Modified: trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -73,6 +73,10 @@ return new BooleanConfigOption("terminateOnNoiseReached", "specifies whether to terminate when noise criterion is met", terminateOnNoiseReachedDefault); } + public static IntegerConfigOption getMaxDepth(int defaultValue) { + return new IntegerConfigOption("maxDepth", "maximum depth of description", defaultValue); + } + public static DoubleConfigOption getPercentPerLenghtUnitOption(double defaultValue) { DoubleConfigOption option = new DoubleConfigOption("percentPerLenghtUnit", "describes the reduction in classification accuracy in percent one is willing to accept for reducing the length of the concept by one", defaultValue); option.setLowerLimit(0.0); @@ -153,6 +157,10 @@ return new IntegerConfigOption("maxExecutionTimeInSeconds", "algorithm will stop after specified seconds",maxExecutionTimeInSecondsDefault); } + public static IntegerConfigOption maxExecutionTimeInSeconds(int defaultValue) { + return new IntegerConfigOption("maxExecutionTimeInSeconds", "algorithm will stop after specified seconds",defaultValue); + } + public static IntegerConfigOption minExecutionTimeInSeconds() { return new IntegerConfigOption("minExecutionTimeInSeconds", "algorithm will run at least specified seconds",minExecutionTimeInSecondsDefault); } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/learningproblems/ClassLearningProblem.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -28,6 +28,7 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.ClassLearningProblemConfigurator; +import org.dllearner.core.configurators.PosNegLPStandardConfigurator; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; @@ -55,6 +56,7 @@ public ClassLearningProblem(ReasonerComponent reasoner) { super(reasoner); + configurator = new ClassLearningProblemConfigurator(this); } public static Collection<ConfigOption<?>> createConfigOptions() { Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-16 13:03:46 UTC (rev 1605) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2009-02-16 17:09:30 UTC (rev 1606) @@ -335,6 +335,11 @@ throw new RuntimeException(); } + @Override + public Set<Description> refine(Description description, int maxLength) { + return refine(description, maxLength, null, startClass); + } + /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |