Package de.bwaldvogel.liblinear
Class Linear
java.lang.Object
de.bwaldvogel.liblinear.Linear
Java port of liblinear
The usage should be pretty similar to the C version of liblinear.
Please consider reading the README file of liblinear.
The port was done by Benedikt Waldvogel (mail at bwaldvogel.de)
- Version:
- 2.44
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classused as complex return type -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static PrintStreamprivate static final Locale(package private) static final Charsetprivate static final Object(package private) static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static double(package private) static intprivate static doublecalc_max_p(Problem prob) private static doublecalc_start_C(Problem prob, Parameter param) private static voidcheckProblemSize(int n, int nr_class) verify the size and throw an exception early if the problem is too largestatic voidcrossValidation(Problem prob, Parameter param, int nr_fold, double[] target) static voidstatic voidstatic ParameterCSearchResultfind_parameter_C(Problem prob, Parameter param_tmp, double start_C, double max_C, int[] fold_start, int[] perm, Problem[] subprob, int nr_fold) static ParameterSearchResultfindParameters(Problem prob, Parameter param, int nr_fold, double start_C, double start_p) private static intGETI(byte[] y, int i) private static intGETI_SVR(int i) static intprivate static Linear.GroupClassesReturngroupClasses(Problem prob, int[] perm) (package private) static void(package private) static voidstatic ModelDeprecated.static ModelLoads the model from inputReader.static ModelLoads the model from the file with ISO-8859-1 charset.static doublestatic doublepredictProbability(Model model, Feature[] x, double[] prob_estimates) static doublepredictValues(Model model, Feature[] x, double[] dec_values) (package private) static voidstatic voidDeprecated.UseParameter.setRandom(Random)insteadstatic voidDeprecated.usesaveModel(Path, Model)insteadstatic voidWrites the model to the modelOutput.static voidWrites the model to the file with ISO-8859-1 charset.static voidsetDebugOutput(PrintStream debugOutput) private static intsolve_l1r_l2_svc(Problem prob_col, Parameter param, double[] w, double Cp, double Cn, double eps, int max_iter) A coordinate descent algorithm for L1-regularized L2-loss support vector classificationprivate static intsolve_l1r_lr(Problem prob_col, Parameter param, double[] w, double Cp, double Cn, double eps, int max_iter) A coordinate descent algorithm for L1-regularized logistic regression problemsprivate static intsolve_l2r_l1l2_svc(Problem prob, Parameter param, double[] w, double Cp, double Cn, int max_iter) A coordinate descent algorithm for L1-loss and L2-loss SVM dual problemsprivate static intsolve_l2r_l1l2_svr(Problem prob, Parameter param, double[] w, int max_iter) A coordinate descent algorithm for L1-loss and L2-loss epsilon-SVR dual problem min_\beta 0.5\beta^T (Q + diag(lambda)) \beta - p \sum_{i=1}^l|\beta_i| + \sum_{i=1}^l yi\beta_i, s.t.private static intsolve_l2r_lr_dual(Problem prob, Parameter param, double[] w, double Cp, double Cn, int max_iter) A coordinate descent algorithm for the dual of L2-regularized logistic regression problems(package private) static intsolve_oneclass_svm(Problem prob, Parameter param, double[] w, MutableDouble rho, int max_iter) (package private) static voidswap(double[] array, int idxA, int idxB) (package private) static voidswap(int[] array, int idxA, int idxB) (package private) static void(package private) static voidswap(IntArrayPointer array, int idxA, int idxB) static Modelprivate static void(package private) static Problem
-
Field Details
-
VERSION
static final int VERSION- See Also:
-
FILE_CHARSET
-
DEFAULT_LOCALE
-
OUTPUT_MUTEX
-
DEBUG_OUTPUT
-
-
Constructor Details
-
Linear
public Linear()
-
-
Method Details
-
crossValidation
- Parameters:
target- predicted classes
-
findParameters
public static ParameterSearchResult findParameters(Problem prob, Parameter param, int nr_fold, double start_C, double start_p) -
groupClasses
-
info
-
info
-
atof
- Parameters:
s- the string to parse for the double value- Throws:
IllegalArgumentException- if s is empty or represents NaN or InfinityNumberFormatException- seeDouble.parseDouble(String)
-
atoi
- Parameters:
s- the string to parse for the integer value- Throws:
IllegalArgumentException- if s is emptyNumberFormatException- seeInteger.parseInt(String)
-
loadModel
Loads the model from inputReader. It usesLocale.ENGLISHfor number formatting.Note: The inputReader is NOT closed after reading or in case of an exception.
- Throws:
IOException
-
loadModel
Deprecated.useloadModel(Path)insteadLoads the model from the file with ISO-8859-1 charset. It usesLocale.ENGLISHfor number formatting.- Throws:
IOException
-
loadModel
Loads the model from the file with ISO-8859-1 charset. It usesLocale.ENGLISHfor number formatting.- Throws:
IOException
-
predict
-
predictProbability
public static double predictProbability(Model model, Feature[] x, double[] prob_estimates) throws IllegalArgumentException - Throws:
IllegalArgumentException- if model is not probabilistic (seeModel.isProbabilityModel())
-
predictValues
-
printf
- Throws:
IOException
-
saveModel
Writes the model to the modelOutput. It usesLocale.ENGLISHfor number formatting.Note: The modelOutput is closed after reading or in case of an exception.
- Throws:
IOException
-
saveModel
Deprecated.usesaveModel(Path, Model)insteadWrites the model to the file with ISO-8859-1 charset. It usesLocale.ENGLISHfor number formatting.- Throws:
IOException
-
saveModel
Writes the model to the file with ISO-8859-1 charset. It usesLocale.ENGLISHfor number formatting.- Throws:
IOException
-
GETI
private static int GETI(byte[] y, int i) -
solve_l2r_l1l2_svc
private static int solve_l2r_l1l2_svc(Problem prob, Parameter param, double[] w, double Cp, double Cn, int max_iter) A coordinate descent algorithm for L1-loss and L2-loss SVM dual problemsmin_\alpha 0.5(\alpha^T (Q + D)\alpha) - e^T \alpha, s.t. 0 invalid input: '<'= \alpha_i invalid input: '<'= upper_bound_i, where Qij = yi yj xi^T xj and D is a diagonal matrix In L1-SVM case: upper_bound_i = Cp if y_i = 1 upper_bound_i = Cn if y_i = -1 D_ii = 0 In L2-SVM case: upper_bound_i = INF D_ii = 1/(2*Cp) if y_i = 1 D_ii = 1/(2*Cn) if y_i = -1 Given: x, y, Cp, Cn eps is the stopping tolerance solution will be put in w this function returns the number of iterations See Algorithm 3 of Hsieh et al., ICML 2008 -
GETI_SVR
private static int GETI_SVR(int i) -
solve_l2r_l1l2_svr
A coordinate descent algorithm for L1-loss and L2-loss epsilon-SVR dual problem min_\beta 0.5\beta^T (Q + diag(lambda)) \beta - p \sum_{i=1}^l|\beta_i| + \sum_{i=1}^l yi\beta_i, s.t. -upper_bound_i invalid input: '<'= \beta_i invalid input: '<'= upper_bound_i, where Qij = xi^T xj and D is a diagonal matrix In L1-SVM case: upper_bound_i = C lambda_i = 0 In L2-SVM case: upper_bound_i = INF lambda_i = 1/(2*C) Given: x, y, p, C eps is the stopping tolerance solution will be put in w this function returns the number of iterations See Algorithm 4 of Ho and Lin, 2012 -
solve_l2r_lr_dual
private static int solve_l2r_lr_dual(Problem prob, Parameter param, double[] w, double Cp, double Cn, int max_iter) A coordinate descent algorithm for the dual of L2-regularized logistic regression problemsmin_\alpha 0.5(\alpha^T Q \alpha) + \sum \alpha_i log (\alpha_i) + (upper_bound_i - \alpha_i) log (upper_bound_i - \alpha_i) , s.t. 0 invalid input: '<'= \alpha_i invalid input: '<'= upper_bound_i, where Qij = yi yj xi^T xj and upper_bound_i = Cp if y_i = 1 upper_bound_i = Cn if y_i = -1 Given: x, y, Cp, Cn eps is the stopping tolerance solution will be put in w this function returns the number of iterations See Algorithm 5 of Yu et al., MLJ 2010- Since:
- 1.7
-
solve_l1r_l2_svc
private static int solve_l1r_l2_svc(Problem prob_col, Parameter param, double[] w, double Cp, double Cn, double eps, int max_iter) A coordinate descent algorithm for L1-regularized L2-loss support vector classificationmin_w \sum |wj| + C \sum max(0, 1-yi w^T xi)^2, Given: x, y, Cp, Cn eps is the stopping tolerance solution will be put in w this function returns the number of iterations See Yuan et al. (2010) and appendix of LIBLINEAR paper, Fan et al. (2008) To not regularize the bias (i.e., regularize_bias = 0), a constant feature = 1 must have been added to the original data. (see -B and -R option)
- Since:
- 1.5
-
solve_l1r_lr
private static int solve_l1r_lr(Problem prob_col, Parameter param, double[] w, double Cp, double Cn, double eps, int max_iter) A coordinate descent algorithm for L1-regularized logistic regression problemsmin_w \sum |wj| + C \sum log(1+exp(-yi w^T xi)), Given: x, y, Cp, Cn eps is the stopping tolerance solution will be put in w this function returns the number of iterations See Yuan et al. (2011) and appendix of LIBLINEAR paper, Fan et al. (2008) To not regularize the bias (i.e., regularize_bias = 0), a constant feature = 1 must have been added to the original data. (see -B and -R option)
- Since:
- 1.5
-
solve_oneclass_svm
static int solve_oneclass_svm(Problem prob, Parameter param, double[] w, MutableDouble rho, int max_iter) -
transpose
-
swap
static void swap(double[] array, int idxA, int idxB) -
swap
static void swap(int[] array, int idxA, int idxB) -
swap
-
swap
-
train
- Throws:
IllegalArgumentException- if the feature nodes of prob are not sorted in ascending order
-
checkProblemSize
private static void checkProblemSize(int n, int nr_class) verify the size and throw an exception early if the problem is too large -
train_one
-
calc_start_C
-
calc_max_p
-
find_parameter_C
public static ParameterCSearchResult find_parameter_C(Problem prob, Parameter param_tmp, double start_C, double max_C, int[] fold_start, int[] perm, Problem[] subprob, int nr_fold) -
disableDebugOutput
public static void disableDebugOutput() -
enableDebugOutput
public static void enableDebugOutput() -
setDebugOutput
-
getVersion
public static int getVersion() -
resetRandom
public static void resetRandom()Deprecated.UseParameter.setRandom(Random)insteadresets the PRNG
-
loadModel(Path)instead