From: <jen...@us...> - 2008-02-04 18:56:24
|
Revision: 490 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=490&view=rev Author: jenslehmann Date: 2008-02-04 10:56:10 -0800 (Mon, 04 Feb 2008) Log Message: ----------- started cross validator (not working yet) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-04 14:54:07 UTC (rev 489) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-04 18:56:10 UTC (rev 490) @@ -94,6 +94,10 @@ private static Logger logger = Logger.getRootLogger(); + private LearningAlgorithm la; + private LearningProblem lp; + private ReasoningService rs; + /** * Entry point for CLI interface. * @@ -101,12 +105,11 @@ */ public static void main(String[] args) { File file = new File(args[args.length - 1]); - String baseDir = file.getParentFile().getPath(); - + boolean inQueryMode = false; if (args.length > 1 && args[0].equals("-q")) inQueryMode = true; - + // create logger (a simple logger which outputs // its messages to the console) SimpleLayout layout = new SimpleLayout(); @@ -115,6 +118,17 @@ logger.addAppender(consoleAppender); logger.setLevel(Level.INFO); + Start start = new Start(file); + start.start(inQueryMode); + } + + /** + * Initialise all components based on conf file. + * @param file Conf file to read. + */ + public Start(File file) { + String baseDir = file.getParentFile().getPath(); + // create component manager instance System.out.print("starting component manager ... "); long cmStartTime = System.nanoTime(); @@ -161,12 +175,11 @@ ReasonerComponent reasoner = cm.reasoner(reasonerClass, sources); configureComponent(cm, reasoner, componentPrefixMapping, parser); initComponent(cm, reasoner); - ReasoningService rs = cm.reasoningService(reasoner); + rs = cm.reasoningService(reasoner); // step 3: detect learning problem ConfFileOption problemOption = parser.getConfOptionsByName("problem"); Class<? extends LearningProblem> lpClass = null; - LearningProblem lp = null; if (problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) lpClass = PosNegDefinitionLP.class; else if (problemOption.getStringValue().equals("posNegInclusion")) @@ -187,7 +200,6 @@ // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); - LearningAlgorithm la = null; Class<? extends LearningAlgorithm> laClass = null; if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; @@ -229,8 +241,10 @@ } // handle any CLI options - processCLIOptions(cm, parser, rs); - + processCLIOptions(cm, parser, rs); + } + + public void start(boolean inQueryMode) { if (inQueryMode) processQueryMode(lp, rs); else { @@ -240,10 +254,9 @@ long algDuration = System.nanoTime() - algStartTime; printConclusions(rs, algDuration); - } - + } } - + // creates a mapping from components to option prefix strings private static Map<Class<? extends Component>, String> createComponentPrefixMapping() { Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); @@ -693,4 +706,8 @@ System.exit(0); } + public LearningAlgorithm getLearningAlgorithm() { + return la; + } + } Added: trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-04 18:56:10 UTC (rev 490) @@ -0,0 +1,69 @@ +/** + * 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.utilities; + +import java.io.File; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.dllearner.cli.Start; +import org.dllearner.core.LearningAlgorithm; + +/** + * Performs cross validation for the given problem. + * + * @author Jens Lehmann + * + */ +public class CrossValidation { + + private static Logger logger = Logger.getRootLogger(); + + public static void main(String[] args) { + File file = new File(args[0]); + + int folds = 10; + if(args.length > 1) + folds = Integer.parseInt(args[1]); + + // create logger (a simple logger which outputs + // its messages to the console) + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.INFO); + + new CrossValidation(file, folds); + + } + + public CrossValidation(File file, int folds) { + Start start = new Start(file); + LearningAlgorithm la = start.getLearningAlgorithm(); + + for(int currFold=0; currFold<folds; currFold++) { + la.start(); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |