From: <jen...@us...> - 2011-11-29 18:15:25
|
Revision: 3449 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3449&view=rev Author: jenslehmann Date: 2011-11-29 18:15:18 +0000 (Tue, 29 Nov 2011) Log Message: ----------- - fixed bug which occurred when using OCEL with manual heuristics in conf file - improved efficiency of rho refinement operator Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/examples/family/grandfather.conf Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -276,12 +276,12 @@ if(operator == null) { operator = new RhoDRDown(); ((RhoDRDown)operator).setStartClass(startClass); - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); ((RhoDRDown)operator).setReasoner(reasoner); - ((RhoDRDown)operator).init(); - } else { - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); } + ((RhoDRDown)operator).setSubHierarchy(classHierarchy); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + ((RhoDRDown)operator).init(); // operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); @@ -1002,6 +1002,14 @@ public void setUseMinimizer(boolean useMinimizer) { this.useMinimizer = useMinimizer; + } + + public OEHeuristicRuntime getHeuristic() { + return heuristic; + } + + public void setHeuristic(OEHeuristicRuntime heuristic) { + this.heuristic = heuristic; } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -215,4 +215,20 @@ public void setExpansionPenaltyFactor(double expansionPenaltyFactor) { this.expansionPenaltyFactor = expansionPenaltyFactor; } + + public int getNrOfNegativeExamples() { + return nrOfNegativeExamples; + } + + public void setNrOfNegativeExamples(int nrOfNegativeExamples) { + this.nrOfNegativeExamples = nrOfNegativeExamples; + } + + public int getNrOfExamples() { + return nrOfExamples; + } + + public void setNrOfExamples(int nrOfExamples) { + this.nrOfExamples = nrOfExamples; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -104,7 +104,7 @@ private File searchTreeFile; private boolean replaceSearchTree = false; private static String defaultSearchTreeFile = "log/searchTree.txt"; - private String heuristicStr = "multi"; +// private String heuristicStr = "multi"; Set<NamedClass> allowedConcepts; Set<ObjectProperty> allowedRoles; Set<NamedClass> ignoredConcepts; @@ -239,84 +239,6 @@ } /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings({"unchecked"}) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if(name.equals("writeSearchTree")) - writeSearchTree = (Boolean) entry.getValue(); - else if(name.equals("searchTreeFile")) - searchTreeFile = new File((String)entry.getValue()); - else if(name.equals("replaceSearchTree")) - replaceSearchTree = (Boolean) entry.getValue(); - else if(name.equals("heuristic")) { - String value = (String) entry.getValue(); - if(value.equals("lexicographic")) - heuristicStr = "lexicographic"; - else - heuristicStr = "flexible"; - } else if(name.equals("allowedConcepts")) { - allowedConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); - } else if(name.equals("allowedRoles")) { - allowedRoles = CommonConfigMappings.getAtomicRoleSet((Set<String>)entry.getValue()); - } else if(name.equals("ignoredConcepts")) { - ignoredConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); - } else if(name.equals("ignoredRoles")) { - ignoredRoles = CommonConfigMappings.getAtomicRoleSet((Set<String>)entry.getValue()); - } else if(name.equals("applyAllFilter")) { -// applyAllFilter = (Boolean) entry.getValue(); - } else if(name.equals("applyExistsFilter")) { -// applyExistsFilter = (Boolean) entry.getValue(); - } else if(name.equals("useTooWeakList")) { - useTooWeakList = (Boolean) entry.getValue(); - } else if(name.equals("useOverlyGeneralList")) { - useOverlyGeneralList = (Boolean) entry.getValue(); - } else if(name.equals("useShortConceptConstruction")) { - useShortConceptConstruction = (Boolean) entry.getValue(); - } else if(name.equals("improveSubsumptionHierarchy")) { - improveSubsumptionHierarchy = (Boolean) entry.getValue(); - } else if(name.equals("useAllConstructor")) { -// useAllConstructor = (Boolean) entry.getValue(); - } else if(name.equals("useExistsConstructor")) { -// useExistsConstructor = (Boolean) entry.getValue(); - } else if(name.equals("useHasValueConstructor")) { -// useHasValueConstructor = (Boolean) entry.getValue(); - } else if(name.equals("valueFrequencyThreshold")) { -// valueFrequencyThreshold = (Integer) entry.getValue(); - } else if(name.equals("useCardinalityRestrictions")) { -// useCardinalityRestrictions = (Boolean) entry.getValue(); - } else if(name.equals("useNegation")) { -// useNegation = (Boolean) entry.getValue(); - } else if(name.equals("noisePercentage")) { - noisePercentage = (Double) entry.getValue(); - } else if(name.equals("useBooleanDatatypes")) { -// useBooleanDatatypes = (Boolean) entry.getValue(); - } else if(name.equals("useDoubleDatatypes")) { -// useDoubleDatatypes = (Boolean) entry.getValue(); - } else if(name.equals("usePropernessChecks")) { - usePropernessChecks = (Boolean) entry.getValue(); - } else if(name.equals("maxPosOnlyExpansion")) { - maxPosOnlyExpansion = (Integer) entry.getValue(); - } else if(name.equals("startClass")) { - startClass = new NamedClass((String)entry.getValue()); - }else if(name.equals("maxExecutionTimeInSeconds")) { - maxExecutionTimeInSeconds = (Integer) entry.getValue(); - }else if(name.equals("minExecutionTimeInSeconds")) { - minExecutionTimeInSeconds = (Integer) entry.getValue(); - }else if(name.equals("guaranteeXgoodDescriptions")) { - guaranteeXgoodDescriptions = (Integer) entry.getValue(); - } else if(name.equals("maxClassDescriptionTests")) { - maxClassDescriptionTests = (Integer) entry.getValue(); - } else if(name.equals("logLevel")) { - logLevel = ((String)entry.getValue()).toUpperCase(); - } else if(name.equals("forceRefinementLengthIncrease")) { - forceRefinementLengthIncrease = (Boolean) entry.getValue(); - } - } - - /* (non-Javadoc) * @see org.dllearner.core.Component#init() */ @Override @@ -340,22 +262,47 @@ // adjust heuristic if(heuristic == null) { - if(heuristicStr == "lexicographic") - heuristic = new LexicographicHeuristic(); - else if(heuristicStr == "flexible") { - if(learningProblem instanceof PosOnlyLP) { - throw new RuntimeException("does not work with positive examples only yet"); - } - heuristic = new FlexibleHeuristic(((PosNegLP) getLearningProblem()).getNegativeExamples().size(), ((PosNegLP) getLearningProblem()).getPercentPerLengthUnit()); - } else { if(getLearningProblem() instanceof PosOnlyLP) { throw new RuntimeException("does not work with positive examples only yet"); // heuristic = new MultiHeuristic(((PosOnlyLP) getLearningProblem()).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } else { heuristic = new MultiHeuristic(((PosNegLP) getLearningProblem()).getPositiveExamples().size(),((PosNegLP) getLearningProblem()).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); + } + + // OLD CODE below: in the new framework we assume that the + // heuristic is always injected as object (not as string) +// if(heuristicStr == "lexicographic") +// heuristic = new LexicographicHeuristic(); +// else if(heuristicStr == "flexible") { +// if(learningProblem instanceof PosOnlyLP) { +// throw new RuntimeException("does not work with positive examples only yet"); +// } +// heuristic = new FlexibleHeuristic(((PosNegLP) getLearningProblem()).getNegativeExamples().size(), ((PosNegLP) getLearningProblem()).getPercentPerLengthUnit()); +// } else { +// if(getLearningProblem() instanceof PosOnlyLP) { +// throw new RuntimeException("does not work with positive examples only yet"); +// // heuristic = new MultiHeuristic(((PosOnlyLP) getLearningProblem()).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); +// } else { +// heuristic = new MultiHeuristic(((PosNegLP) getLearningProblem()).getPositiveExamples().size(),((PosNegLP) getLearningProblem()).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); +// } +// } + } else { + // we need to set some variables to make the heuristic work + if(heuristic instanceof MultiHeuristic) { + MultiHeuristic mh = ((MultiHeuristic)heuristic); + if(mh.getNrOfNegativeExamples() == 0) { + mh.setNrOfNegativeExamples(((PosNegLP) getLearningProblem()).getNegativeExamples().size()); + } + int nrPosEx = ((PosNegLP) getLearningProblem()).getPositiveExamples().size(); + int nrNegEx = ((PosNegLP) getLearningProblem()).getNegativeExamples().size(); + if(mh.getNrOfExamples() == 0) { + mh.setNrOfExamples(nrPosEx + nrNegEx); + } + if(mh.getNrOfNegativeExamples() == 0) { + mh.setNrOfNegativeExamples(nrNegEx); + } } } - } // warn the user if he/she sets any non-standard heuristic, because it will just be ignored if(learningProblem instanceof PosNegLPStandard) { @@ -411,9 +358,7 @@ if(operator == null) { // we use a default operator and inject the class hierarchy for now operator = new RhoDRDown(); - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); ((RhoDRDown)operator).setReasoner(reasoner); - ((RhoDRDown)operator).init(); // operator = new RhoDRDown( // reasoner, @@ -436,10 +381,11 @@ // useStringDatatypes, // instanceBasedDisjoints // ); - } else { - // we still have to inject the class hierarchy even if the operator is configured - operator.setSubHierarchy(classHierarchy); } + ((RhoDRDown)operator).setSubHierarchy(classHierarchy); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + ((RhoDRDown)operator).init(); // create an algorithm object and pass all configuration // options to it @@ -572,14 +518,6 @@ this.replaceSearchTree = replaceSearchTree; } - public String getHeuristicStr() { - return heuristicStr; - } - - public void setHeuristicStr(String heuristic) { - this.heuristicStr = heuristic; - } - public Set<NamedClass> getAllowedConcepts() { return allowedConcepts; } Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -45,6 +45,7 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DoubleMaxValue; @@ -60,6 +61,7 @@ import org.dllearner.core.owl.ObjectMinCardinalityRestriction; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; @@ -98,6 +100,8 @@ // hierarchies private ClassHierarchy subHierarchy; + private ObjectPropertyHierarchy objectPropertyHierarchy; + private DatatypePropertyHierarchy dataPropertyHierarchy; // domains and ranges private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>(); @@ -262,6 +266,7 @@ // subHierarchy = rs.getClassHierarchy(); public void init() { // System.out.println("subHierarchy: " + subHierarchy); +// System.out.println("object properties: " + ); // query reasoner for domains and ranges // (because they are used often in the operator) @@ -560,7 +565,9 @@ // rule 2: EXISTS r.D => EXISTS s.D or EXISTS r^-1.D => EXISTS s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); + // remove reasoner calls +// Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) refinements.add(new ObjectSomeRestriction(moreSpecialRole, description.getChild(0))); @@ -604,7 +611,8 @@ // rule 3: ALL r.D => ALL s.D or ALL r^-1.D => ALL s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); +// Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) { refinements.add(new ObjectAllRestriction(moreSpecialRole, description.getChild(0))); } @@ -961,9 +969,9 @@ topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; // if(domain == null) { -// System.out.println("computed top refinements: " + topRefinementsCumulative.get(maxLength)); +// System.out.println("computed top refinements up to length " + topRefinementsLength + ": " + topRefinementsCumulative.get(maxLength)); // } else { -// System.out.println("computed top refinements: " + topARefinementsCumulative.get(domain).get(maxLength)); +// System.out.println("computed top refinements up to length " + topARefinementsLength + ": (domain: "+domain+"): " + topARefinementsCumulative.get(domain).get(maxLength)); // } } @@ -1002,6 +1010,7 @@ SortedSet<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { // only uses most general roles +// System.out.println("EXISTS: " + reasoner.getMostGeneralProperties()); for(ObjectProperty r : reasoner.getMostGeneralProperties()) { m3.add(new ObjectSomeRestriction(r, new Thing())); } @@ -1674,4 +1683,20 @@ public void setCardinalityLimit(int cardinalityLimit) { this.cardinalityLimit = cardinalityLimit; } + + public ObjectPropertyHierarchy getObjectPropertyHierarchy() { + return objectPropertyHierarchy; + } + + public void setObjectPropertyHierarchy(ObjectPropertyHierarchy objectPropertyHierarchy) { + this.objectPropertyHierarchy = objectPropertyHierarchy; + } + + public DatatypePropertyHierarchy getDataPropertyHierarchy() { + return dataPropertyHierarchy; + } + + public void setDataPropertyHierarchy(DatatypePropertyHierarchy dataPropertyHierarchy) { + this.dataPropertyHierarchy = dataPropertyHierarchy; + } } \ No newline at end of file Modified: trunk/examples/family/grandfather.conf =================================================================== --- trunk/examples/family/grandfather.conf 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/examples/family/grandfather.conf 2011-11-29 18:15:18 UTC (rev 3449) @@ -40,12 +40,13 @@ op.reasoner = reasoner // create a heuristic and configure it -h.type = "multiheuristic" -h.expansionPenaltyFactor = 0.2 +// h.type = "multiheuristic" +// h.expansionPenaltyFactor = 0.2 // create learning algorithm to run alg.type = "ocel" alg.reasoner = reasoner alg.operator = op -alg.heuristic = h -alg.maxExecutionTimeInSeconds = 15 +// alg.heuristic = h +alg.maxExecutionTimeInSeconds = 5 + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |