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)
-
DEBUG_MESSAGES
- SVM-Light kernel prints full debug information.
-
LINEAR_KERNEL
- Basic linear kernel type.
-
NUM_KERNEL_TYPES
- The nubmer of kernel types.
-
NUM_MESSAGE_TYPES
- The number of verbosity levels.
-
POLYNOMIAL_KERNEL
- Polynomial kernel: (a*b+1)^d
-
QUIET_MESSAGES
- SVM-Light kernel prints minimal messages.
-
RADIAL_BASIS_KERNEL
- Radial basis function: exp(-gamma ||a-b||^2)
-
SIGMOID_KERNEL
- Sigmoid kernel: tanh(s a*b + c)
-
SILENT_MESSAGES
- SVM-Light kernel prints no messages at all.
-
USER_KERNEL
- User defined kernel from kernel.h
-
VERBOSE_MESSAGES
- SVM-Light kernel prints standard messages.
-
Svm()
- Class constructor.
-
buildModels(TrainingSet)
- Builds a set of models based on the training data in C.
-
classify(FeatureSet)
- Classifies this feature set based on the current
model.
-
classify(TrainingSet)
- Classifies test examples, returns the predictions, and calculates
the accuracy of the classification.
-
classify(TrainingType)
- Classifies test examples, returns the predictions, and calculates
the accuracy of the classification.
-
classify(Vector)
- Classifies test examples and returns the predictions.
-
getID()
- Gets the ID for this
Svm
object.
-
getVerbosityLevel()
- Gets the current verbosity level.
-
loadModels(InputStream)
- Loads and builds model data structures for classifiers in C.
- Reads classifier models from input stream.
- Forms a byte array.
- Sends the byte array to C.
- Reads data from the array and builds data structure in C.
-
loadTrainingData(InputStream, boolean)
- Loads training data.
-
readLabeledTestCases(InputStream)
- Reads labeled test cases from input stream.
-
readOrigLabeledTestCases(InputStream)
- Reads labeled test cases from input stream.
-
readTestCases(InputStream)
- Reads unlabeled test cases from input stream.
-
removeModels()
- Removes existing model data structures in C.
-
setEpsilon(double)
- eps: Allow that error when fitting constraints
y [w*x+b] >= 1-eps (default 0.001)
-
setKernelType(long)
- Sets the kernel function type.
-
setMaxKernelCacheSize(long)
- Sets the size of the cache for kernel evaluations (default 1000)
-
setMaxQPSize(long)
- Sets the maximum size of QP-subproblems (default 50)
-
setPolyD(double)
- Sets the parameter d in polynomial kernel.
-
setRbfG(double)
- Sets the parameter gamma in rbf kernel.
-
setRemoveInconsistent(boolean)
- Removes inconsistent training examples and retrain (default 1)
-
setSigmoidC(double)
- Sets the parameter c in sigmoid kernel.
-
setSigmoidS(double)
- Sets the parameter s in sigmoid kernel.
-
setTradeOffErrorAndMargin(double)
- Sets the trade-off between training error and margin (default 1000)
-
setUserDefinedKernel(String)
- Sets the parameter of user defined kernel.
-
setVerbosityLevel(int)
- Verbosity level.
-
writeModels(OutputStream)
- Writes out model text representation to the output stream.
- Constructs byte stream from the model data structure in C.
- Transfers the byte stream to Java.
- Writes it to output stream.
-
writePredictions(OutputStream, Vector)
- Writes the prediction results to an output stream.
SILENT_MESSAGES
public static int SILENT_MESSAGES
- SVM-Light kernel prints no messages at all.
QUIET_MESSAGES
public static int QUIET_MESSAGES
- SVM-Light kernel prints minimal messages.
VERBOSE_MESSAGES
public static int VERBOSE_MESSAGES
- SVM-Light kernel prints standard messages.
DEBUG_MESSAGES
public static int DEBUG_MESSAGES
- SVM-Light kernel prints full debug information.
NUM_MESSAGE_TYPES
public static int NUM_MESSAGE_TYPES
- The number of verbosity levels.
LINEAR_KERNEL
public static final int LINEAR_KERNEL
- Basic linear kernel type.
POLYNOMIAL_KERNEL
public static final int POLYNOMIAL_KERNEL
- Polynomial kernel: (a*b+1)^d
RADIAL_BASIS_KERNEL
public static final int RADIAL_BASIS_KERNEL
- Radial basis function: exp(-gamma ||a-b||^2)
SIGMOID_KERNEL
public static final int SIGMOID_KERNEL
- Sigmoid kernel: tanh(s a*b + c)
USER_KERNEL
public static final int USER_KERNEL
- User defined kernel from kernel.h
NUM_KERNEL_TYPES
public static final int NUM_KERNEL_TYPES
- The nubmer of kernel types.
Svm
public Svm()
- Class constructor.
getID
public long getID()
- Gets the ID for this
Svm
object.
- Returns:
- the ID for this Svm object.
removeModels
public void removeModels()
- Removes existing model data structures in C.
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.
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.
- Allocates memory for classes.
- Initializes classes.
- Calls svm_learn to train on the data and build the models.
- Removes the training data in C, because it will no longer be used.
- Parameters:
- set - The data to be trained on.
- Throws:
SvmException
- If models already exist or
if there are not training data.
writeModels
public void writeModels(OutputStream out) throws SvmException, IOException
- Writes out model text representation to the output stream.
- Constructs byte stream from the model data structure in C.
- Transfers the byte stream to Java.
- Writes it to 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.
loadModels
public void loadModels(InputStream in) throws SvmException, IOException
- Loads and builds model data structures for classifiers in C.
- Reads classifier models from input stream.
- Forms a byte array.
- Sends the byte array to C.
- Reads data from the array and builds data structure 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.
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.
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.
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.
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.
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.
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.
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.
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.
setVerbosityLevel
public void setVerbosityLevel(int i)
- Verbosity level. Options include SILENT_MESSAGES,
QUIET_MESSAGES, VERBOSE_MESSAGES, DEBUG_MESSAGES.
getVerbosityLevel
public int getVerbosityLevel()
- Gets the current verbosity level.
- Returns:
- The current verbosity level.
setRemoveInconsistent
public void setRemoveInconsistent(boolean val)
- Removes inconsistent training examples and retrain (default 1)
setMaxQPSize
public void setMaxQPSize(long l)
- Sets the maximum size of QP-subproblems (default 50)
setMaxKernelCacheSize
public void setMaxKernelCacheSize(long l)
- Sets the size of the cache for kernel evaluations (default 1000)
setTradeOffErrorAndMargin
public void setTradeOffErrorAndMargin(double d)
- Sets the trade-off between training error and margin (default 1000)
setEpsilon
public void setEpsilon(double d)
- eps: Allow that error when fitting constraints
y [w*x+b] >= 1-eps (default 0.001)
setKernelType
public void setKernelType(long l)
- Sets the kernel function type.
Types include LINEAR_KERNEL, POLYNOMIAL_KERNEL,
RADIAL_BASIS_KERNEL, SIGMOID_KERNEL, USER_KERNEL.
setPolyD
public void setPolyD(double l)
- Sets the parameter d in polynomial kernel.
setRbfG
public void setRbfG(double d)
- Sets the parameter gamma in rbf kernel.
setSigmoidS
public void setSigmoidS(double d)
- Sets the parameter s in sigmoid kernel.
setSigmoidC
public void setSigmoidC(double d)
- Sets the parameter c in sigmoid kernel.
setUserDefinedKernel
public void setUserDefinedKernel(String s)
- Sets the parameter of user defined kernel.
All Packages Class Hierarchy This Package Previous Next Index