edu.cmu.minorthird.classify.algorithms.svm
Class SVMUtils

java.lang.Object
  extended by edu.cmu.minorthird.classify.algorithms.svm.SVMUtils

public class SVMUtils
extends java.lang.Object

Provides some basic utilities for dealing with libsvm. It can convert Features to nodes, instances to node arrays and Datasets to problems.

Author:
ksteppe, Frank Lin

Constructor Summary
SVMUtils()
           
 
Method Summary
static libsvm.svm_problem convertToSVMProblem(Dataset dataset)
          convert the given dataset into a svm_problem object by looping through the examples and features - features are resorted numericly
static libsvm.svm_node featureToNode(Feature feature, Instance instance)
          converts the feature into an svm_node
static libsvm.svm_node[] instanceToNodeArray(Instance instance)
          creates the node array from an instance
static Instance nodeArrayToInstance(libsvm.svm_node[] nodes, FeatureFactory featureFactory)
          creates an instance from the node array
static Feature nodeToFeature(libsvm.svm_node node, FeatureFactory featureFactory)
          convert a svm_node to a feature
static java.lang.String toString(libsvm.svm_node node)
           
static java.lang.String toString(libsvm.svm_node[] nodes)
           
static java.lang.String toString(libsvm.svm_problem problem)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SVMUtils

public SVMUtils()
Method Detail

toString

public static java.lang.String toString(libsvm.svm_node node)

toString

public static java.lang.String toString(libsvm.svm_node[] nodes)

toString

public static java.lang.String toString(libsvm.svm_problem problem)

featureToNode

public static libsvm.svm_node featureToNode(Feature feature,
                                            Instance instance)
converts the feature into an svm_node

Parameters:
feature - Feature to convert into a node
instance - Instance feature is in - used to retrieve the weight of the feature
Returns:
svm_node

instanceToNodeArray

public static libsvm.svm_node[] instanceToNodeArray(Instance instance)
creates the node array from an instance

Parameters:
instance - Instance to convert
Returns:
node array with all the features from the instance

convertToSVMProblem

public static libsvm.svm_problem convertToSVMProblem(Dataset dataset)
convert the given dataset into a svm_problem object by looping through the examples and features - features are resorted numericly

Parameters:
dataset - - must contain features with integer names
Returns:
a fully loaded svm_problem object

nodeToFeature

public static Feature nodeToFeature(libsvm.svm_node node,
                                    FeatureFactory featureFactory)
convert a svm_node to a feature

Parameters:
node - svm_node from LIBSVM
featureFactory - FeatureIdFactory object holds feature and its id information.
Returns:
Feature Feature converted from svm_node

nodeArrayToInstance

public static Instance nodeArrayToInstance(libsvm.svm_node[] nodes,
                                           FeatureFactory featureFactory)
creates an instance from the node array

Parameters:
nodes - svm_node array from LIBSVM
featureFactory - FeatureFactory object holds feature and its id
Returns:
Instance Instance with the Features converted from input node array