From: <jen...@us...> - 2009-06-25 16:56:22
|
Revision: 1809 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1809&view=rev Author: jenslehmann Date: 2009-06-25 16:56:18 +0000 (Thu, 25 Jun 2009) Log Message: ----------- disjunctive EL algorithm ctd. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/DisjunctiveHeuristic.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmDisjunctiveConfigurator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/DisjunctiveHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/DisjunctiveHeuristic.java 2009-06-25 10:17:14 UTC (rev 1808) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/DisjunctiveHeuristic.java 2009-06-25 16:56:18 UTC (rev 1809) @@ -8,8 +8,11 @@ double diff = tree1.getScore()-tree2.getScore(); if(diff < 0.00001 && diff > -0.00001) { return edt.compare(tree1.getDescriptionTree(), tree2.getDescriptionTree()); + } else if(diff > 0){ + return 1; +// return (int)Math.signum(diff); } else { - return (int)Math.signum(diff); + return -1; } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2009-06-25 10:17:14 UTC (rev 1808) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2009-06-25 16:56:18 UTC (rev 1809) @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; @@ -33,12 +34,13 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.configurators.ELLearningAlgorithmConfigurator; +import org.dllearner.core.configurators.ELLearningAlgorithmDisjunctiveConfigurator; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; @@ -71,32 +73,38 @@ public class ELLearningAlgorithmDisjunctive extends LearningAlgorithm { private static Logger logger = Logger.getLogger(ELLearningAlgorithmDisjunctive.class); - private ELLearningAlgorithmConfigurator configurator; + private ELLearningAlgorithmDisjunctiveConfigurator configurator; + String baseURI; + Map<String,String> prefixes; + private ELDown2 operator; private boolean isRunning = false; private boolean stop = false; + private Description startClass; private SearchTreeNode startNode; private ELHeuristic heuristic; private TreeSet<SearchTreeNode> candidates; // tree search + private double noise = 0; private List<ELDescriptionTree> currentSolution = new LinkedList<ELDescriptionTree>(); private EvaluatedDescription bestEvaluatedDescription; - // how important not cover - private double posWeight = 5; + // how important not to cover negatives + private double posWeight = 2; private int startPosExamplesSize; private int startNegExamplesSize; private SortedSet<Individual> currentPosExamples; private SortedSet<Individual> currentNegExamples; - private ELDescriptionTree bestCurrentTree; + private SearchTreeNode bestCurrentNode; private double bestCurrentScore = 0; private long treeStartTime; public ELLearningAlgorithmDisjunctive(PosNegLP problem, ReasonerComponent reasoner) { super(problem, reasoner); + configurator = new ELLearningAlgorithmDisjunctiveConfigurator(this); } public static String getName() { @@ -132,7 +140,17 @@ heuristic = new DisjunctiveHeuristic(); candidates = new TreeSet<SearchTreeNode>(heuristic); + if(configurator.getStartClass() != null) { + startClass = new NamedClass(configurator.getStartClass()); + } else { + startClass = Thing.instance; + } operator = new ELDown2(reasoner); + + noise = configurator.getNoisePercentage()/(double)100; + + baseURI = reasoner.getBaseURI(); + prefixes = reasoner.getPrefixes(); } @Override @@ -146,9 +164,9 @@ treeStartTime = System.nanoTime(); // create start node - ELDescriptionTree top = new ELDescriptionTree(reasoner, Thing.instance); - addDescriptionTree(top, null); - bestCurrentTree = top; + ELDescriptionTree startTree = new ELDescriptionTree(reasoner, startClass); + addDescriptionTree(startTree, null); +// bestCurrentTree = top; bestCurrentScore = Double.NEGATIVE_INFINITY; // main loop @@ -156,6 +174,8 @@ while(!stop && !treeCriteriaSatisfied()) { // pick the best candidate according to the heuristic SearchTreeNode best = candidates.pollLast(); +// System.out.println("best: " + best); + // apply operator List<ELDescriptionTree> refinements = operator.refine(best.getDescriptionTree()); // add all refinements to search tree, candidates, best descriptions @@ -169,11 +189,18 @@ logger.trace(startNode.getTreeString()); logger.trace("Loop " + loop + " completed."); } + +// for(SearchTreeNode node : candidates) { +// System.out.println(node); +// } +// System.out.println(candidates.last()); +// System.out.println(candidates.first()); +// System.out.println("=="); } // we found a tree (partial solution) - currentSolution.add(bestCurrentTree); - Description bestDescription = bestCurrentTree.transformToDescription(); + currentSolution.add(bestCurrentNode.getDescriptionTree()); + Description bestDescription = bestCurrentNode.getDescriptionTree().transformToDescription(); // form union of trees found so far with if(treeCount==0) { bestEvaluatedDescription = learningProblem.evaluate(bestDescription); @@ -201,13 +228,16 @@ negCov++; } } - logger.info("tree found: " + bestDescription + " (" + posCov + " pos covered, " + currentPosExamples.size() + " remaining, " + negCov + " neg covered, " + currentNegExamples.size() + " remaining"); + logger.info("tree found: " + bestDescription.toManchesterSyntaxString(baseURI, prefixes) + " (" + posCov + " pos covered, " + currentPosExamples.size() + " remaining, " + negCov + " neg covered, " + currentNegExamples.size() + " remaining, score: " + bestCurrentNode.getScore() + ")"); + // reset temporary variables + candidates.clear(); + treeCount++; } // print solution - logger.info("solution : " + bestEvaluatedDescription); + logger.info("solution : " + bestEvaluatedDescription.getDescription().toManchesterSyntaxString(baseURI, prefixes) + "(acc: " + bestEvaluatedDescription.getAccuracy() + ")"); isRunning = false; } @@ -231,12 +261,13 @@ // TODO: define "too weak" as a coverage on negative examples, which is // too high for the tree to be considered + if(score != Double.NEGATIVE_INFINITY) { + candidates.add(node); + } - candidates.add(node); - // check whether this is the best tree if(score > bestCurrentScore) { - bestCurrentTree = descriptionTree; + bestCurrentNode = node; bestCurrentScore = score; } } @@ -259,8 +290,11 @@ // penalty if a minimum coverage is not achieved (avoids too many trees where // each tree has only little impact) - if(startPosExamplesSize > 10 && posCovered<3 || posCovered < 1) { - score -= 10; + if((startPosExamplesSize > 10 && posCovered<3) || posCovered < 1) { +// score -= 100; + // further refining such a tree will not cover more positives + // => reject + return Double.NEGATIVE_INFINITY; } // test coverage on current negative examples @@ -273,16 +307,25 @@ } // double negPercentage = negCovered/(double)currentNegExamples.size(); + // remove - does not make sense + // check whether tree is too weak, i.e. covers more than noise % negatives +// int maxNegCov = (int) Math.round(noise * currentNegExamples.size()); +// if(negCovered > maxNegCov) { +// return Double.NEGATIVE_INFINITY; +// } + // length penalty score -= 0.1*tree.getSize(); +// System.out.println("score: " + score); + return score; } private boolean treeCriteriaSatisfied() { long runTime = System.nanoTime() - treeStartTime; // more than one second has passed - if(runTime / 1000000000 > 1) { + if(runTime / (double) 1000000000 >= 10) { return true; } else { return false; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2009-06-25 10:17:14 UTC (rev 1808) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2009-06-25 16:56:18 UTC (rev 1809) @@ -26,6 +26,7 @@ import org.dllearner.algorithms.RandomGuesser; import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.el.ELLearningAlgorithm; +import org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive; import org.dllearner.algorithms.gp.GP; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.algorithms.refinement2.ROLComponent2; @@ -208,6 +209,16 @@ * @param learningProblem see LearningProblem * @param reasoningService see ReasoningService * @throws LearningProblemUnsupportedException see +* @return a component ready for initialization ELLearningAlgorithmDisjunctive +**/ +public static ELLearningAlgorithmDisjunctive getELLearningAlgorithmDisjunctive(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { +return ELLearningAlgorithmDisjunctiveConfigurator.getELLearningAlgorithmDisjunctive(learningProblem, reasoningService); +} + +/** +* @param learningProblem see LearningProblem +* @param reasoningService see ReasoningService +* @throws LearningProblemUnsupportedException see * @return a component ready for initialization GP **/ public static GP getGP(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { Added: trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmDisjunctiveConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmDisjunctiveConfigurator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmDisjunctiveConfigurator.java 2009-06-25 16:56:18 UTC (rev 1809) @@ -0,0 +1,105 @@ +/** + * Copyright (C) 2007-2008, 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.core.configurators; + +import org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.ReasonerComponent; + +/** +* automatically generated, do not edit manually. +* run org.dllearner.scripts.ConfigJavaGenerator to update +**/ +public class ELLearningAlgorithmDisjunctiveConfigurator implements Configurator { + +private boolean reinitNecessary = false; +@SuppressWarnings("unused") + +private ELLearningAlgorithmDisjunctive eLLearningAlgorithmDisjunctive; + +/** +* @param eLLearningAlgorithmDisjunctive see ELLearningAlgorithmDisjunctive +**/ +public ELLearningAlgorithmDisjunctiveConfigurator(ELLearningAlgorithmDisjunctive eLLearningAlgorithmDisjunctive){ +this.eLLearningAlgorithmDisjunctive = eLLearningAlgorithmDisjunctive; +} + +/** +* @param reasoningService see reasoningService +* @param learningProblem see learningProblem +* @throws LearningProblemUnsupportedException see +* @return ELLearningAlgorithmDisjunctive +**/ +public static ELLearningAlgorithmDisjunctive getELLearningAlgorithmDisjunctive(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException{ +ELLearningAlgorithmDisjunctive component = ComponentManager.getInstance().learningAlgorithm(ELLearningAlgorithmDisjunctive.class, learningProblem, reasoningService); +return component; +} + +/** +* noisePercentage the (approximated) percentage of noise within the examples. +* mandatory: false| reinit necessary: true +* default value: 0.0 +* @return double +**/ +public double getNoisePercentage() { +return (Double) ComponentManager.getInstance().getConfigOptionValue(eLLearningAlgorithmDisjunctive, "noisePercentage") ; +} +/** +* startClass the named class which should be used to start the algorithm (GUI: needs a widget for selecting a class). +* mandatory: false| reinit necessary: true +* default value: null +* @return String +**/ +public String getStartClass() { +return (String) ComponentManager.getInstance().getConfigOptionValue(eLLearningAlgorithmDisjunctive, "startClass") ; +} + +/** +* @param noisePercentage the (approximated) percentage of noise within the examples. +* mandatory: false| reinit necessary: true +* default value: 0.0 +**/ +public void setNoisePercentage(double noisePercentage) { +ComponentManager.getInstance().applyConfigEntry(eLLearningAlgorithmDisjunctive, "noisePercentage", noisePercentage); +reinitNecessary = true; +} +/** +* @param startClass the named class which should be used to start the algorithm (GUI: needs a widget for selecting a class). +* mandatory: false| reinit necessary: true +* default value: null +**/ +public void setStartClass(String startClass) { +ComponentManager.getInstance().applyConfigEntry(eLLearningAlgorithmDisjunctive, "startClass", startClass); +reinitNecessary = true; +} + +/** +* true, if this component needs reinitializsation. +* @return boolean +**/ +public boolean isReinitNecessary(){ +return reinitNecessary; +} + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |