⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configuration.java

📁 Boosting算法软件包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package jboost.controller;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.IOException;import java.util.HashMap;import java.util.Iterator;import java.util.Set;import java.util.StringTokenizer;import java.util.Vector;import jboost.monitor.Monitor;import jboost.util.FileLoader;/** * This class provides the utilities for parsing the command line which * specifies the setting of the options in the different packages. *  * <p> * The syntax of the command line is as follows * <ul> * <li>A list of options seperated by spaces * <li>each option consists of a name and an (optional) value. seperated by * spaces * <li>the name (flag) is of the form -[a-zA-Z]\m_w* As a standard, we suggest * that options that are associated with a particular package are of the form * "\s*_\s*" where the first string is the name of the package and the second * identifies the particular option. * <li>the value can be either empty, a number, a string , or a sequence of * numbers or strings seperated by commas. The value cannot start with a * "-\m_w" * </ul> * <p> * The option to specify the configuration file is CONFIG. Options have the * following precedence: command line, environment, configuration file. * <p> * All arguments to the software will be accessed through this class. * <p> * For example: * <p>// Construct a Configuration in the Controller * <p> * Configuration p=new Configuration("jboost.man"); // Specifies the man file. * <p> * p.parseArgv(argv); // Parse the command line * <p> * p.parseCommandFile("jboost.config"); // Parse the configuration file. * <p> * * @author Nigel Duffy (parts rewritten by Aaron Arvey) */public class Configuration {        private HashMap m_parsedCommands;    private Vector m_validCommands;    private String m_unSpecified;    public final static String VERSION="1.4";     private final static String m_usage = ""	+ "jboost Version " + VERSION + "\n"	+ "\n"	+ "** Config Options:\n"	+ "\n"	+ "\t-p N       Specify number of threads (default: 1)\n"	+ "\t-CONFIG    The name of the configuration file (default \"jboost.config\")\n"	+ "\t           All options can be specified in this file instead of\n"	+ "\t           on the command line.\n"	+ "\t-V         Print version and exit\n"	+ "\n"	+ "** Data File Options:\n"	+ "\n"	+ "\t-S stem        Base (stem) name for the files (default: \"data\")\n"	+ "\t-n file.spec   Specfile name (default: stem+\".spec\")\n" 		+ "\t-t file.train  Training file name (default: stem+\".train\")\n"	+ "\t-T file.test   Test file name (default: stem+\".test\")\n"	+ "\t-serialTreeInput file.tree    Java object output of adtree (can be loaded\n"	+ "\t                              at a later date)\n"	+ "\n"	+ "** Boosting Options:\n"	+ "\n"	+ "\t-b type   The type of booster to use (default: AdaBoost).\n"	+ "\t          AdaBoost     Loss function: exp(-margin)\n"	+ "\t          LogLossBoost Loss: log(1 + exp(-margin))\n"	+ "\t          BrownBoost   Loss: 1/2 - 1/2 * erf((-margin + time_remaining)\n"	+ "\t                                             / sqrt(total_time))\n"	+ "\t          YabaBoost    Loss: see documentation (it's a tad complicated...).\n"	+ "\t-numRounds N  The number of rounds of boosting that are to be executed.\n"	+ "\t              This option should be used with AdaBoost and LogitBoost\n"	+ "\t-ATreeType type   The type of ATree to create.  There are several options:\n"	+ "\t                  ADD_ALL               Create a full ADTree (default)\n"        + "\t                  ADD_ROOT              Add splits only at the root producing a glat tree.\n"	+ "\t                                        This is equivalent to boosting decision stumps\n"	+ "\t                  ADD_SINGLES           Create a decision tree\n"	+ "\t                  ADD_ROOT_OR_SINGLES   Create a linear combination of decision trees.\n"		+ "\t                                        This is equivalent to simultaneously growing \n"	+ "\t                                        boosted decision trees.\n"		+ "\t-BoosTexter	   Only make a zero prediction at the root node.\n"	+ "\t-booster_smooth sf   Smoothing factor for prediction computation (default: 0.5)\n"	+ "\t                     Described Shapire & Singer 1999 (smoothing the predictions), \n"	+ "\t                     $epsilon = sf / total_num_examples$  \n"	+ "\t-booster_paranoid Use safe version of booster (default: false)\n"	+ "\n"	+ "******** BrownBoost Options:\n"	+ "\n"	+ "\t\t-r c  The \"runtime\" of the boosting game.\n"	+ "\t\t      This option should be used with BrownBoost and YabaBoost\n"	+ "\t\t-potential  Prints the potential associated with the runtime\n"	+ "\n"	+ "******** YabaBoost Options (includes BrownBoost options):\n"	+ "\n"	+ "\t\t-c1    NUM  See documentation.\n"	+ "\t\t-c2    NUM  See documentation.\n"	+ "\t\t-theta NUM  See documentation.\n"	+ "\n"	+ "** Output Options:\n"	+ "\n"	+ "\t-O file.tree   Output tree file name (default: stem+\".output.tree\")\n"	+ "\t-serialTreeOutput file.tree   Java object output of adtree (can be loaded\n"	+ "\t                              at a later date)\n"	+ "\t-j filename    Output java code file name (default: stem+\".output.java\"\n"	+ "\t-c filename    Output C code file name (default: stem+\".output.c\")\n" 	+ "\t-m filename    Output matlab code file name (default: stem+\".output.java\"\n"	+ "\t-cOutputProc name  Name of procedure for output C code (default: 'predict')\n"	+ "\t-javaStandAlone    Output java code that can stand alone, but\n" 	+ "\t                   cannot read jboost-format data\n"	+ "\t-javaOutputClass name     Name of class for output java code (default: 'Predict')\n"	+ "\t-javaOutputMethod name    Name of method for output java code (default: 'predict')\n"	+ "\n"	+ "** Logging Options:\n"	+ "\n"    	+ "\t-info filename      High-level log file name (default: stem+\".info\")\n"	+ "\t-log  filename      Debugging log (default stem+\".log\")\n"	+ "\t-loglevel N   Amount of information to be output to log \n"	+ "\t              The larger N is, the more information will be output.\n"	+ "\t              This is meant to be used as a debugging tool.\n"	+ "\t-a iter      Generate margin (score) logs \n"	+ "\t             iter>0   log only on iteration iter,\n"	+ "\t             iter=-1  log on iters 1,2..9,10,20,...,90,100,200 ...)\n"	+ "\t             iter=-2  log on all iterations\n";           /**     * Constructor - takes no parameters, requiring the list of options to be     * filled later     */    public Configuration() {	m_parsedCommands= new HashMap(20);	m_validCommands= new Vector(20);	m_unSpecified= new String();    }    /**     * Default Constructor - parses the command line and gets parameters from the     * default configuration file "jboost.config" unless an alternative is     * specified in -CONFIG     *      * @param Name of the man page file     * @param list of arguments from the command line     */    public Configuration(String manfile, String[] argv)	throws IOException, BadCommandException {	m_parsedCommands= new HashMap(20);	m_validCommands= new Vector(20);	m_unSpecified= new String();	String tmp= null;	parseArgv(argv);	String commandfile= getString("CONFIG", "jboost.config");	parseCommandFile(commandfile);    }    /** Print m_usage message */    public void printUsage() {	System.out.print(m_usage);	if (Monitor.logLevel > 3) {	    Monitor.log(m_usage);	}    }    /** Print out all parsed commands that this configuration currently contains. */    public String toString() {	String retval= new String();	Set commands= m_parsedCommands.keySet();	for (Iterator iter= commands.iterator(); iter.hasNext(); ) {	    String option= (String) iter.next();	    retval += option + " = " + m_parsedCommands.get(option) + "\n";	}	return retval;    }      /**     * Parse the list of arguments given on the command line     * @param argv the array containing the parameters for this configuration      */    public void parseArgv(String[] argv) throws BadCommandException {	int i= 0;	String command= null;	if (argv != null) {	    String args= "";	    for (i= 0; i < argv.length; i++) {		if (argv[i].charAt(0) != '-') {		    throw (new BadCommandException("Flag does not start with '-': " + argv[i]));		}        		if (!Character.isLetter(argv[i].charAt(1))) {		    throw (new BadCommandException("Name does not start with a letter: " + argv[i]));		}        		/** What if value is empty? */		if ((i + 1) >= argv.length || (argv[i + 1].charAt(0) == '-'					       && Character.isLetter(argv[i + 1].charAt(1)))) {		    command= argv[i].substring(1);		    m_parsedCommands.put(command, "true");		} else {		    /** else the value is not empty */		    command= argv[i].substring(1);		    m_parsedCommands.put(command,argv[i+1]);		    i++;		}		args= args + " " + argv[i];	    }	    addOption("args", args);	}    }    /**     * Parse a string tokenizer that provides arguments in the same     *      * @param st     */    public void parseStringTokenizer(StringTokenizer st)	throws BadCommandException {	String[] args= new String[st.countTokens()];	int i= 0;	while (st.hasMoreTokens()) {	    args[i]= st.nextToken();	    System.out.println(args[i]);	    i++;	}	parseArgv(args);    }        /**      * Parse a string that contains arguments in the same form as a command line     * @param command       */    public void parseCommandString(String command) throws BadCommandException {	parseStringTokenizer(new StringTokenizer(command));    }    /**     * Parse a file of strings that contain arguments in the same form as a     * command line     *      * @param filename containing configuration info     */    public void parseCommandFile(String filename)	throws IOException, BadCommandException {	String tmp= null;	BufferedReader f= null;	try {	    //      Class c= this.getClass();	    f= new BufferedReader(FileLoader.createFileReader(filename));	    if (f == null) {		throw new FileNotFoundException();	    }	} catch (FileNotFoundException e) {	    String s="WARNING: configuration file " + filename + " not found.  Continuing...";	    System.err.println(s);	    return;	}	tmp= f.readLine();	while (tmp != null) {	    parseCommandString(tmp);	    tmp= f.readLine();	}    }    /* service methods */    /**     * Returns the integer value corresponding to an option name or the def value     * If the name is not contained in the parsedCommands, then returl the     * default value, after updating the list of unspecified configuration options.     *      * @return retval the value of the configuration parameter     */    public int getInt(String name, int def) {	String v= null;	int retval= def;	if (m_parsedCommands.containsKey(name)) {	    try {		v= (String) m_parsedCommands.get(name);		retval= Integer.parseInt(v);	    } catch (NumberFormatException e) {		if (Monitor.logLevel > 3)		    Monitor.log("Error Parsing Option: " + v);	    }	} else {	    m_unSpecified += name + ",";	}	return (retval);    }    /**     * Returns the double value corresponding to an option name or the def value     * If the name is not contained in the parsedCommands, then returl the     * default value, after updating the list of unspecified configuration options.     * @param name of the option     * @param def default value if option name is not found     * @return retval the value of the configuration parameter     */    public double getDouble(String name, double def) {	String v= null;	double retval= def;	if (m_parsedCommands.containsKey(name)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -