From: <jen...@us...> - 2008-11-16 19:20:38
|
Revision: 1518 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1518&view=rev Author: jenslehmann Date: 2008-11-16 19:20:34 +0000 (Sun, 16 Nov 2008) Log Message: ----------- - cardinality limit option - reasoner unit test extended - small fixes Modified Paths: -------------- trunk/examples/carcinogenesis/train.conf trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java Modified: trunk/examples/carcinogenesis/train.conf =================================================================== --- trunk/examples/carcinogenesis/train.conf 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/examples/carcinogenesis/train.conf 2008-11-16 19:20:34 UTC (rev 1518) @@ -1,15 +1,21 @@ import("carcinogenesis.owl"); -// store some settings to make the experiment reproducable in the future +// general setup reasoner = fastInstanceChecker; algorithm = refexamples; refexamples.noisePercentage = 32; refexamples.startClass = "http://dl-learner.org/carcinogenesis#Compound"; + +// search tree refexamples.writeSearchTree = false; refexamples.searchTreeFile = "log/carcinogenesis/searchTree.log"; + +// store some default settings to make the experiment reproducable in the future refexamples.negativeWeight = 0.8; -refexamples.startNodeBonus = 2.0; +refexamples.startNodeBonus = 1.0; refexamples.forceRefinementLengthIncrease = false; +refexamples.cardinalityLimit = 5; +refexamples.usePropernessChecks = false; +"http://dl-learner.org/carcinogenesis#d1" +"http://dl-learner.org/carcinogenesis#d10" Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -25,6 +25,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.configurators.ExampleBasedROLComponentConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.utilities.owl.ConceptComparator; @@ -41,6 +42,8 @@ */ public class ExampleBasedNode { + private ExampleBasedROLComponentConfigurator configurator; + private static DecimalFormat df = new DecimalFormat(); // example based variables @@ -72,7 +75,8 @@ // a flag whether this could be a solution for a posonly learning problem private boolean isPosOnlyCandidate = true; - public ExampleBasedNode(Description concept) { + public ExampleBasedNode(ExampleBasedROLComponentConfigurator configurator, Description concept) { + this.configurator = configurator; this.concept = concept; horizontalExpansion = 0; isQualityEvaluated = false; @@ -165,7 +169,7 @@ ret += "acc:" + df.format(accuracy) + "% "; // comment this out to display the heuristic score with default parameters - double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples); + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, configurator); ret += "h:" +df.format(heuristicScore) + " "; int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); @@ -188,7 +192,7 @@ ret += "<b>acc: " + df.format(accuracy) + "% </b>"; // comment this out to display the heuristic score with default parameters - double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples); + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, configurator); ret += "h:" +df.format(heuristicScore) + " "; int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); @@ -212,7 +216,7 @@ ret += "acc:" + df.format(accuracy) + "% "; // comment this out to display the heuristic score with default parameters - double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples); + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, configurator); ret += "h:" +df.format(heuristicScore) + " "; int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -196,6 +196,7 @@ options.add(CommonConfigOptions.useHasValueConstructor()); options.add(CommonConfigOptions.valueFreqencyThreshold()); options.add(CommonConfigOptions.useCardinalityRestrictions()); + options.add(CommonConfigOptions.cardinalityLimit()); options.add(CommonConfigOptions.useNegation()); options.add(CommonConfigOptions.useBooleanDatatypes()); options.add(CommonConfigOptions.useDoubleDatatypes()); @@ -376,6 +377,7 @@ RhoDRDown operator = new RhoDRDown( reasoner, classHierarchy, + configurator, applyAllFilter, applyExistsFilter, useAllConstructor, @@ -392,6 +394,7 @@ // create an algorithm object and pass all configuration // options to it algorithm = new ExampleBasedROLearner( + configurator, learningProblem, reasoner, operator, Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -37,6 +37,7 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; +import org.dllearner.core.configurators.ExampleBasedROLComponentConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; @@ -73,6 +74,7 @@ public class ExampleBasedROLearner { private static Logger logger = Logger.getLogger(ExampleBasedROLearner.class); + private ExampleBasedROLComponentConfigurator configurator; // basic setup: learning problem and reasoning service private ReasonerComponent rs; @@ -232,6 +234,7 @@ private Map<String, String> prefixes; public ExampleBasedROLearner( + ExampleBasedROLComponentConfigurator configurator, LearningProblem learningProblem, ReasonerComponent rs, RefinementOperator operator, @@ -268,6 +271,7 @@ // nrOfNegativeExamples = lp.getPseudoNegatives().size(); nrOfNegativeExamples = 0; } + this.configurator = configurator; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; this.rs = rs; this.operator = (RhoDRDown) operator; @@ -384,10 +388,10 @@ // start search with start class if (startDescription == null) { - startNode = new ExampleBasedNode(Thing.instance); + startNode = new ExampleBasedNode(configurator, Thing.instance); startNode.setCoveredExamples(positiveExamples, negativeExamples); } else { - startNode = new ExampleBasedNode(startDescription); + startNode = new ExampleBasedNode(configurator, startDescription); Set<Individual> coveredNegatives = rs.hasType(startDescription, negativeExamples); Set<Individual> coveredPositives = rs.hasType(startDescription, positiveExamples); startNode.setCoveredExamples(coveredPositives, coveredNegatives); @@ -673,7 +677,7 @@ properRefinements.add(refinement); tooWeakList.add(refinement); - ExampleBasedNode newNode = new ExampleBasedNode(refinement); + ExampleBasedNode newNode = new ExampleBasedNode(configurator, refinement); newNode.setHorizontalExpansion(refinement.getLength() - 1); newNode.setTooWeak(true); newNode @@ -763,7 +767,7 @@ if (nonRedundant) { // newly created node - ExampleBasedNode newNode = new ExampleBasedNode(refinement); + ExampleBasedNode newNode = new ExampleBasedNode(configurator, refinement); // die -1 ist wichtig, da sonst keine gleich langen Refinements // für den neuen Knoten erlaubt wären z.B. person => male newNode.setHorizontalExpansion(refinement.getLength() - 1); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -69,6 +69,7 @@ public class MultiHeuristic implements ExampleBasedHeuristic { private ConceptComparator conceptComparator = new ConceptComparator(); +// private ExampleBasedROLComponentConfigurator configurator; // heuristic parameters private double expansionPenaltyFactor = 0.02; @@ -83,6 +84,7 @@ private int nrOfNegativeExamples; private int nrOfExamples; + @Deprecated public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples) { this.nrOfNegativeExamples = nrOfNegativeExamples; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; @@ -92,10 +94,9 @@ public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, ExampleBasedROLComponentConfigurator configurator) { this.nrOfNegativeExamples = nrOfNegativeExamples; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; +// this.configurator = configurator; negativeWeight = configurator.getNegativeWeight(); startNodeBonus = configurator.getStartNodeBonus(); - System.out.println(negativeWeight); - System.out.println(startNodeBonus); } // public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, double expansionPenaltyFactor, double gainBonusFactor) { @@ -141,8 +142,8 @@ return (coveredPositives + negativeWeight * (nrOfNegativeExamples - coveredNegatives))/(double)nrOfExamples; } - public static double getNodeScore(ExampleBasedNode node, int nrOfPositiveExamples, int nrOfNegativeExamples) { - MultiHeuristic multi = new MultiHeuristic(nrOfPositiveExamples, nrOfNegativeExamples); + public static double getNodeScore(ExampleBasedNode node, int nrOfPositiveExamples, int nrOfNegativeExamples, ExampleBasedROLComponentConfigurator configurator) { + MultiHeuristic multi = new MultiHeuristic(nrOfPositiveExamples, nrOfNegativeExamples, configurator); return multi.getNodeScore(node); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -601,8 +601,7 @@ SortedSet<Constant> values = e.getValue(); if (values.size() > 1) { logger.warn("Property " + datatypeProperty + " has more than one value " + e.getValue() - + " for individual " + e.getKey() + ". We ignore the value."); - // d135 + + " for individual " + e.getKey() + ". We ignore the value."); } else { if (values.first().getLiteral().equalsIgnoreCase("true")) { ret.add(e.getKey()); Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -241,6 +241,15 @@ return (Boolean) ComponentManager.getInstance().getConfigOptionValue(exampleBasedROLComponent, "useCardinalityRestrictions") ; } /** +* cardinalityLimit Gives the maximum number used in cardinality restrictions.. +* mandatory: false| reinit necessary: true +* default value: 5 +* @return int +**/ +public int getCardinalityLimit() { +return (Integer) ComponentManager.getInstance().getConfigOptionValue(exampleBasedROLComponent, "cardinalityLimit") ; +} +/** * useNegation specifies whether negation is used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true @@ -557,6 +566,15 @@ reinitNecessary = true; } /** +* @param cardinalityLimit Gives the maximum number used in cardinality restrictions.. +* mandatory: false| reinit necessary: true +* default value: 5 +**/ +public void setCardinalityLimit(int cardinalityLimit) { +ComponentManager.getInstance().applyConfigEntry(exampleBasedROLComponent, "cardinalityLimit", cardinalityLimit); +reinitNecessary = true; +} +/** * @param useNegation specifies whether negation is used in the learning algorothm. * mandatory: false| reinit necessary: true * default value: true Modified: trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -43,6 +43,7 @@ public static boolean useHasValueConstructorDefault = false; public static int valueFrequencyThresholdDefault = 3; public static boolean useCardinalityRestrictionsDefault = true; + public static int cardinalityLimitDefault = 5; public static boolean useNegationDefault = true; public static boolean useBooleanDatatypesDefault = true; public static boolean useDoubleDatatypesDefault = true; @@ -115,6 +116,10 @@ return new BooleanConfigOption("useCardinalityRestrictions", "specifies whether CardinalityRestrictions is used in the learning algorithm",useCardinalityRestrictionsDefault); } + public static IntegerConfigOption cardinalityLimit() { + return new IntegerConfigOption("cardinalityLimit", "Gives the maximum number used in cardinality restrictions.",cardinalityLimitDefault); + } + public static BooleanConfigOption useNegation() { return new BooleanConfigOption("useNegation", "specifies whether negation is used in the learning algorothm",useNegationDefault); } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -35,6 +35,7 @@ import org.apache.log4j.Logger; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.configurators.ExampleBasedROLComponentConfigurator; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DataRange; @@ -102,8 +103,7 @@ // limit for cardinality restrictions (this makes sense if we e.g. have compounds with up to // more than 200 atoms but we are only interested in atoms with certain characteristics and do // not want something like e.g. >= 204 hasAtom.NOT Carbon-87; which blows up the search space - //RBC - private int cardinalityLimit = 2; + private int cardinalityLimit = 5; // start concept (can be used to start from an arbitrary concept, needs // to be Thing or NamedClass), note that when you use e.g. Compound as @@ -182,14 +182,15 @@ // private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); public RhoDRDown(ReasonerComponent reasoningService) { - this(reasoningService, reasoningService.getClassHierarchy(), true, true, true, true, true, 3, true, true, true, true, null); +// this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null); + this.rs = reasoningService; } // TODO constructor which takes a RhoDRDownConfigurator object; // this should be an interface implemented e.g. by ExampleBasedROLComponentConfigurator; // the goal is to use the configurator system while still being flexible enough to // use one refinement operator in several learning algorithms - public RhoDRDown(ReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, + public RhoDRDown(ReasonerComponent reasoningService, ClassHierarchy subHierarchy, ExampleBasedROLComponentConfigurator configurator, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass) { this.rs = reasoningService; this.subHierarchy = subHierarchy; @@ -200,6 +201,7 @@ this.useHasValueConstructor = useHasValueConstructor; this.frequencyThreshold = valueFrequencyThreshold; this.useCardinalityRestrictions = useCardinalityRestrictions; + cardinalityLimit = configurator.getCardinalityLimit(); this.useNegation = useNegation; this.useBooleanDatatypes = useBooleanDatatypes; this.useDoubleDatatypes = useDoubleDatatypes; Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-11-16 14:38:32 UTC (rev 1517) +++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-11-16 19:20:34 UTC (rev 1518) @@ -21,6 +21,9 @@ import static org.junit.Assert.assertTrue; +import java.io.File; +import java.net.MalformedURLException; +import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; @@ -32,8 +35,10 @@ import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.KB; import org.dllearner.kb.KBFile; +import org.dllearner.kb.OWLFile; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.OWLAPIReasoner; import org.junit.Test; /** @@ -45,6 +50,8 @@ public class ReasonerTests { private static Logger logger = Logger.getLogger(ReasonerTests.class); + + private String baseURI; public KB getSimpleKnowledgeBase() { String kb = "person SUB TOP."; @@ -101,5 +108,65 @@ e.printStackTrace(); } } + + /** + * Test of fast instance check algorithm on carcinogenesis data set. + * @throws ComponentInitException + * @throws ParseException + */ + @Test + public void fastInstanceCheckTest() throws ComponentInitException, ParseException { + String file = "examples/carcinogenesis/carcinogenesis.owl"; + ComponentManager cm = ComponentManager.getInstance(); + KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); + try { + cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL()); + } catch (MalformedURLException e) { + // should never happen + e.printStackTrace(); + } + ks.init(); + ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, ks); + reasoner.init(); + baseURI = reasoner.getBaseURI(); + + List<Description> testDescriptions = new LinkedList<Description>(); + List<List<Individual>> posIndividuals = new LinkedList<List<Individual>>(); + List<List<Individual>> negIndividuals = new LinkedList<List<Individual>>(); + + // TODO manually verify that the results are indeed correct + testDescriptions.add(KBParser.parseConcept("\"http://dl-learner.org/carcinogenesis#Compound\" AND (\"http://dl-learner.org/carcinogenesis#amesTestPositive\" = true OR >= 2 \"http://dl-learner.org/carcinogenesis#hasStructure\" \"http://dl-learner.org/carcinogenesis#Ar_halide\"))")); + posIndividuals.add(getIndSet("d113","d133","d171","d262","d265","d294","d68","d77","d79")); + negIndividuals.add(getIndSet("d139","d199","d202","d203","d283","d42")); + // TODO add more descriptions and instances + + // make the specified assertions + for(int i=0; i<testDescriptions.size(); i++) { + Description description = testDescriptions.get(i); + List<Individual> pos = posIndividuals.get(i); + List<Individual> neg = negIndividuals.get(i); + + for(Individual ind : pos) { + assertTrue(reasoner.hasType(description, ind)); + } + + for(Individual ind : neg) { + assertTrue(!reasoner.hasType(description, ind)); + } + } + } + + private List<Individual> getIndSet(String... inds) { + List<Individual> individuals = new LinkedList<Individual>(); + for(String ind : inds) { + individuals.add(new Individual(uri(ind))); + } + return individuals; + } + + private String uri(String name) { + return "\""+baseURI+name+"\""; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |