All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class jsvm.Svm

java.lang.Object
    |
    +----jsvm.Svm

public class Svm
extends Object
A Java wrapper for Thorsten Joachims's SVM(light) package. Provides a high-level native interface to invoke C implementations of SVM algorithm.

Version:
$Id$
Author:
Heloise Hse (hwawen@eecs.berkeley.edu)
Author:
Michael Shilman (michaels@eecs.berkeley.edu)

Variable Index

 o DEBUG_MESSAGES
SVM-Light kernel prints full debug information.
 o LINEAR_KERNEL
Basic linear kernel type.
 o NUM_KERNEL_TYPES
The nubmer of kernel types.
 o NUM_MESSAGE_TYPES
The number of verbosity levels.
 o POLYNOMIAL_KERNEL
Polynomial kernel: (a*b+1)^d
 o QUIET_MESSAGES
SVM-Light kernel prints minimal messages.
 o RADIAL_BASIS_KERNEL
Radial basis function: exp(-gamma ||a-b||^2)
 o SIGMOID_KERNEL
Sigmoid kernel: tanh(s a*b + c)
 o SILENT_MESSAGES
SVM-Light kernel prints no messages at all.
 o USER_KERNEL
User defined kernel from kernel.h
 o VERBOSE_MESSAGES
SVM-Light kernel prints standard messages.

Constructor Index

 o Svm()
Class constructor.

Method Index

 o buildModels(TrainingSet)
Builds a set of models based on the training data in C.
 o classify(FeatureSet)
Classifies this feature set based on the current model.
 o classify(TrainingSet)
Classifies test examples, returns the predictions, and calculates the accuracy of the classification.
 o classify(TrainingType)
Classifies test examples, returns the predictions, and calculates the accuracy of the classification.
 o classify(Vector)
Classifies test examples and returns the predictions.
 o getID()
Gets the ID for this Svm object.
 o getVerbosityLevel()
Gets the current verbosity level.
 o loadModels(InputStream)
Loads and builds model data structures for classifiers in C.

 o loadTrainingData(InputStream, boolean)
Loads training data.
 o readLabeledTestCases(InputStream)
Reads labeled test cases from input stream.
 o readOrigLabeledTestCases(InputStream)
Reads labeled test cases from input stream.
 o readTestCases(InputStream)
Reads unlabeled test cases from input stream.
 o removeModels()
Removes existing model data structures in C.
 o setEpsilon(double)
eps: Allow that error when fitting constraints y [w*x+b] >= 1-eps (default 0.001)
 o setKernelType(long)
Sets the kernel function type.
 o setMaxKernelCacheSize(long)
Sets the size of the cache for kernel evaluations (default 1000)
 o setMaxQPSize(long)
Sets the maximum size of QP-subproblems (default 50)
 o setPolyD(double)
Sets the parameter d in polynomial kernel.
 o setRbfG(double)
Sets the parameter gamma in rbf kernel.
 o setRemoveInconsistent(boolean)
Removes inconsistent training examples and retrain (default 1)
 o setSigmoidC(double)
Sets the parameter c in sigmoid kernel.
 o setSigmoidS(double)
Sets the parameter s in sigmoid kernel.
 o setTradeOffErrorAndMargin(double)
Sets the trade-off between training error and margin (default 1000)
 o setUserDefinedKernel(String)
Sets the parameter of user defined kernel.
 o setVerbosityLevel(int)
Verbosity level.
 o writeModels(OutputStream)
Writes out model text representation to the output stream.

 o writePredictions(OutputStream, Vector)
Writes the prediction results to an output stream.

Variables

 o SILENT_MESSAGES
public static int SILENT_MESSAGES
SVM-Light kernel prints no messages at all.

 o QUIET_MESSAGES
public static int QUIET_MESSAGES
SVM-Light kernel prints minimal messages.

 o VERBOSE_MESSAGES
public static int VERBOSE_MESSAGES
SVM-Light kernel prints standard messages.

 o DEBUG_MESSAGES
public static int DEBUG_MESSAGES
SVM-Light kernel prints full debug information.

 o NUM_MESSAGE_TYPES
public static int NUM_MESSAGE_TYPES
The number of verbosity levels.

 o LINEAR_KERNEL
public static final int LINEAR_KERNEL
Basic linear kernel type.

 o POLYNOMIAL_KERNEL
public static final int POLYNOMIAL_KERNEL
Polynomial kernel: (a*b+1)^d

 o RADIAL_BASIS_KERNEL
public static final int RADIAL_BASIS_KERNEL
Radial basis function: exp(-gamma ||a-b||^2)

 o SIGMOID_KERNEL
public static final int SIGMOID_KERNEL
Sigmoid kernel: tanh(s a*b + c)

 o USER_KERNEL
public static final int USER_KERNEL
User defined kernel from kernel.h

 o NUM_KERNEL_TYPES
public static final int NUM_KERNEL_TYPES
The nubmer of kernel types.

Constructors

 o Svm
public Svm()
Class constructor.

Methods

 o getID
public long getID()
Gets the ID for this Svm object.

Returns:
the ID for this Svm object.
 o removeModels
public void removeModels()
Removes existing model data structures in C.

 o loadTrainingData
public static TrainingSet loadTrainingData(InputStream in,
                                           boolean isNew) throws IOException
Loads training data. Builds data structure on Java side.

Parameters:
in - The inputstream containing the training data.
isNew - Identifies which parser to use. If the data file name has extension, .ntr, set isNew to true. If the extension is .trn, set isNew to false.
Returns:
The training data structure.
Throws: IOException
If an IO error occured.
 o buildModels
public void buildModels(TrainingSet set) throws SvmException
Builds a set of models based on the training data in C. Calls native methods to allocate memory, and initialize and train on the examples.

Parameters:
set - The data to be trained on.
Throws: SvmException
If models already exist or if there are not training data.
 o writeModels
public void writeModels(OutputStream out) throws SvmException, IOException
Writes out model text representation to the output stream.

Parameters:
out - The output stream of which the model is written out to.
Throws: SvmException
If models do not exist.
Throws: IOException
If an IO error occured.
 o loadModels
public void loadModels(InputStream in) throws SvmException, IOException
Loads and builds model data structures for classifiers in C.

Parameters:
in - The input stream containing model data.
Throws: SvmException
If models already exist in the system.
Throws: IOException
If an IO error occured.

Another alternative is to parse and build models on Java side, and then transfer the data structure over to the native side. However, we want to minimize the amount of data transferring between Java and native code in order to maintain the efficiency of the program. Therefore, we choose to transfer a byte array and perform data processing using native implementation.

 o classify
public ClassificationSet classify(FeatureSet s) throws SvmException
Classifies this feature set based on the current model. (Note that this implies that there is a current model; the user must have called buildModels() or loadModels() beforehand).

Parameters:
s - The example to be classified.
Returns:
An enumeration of Classification objects, in order of highest confidence to lowest confidence.
Throws: SvmException
If there's no model to do the classification.
 o classify
public Vector classify(Vector examples) throws SvmException
Classifies test examples and returns the predictions.

Parameters:
examples - A vector of FeatureSet items, each of which defines a test case.
Returns:
A vector of ClassificationSet elements, each of which contains the confidence values for an example.
Throws: SvmException
If there's no model to do the classification.
 o classify
public Vector classify(TrainingSet set) throws SvmException
Classifies test examples, returns the predictions, and calculates the accuracy of the classification.

Parameters:
set - Examples from a set of classes.
Returns:
A vector of ClassificationSet elements, each of which contains the confidence values for an example.
Throws: SvmException
If there's no model to do the classification.
 o classify
public Vector classify(TrainingType type) throws SvmException
Classifies test examples, returns the predictions, and calculates the accuracy of the classification.

Parameters:
type - A set of examples from class type.
Returns:
A vector of ClassificationSet elements, each of which contains the confidence values for an example.
Throws: SvmException
If there's no model to do the classification.
 o readOrigLabeledTestCases
public static TrainingType readOrigLabeledTestCases(InputStream in) throws IOException
Reads labeled test cases from input stream. Parses and builds data structure.

Reads from .lts files.

Parameters:
in - The input stream containing test examples.
Returns:
A TrainingType data structure containing the test cases with labels for a class.
Throws: IOException
If an IO error occured.
 o readLabeledTestCases
public static TrainingSet readLabeledTestCases(InputStream in) throws IOException
Reads labeled test cases from input stream. Parses and builds data structure.

Reads from .ntr files.

Parameters:
in - The input stream containing test examples.
Returns:
A TrainingSet data structure containing the test cases with labels for multiple classes.
Throws: IOException
If an IO error occured.
 o readTestCases
public static Vector readTestCases(InputStream in) throws IOException
Reads unlabeled test cases from input stream. Parses and builds data structure.

Reads from .tst files.

Parameters:
in - The input stream containing test examples.
Returns:
A vector of FeatureSet elements, each of which defines a test case.
Throws: IOException
If an IO error occured.
 o writePredictions
public static void writePredictions(OutputStream out,
                                    Vector results) throws IOException
Writes the prediction results to an output stream.

Parameters:
out - The output stream to write to.
results - A vector of predictions of type ClassificationSet.
Throws: IOException
If an IO error occured.
 o setVerbosityLevel
public void setVerbosityLevel(int i)
Verbosity level. Options include SILENT_MESSAGES, QUIET_MESSAGES, VERBOSE_MESSAGES, DEBUG_MESSAGES.

 o getVerbosityLevel
public int getVerbosityLevel()
Gets the current verbosity level.

Returns:
The current verbosity level.
 o setRemoveInconsistent
public void setRemoveInconsistent(boolean val)
Removes inconsistent training examples and retrain (default 1)

 o setMaxQPSize
public void setMaxQPSize(long l)
Sets the maximum size of QP-subproblems (default 50)

 o setMaxKernelCacheSize
public void setMaxKernelCacheSize(long l)
Sets the size of the cache for kernel evaluations (default 1000)

 o setTradeOffErrorAndMargin
public void setTradeOffErrorAndMargin(double d)
Sets the trade-off between training error and margin (default 1000)

 o setEpsilon
public void setEpsilon(double d)
eps: Allow that error when fitting constraints y [w*x+b] >= 1-eps (default 0.001)

 o setKernelType
public void setKernelType(long l)
Sets the kernel function type. Types include LINEAR_KERNEL, POLYNOMIAL_KERNEL, RADIAL_BASIS_KERNEL, SIGMOID_KERNEL, USER_KERNEL.

 o setPolyD
public void setPolyD(double l)
Sets the parameter d in polynomial kernel.

 o setRbfG
public void setRbfG(double d)
Sets the parameter gamma in rbf kernel.

 o setSigmoidS
public void setSigmoidS(double d)
Sets the parameter s in sigmoid kernel.

 o setSigmoidC
public void setSigmoidC(double d)
Sets the parameter c in sigmoid kernel.

 o setUserDefinedKernel
public void setUserDefinedKernel(String s)
Sets the parameter of user defined kernel.


All Packages  Class Hierarchy  This Package  Previous  Next  Index