From: <jen...@us...> - 2009-02-09 16:41:51
|
Revision: 1591 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1591&view=rev Author: jenslehmann Date: 2009-02-09 16:41:44 +0000 (Mon, 09 Feb 2009) Log Message: ----------- refactored Score and EvaluatedDescription such that a broader range of learning problems can be implemented (DL-Learner core makes less restrictions) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.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/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/core/LearningProblem.java trunk/src/dl-learner/org/dllearner/core/Score.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java trunk/src/dl-learner/org/dllearner/scripts/DumbLPFinder.java trunk/src/dl-learner/org/dllearner/scripts/NewSample.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/tools/ore/ColumnListCellRenderer.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java trunk/src/dl-learner/org/dllearner/learningproblems/ScorePosNeg.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -26,11 +26,9 @@ import java.util.List; import java.util.Map; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.BruteForceLearnerConfigurator; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.options.ConfigEntry; @@ -47,6 +45,7 @@ import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; +import org.dllearner.learningproblems.ScorePosNeg; /** * A brute force learning algorithm. @@ -70,7 +69,7 @@ private ReasonerComponent rs; private Description bestDefinition; - private Score bestScore; + private ScorePosNeg bestScore; //changing this wont have any effect any more private Integer maxLength = 7; @@ -173,7 +172,7 @@ double bestScorePoints = Double.NEGATIVE_INFINITY; int overallCount = 0; int count = 0; - Score tmp; + ScorePosNeg tmp; double score; for(int i=1; i<=maxLength && !stop; i++) { @@ -193,8 +192,8 @@ } else newRoot = program; - tmp = learningProblem.computeScore(newRoot); - score = tmp.getScore(); + tmp = (ScorePosNeg) learningProblem.computeScore(newRoot); + score = tmp.getScoreValue(); // TODO: find termination criterion if(score > bestScorePoints) { @@ -288,7 +287,7 @@ } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { return bestScore; } @@ -298,8 +297,8 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { - return new EvaluatedDescription(bestDefinition,bestScore); + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescriptionPosNeg(bestDefinition,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -29,7 +29,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.configurators.DBpediaNavigationSuggestorConfigurator; import org.dllearner.core.options.BooleanConfigOption; @@ -43,6 +42,7 @@ import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.learningproblems.ScorePosNeg; /** * The DBpedia Navigation suggestor takes a knowledge fragment extracted @@ -51,6 +51,9 @@ * implement a completely new learning algorithm itself, but uses the * example based refinement operator learning algorithm. * + * TODO: This should not be implemented as a learning algorithm (as it does + * almost nothing by itself) and maybe can be completely deleted. + * * @author Jens Lehmann * */ @@ -180,17 +183,17 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { return learner.getCurrentlyBestEvaluatedDescription(); } @Override - public List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions){ + public List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions){ return learner.getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions, accuracyThreshold, filterNonMinimalDescriptions); } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { return learner.getSolutionScore(); } Copied: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java (from rev 1590, trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -0,0 +1,168 @@ +/** + * 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.algorithms; + +import java.util.Set; + +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.Score; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.ScorePosNeg; +import org.dllearner.learningproblems.ScoreTwoValued; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIRenderers; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.semanticweb.owl.model.OWLDescription; + +/** + * This represents a class description, which has been + * evaluated by the learning algorithm, i.e. it has been checked + * which examples it covers. It can be used as return value for + * learning algorithms to make it easier for applications to + * assess how good an offered class description is and how it + * classifies particular examples. + * + * @author Jens Lehmann + * + */ +public class EvaluatedDescriptionPosNeg extends EvaluatedDescription { + + private ScorePosNeg score2; + + /** + * Constructs an evaluated description using its score. + * @param description The description, which was evaluated. + * @param score The score of the description. + */ + public EvaluatedDescriptionPosNeg(Description description, ScorePosNeg score) { + super(description, score); + score2 = (ScorePosNeg) score; + } + + /** + * Constructs an evaluated description using example coverage. + * @param description The description, which was evaluated. + * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description. + * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description. + * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description. + * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description. + */ + public EvaluatedDescriptionPosNeg(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { + // usually core methods should not depend on methods outside of the core package (except utilities) + // in this case, this is just a convenience constructor + super(description, new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg)); + score2 = (ScorePosNeg) score; + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getAccuracy() + * @return Accuracy of the description. + */ + public double getAccuracy() { + return score2.getAccuracy(); + } + + /** + * Gets the score of this description. This can be used to get + * further statistical values. + * @see org.dllearner.learningproblems.ScorePosNeg + * @return The score object associated with this evaluated description. + */ + public ScorePosNeg getScore() { + return score2; + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredNegatives() + * @return Negative examples covered by the description. + */ + public Set<Individual> getCoveredNegatives() { + return score2.getCoveredNegatives(); + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredPositives() + * @return Positive examples covered by the description. + */ + public Set<Individual> getCoveredPositives() { + return score2.getCoveredPositives(); + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredNegatives() + * @return Negative examples not covered by the description. + */ + public Set<Individual> getNotCoveredNegatives() { + return score2.getNotCoveredNegatives(); + } + + /** + * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredPositives() + * @return Positive examples not covered by the description. + */ + public Set<Individual> getNotCoveredPositives() { + return score2.getNotCoveredPositives(); + } + + /** + * This convenience method can be used to store and exchange evaluated + * descriptions by transforming them to a JSON string. + * @return A JSON representation of an evaluated description. + */ + @Override + public String asJSON() { + JSONObject object = new JSONObject(); + try { + object.put("descriptionManchesterSyntax", description.toManchesterSyntaxString(null, null)); + OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description); + object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d)); + object.put("descriptionKBSyntax", description.toKBSyntaxString()); + object.put("accuracy", score2.getAccuracy()); + object.put("coveredPositives", getJSONArray(score2.getCoveredPositives())); + object.put("coveredNegatives", getJSONArray(score2.getCoveredNegatives())); + object.put("notCoveredPositives", getJSONArray(score2.getNotCoveredPositives())); + object.put("notCoveredNegatives", getJSONArray(score2.getNotCoveredNegatives())); + return object.toString(3); + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public String toString() { + return description.toString() + "(accuracy: " + getAccuracy() + ")"; + } + + // we need to use this method instead of the standard JSON array constructor, + // otherwise we'll get unexpected results (JSONArray does not take Individuals + // as arguments and does not use toString) + private static JSONArray getJSONArray(Set<Individual> individuals) { + JSONArray j = new JSONArray(); + for(Individual i : individuals) { + j.put(i.getName()); + } + return j; + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -25,17 +25,16 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.algorithms.gp.Program; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.RandomGuesserConfigurator; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.IntegerConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.Description; +import org.dllearner.learningproblems.ScorePosNeg; public class RandomGuesser extends LearningAlgorithm { @@ -46,7 +45,7 @@ } private Description bestDefinition = null; - private Score bestScore; + private ScorePosNeg bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; private int numberOfTrees; @@ -121,7 +120,7 @@ } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { return bestScore; } @@ -131,8 +130,8 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { - return new EvaluatedDescription(bestDefinition,bestScore); + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescriptionPosNeg(bestDefinition,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -23,10 +23,8 @@ import java.util.List; import java.util.Set; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.SimpleSuggestionLearningAlgorithmConfigurator; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.owl.Description; @@ -34,6 +32,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.ScorePosNeg; /** * Algorithm for getting "simple" suggestions, e.g. it tests some of the most likely candidates on whether @@ -51,7 +50,7 @@ } // private boolean stop = false; - private Score solutionScore; + private ScorePosNeg solutionScore; private Description bestSollution; private Set<Description> simpleSuggestions; @@ -66,8 +65,8 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { - return new EvaluatedDescription(bestSollution, solutionScore); + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescriptionPosNeg(bestSollution, solutionScore); } public static String getName() { @@ -95,7 +94,7 @@ } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { return solutionScore; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -19,8 +19,8 @@ */ package org.dllearner.algorithms.celoe; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.Configurator; @@ -54,7 +54,7 @@ * @see org.dllearner.core.LearningAlgorithm#getCurrentlyBestEvaluatedDescription() */ @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { // TODO Auto-generated method stub return null; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -26,17 +26,18 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.configurators.ELLearningAlgorithmConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.ELDown2; import org.dllearner.utilities.owl.EvaluatedDescriptionSet; @@ -168,8 +169,8 @@ // at least as high accuracy - if not we can save the reasoner calls // for fully computing the evaluated description if(bestEvaluatedDescriptions.size() == 0 || bestEvaluatedDescriptions.getWorst().getCoveredNegatives().size() >= node.getCoveredNegatives()) { - Score score = learningProblem.computeScore(description); - EvaluatedDescription ed = new EvaluatedDescription(description, score); + ScorePosNeg score = (ScorePosNeg) learningProblem.computeScore(description); + EvaluatedDescriptionPosNeg ed = new EvaluatedDescriptionPosNeg(description, score); bestEvaluatedDescriptions.add(ed); } @@ -216,7 +217,7 @@ } @Override - public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { return bestEvaluatedDescriptions.getSet(); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -29,12 +29,11 @@ import java.util.Set; import java.util.Map.Entry; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.algorithms.hybridgp.Psi; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.GPConfigurator; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigEntry; @@ -46,6 +45,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.utilities.Helper; /** @@ -126,7 +126,7 @@ private long startTime; - private Score bestScore; + private ScorePosNeg bestScore; private Description bestConcept; // private GeneticRefinementOperator psi; @@ -532,19 +532,19 @@ // nachschauen, ob ev. noch bessere Konzepte im Psi-Cache sind boolean betterValueFoundInPsiCache = false; - double bestValue = bestScore.getScore(); + double bestValue = bestScore.getScoreValue(); if(refinementProbability > 0) { // das Problem ist hier, dass die gecachte Score nicht unbedingt // der echten Score entsprechen muss, d.h. hier muss die // Konzeptlänge mit einberechnet werden => deswegen werden // neue Score-Objekte generiert - Set<Entry<Description,Score>> entrySet = psi.evalCache.entrySet(); - for(Entry<Description,Score> entry : entrySet) { - Score tmpScore = entry.getValue(); + Set<Entry<Description,ScorePosNeg>> entrySet = psi.evalCache.entrySet(); + for(Entry<Description,ScorePosNeg> entry : entrySet) { + ScorePosNeg tmpScore = entry.getValue(); Description c = entry.getKey(); tmpScore = tmpScore.getModifiedLengthScore(c.getLength()); - double tmpScoreValue = tmpScore.getScore(); + double tmpScoreValue = tmpScore.getScoreValue(); if(tmpScoreValue>bestValue) { bestValue = tmpScoreValue; betterValueFoundInPsiCache = true; @@ -947,7 +947,7 @@ } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { return bestScore; } @@ -957,9 +957,9 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { // return fittestIndividual.getTree(); - return new EvaluatedDescription(bestConcept,bestScore); + return new EvaluatedDescriptionPosNeg(bestConcept,bestScore); } @Override Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -10,7 +10,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; -import org.dllearner.core.Score; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; @@ -24,6 +23,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegDefinitionLPStrict; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.learningproblems.ScoreThreeValued; import org.dllearner.reasoning.FastRetrieval; import org.dllearner.reasoning.ReasonerType; @@ -54,7 +54,7 @@ private static Random rand = new Random(); - private static Score calculateFitness(LearningProblem learningProblem, Description hypothesis) { + private static ScorePosNeg calculateFitness(LearningProblem learningProblem, Description hypothesis) { return calculateFitness(learningProblem, hypothesis, null); } @@ -63,7 +63,7 @@ // (macht aber nicht so viel Sinn, da man das bei richtigen Reasoning-Algorithmen // ohnehin mit einer Erweiterung der Wissensbasis um die Inklusion Target SUBSETOF ReturnType // erschlagen kann) - private static Score calculateFitness(LearningProblem learningProblem, Description hypothesis, Description adc) { + private static ScorePosNeg calculateFitness(LearningProblem learningProblem, Description hypothesis, Description adc) { Description extendedHypothesis; // return type temporarily disabled @@ -87,13 +87,13 @@ // } else extendedHypothesis = hypothesis; - Score score; + ScorePosNeg score; if(adc != null) // TODO: ADC-Support // score = learningProblem.computeScore(extendedHypothesis, adc); throw new RuntimeException("ADC not supported"); else - score = learningProblem.computeScore(extendedHypothesis); + score = (ScorePosNeg) learningProblem.computeScore(extendedHypothesis); // System.out.println(hypothesis); // System.out.println(score.getScore()); @@ -143,18 +143,18 @@ if(Math.random()<0.5) { Description mainTree = mutation(learningProblem, rs, p.getTree(),true); Description adc = p.getAdc(); - Score score = calculateFitness(learningProblem,mainTree,adc); + ScorePosNeg score = calculateFitness(learningProblem,mainTree,adc); return new Program(score, mainTree, adc); } else { Description mainTree = p.getTree(); Description adc = mutation(learningProblem, rs, p.getAdc(),false); - Score score = calculateFitness(learningProblem,mainTree,adc); + ScorePosNeg score = calculateFitness(learningProblem,mainTree,adc); return new Program(score, mainTree, adc); } } else { Description tree = mutation(learningProblem, rs,p.getTree(),false); - Score score = calculateFitness(learningProblem, tree); + ScorePosNeg score = calculateFitness(learningProblem, tree); return new Program(score, tree); } } @@ -340,7 +340,7 @@ // double bestScore = score.getScore()+Config.accuracyPenalty/2; double bestScore = 0; Map<Integer,List<String>> bestNeighbours = new TreeMap<Integer,List<String>>(); - Score tmpScore; + ScorePosNeg tmpScore; SortedSetTuple<String> tmp, tmp2; // FlatABox abox = ((FastRetrievalReasoner)learningProblem.getReasoner().getFastRetrieval().getAbox(); // FlatABox abox = Main.getFlatAbox(); @@ -363,16 +363,16 @@ tmp2 = FastRetrieval.calculateDisjunctionSets(stringTuple, tmp); tmpScore = getScore(node.getLength()+2, learningProblem, rs, Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet())); - if(tmpScore.getScore()==bestScore) + if(tmpScore.getScoreValue()==bestScore) bestNeighbours = updateMap(bestNeighbours,1,concept,false); - else if(tmpScore.getScore()>bestScore) + else if(tmpScore.getScoreValue()>bestScore) bestNeighbours = updateMap(bestNeighbours,1,concept,true); tmp2 = FastRetrieval.calculateConjunctionSets(stringTuple, tmp); tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet())); - if(tmpScore.getScore()==bestScore) + if(tmpScore.getScoreValue()==bestScore) bestNeighbours = updateMap(bestNeighbours,2,concept,false); - else if(tmpScore.getScore()>bestScore) + else if(tmpScore.getScoreValue()>bestScore) bestNeighbours = updateMap(bestNeighbours,2,concept,true); } @@ -380,16 +380,16 @@ for(String role : abox.roles) { tmp = FastRetrieval.calculateAllSet(abox,role,stringTuple); tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet())); - if(tmpScore.getScore()==bestScore) + if(tmpScore.getScoreValue()==bestScore) bestNeighbours = updateMap(bestNeighbours,3,role,false); - else if(tmpScore.getScore()>bestScore) + else if(tmpScore.getScoreValue()>bestScore) bestNeighbours = updateMap(bestNeighbours,3,role,true); tmp = FastRetrieval.calculateExistsSet(abox,role,stringTuple); tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet())); - if(tmpScore.getScore()==bestScore) + if(tmpScore.getScoreValue()==bestScore) bestNeighbours = updateMap(bestNeighbours,4,role,false); - else if(tmpScore.getScore()>bestScore) + else if(tmpScore.getScoreValue()>bestScore) bestNeighbours = updateMap(bestNeighbours,4,role,true); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -20,8 +20,8 @@ package org.dllearner.algorithms.gp; -import org.dllearner.core.Score; import org.dllearner.core.owl.Description; +import org.dllearner.learningproblems.ScorePosNeg; /** * This class represents a program, i.e. an individual. @@ -39,7 +39,7 @@ private Description adc; - private Score score; + private ScorePosNeg score; // private Score scoreAdc; @@ -51,11 +51,11 @@ * Create a new program. * */ - public Program(Score score, Description hypothesis) { + public Program(ScorePosNeg score, Description hypothesis) { this(score, hypothesis, null); } - public Program(Score score, Description hypothesis, Description adc) { + public Program(ScorePosNeg score, Description hypothesis, Description adc) { // this.learningProblem = learningProblem; this.score = score; this.hypothesis = hypothesis; @@ -64,7 +64,7 @@ // Implementierung falsch !! // fitness = score.getScore() - hypothesis.getLength() * Config.percentPerLengthUnit; // => in getScore() ist jetzt schon der length penalty integriert - fitness = score.getScore(); + fitness = score.getScoreValue(); // fitnessEvaluations++; // System.out.println("new program: " + hypothesis); @@ -128,7 +128,7 @@ return hypothesis; } - public Score getScore() { + public ScorePosNeg getScore() { return score; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -7,9 +7,9 @@ import org.dllearner.algorithms.gp.Program; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.PsiDown; import org.dllearner.refinementoperators.PsiUp; import org.dllearner.utilities.owl.ConceptComparator; @@ -26,7 +26,7 @@ // Cache, damit keine Konzepte doppelt ausgewertet werden ConceptComparator conceptComparator = new ConceptComparator(); - public SortedMap<Description,Score> evalCache = new TreeMap<Description,Score>(conceptComparator); + public SortedMap<Description,ScorePosNeg> evalCache = new TreeMap<Description,ScorePosNeg>(conceptComparator); // Cache, damit PsiDown bzw. PsiUp nicht mehrfach für gleiches Konzept // aufgerufen werden @@ -190,7 +190,7 @@ Description conceptModForCache = ConceptTransformation.applyEquivalenceRules(conceptMod); ConceptTransformation.transformToOrderedForm(conceptModForCache, conceptComparator); - Score score = program.getScore(); + ScorePosNeg score = program.getScore(); // Eval-Cache füllen evalCache.put(conceptModForCache, score); @@ -214,11 +214,11 @@ // versuchen Reasoner-Cache zu treffen // Problem: Score hängt von Konzeptlänge ab!! => muss hier explizit // reingerechnet werden - Score newScore = evalCache.get(newConceptMod); + ScorePosNeg newScore = evalCache.get(newConceptMod); if(newScore==null) { psiReasoningStartTime = System.nanoTime(); - newScore = learningProblem.computeScore(newConcept); + newScore = (ScorePosNeg) learningProblem.computeScore(newConcept); psiReasoningTimeNs += System.nanoTime() - psiReasoningStartTime; evalCache.put(newConceptMod, newScore); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -29,12 +29,11 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; 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.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; @@ -52,6 +51,7 @@ import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.reasoning.ReasonerType; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; @@ -436,7 +436,7 @@ } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { return algorithm.getSolutionScore(); } @@ -451,12 +451,12 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { - return new EvaluatedDescription(algorithm.getBestSolution(),algorithm.getSolutionScore()); + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescriptionPosNeg(algorithm.getBestSolution(),algorithm.getSolutionScore()); } @Override - public synchronized SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + public synchronized SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() { return algorithm.getCurrentlyBestEvaluatedDescriptions(); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -33,10 +33,9 @@ import java.util.concurrent.ConcurrentSkipListSet; import org.apache.log4j.Logger; -import org.dllearner.core.EvaluatedDescription; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; 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; @@ -45,6 +44,7 @@ import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; @@ -52,7 +52,7 @@ import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; -import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; +import org.dllearner.utilities.owl.EvaluatedDescriptionPosNegComparator; import com.jamonapi.Monitor; @@ -184,7 +184,7 @@ // comparator used to create ordered sets of concepts private ConceptComparator conceptComparator = new ConceptComparator(); // comparator for evaluated descriptions - private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator(); + private EvaluatedDescriptionPosNegComparator edComparator = new EvaluatedDescriptionPosNegComparator(); // utility variables private DecimalFormat df = new DecimalFormat(); @@ -1255,13 +1255,13 @@ return best; } - public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + public SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() { Iterator<ExampleBasedNode> it = candidatesStable.descendingIterator(); int count = 0; - SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator); + SortedSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator); while(it.hasNext()) { ExampleBasedNode eb = it.next(); - cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept()))); + cbd.add(new EvaluatedDescriptionPosNeg(eb.getConcept(), getScore(eb.getConcept()))); // return a maximum of 200 elements (we need a maximum, because the // candidate set can be very large) if (count > 200) @@ -1304,18 +1304,18 @@ } - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { if (posOnly) return posOnlyLearningProblem.computeScore(getBestSolution()); else - return learningProblem.computeScore(getBestSolution()); + return (ScorePosNeg) learningProblem.computeScore(getBestSolution()); } - private Score getScore(Description d) { + private ScorePosNeg getScore(Description d) { if (posOnly) return posOnlyLearningProblem.computeScore(d); else - return learningProblem.computeScore(d); + return (ScorePosNeg) learningProblem.computeScore(d); } public ExampleBasedNode getStartNode() { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -14,11 +14,10 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.dllearner.core.EvaluatedDescription; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.configurators.ROLearnerConfigurator; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; @@ -36,12 +35,13 @@ import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; -import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; +import org.dllearner.utilities.owl.EvaluatedDescriptionPosNegComparator; public class ROLearner extends LearningAlgorithm { @@ -107,7 +107,7 @@ private NodeComparatorStable nodeComparatorStable = new NodeComparatorStable(); private ConceptComparator conceptComparator = new ConceptComparator(); // comparator for evaluated descriptions - private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator(); + private EvaluatedDescriptionPosNegComparator edComparator = new EvaluatedDescriptionPosNegComparator(); DecimalFormat df = new DecimalFormat(); private PosNegLP learningProblem; @@ -1054,17 +1054,17 @@ } @Override - public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { - return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore()); + public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() { + return new EvaluatedDescriptionPosNeg(candidatesStable.last().getConcept(), getSolutionScore()); } @Override - public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + public SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() { int count = 0; SortedSet<Node> rev = candidatesStable.descendingSet(); - SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator); + SortedSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator); for(Node eb : rev) { - cbd.add(new EvaluatedDescription(eb.getConcept(), getSolutionScore(eb.getConcept()))); + cbd.add(new EvaluatedDescriptionPosNeg(eb.getConcept(), getSolutionScore(eb.getConcept()))); // return a maximum of 200 elements (we need a maximum, because the // candidate set can be very large) if(count > 200) @@ -1100,19 +1100,19 @@ } // @Override - public Score getSolutionScore() { + public ScorePosNeg getSolutionScore() { if(posOnly) return posOnlyLearningProblem.computeScore(getCurrentlyBestDescription()); else - return learningProblem.computeScore(getCurrentlyBestDescription()); + return (ScorePosNeg) learningProblem.computeScore(getCurrentlyBestDescription()); } - public Score getSolutionScore(Description d) { + public ScorePosNeg getSolutionScore(Description d) { if(posOnly) return posOnlyLearningProblem.computeScore(d); else - return learningProblem.computeScore(d); + return (ScorePosNeg) learningProblem.computeScore(d); } @Override Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -57,7 +57,6 @@ import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.Score; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; @@ -77,6 +76,7 @@ import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.parser.ConfParser; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -840,7 +840,7 @@ logger.info("retrieval result (" + result.size() + "): " + result); - Score score = lp.computeScore(concept); + ScorePosNeg score = (ScorePosNeg) lp.computeScore(concept); logger.info(score); } Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2009, Jens Lehmann * * This file is part of DL-Learner. * @@ -19,34 +19,25 @@ */ package org.dllearner.core; -import java.util.Set; - import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; -import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLAPIRenderers; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.semanticweb.owl.model.OWLDescription; /** - * This represents a class description, which has been - * evaluated by the learning algorithm, i.e. it has been checked - * which examples it covers. It can be used as return value for - * learning algorithms to make it easier for applications to - * assess how good an offered class description is and how it - * classifies particular examples. + * An evaluated description is a description and its score (with some + * convenience method and serialisation formats). * * @author Jens Lehmann * */ public class EvaluatedDescription { - private Description description; - private Score score; + protected Description description; + protected Score score; /** * Constructs an evaluated description using its score. @@ -59,21 +50,6 @@ } /** - * Constructs an evaluated description using example coverage. - * @param description The description, which was evaluated. - * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description. - * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description. - * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description. - * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description. - */ - public EvaluatedDescription(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) { - this.description = description; - // usually core methods should not depend on methods outside of the core package (except utilities) - // in this case, this is just a convenience constructor - score = new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg); - } - - /** * Gets the description, which was evaluated. * @return The underlying description. */ @@ -107,56 +83,14 @@ } /** - * @see org.dllearner.core.Score#getAccuracy() - * @return Accuracy of the description. + * @see org.dllearner.core.Score#getScoreValue() + * @return Value in this score system. */ - public double getAccuracy() { - return score.getAccuracy(); + public double getScoreValue() { + return score.getScoreValue(); } /** - * Gets the score of this description. This can be used to get - * further statistical values. - * @see org.dllearner.core.Score - * @return The score object associated with this evaluated description. - */ - public Score getScore() { - return score; - } - - /** - * @see org.dllearner.core.Score#getCoveredNegatives() - * @return Negative examples covered by the description. - */ - public Set<Individual> getCoveredNegatives() { - return score.getCoveredNegatives(); - } - - /** - * @see org.dllearner.core.Score#getCoveredPositives() - * @return Positive examples covered by the description. - */ - public Set<Individual> getCoveredPositives() { - return score.getCoveredPositives(); - } - - /** - * @see org.dllearner.core.Score#getNotCoveredNegatives() - * @return Negative examples not covered by the description. - */ - public Set<Individual> getNotCoveredNegatives() { - return score.getNotCoveredNegatives(); - } - - /** - * @see org.dllearner.core.Score#getNotCoveredPositives() - * @return Positive examples not covered by the description. - */ - public Set<Individual> getNotCoveredPositives() { - return score.getNotCoveredPositives(); - } - - /** * Returns a SPARQL query to get instances of this description * from a SPARQL endpoint. Of course, results may be incomplete, * because no inference is done. The SPARQL query is a straightforward @@ -169,7 +103,7 @@ */ public String getSparqlQuery(int limit) { return SparqlQueryDescriptionConvertVisitor.getSparqlQuery(description, limit); - } + } /** * This convenience method can be used to store and exchange evaluated @@ -183,32 +117,12 @@ OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description); object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d)); object.put("descriptionKBSyntax", description.toKBSyntaxString()); - object.put("accuracy", score.getAccuracy()); - object.put("coveredPositives", getJSONArray(score.getCoveredPositives())); - object.put("coveredNegatives", getJSONArray(score.getCoveredNegatives())); - object.put("notCoveredPositives", getJSONArray(score.getNotCoveredPositives())); - object.put("notCoveredNegatives", getJSONArray(score.getNotCoveredNegatives())); + object.put("scoreValue", score.getScoreValue()); return object.toString(3); } catch (JSONException e) { e.printStackTrace(); return null; } - } - - @Override - public String toString() { - return description.toString() + "(accuracy: " + getAccuracy() + ")"; - } - - // we need to use this method instead of the standard JSON array constructor, - // otherwise we'll get unexpected results (JSONArray does not take Individuals - // as arguments and does not use toString) - private static JSONArray getJSONArray(Set<Individual> individuals) { - JSONArray j = new JSONArray(); - for(Individual i : individuals) { - j.put(i.getName()); - } - return j; - } + } } Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -207,7 +207,7 @@ * first. * @return Best class descriptions found so far. */ - public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { TreeSet<EvaluatedDescription> ds = new TreeSet<EvaluatedDescription>(); ds.add(getCurrentlyBestEvaluatedDescription()); return ds; @@ -231,14 +231,15 @@ * * @return A list of currently best class descriptions. */ - public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) { - SortedSet<EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions(); + public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) { + SortedSet<? extends EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions(); List<EvaluatedDescription> returnList = new LinkedList<EvaluatedDescription>(); for(EvaluatedDescription ed : currentlyBest) { // once we hit a description with a below threshold accuracy, we simply return // because learning algorithms are advised to order descriptions by accuracy, // so we won't find any concept with higher accuracy in the remaining list - if(ed.getAccuracy() < accuracyThreshold) { +// if(ed.getAccuracy() < accuracyThreshold) { + if(ed.getScoreValue() < accuracyThreshold) { return returnList; } @@ -270,7 +271,7 @@ * @param nrOfDescriptions Maximum number of descriptions returned. * @return Return value is getCurrentlyBestDescriptions(nrOfDescriptions, 0.0, false). */ - public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions) { + public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions) { return getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions, 0.0, false); } @@ -279,7 +280,7 @@ * @param accuracyThreshold Only return solutions with this accuracy or higher. * @return Return value is getCurrentlyBestDescriptions(Integer.MAX_VALUE, accuracyThreshold, false). */ - public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) { + public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) { return getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, accuracyThreshold, false); } Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -20,6 +20,7 @@ package org.dllearner.core; import org.dllearner.core.owl.Description; +import org.dllearner.learningproblems.ScorePosNeg; /** * Base class for all learning problems. Modified: trunk/src/dl-learner/org/dllearner/core/Score.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Score.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/core/Score.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2009, Jens Lehmann * * This file is part of DL-Learner. * @@ -17,48 +17,28 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ - package org.dllearner.core; -import java.util.Set; - -import org.dllearner.core.owl.Individual; - /** * The score class is used to store how well a class description did - * on a learning problem. + * on a learning problem. Depending on the learning problem at hand, + * different criteria can be used. (Similar learning problems probably + * score class descriptions/hypothesis in a similar way.) * - * TODO: If possible this class should be abstracted further. The current - * implementation requires positive and negative examples, i.e. does not - * allow arbitrary learning problems. - * * @author Jens Lehmann * */ public abstract class Score { - - // accuracy - public abstract double getAccuracy(); - - // example coverage - public abstract Set<Individual> getCoveredPositives(); - public abstract Set<Individual> getCoveredNegatives(); - public abstract Set<Individual> getNotCoveredPositives(); - public abstract Set<Individual> getNotCoveredNegatives(); - - // older methods (not frequently used anymore) - public abstract double getScore(); + /** - * The score of a concept depends on how good it classifies the - * examples of a learning problem and the length of the concept - * itself. If a given concept is known to have equal classification - * properties than the concept this score object is based on, then - * this method can be used to calculate its score value by using the - * length of this concept as parameter. + * This method returns a value, which indicates how well a + * class description solves a learning problem. Different implementations + * of scoring systems can implement this differently. Higher values + * are better and it is recommended to assign a score value in + * the closed interval from 0 to 1 if possible. * - * @param newLength Length of the concept. - * @return Score. + * @return A value indicating the quality (of a class description). */ - public abstract Score getModifiedLengthScore(int newLength); + public abstract double getScoreValue(); } Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2009-02-09 12:39:09 UTC (rev 1590) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2009-02-09 16:41:44 UTC (rev 1591) @@ -48,6 +48,7 @@ import javax.swing.*; +import org.dllearner.algorithms.EvaluatedDescriptionPosNeg; import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.core.EvaluatedDescription; import org.dllearner.learningproblems.PosNegDefinitionLP; @@ -377,12 +378,12 @@ gbc.weighty = wy; } - private String getSolutionString(List<EvaluatedDescription> solutions) { + private String getSolutionString(List<? extends EvaluatedDescription> solutions) { String baseURI = config.getReasoner().getBaseURI(); Map<String,String> prefixes = conf... [truncated message content] |