MaltParser 1.0.2

org.maltparser.ml.libsvm
Class Libsvm

java.lang.Object
  extended by org.maltparser.ml.libsvm.Libsvm
All Implemented Interfaces:
LearningMethod

public class Libsvm
extends Object
implements LearningMethod

Implements an interface to the LIBSVM learner (currently the LIBSVM 2.84 is used). More information about LIBSVM can be found at LIBSVM -- A Library for Support Vector Machines.

Since:
1.0
Author:
Johan Hall

Field Summary
protected  boolean excludeNullValues
           
protected  Integer learnerMode
           
static String LIBSVM_VERSION
           
protected  String name
           
protected  int numberOfInstances
           
protected  InstanceModel owner
           
protected  String pathExternalSVMTrain
           
protected  boolean saveInstanceFiles
           
 
Fields inherited from interface org.maltparser.ml.LearningMethod
CLASSIFY, TRAIN
 
Constructor Summary
Libsvm(InstanceModel owner, Integer learnerMode)
          Constructs a LIBSVM learner.
 
Method Summary
 void addInstance(ClassTable classCodeTable, FeatureVector features)
           
protected  void addInstanceExcludeNull(ClassTable classCodeTable, FeatureVector features)
           
protected  void closeInstanceWriter()
           
 void decreaseNumberOfInstances()
           
 void finalize()
           
 void finalizeSentence(Sentence sentence, DependencyGraph dependencyGraph)
           
 Configuration getConfiguration()
          Returns the current configuration
protected  File getFile(String suffix)
           
protected  InputStreamReader getInstanceInputStreamReader(String suffix)
           
protected  OutputStreamWriter getInstanceOutputStreamWriter(String suffix)
           
 BufferedWriter getInstanceWriter()
           
 Integer getLearnerMode()
           
 String getLearningMethodName()
           
 int getNumberOfInstances()
           
 InstanceModel getOwner()
           
 String getParamString()
          Returns the parameter string for used for configure LIBSVM
 String[] getSVMParamStringArray(libsvm.svm_parameter param)
           
 void increaseNumberOfInstances()
           
protected  void initParameters(libsvm.svm_parameter param)
          Assign a default value to all svm parameters
protected  void initSpecialParameters()
           
protected  void initSvmParam(String paramString)
          Initialize the LIBSVM according to the parameter string
static void maltSVMFormat2OriginalSVMFormat(InputStreamReader isr, OutputStreamWriter osw, ArrayList<Integer> cardinality)
          Converts the instance file (Malt's own SVM format) into the LIBSVM (SVMLight) format.
 void moveAllInstances(LearningMethod method, Feature divideFeature, ArrayList<Integer> divideFeatureIndexVector)
           
 void noMoreInstances()
           
 void parseParameters(String paramstring, libsvm.svm_parameter param)
          Parses the parameter string.
 boolean predict(FeatureVector features, KBestList kBestList)
           
 void readProblemMaltSVMFormat(InputStreamReader isr, libsvm.svm_problem prob, ArrayList<Integer> cardinality, libsvm.svm_parameter param)
          Reads an instance file into a svm_problem object according to the Malt-SVM format, which is column fixed format (tab-separated).
 void setLearnerMode(Integer learnerMode)
           
protected  void setLearningMethodName(String name)
           
protected  void setNumberOfInstances(int numberOfInstances)
           
protected  void setOwner(InstanceModel owner)
           
 void svm_predict_with_kbestlist(libsvm.svm_model model, libsvm.svm_node[] x, KBestList kBestList)
           
 String toString()
           
 String toStringParameters(libsvm.svm_parameter param)
          Returns a string containing all svm-parameters of interest
 void train(FeatureVector features)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LIBSVM_VERSION

public static final String LIBSVM_VERSION
See Also:
Constant Field Values

owner

protected InstanceModel owner

learnerMode

protected Integer learnerMode

name

protected String name

numberOfInstances

protected int numberOfInstances

saveInstanceFiles

protected boolean saveInstanceFiles

excludeNullValues

protected boolean excludeNullValues

pathExternalSVMTrain

protected String pathExternalSVMTrain
Constructor Detail

Libsvm

public Libsvm(InstanceModel owner,
              Integer learnerMode)
       throws MaltChainedException
Constructs a LIBSVM learner.

Parameters:
owner - the guide model owner
learnerMode - the mode of the learner TRAIN or CLASSIFY
Throws:
MaltChainedException
Method Detail

addInstance

public void addInstance(ClassTable classCodeTable,
                        FeatureVector features)
                 throws MaltChainedException
Specified by:
addInstance in interface LearningMethod
Throws:
MaltChainedException

addInstanceExcludeNull

protected void addInstanceExcludeNull(ClassTable classCodeTable,
                                      FeatureVector features)
                               throws MaltChainedException
Throws:
MaltChainedException

finalizeSentence

public void finalizeSentence(Sentence sentence,
                             DependencyGraph dependencyGraph)
                      throws MaltChainedException
Specified by:
finalizeSentence in interface LearningMethod
Throws:
MaltChainedException

noMoreInstances

public void noMoreInstances()
                     throws MaltChainedException
Specified by:
noMoreInstances in interface LearningMethod
Throws:
MaltChainedException

train

public void train(FeatureVector features)
           throws MaltChainedException
Specified by:
train in interface LearningMethod
Throws:
MaltChainedException

moveAllInstances

public void moveAllInstances(LearningMethod method,
                             Feature divideFeature,
                             ArrayList<Integer> divideFeatureIndexVector)
                      throws MaltChainedException
Specified by:
moveAllInstances in interface LearningMethod
Throws:
MaltChainedException

predict

public boolean predict(FeatureVector features,
                       KBestList kBestList)
                throws MaltChainedException
Specified by:
predict in interface LearningMethod
Throws:
MaltChainedException

finalize

public void finalize()
              throws MaltChainedException
Specified by:
finalize in interface LearningMethod
Overrides:
finalize in class Object
Throws:
MaltChainedException

getInstanceWriter

public BufferedWriter getInstanceWriter()
Specified by:
getInstanceWriter in interface LearningMethod

closeInstanceWriter

protected void closeInstanceWriter()
                            throws MaltChainedException
Throws:
MaltChainedException

initSvmParam

protected void initSvmParam(String paramString)
                     throws MaltChainedException
Initialize the LIBSVM according to the parameter string

Parameters:
paramString - the parameter string to configure the LIBSVM learner.
Throws:
MaltChainedException

getParamString

public String getParamString()
Returns the parameter string for used for configure LIBSVM

Returns:
the parameter string for used for configure LIBSVM

getOwner

public InstanceModel getOwner()

setOwner

protected void setOwner(InstanceModel owner)

getLearnerMode

public Integer getLearnerMode()

setLearnerMode

public void setLearnerMode(Integer learnerMode)

getLearningMethodName

public String getLearningMethodName()

getConfiguration

public Configuration getConfiguration()
                               throws MaltChainedException
Returns the current configuration

Returns:
the current configuration
Throws:
MaltChainedException

getNumberOfInstances

public int getNumberOfInstances()

increaseNumberOfInstances

public void increaseNumberOfInstances()
Specified by:
increaseNumberOfInstances in interface LearningMethod

decreaseNumberOfInstances

public void decreaseNumberOfInstances()
Specified by:
decreaseNumberOfInstances in interface LearningMethod

setNumberOfInstances

protected void setNumberOfInstances(int numberOfInstances)

setLearningMethodName

protected void setLearningMethodName(String name)

getInstanceOutputStreamWriter

protected OutputStreamWriter getInstanceOutputStreamWriter(String suffix)
                                                    throws MaltChainedException
Throws:
MaltChainedException

getInstanceInputStreamReader

protected InputStreamReader getInstanceInputStreamReader(String suffix)
                                                  throws MaltChainedException
Throws:
MaltChainedException

getFile

protected File getFile(String suffix)
                throws MaltChainedException
Throws:
MaltChainedException

readProblemMaltSVMFormat

public void readProblemMaltSVMFormat(InputStreamReader isr,
                                     libsvm.svm_problem prob,
                                     ArrayList<Integer> cardinality,
                                     libsvm.svm_parameter param)
                              throws LibsvmException
Reads an instance file into a svm_problem object according to the Malt-SVM format, which is column fixed format (tab-separated).

Parameters:
isr - the instance stream reader for the instance file
prob - a svm_problem object
cardinality - a vector containing the number of distinct values for a particular column.
param - a svm_parameter object
Throws:
LibsvmException

initSpecialParameters

protected void initSpecialParameters()
                              throws MaltChainedException
Throws:
MaltChainedException

initParameters

protected void initParameters(libsvm.svm_parameter param)
                       throws LibsvmException
Assign a default value to all svm parameters

Parameters:
param - a svm_parameter object
Throws:
LibsvmException

toStringParameters

public String toStringParameters(libsvm.svm_parameter param)
Returns a string containing all svm-parameters of interest

Parameters:
param - a svm_parameter object
Returns:
a string containing all svm-parameters of interest

getSVMParamStringArray

public String[] getSVMParamStringArray(libsvm.svm_parameter param)

parseParameters

public void parseParameters(String paramstring,
                            libsvm.svm_parameter param)
                     throws LibsvmException
Parses the parameter string. The parameter string must contain parameter and value pairs, which are seperated by a blank or a underscore. The parameter begins with a character '-' followed by a one-character flag and the value must comply with the parameters data type. Some examples: -s 0 -t 1 -d 2 -g 0.4 -e 0.1 -s_0_-t_1_-d_2_-g_0.4_-e_0.1

Parameters:
paramstring - the parameter string
param - a svm_parameter object
Throws:
LibsvmException

svm_predict_with_kbestlist

public void svm_predict_with_kbestlist(libsvm.svm_model model,
                                       libsvm.svm_node[] x,
                                       KBestList kBestList)

maltSVMFormat2OriginalSVMFormat

public static void maltSVMFormat2OriginalSVMFormat(InputStreamReader isr,
                                                   OutputStreamWriter osw,
                                                   ArrayList<Integer> cardinality)
                                            throws LibsvmException
Converts the instance file (Malt's own SVM format) into the LIBSVM (SVMLight) format. The input instance file is removed (replaced) by the instance file in the LIBSVM (SVMLight) format. If a column contains -1, the value will be removed in destination file.

Parameters:
isr - the input stream reader for the source instance file
osw - the output stream writer for the destination instance file
cardinality - a vector containing the number of distinct values for a particular column
Throws:
LibsvmException

toString

public String toString()
Overrides:
toString in class Object

MaltParser 1.0.2

Copyright 2007 Johan Hall, Jens Nilsson and Joakim Nivre.