MaltParser 1.4.1

org.maltparser.ml.liblinear
Class Liblinear

java.lang.Object
  extended by org.maltparser.ml.liblinear.Liblinear
All Implemented Interfaces:
LearningMethod

public class Liblinear
extends Object
implements LearningMethod


Nested Class Summary
static class Liblinear.Verbostity
           
 
Field Summary
protected  boolean excludeNullValues
           
protected  int learnerMode
           
static String LIBLINEAR_VERSION
           
protected  String name
           
protected  int numberOfInstances
           
protected  InstanceModel owner
           
protected  String pathExternalLiblinearTrain
           
protected  boolean saveInstanceFiles
           
 
Fields inherited from interface org.maltparser.ml.LearningMethod
BATCH, CLASSIFY
 
Constructor Summary
Liblinear(InstanceModel owner, Integer learnerMode)
          Constructs a Liblinear learner.
 
Method Summary
 void addInstance(SingleDecision decision, FeatureVector featureVector)
           
protected  void closeInstanceWriter()
           
 Map<Integer,Integer> createFeatureIdToCountMap(ArrayList<Integer> divideFeatureIndexVector)
           
 double crossValidate(FeatureVector featureVector, int nrOfSplits)
          This method does a cross validation of the training instances added and return the average score over the nrOfSplit divisions.
 void decreaseNumberOfInstances()
           
 void divideByFeatureSet(Set<Integer> featureIdsToCreateSeparateBranchesForSet, ArrayList<Integer> divideFeatureIndexVector, String otherId)
           
protected  void finalize()
           
 void finalizeSentence(DependencyStructure dependencyGraph)
           
 double getBias()
           
protected  JarEntry getConfigFileEntry(String suffix)
           
 DependencyParserConfig getConfiguration()
          Returns the current configuration
protected  File getFile(String suffix)
           
protected  InputStreamReader getInstanceInputStreamReader(String suffix)
           
protected  InputStreamReader getInstanceInputStreamReaderFromConfigFile(String suffix)
           
protected  OutputStreamWriter getInstanceOutputStreamWriter(String suffix)
           
 BufferedWriter getInstanceWriter()
           
 int getLearnerMode()
           
 String getLearningMethodName()
           
 String getLibLinearOptions()
           
 liblinear.Parameter getLiblinearParameters()
           
 String[] getLibLinearParamStringArray()
           
 int getNumberOfInstances()
           
 InstanceModel getOwner()
           
 String getParamString()
          Returns the parameter string for used for configure Liblinear
 void increaseNumberOfInstances()
           
 void initLiblinearOptions()
           
protected  void initSpecialParameters()
           
 void liblinear_predict_with_kbestlist(liblinear.Model model, liblinear.FeatureNode[] x, KBestList kBestList)
           
