📄 svmcplex.java
字号:
} /** Check whether the SVM has been trained * @return true if the SVM has been train and is ready to classify instances */ public boolean trained() { return m_svmTrained; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector newVector = new Vector(2); newVector.addElement(new Option( "\tOutput debug information", "D", 0, "-D")); return newVector.elements(); } /** * Parses a given list of options. Valid options are:<p> * * -D <br> * output debugging information <p> * * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setDebug(Utils.getFlag('D', options)); String verbosityString = Utils.getOption('v', options); if (verbosityString.length() != 0) { setVerbosityLevel(Integer.parseInt(verbosityString)); } if (Utils.getFlag('A', options)) { setAutoBounds(true); } else { String minMarginString = Utils.getOption('n', options); if (minMarginString.length() != 0) { setMinMargin(Double.parseDouble(minMarginString)); } String maxMarginString = Utils.getOption('m', options); if (maxMarginString.length() != 0) { setMaxMargin(Double.parseDouble(maxMarginString)); } } String cString = Utils.getOption('c', options); if (cString.length() != 0) { setC(Double.parseDouble(cString)); } if (Utils.getFlag('F', options)) { setUseAllFeaturesExample(true); } // kernel-type related options if (Utils.getFlag('L', options)) { setKernelType(new SelectedTag(KERNEL_LINEAR, TAGS_KERNEL_TYPE)); } else if (Utils.getFlag('O', options)) { setKernelType(new SelectedTag(KERNEL_POLYNOMIAL, TAGS_KERNEL_TYPE)); String dString = Utils.getOption('d', options); if (dString.length() != 0) { setD(Integer.parseInt(dString)); } String sString = Utils.getOption('s', options); if (sString.length() != 0) { setS(Double.parseDouble(sString)); } String c1String = Utils.getOption('r', options); if (c1String.length() != 0) { setC1(Double.parseDouble(c1String)); } } else if (Utils.getFlag('B', options)) { setKernelType(new SelectedTag(KERNEL_RBF, TAGS_KERNEL_TYPE)); String gammaString = Utils.getOption('g', options); if (gammaString.length() != 0) { setC1(Double.parseDouble(gammaString)); } } Utils.checkForRemainingOptions(options); } /** * Gets the current settings * * @return an array of strings suitable for passing to setOptions() */ public String [] getOptions() { String [] options = new String [20]; int current = 0; if (m_debug) { options[current++] = "-D"; } options[current++] = "-v"; options[current++] = "" + m_verbosityLevel; if (m_autoBounds) { options[current++] = "-A"; } else { options[current++] = "-n"; options[current++] = "" + m_minMargin; options[current++] = "-m"; options[current++] = "" + m_maxMargin; } options[current++] = "-c"; options[current++] = "" + m_C; if (m_useAllFeaturesExample) { options[current++] = "-F"; } switch (m_kernelType) { case KERNEL_LINEAR: options[current++] = "-L"; break; case KERNEL_POLYNOMIAL: options[current++] = "-O"; options[current++] = "-d"; options[current++] = "" + m_d; options[current++] = "-s"; options[current++] = "" + m_s; options[current++] = "-r"; options[current++] = "" + m_c1; break; case KERNEL_RBF: options[current++] = "-B"; options[current++] = "-g"; options[current++] = "" + m_gamma; break; default: System.err.println("UNKNOWN KERNEL TYPE: " + m_kernelType); } while (current < options.length) { options[current++] = ""; } return options; } /** Turn debugging output on/off * @param debug if true, SVM-light output and other debugging info will be printed */ public void setDebug(boolean debug) { m_debug = debug; } /** See whether debugging output is on/off * @returns if true, SVM-light output and other debugging info will be printed */ public boolean getDebug() { return m_debug; } /** Set SVM-light to operate via in/out bufffers or via temporary files * @param bufferedMode if true, SVM-light classification is performed via stdin/stdout */ public void setBufferedMode(boolean bufferedMode) { m_bufferedMode = bufferedMode; } /** See whether SVM-light is operating via in/out bufffers or via temporary files * @returns if true, SVM-light classification is performed via stdin/stdout */ public boolean getBufferedMode() { return m_bufferedMode; } /** Set verbosity level, can be anything between 0 and 3 * @param verbosity Verbosity level for SVM-light */ public void setVerbosityLevel(int verbosity) { m_verbosityLevel = verbosity; } /** Get verbosity level, can be anything between 0 and 3 * @param verbosity Verbosity level for SVM-light */ public int getVerbosityLevel() { return m_verbosityLevel; } /** Set the trade-off between training error and margin (default 0 corresponds to [avg. x*x]^-1) */ public void setC(double C) { m_C = C; } /** Get the trade-off between training error and margin (default 0 corresponds to [avg. x*x]^-1) */ public double getC() { return m_C; } /** Set the kernel type for SVM-light * @param type one of the kernel types */ public void setKernelType(SelectedTag kernelType) { if (kernelType.getTags() == TAGS_KERNEL_TYPE) { m_kernelType = kernelType.getSelectedTag().getID(); } } /** Get the SVM-light kernel type * @return kernel type */ public SelectedTag getKernelType() { return new SelectedTag(m_kernelType, TAGS_KERNEL_TYPE); } /** Set parameter d in polynomial kernel */ public void setD(int d) { m_d = d; } /** Get parameter d in polynomial kernel */ public int getD() { return m_d; } /** Set parameter gamma in rbf kernel */ public void setGamma(double gamma) { m_gamma = gamma; } /** Get parameter gamma in rbf kernel */ public double getGamma() { return m_gamma; } /** Set parameter s in sigmoid/polynomial kernel */ public void setS(double s) { m_s = s; } /** Get parameter s in sigmoid/polynomial kernel */ public double getS() { return m_s; } /** Set parameter c in sigmoid/poly kernel */ public void setC1(double c1) { m_c1 = c1; } /** Get parameter c in sigmoid/poly kernel */ public double getC1() { return m_c1; } /** Set the maxMargin that an SVM can return */ public void setMaxMargin(double maxMargin) { m_maxMargin = maxMargin; } /** Get the maxMargin that an SVM can return */ public double getMaxMargin() { return m_maxMargin; } /** Set the minMargin that an SVM can return */ public void setMinMargin(double minMargin) { m_minMargin = minMargin; } /** Get the minMargin that an SVM can return */ public double getMinMargin() { return m_minMargin; } /** Set whether min/max margins are determined automatically */ public void setAutoBounds(boolean autoBounds) { m_autoBounds = autoBounds; } /** Get whether min/max margins are determined automatically */ public boolean getAutoBounds() { return m_autoBounds; } /** The useAllFeaturesExample option */ public void setUseAllFeaturesExample(boolean use) { m_useAllFeaturesExample = use; } public boolean getUseAllFeaturesExample() { return m_useAllFeaturesExample; } /** * Returns a description of this classifier. * * @return a description of this classifier as a string. */ public String toString() { if (m_train == null) { return "SVMcplex: No model built yet."; } String result = "SVM-light classifier\n"; return result; } /** A little helper to create a single String from an array of Strings * @param strings an array of strings * @returns a single concatenated string, separated by commas */ public static String concatStringArray(String[] strings) { String result = new String(); for (int i = 0; i < strings.length; i++) { result = result + "\"" + strings[i] + "\" "; } return result; } /** * Main method for testing this class. * * @param argv should contain command line options (see setOptions) */ public static void main(String [] argv) { try { System.out.println(Evaluation.evaluateModel(new SVMcplex(), argv)); } catch (Exception e) { e.printStackTrace(); System.err.println(e.getMessage()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -