public class SVM
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
SVM.EX
Expectile regression learning scenario.
|
static class |
SVM.LS
Least squares regression learning scenario.
|
static class |
SVM.MC
Binary and multi-class learning scenario.
|
static class |
SVM.NPL
Neyman-Pearson lemma learning scenario.
|
static class |
SVM.QT
Quantile regression learning scenario.
|
static class |
SVM.ROC
Receiver Operating Characteristic curve learning scenario.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
ENABLE_LOAD_WITHOUT_LIBRARY |
static int |
MAX_CPU |
Constructor and Description |
---|
SVM()
For quick demonstration initialize a least squares SVM using the trees dataset.
|
SVM(java.lang.String scenario,
double[][] data,
double[] labels,
Config config)
Initializes an SVM with training data and optionally configuration options and a scenario.
|
SVM(java.lang.String scenario,
LiquidData.Data data,
Config config)
Initializes an SVM with training data and optionally configuration options and a scenario.
|
SVM(java.lang.String scenario,
LiquidData data,
Config config)
Initializes an SVM with training data and optionally configuration options and a scenario
and performs testing.
|
Modifier and Type | Method and Description |
---|---|
static double[][] |
calculateDataCover(int NNs,
double[][] data)
Helper function to calculate Voronoi centers that cover the
data set
s.t. each cell should not have more than NNs samples. |
void |
clean() |
protected void |
finalize() |
java.lang.String |
getConfig(java.lang.String name)
Gets configuration of this SVM
|
int[] |
getCover(int task) |
ResultAndErrors |
getLastResult()
Keeps the last result and errors around after
test(double[][], double[], java.lang.String...) ing. |
double[][] |
getSelectErrs()
Returns many information upon
select(java.lang.String...) ing. |
double[] |
getSolutionCoeffs(int task,
int cell,
int fold) |
int[] |
getSolutionSVs(int task,
int cell,
int fold) |
double[][] |
getTrainErrs()
Returns many information upon
train(java.lang.String...) ing. |
boolean |
isSelected()
Has the SVM already been selected.
|
boolean |
isTrained()
Has the SVM already been trained.
|
double[] |
predict(double[][] test,
java.lang.String... argv)
Predicts labels for the given
test data. |
int |
readSVM(java.lang.String filename) |
double[][] |
select(java.lang.String... argv)
Selects the best hyperparameter pair according to validation error.
|
SVM |
setConfig(java.lang.String name,
double value)
Sets configuration directly in the SVM.
|
SVM |
setConfig(java.lang.String name,
double[] value)
Sets configuration directly in the SVM.
|
SVM |
setConfig(java.lang.String name,
int value)
Sets configuration directly in the SVM.
|
SVM |
setConfig(java.lang.String name,
java.lang.String value)
Sets configuration directly in the SVM.
|
SVM |
setConfigAll(Config config)
Sets all the values in the
config in this SVM. |
ResultAndErrors |
test(double[][] test,
double[] labs,
java.lang.String... argv)
Predicts labels for the given
test data and compares
these to the given labs . |
ResultAndErrors |
test(LiquidData.Data test,
java.lang.String... argv)
Predicts labels for the given
test.x data and compares
these to the given test.y . |
double[][] |
train(java.lang.String... argv)
Performs training on the hyperparameter grid.
|
public static boolean ENABLE_LOAD_WITHOUT_LIBRARY
public static final int MAX_CPU
public SVM()
LiquidData.trees
public SVM(java.lang.String scenario, double[][] data, double[] labels, Config config)
SVM.LS
, SVM.MC
, SVM.QT
, SVM.EX
, SVM.NPL
, or SVM.ROC
.
After the training data and the configuration are set,
Config.train(boolean)
and Config.select(boolean)
determine whether train(String...)
and select(String...)
should be started.
If config==NULL
they are performed.public SVM(java.lang.String scenario, LiquidData.Data data, Config config)
SVM.LS
, SVM.MC
, SVM.QT
, SVM.EX
, SVM.NPL
, or SVM.ROC
.
After the training data and the configuration are set,
Config.train(boolean)
and Config.select(boolean)
determine whether train(String...)
and select(String...)
should be started.
If config==NULL
they are performed.public SVM(java.lang.String scenario, LiquidData data, Config config)
SVM.LS
, SVM.MC
, SVM.QT
, SVM.EX
, SVM.NPL
, or SVM.ROC
.
After the training data and the configuration are set,
Config.train(boolean)
and Config.select(boolean)
determine whether train(String...)
and select(String...)
should be started.
If config==NULL
they are performed.public double[][] getTrainErrs()
train(java.lang.String...)
ing.
For every point in the hyperparametergrid, every fold,
every cell, and every task there is one line.public double[][] getSelectErrs()
select(java.lang.String...)
ing.
For every cell, and every task there is one line.public ResultAndErrors getLastResult()
test(double[][], double[], java.lang.String...)
ing.public double[][] train(java.lang.String... argv)
argv
can be used by experts in the same way
as in the svm-train
command line program of liquidSVM interface.
Most users should rather use Config
.argv
- further command line arguments (for experts)getTrainErrs()
public double[][] select(java.lang.String... argv)
argv
can be used by experts in the same way
as in the svm-select
command line program of liquidSVM interface.
Most users should rather use Config
.argv
- further command line arguments (for experts)getSelectErrs()
java.lang.IllegalStateException
- if the model has not been trainedpublic double[] predict(double[][] test, java.lang.String... argv)
test
data.
argv
can be used by experts in the same way
as in the svm-test
command line program of liquidSVM interface.
Most users should rather use Config
.test
- array of test samples features (X)argv
- further command line arguments (for experts)java.lang.IllegalStateException
- if the model has neither been trained nor selectedpublic ResultAndErrors test(double[][] test, double[] labs, java.lang.String... argv)
test
data and compares
these to the given labs
.
argv
can be used by experts in the same way
as in the svm-test
command line program of liquidSVM interface.
Most users should rather use Config
.test
- array of test samples features (X)labs
- array of test labelsargv
- further command line arguments (for experts)java.lang.IllegalStateException
- if the model has neither been trained nor selectedpublic ResultAndErrors test(LiquidData.Data test, java.lang.String... argv)
test.x
data and compares
these to the given test.y
.
argv
can be used by experts in the same way
as in the svm-test
command line program of liquidSVM interface.
Most users should rather use Config
.test
- array of test samplesargv
- further command line arguments (for experts)java.lang.IllegalStateException
- if the model has neither been trained nor selectedpublic void clean()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public static double[][] calculateDataCover(int NNs, double[][] data)
data
set
s.t. each cell should not have more than NNs
samples.NNs
- biggest size of cellsdata
- data set to coverpublic SVM setConfig(java.lang.String name, java.lang.String value)
Config
.name
- value
- public SVM setConfig(java.lang.String name, int value)
Config
.name
- value
- public SVM setConfig(java.lang.String name, double value)
Config
.name
- value
- public SVM setConfig(java.lang.String name, double[] value)
Config
.
The values get joined by spaces to form a string.name
- value
- public SVM setConfigAll(Config config)
config
in this SVM.config
- public java.lang.String getConfig(java.lang.String name)
name
- key
in tihs SVM.public boolean isTrained()
train(String...)
public boolean isSelected()
select(String...)
public int[] getCover(int task)
public int[] getSolutionSVs(int task, int cell, int fold)
public double[] getSolutionCoeffs(int task, int cell, int fold)
public int readSVM(java.lang.String filename)