static void maltSVMFormat2OriginalSVMFormat(InputStreamReader isr, OutputStreamWriter osw, int[] cardinalities)
          Converts the instance file (Malt's own SVM format) into the Liblinear (SVMLight) format.
 void moveAllInstances(LearningMethod method, FeatureFunction divideFeature, ArrayList<Integer> divideFeatureIndexVector)
           
 void noMoreInstances()
           
 void parseParameters(String paramstring)
           
 boolean predict(FeatureVector featureVector, SingleDecision decision)
           
 liblinear.Problem readLibLinearProblem(InputStreamReader isr, int[] cardinalities)
          Reads an instance file into a svm_problem object according to the Malt-SVM format, which is column fixed format (tab-separated).
 void setLearnerMode(int learnerMode)
           
protected  void setLearningMethodName(String name)
           
protected  void setNumberOfInstances(int numberOfInstances)
           
protected  void setOwner(InstanceModel owner)
           
 void terminate()
           
 String toString()
           
 void train(FeatureVector featureVector)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LIBLINEAR_VERSION

public static final String LIBLINEAR_VERSION
See Also:
Constant Field Values

owner

protected InstanceModel owner

learnerMode

protected int learnerMode

name

protected String name

numberOfInstances

protected int numberOfInstances

saveInstanceFiles

protected boolean saveInstanceFiles

excludeNullValues

protected boolean excludeNullValues

pathExternalLiblinearTrain

protected String pathExternalLiblinearTrain
Constructor Detail

Liblinear

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

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

addInstance

public void addInstance(SingleDecision decision,
                        FeatureVector featureVector)
                 throws MaltChainedException
Specified by:
addInstance in interface LearningMethod
Throws:
MaltChainedException

finalizeSentence

public void finalizeSentence(DependencyStructure 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 featureVector)
           throws MaltChainedException
Specified by:
train in interface LearningMethod
Throws:
MaltChainedException

crossValidate

public double crossValidate(FeatureVector featureVector,
                            int nrOfSplits)
                     throws MaltChainedException
Description copied from interface: LearningMethod
This method does a cross validation of the training instances added and return the average score over the nrOfSplit divisions. This method is used by the decision tree model when deciding which parts of the tree that shall be pruned.

Specified by:
crossValidate in interface LearningMethod
Returns:
a double
Throws:
MaltChainedException

moveAllInstances

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

predict

public boolean predict(FeatureVector featureVector,
                       SingleDecision decision)
                throws MaltChainedException
Specified by:
predict in interface LearningMethod
Throws:
MaltChainedException

terminate

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

getInstanceWriter

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

closeInstanceWriter

protected void closeInstanceWriter()
                            throws MaltChainedException
Throws:
MaltChainedException

getParamString

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

Returns:
the parameter string for used for configure Liblinear

getOwner

public InstanceModel getOwner()

setOwner

protected void setOwner(InstanceModel owner)

getLearnerMode

public int getLearnerMode()

setLearnerMode

public void setLearnerMode(int learnerMode)
                    throws MaltChainedException
Throws:
MaltChainedException

getLearningMethodName

public String getLearningMethodName()

getConfiguration

public DependencyParserConfig getConfiguration()
                                        throws MaltChainedException
Returns the current configuration

Returns:
the current configuration
Throws:
MaltChainedException

getNumberOfInstances

public int getNumberOfInstances()
                         throws MaltChainedException
Throws:
MaltChainedException

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

getInstanceInputStreamReaderFromConfigFile

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

getFile

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

getConfigFileEntry

protected JarEntry getConfigFileEntry(String suffix)
                               throws MaltChainedException
Throws:
MaltChainedException

readLibLinearProblem

public liblinear.Problem readLibLinearProblem(InputStreamReader isr,
                                              int[] cardinalities)
                                       throws MaltChainedException
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
cardinalities - a array containing the number of distinct values for a particular column.
Throws:
LiblinearException
MaltChainedException

initSpecialParameters

protected void initSpecialParameters()
                              throws MaltChainedException
Throws:
MaltChainedException

getLibLinearOptions

public String getLibLinearOptions()

parseParameters

public void parseParameters(String paramstring)
                     throws MaltChainedException
Throws:
MaltChainedException

getBias

public double getBias()
               throws MaltChainedException
Throws:
MaltChainedException

getLiblinearParameters

public liblinear.Parameter getLiblinearParameters()
                                           throws MaltChainedException
Throws:
MaltChainedException

initLiblinearOptions

public void initLiblinearOptions()

getLibLinearParamStringArray

public String[] getLibLinearParamStringArray()

liblinear_predict_with_kbestlist

public void liblinear_predict_with_kbestlist(liblinear.Model model,
                                             liblinear.FeatureNode[] x,
                                             KBestList kBestList)
                                      throws MaltChainedException
Throws:
MaltChainedException

maltSVMFormat2OriginalSVMFormat

public static void maltSVMFormat2OriginalSVMFormat(InputStreamReader isr,
                                                   OutputStreamWriter osw,
                                                   int[] cardinalities)
                                            throws MaltChainedException
Converts the instance file (Malt's own SVM format) into the Liblinear (SVMLight) format. The input instance file is removed (replaced) by the instance file in the Liblinear (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
cardinalities - a vector containing the number of distinct values for a particular column
Throws:
LiblinearException
MaltChainedException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

toString

public String toString()
Overrides:
toString in class Object

divideByFeatureSet

public void divideByFeatureSet(Set<Integer> featureIdsToCreateSeparateBranchesForSet,
                               ArrayList<Integer> divideFeatureIndexVector,
                               String otherId)
                        throws MaltChainedException
Specified by:
divideByFeatureSet in interface LearningMethod
Throws:
MaltChainedException

createFeatureIdToCountMap

public Map<Integer,Integer> createFeatureIdToCountMap(ArrayList<Integer> divideFeatureIndexVector)
                                               throws MaltChainedException
Specified by:
createFeatureIdToCountMap in interface LearningMethod
Throws:
MaltChainedException

MaltParser 1.4.1

Copyright 2007-2010 Johan Hall, Jens Nilsson and Joakim Nivre.