Package de.bwaldvogel.liblinear
Class Model
- java.lang.Object
-
- de.bwaldvogel.liblinear.Model
-
- All Implemented Interfaces:
java.io.Serializable
public final class Model extends java.lang.Object implements java.io.Serializable
Model stores the model obtained from the training procedure
use
Linear.loadModel(Path)
andLinear.saveModel(Path, Model)
to load/save it- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) double
bias
(package private) int[]
label
label of each class(package private) int
nr_class
(package private) int
nr_feature
(package private) double
rho
one-class SVM onlyprivate static long
serialVersionUID
(package private) SolverType
solverType
(package private) double[]
w
feature weight array
-
Constructor Summary
Constructors Constructor Description Model()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static boolean
arrayEquals(double[] a, double[] a2)
don't useArrays.equals(double[], double[])
here, cause 0.0 and -0.0 should be handled the sameprivate static int
arrayHashCode(double[] w)
seeArrays.hashCode(double[])
but treat 0.0 and -0.0 the sameboolean
equals(java.lang.Object o)
private double
get_w_value(int idx, int label_idx)
double
getBias()
double
getDecfunBias(int labelIdx)
This function gives the bias term corresponding to the class with the label_idx.double
getDecfunCoef(int featIdx, int labelIdx)
This function gives the coefficient for the feature with feature index = feat_idx and the class with label index = label_idx.double
getDecfunRho()
This function gives rho, the bias term used in one-class SVM only.double[]
getFeatureWeights()
The array w gives feature weights; its size is nr_feature*nr_class but is nr_feature if nr_class = 2.int[]
getLabels()
int
getNrClass()
int
getNrFeature()
SolverType
getSolverType()
int
hashCode()
boolean
isProbabilityModel()
static Model
load(java.io.File modelFile)
Deprecated.useload(Path)
insteadstatic Model
load(java.io.Reader inputReader)
static Model
load(java.nio.file.Path modelPath)
void
save(java.io.File modelFile)
Deprecated.usesave(Path)
insteadvoid
save(java.io.Writer writer)
void
save(java.nio.file.Path modelPath)
java.lang.String
toString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
bias
double bias
-
label
int[] label
label of each class
-
nr_class
int nr_class
-
nr_feature
int nr_feature
-
solverType
SolverType solverType
-
w
double[] w
feature weight array
-
rho
double rho
one-class SVM only
-
-
Method Detail
-
getNrClass
public int getNrClass()
- Returns:
- number of classes
-
getNrFeature
public int getNrFeature()
- Returns:
- number of features
-
getLabels
public int[] getLabels()
-
getSolverType
public SolverType getSolverType()
-
getFeatureWeights
public double[] getFeatureWeights()
The array w gives feature weights; its size is nr_feature*nr_class but is nr_feature if nr_class = 2. We use one against the rest for multi-class classification, so each feature index corresponds to nr_class weight values. Weights are organized in the following way+------------------+------------------+------------+ | nr_class weights | nr_class weights | ... | for 1st feature | for 2nd feature | +------------------+------------------+------------+
If bias >= 0, x becomes [x; bias]. The number of features is increased by one, so w is a (nr_feature+1)*nr_class array. The value of bias is stored in the variable bias.- Returns:
- a copy of the feature weight array as described
- See Also:
getBias()
-
isProbabilityModel
public boolean isProbabilityModel()
- Returns:
- true for logistic regression solvers
-
getBias
public double getBias()
- See Also:
getFeatureWeights()
-
get_w_value
private double get_w_value(int idx, int label_idx)
-
getDecfunCoef
public double getDecfunCoef(int featIdx, int labelIdx)
This function gives the coefficient for the feature with feature index = feat_idx and the class with label index = label_idx. Note that feat_idx starts from 1, while label_idx starts from 0. If feat_idx is not in the valid range (1 to nr_feature), then a zero value will be returned. For classification models, if label_idx is not in the valid range (0 to nr_class-1), then a zero value will be returned; for regression models, label_idx is ignored.- Since:
- 1.95
-
getDecfunBias
public double getDecfunBias(int labelIdx)
This function gives the bias term corresponding to the class with the label_idx. For classification models, if label_idx is not in a valid range (0 to nr_class-1), then a zero value will be returned; for regression models, label_idx is ignored.- Since:
- 1.95
-
getDecfunRho
public double getDecfunRho()
This function gives rho, the bias term used in one-class SVM only. This function can only be called for a one-class SVM model.- Since:
- 2.40
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
arrayEquals
private static boolean arrayEquals(double[] a, double[] a2)
don't useArrays.equals(double[], double[])
here, cause 0.0 and -0.0 should be handled the same- See Also:
Linear.saveModel(java.io.Writer, Model)
-
arrayHashCode
private static int arrayHashCode(double[] w)
seeArrays.hashCode(double[])
but treat 0.0 and -0.0 the same
-
save
public void save(java.io.File modelFile) throws java.io.IOException
Deprecated.usesave(Path)
instead- Throws:
java.io.IOException
-
save
public void save(java.nio.file.Path modelPath) throws java.io.IOException
- Throws:
java.io.IOException
-
save
public void save(java.io.Writer writer) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public static Model load(java.io.File modelFile) throws java.io.IOException
Deprecated.useload(Path)
instead- Throws:
java.io.IOException
-
load
public static Model load(java.nio.file.Path modelPath) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public static Model load(java.io.Reader inputReader) throws java.io.IOException
- Throws:
java.io.IOException
-
-