pt.tumba.ngram.svm
Class SVMCategorizer

java.lang.Object
  extended by pt.tumba.ngram.svm.SVMCategorizer

public class SVMCategorizer
extends java.lang.Object

Simple, easy-to-use, and efficient software for SVM classification and regression, based on the LIBSVM implementation of Chin-Chung Chang and Chin-Jen Lin. It can solve C-SVM classification, nu-SVM classification, one-class-SVM, epsilon-SVM regression, and nu-SVM regression. It also provides an automatic model selection tool for C-SVM classification, and multiclass classification through a "one-against-one" approach .

The original implementation was much less "object-oriented", and didn't follow the usual conventions for Java programs. Besides major code refactoring, additional functionalities were also added:


Field Summary
private  boolean crossValidation
           
private  java.lang.String errorMsg
           
private  java.lang.String inputFileName
           
protected  SVMModel model
          Description of the Field
private  java.lang.String modelFileName
           
protected  java.lang.String[] names
           
private  int nrFold
           
protected  SVMParameter param
           
protected  SVMProblem prob
           
protected  java.util.List sortedGrams
           
 
Constructor Summary
SVMCategorizer()
          Construct an uninitialized Cathegorizer.
SVMCategorizer(java.lang.String dirName)
          Construct an Cathegorizer from a whole Directory of resources.
SVMCategorizer(java.lang.String[] fileNames)
          Construct an Cathegorizer from a List of resource file names.
 
Method Summary
private  void doCrossValidation()
           
private static java.util.List exchangePos(java.util.List v, int p1, int p2)
          Exchange two values in a list
private static void exitWithHelp()
           
private  void init(java.io.File fi, java.lang.String[] names)
          Fetch the set of file resources.
static void main(java.lang.String[] argv)
          Sample application, like the text_cat main mode.
 java.lang.String match(java.io.File f)
           
private static void predict(java.io.BufferedReader input, java.io.DataOutputStream output, SVMModel model, int predict_probability)
           
private  void readProblem()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected SVMModel model
Description of the Field


param

protected SVMParameter param

prob

protected SVMProblem prob

names

protected java.lang.String[] names

sortedGrams

protected java.util.List sortedGrams

inputFileName

private java.lang.String inputFileName

modelFileName

private java.lang.String modelFileName

errorMsg

private java.lang.String errorMsg

crossValidation

private boolean crossValidation

nrFold

private int nrFold
Constructor Detail

SVMCategorizer

public SVMCategorizer()
Construct an uninitialized Cathegorizer.


SVMCategorizer

public SVMCategorizer(java.lang.String dirName)
               throws TCatNGException,
                      java.io.FileNotFoundException
Construct an Cathegorizer from a whole Directory of resources.

Parameters:
dirName - Description of the Parameter
Throws:
NGramException - Description of the Exception
java.io.FileNotFoundException - Description of the Exception
TCatNGException

SVMCategorizer

public SVMCategorizer(java.lang.String[] fileNames)
               throws TCatNGException,
                      java.io.FileNotFoundException
Construct an Cathegorizer from a List of resource file names.

Parameters:
fileNames - Description of the Parameter
Throws:
NGramException - Description of the Exception
java.io.FileNotFoundException - Description of the Exception
TCatNGException
Method Detail

init

private final void init(java.io.File fi,
                        java.lang.String[] names)
                 throws TCatNGException,
                        java.io.FileNotFoundException
Fetch the set of file resources.

Parameters:
fi - Description of the Parameter
names - Description of the Parameter
Throws:
NGramException - Description of the Exception
java.io.FileNotFoundException - Description of the Exception
TCatNGException

exchangePos

private static java.util.List exchangePos(java.util.List v,
                                          int p1,
                                          int p2)
Exchange two values in a list

Parameters:
v - The original list
p1 - The index of the first element
p2 - The index of the second element
Returns:
The list with the two elements exchanged

match

public java.lang.String match(java.io.File f)

main

public static void main(java.lang.String[] argv)
Sample application, like the text_cat main mode.

Parameters:
args - The command line arguments

predict

private static void predict(java.io.BufferedReader input,
                            java.io.DataOutputStream output,
                            SVMModel model,
                            int predict_probability)
                     throws java.io.IOException
Throws:
java.io.IOException

exitWithHelp

private static void exitWithHelp()

doCrossValidation

private void doCrossValidation()

readProblem

private void readProblem()
                  throws java.io.IOException
Throws:
java.io.IOException