|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjml.classification.Classifier
jml.classification.MultiClassSVM
public class MultiClassSVM
Multi-class SVM using LIBLINEAR library.
Field Summary | |
---|---|
private double |
bias
Dummy feature, aiming to remove the equality constraint for the dual problem of SVM. |
(package private) double |
C
Parameter for loss term of linear multi-class SVM. |
(package private) double |
eps
Convergence tolerance. |
(package private) de.bwaldvogel.liblinear.Feature[][] |
features
Feature 2D array, indices start from 1. |
(package private) de.bwaldvogel.liblinear.Model |
model
SVM model. |
(package private) de.bwaldvogel.liblinear.Parameter |
parameter
A Parameter instance for linear multi-class SVM. |
(package private) de.bwaldvogel.liblinear.Problem |
problem
A Problem object for this MCSVM classifier. |
private static long |
serialVersionUID
|
Fields inherited from class jml.classification.Classifier |
---|
epsilon, IDLabelMap, labelIDs, labels, nClass, nExample, nFeature, W, X, Y |
Constructor Summary | |
---|---|
MultiClassSVM()
|
|
MultiClassSVM(double C,
double eps)
Maximal feature index, not including the bias feature. |
Method Summary | |
---|---|
(package private) static double |
atof(java.lang.String s)
|
(package private) static int |
atoi(java.lang.String s)
|
private static de.bwaldvogel.liblinear.Problem |
constructProblem(java.util.List<java.lang.Integer> vy,
java.util.List<de.bwaldvogel.liblinear.Feature[]> vx,
int max_index,
double bias)
|
static org.apache.commons.math.linear.RealMatrix |
features2Matrix(de.bwaldvogel.liblinear.Feature[][] features)
Convert features to original data matrix. |
static org.apache.commons.math.linear.RealMatrix |
features2Matrix(de.bwaldvogel.liblinear.Feature[][] features,
double bias)
Convert features to matrix including bias features if bias is nonnegative. |
static org.apache.commons.math.linear.RealMatrix |
features2MatrixWithoutBias(de.bwaldvogel.liblinear.Feature[][] features)
Convert features to original data matrix. |
static org.apache.commons.math.linear.RealMatrix |
features2MatrixWithoutBias(de.bwaldvogel.liblinear.Feature[][] features,
double bias)
Convert features to matrix excluding bias features if bias is nonnegative. |
void |
feedData(org.apache.commons.math.linear.RealMatrix X)
Feed training data with original data matrix for this classifier. |
void |
feedProblem(java.util.ArrayList<java.lang.String> feaArray)
Feed a problem from a string array. |
void |
feedProblem(de.bwaldvogel.liblinear.Problem problem)
Feed a problem for this SVM classifier. |
void |
feedProblem(java.lang.String filePath)
Feed a problem from a file with the LIBLINEAR input data format. |
static int |
getMaxRawFeatureIndex(de.bwaldvogel.liblinear.Feature[][] features,
double bias)
Get the maximal feature index not including the bias feature. |
void |
loadModel(java.lang.String filePath)
Load the model for a classifier. |
void |
loadSVMModel(java.lang.String filePath)
|
static void |
main(java.lang.String[] args)
|
static de.bwaldvogel.liblinear.Feature[][] |
matrix2Features(org.apache.commons.math.linear.RealMatrix A)
Convert original data matrix into Feature[][] including bias features. |
static de.bwaldvogel.liblinear.Feature[][] |
matrix2Features(org.apache.commons.math.linear.RealMatrix A,
double bias)
Convert original data matrix into Feature[][] including bias features if bias is nonnegative. |
int[] |
predict(de.bwaldvogel.liblinear.Feature[][] features)
Predict labels for the test data formated as a feature 2D array. |
int[] |
predict2(de.bwaldvogel.liblinear.Feature[][] data,
int[] labels)
Deprecated. |
static int[] |
predict2(de.bwaldvogel.liblinear.Model model,
de.bwaldvogel.liblinear.Feature[][] data,
int[] labels)
Deprecated. |
int[] |
predict2(org.apache.commons.math.linear.RealMatrix Xt)
Deprecated. |
int[] |
predict2(org.apache.commons.math.linear.RealMatrix Xt,
int[] labels)
Deprecated. |
org.apache.commons.math.linear.RealMatrix |
predictLabelScoreMatrix(org.apache.commons.math.linear.RealMatrix Xt)
Predict label matrix for column vectors of an original data matrix. |
static de.bwaldvogel.liblinear.Problem |
readProblem(java.lang.String filePath)
Read a problem from a file with the LIBSVM data format. |
static de.bwaldvogel.liblinear.Problem |
readProblemFromFile(java.io.File file,
double bias)
Data format (index starts from 1): |
static de.bwaldvogel.liblinear.Problem |
readProblemFromStringArray(java.util.ArrayList<java.lang.String> feaArray)
Read a problem from a string array with default bias feature (1.0). |
static de.bwaldvogel.liblinear.Problem |
readProblemFromStringArray(java.util.ArrayList<java.lang.String> feaArray,
double bias)
Read a problem from a string array. |
private void |
reconstructProjectionMatrix()
|
static void |
run(java.lang.String[] args)
Run this module with arguments in a String array. |
void |
saveModel(java.lang.String filePath)
Save the model for a classifier. |
void |
saveSVMModel(java.lang.String filePath)
|
private static void |
showUsage()
Show usage. |
void |
train()
Train the classifier. |
Methods inherited from class jml.classification.Classifier |
---|
calcNumClass, feedData, feedLabels, feedLabels, feedLabels, getAccuracy, getIDLabelMap, getLabelIDMap, getProjectionMatrix, getTrainingLabelMatrix, labelIndexArray2LabelMatrix, labelScoreMatrix2LabelIndexArray, predict, predict, predictLabelMatrix, predictLabelMatrix, predictLabelScoreMatrix |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
de.bwaldvogel.liblinear.Problem problem
Problem
object for this MCSVM classifier.
de.bwaldvogel.liblinear.Feature[][] features
double C
double eps
de.bwaldvogel.liblinear.Parameter parameter
Parameter
instance for linear multi-class SVM.
private double bias
de.bwaldvogel.liblinear.Model model
Constructor Detail |
---|
public MultiClassSVM(double C, double eps)
public MultiClassSVM()
Method Detail |
---|
public static void main(java.lang.String[] args)
args
- public static void run(java.lang.String[] args)
String
array.
args
- command line argumentsprivate static void showUsage()
public void feedProblem(java.util.ArrayList<java.lang.String> feaArray)
feaArray
- a string array of which each element is a
index value feature representation for an
example with the LIBSVM input data formatpublic void feedProblem(java.lang.String filePath)
filePath
- file path for a file with the LIBLINEAR input
data formatpublic void feedProblem(de.bwaldvogel.liblinear.Problem problem)
problem
- a Problem
objectpublic void feedData(org.apache.commons.math.linear.RealMatrix X)
feedData
in class Classifier
X
- original data matrix without bias dummy featurespublic static int getMaxRawFeatureIndex(de.bwaldvogel.liblinear.Feature[][] features, double bias)
features
- a 2D feature arraybias
- dummy bias feature value
public void train()
Classifier
train
in class Classifier
@Deprecated public static int[] predict2(de.bwaldvogel.liblinear.Model model, de.bwaldvogel.liblinear.Feature[][] data, int[] labels)
@Deprecated public int[] predict2(de.bwaldvogel.liblinear.Feature[][] data, int[] labels)
@Deprecated public int[] predict2(org.apache.commons.math.linear.RealMatrix Xt)
@Deprecated public int[] predict2(org.apache.commons.math.linear.RealMatrix Xt, int[] labels)
public static de.bwaldvogel.liblinear.Problem readProblemFromFile(java.io.File file, double bias)
+1 1:0.708333 2:1 3:1 4:-0.320755 5:-0.105023 6:-1 7:1 8:-0.419847 9:-1 10:-0.225806 12:1 13:-1 -1 1:0.583333 2:-1 3:0.333333 4:-0.603774 5:1 6:-1 7:1 8:0.358779 9:-1 10:-0.483871 12:-1 13:1
file
- bias
-
Problem
instance holding features and labelspublic static de.bwaldvogel.liblinear.Problem readProblem(java.lang.String filePath)
filePath
- file path
Problem
instance holding features and labelspublic static de.bwaldvogel.liblinear.Feature[][] matrix2Features(org.apache.commons.math.linear.RealMatrix A)
A
- original data matrix with each column being a sample
public static de.bwaldvogel.liblinear.Feature[][] matrix2Features(org.apache.commons.math.linear.RealMatrix A, double bias)
A
- original data matrix with each column being a samplebias
- dummy bias feature, i.e., 1
public static de.bwaldvogel.liblinear.Problem readProblemFromStringArray(java.util.ArrayList<java.lang.String> feaArray)
feaArray
- a ArrayList<String>
, each element
is a string with LIBSVM data format
Problem
instance holding features and labelspublic static de.bwaldvogel.liblinear.Problem readProblemFromStringArray(java.util.ArrayList<java.lang.String> feaArray, double bias)
feaArray
- a ArrayList<String>
, each element
is a string with LIBSVM data formatbias
- a real number to append the feature vector e.g., 1
Problem
instance holding features and labelsprivate static de.bwaldvogel.liblinear.Problem constructProblem(java.util.List<java.lang.Integer> vy, java.util.List<de.bwaldvogel.liblinear.Feature[]> vx, int max_index, double bias)
static double atof(java.lang.String s)
s
- the string to parse for the double value
java.lang.IllegalArgumentException
- if s is empty or represents NaN or Infinity
java.lang.NumberFormatException
- see Double.parseDouble(String)
static int atoi(java.lang.String s) throws java.lang.NumberFormatException
s
- the string to parse for the integer value
java.lang.IllegalArgumentException
- if s is empty
java.lang.NumberFormatException
- see Integer.parseInt(String)
public static org.apache.commons.math.linear.RealMatrix features2Matrix(de.bwaldvogel.liblinear.Feature[][] features)
features
- a 2D feature array
public static org.apache.commons.math.linear.RealMatrix features2Matrix(de.bwaldvogel.liblinear.Feature[][] features, double bias)
features
- a 2D feature arraybias
- dummy bias feature
public static org.apache.commons.math.linear.RealMatrix features2MatrixWithoutBias(de.bwaldvogel.liblinear.Feature[][] features)
features
- a 2D feature array
public static org.apache.commons.math.linear.RealMatrix features2MatrixWithoutBias(de.bwaldvogel.liblinear.Feature[][] features, double bias)
features
- a 2D feature arraybias
- dummy bias feature
public org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(org.apache.commons.math.linear.RealMatrix Xt)
predictLabelScoreMatrix
in class Classifier
Xt
- test data matrix with each column being a feature vector
public int[] predict(de.bwaldvogel.liblinear.Feature[][] features)
features
- a 2D feature array
public void loadSVMModel(java.lang.String filePath)
private void reconstructProjectionMatrix()
public void saveSVMModel(java.lang.String filePath)
public void loadModel(java.lang.String filePath)
Classifier
loadModel
in class Classifier
filePath
- file path to load the modelpublic void saveModel(java.lang.String filePath)
Classifier
saveModel
in class Classifier
filePath
- file path to save the model
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |