Package gov.nih.mipav.model.algorithms
Class LIBSVM
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.LIBSVM
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class LIBSVM extends AlgorithmBase
Copyright (c) 2000-2023 Chih-Chung Chang and Chih-Jen Lin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither name of copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. It solves C-SVM classification, nu-SVM classification, one-class-SVM, epsilon-SVM regression, and nu-SVM regression. It also provides an automatic model selection tool for C-SVM classification. This document explains the use of libsvm. Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support vector machines. ACM Transactions on Intelligent Systems and Technology, 2:27:1--27:27, 2011. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm LIBSVM implementation document is available at http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
LIBSVM.Cache
(package private) class
LIBSVM.decision_function
(package private) class
LIBSVM.Kernel
(package private) class
LIBSVM.ONE_CLASS_Q
(package private) class
LIBSVM.QMatrix
(package private) class
LIBSVM.Solver
(package private) class
LIBSVM.Solver_NU
(package private) class
LIBSVM.SVC_Q
class
LIBSVM.svm_model
class
LIBSVM.svm_node
class
LIBSVM.svm_parameter
static interface
LIBSVM.svm_print_interface
class
LIBSVM.svm_problem
(package private) class
LIBSVM.svm_toy_frame
(package private) class
LIBSVM.SVR_Q
-
Field Summary
Fields Modifier and Type Field Description private int
cross_validation
private java.lang.String
error_msg
private double[]
feature_max
private double[]
feature_min
private java.lang.String
input_file_name
(package private) java.lang.String[]
kernel_type_table
int
LIBSVM_VERSION
private java.lang.String
line
private double
lower
private int
max_index
private LIBSVM.svm_model
model
private java.lang.String
model_file_name
private long
new_num_nonzeros
private int
nr_fold
private long
num_nonzeros
private LIBSVM.svm_parameter
param
private LIBSVM.svm_problem
prob
java.util.Random
rand
private LIBSVM.svm_print_interface
svm_print_null
private LIBSVM.svm_print_interface
svm_print_stdout
private LIBSVM.svm_print_interface
svm_print_string
(package private) java.lang.String[]
svm_type_table
private double
upper
private double
y_lower
private double
y_max
private double
y_min
private boolean
y_scaling
private double
y_upper
-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description LIBSVM()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private double
atof(java.lang.String s)
private int
atoi(java.lang.String s)
private void
do_cross_validation()
(package private) double
dot(LIBSVM.svm_node[] x, LIBSVM.svm_node[] y)
(package private) void
info(java.lang.String s)
(package private) double
k_function(LIBSVM.svm_node[] x, LIBSVM.svm_node[] y, LIBSVM.svm_parameter param)
private void
multiclass_probability(int k, double[][] r, double[] p)
private void
output(int index, double value)
private void
output_target(double value)
private void
parse_command_line(java.lang.String[] argv, boolean haveFile)
private double
powi(double base, int times)
private void
predict(java.io.BufferedReader input, java.io.DataOutputStream output, LIBSVM.svm_model model, int predict_probability)
private void
predict_exit_with_help()
private double
predict_one_class_probability(LIBSVM.svm_model model, double dec_value)
private boolean
read_model_header(java.io.BufferedReader fp, LIBSVM.svm_model model)
private void
read_problem()
private void
read_XY(double[][] Xin, double[] y)
private java.lang.String
readline(java.io.BufferedReader fp)
private java.io.BufferedReader
rewind(java.io.BufferedReader fp, java.lang.String filename)
void
run_svm_predict(java.lang.String[] argv)
void
run_svm_scale(java.lang.String[] argv)
void
run_svm_toy(java.lang.String[] args)
LIBSVM.svm_model
run_svm_train(double[][] Xin, double[] y, java.lang.String[] argv)
void
run_svm_train(java.lang.String[] argv)
void
runAlgorithm()
Actually runs the algorithm.private void
scale_exit_with_help()
private double
sigmoid_predict(double decision_value, double A, double B)
private void
sigmoid_train(int l, double[] dec_values, double[] labels, double[] probAB)
private void
solve_c_svc(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si, double Cp, double Cn)
private void
solve_epsilon_svr(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
private void
solve_nu_svc(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
private void
solve_nu_svr(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
private void
solve_one_class(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
private void
svm_binary_svc_probability(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double Cp, double Cn, double[] probAB)
java.lang.String
svm_check_parameter(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param)
int
svm_check_probability_model(LIBSVM.svm_model model)
void
svm_cross_validation(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, int nr_fold, double[] target)
void
svm_get_labels(LIBSVM.svm_model model, int[] label)
int
svm_get_nr_class(LIBSVM.svm_model model)
int
svm_get_nr_sv(LIBSVM.svm_model model)
void
svm_get_sv_indices(LIBSVM.svm_model model, int[] indices)
int
svm_get_svm_type(LIBSVM.svm_model model)
double
svm_get_svr_probability(LIBSVM.svm_model model)
private void
svm_group_classes(LIBSVM.svm_problem prob, int[] nr_class_ret, int[][] label_ret, int[][] start_ret, int[][] count_ret, int[] perm)
LIBSVM.svm_model
svm_load_model(java.io.BufferedReader fp)
LIBSVM.svm_model
svm_load_model(java.lang.String model_file_name)
private int
svm_one_class_probability(LIBSVM.svm_problem prob, LIBSVM.svm_model model, double[] prob_density_marks)
double
svm_predict(LIBSVM.svm_model model, LIBSVM.svm_node[] x)
double
svm_predict_probability(LIBSVM.svm_model model, LIBSVM.svm_node[] x, double[] prob_estimates)
double
svm_predict_values(LIBSVM.svm_model model, LIBSVM.svm_node[] x, double[] dec_values)
void
svm_save_model(java.lang.String model_file_name, LIBSVM.svm_model model)
void
svm_set_print_string_function(LIBSVM.svm_print_interface print_func)
private double
svm_svr_probability(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param)
LIBSVM.svm_model
svm_train(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param)
(package private) LIBSVM.decision_function
svm_train_one(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double Cp, double Cn)
private void
train_exit_with_help()
-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
LIBSVM_VERSION
public final int LIBSVM_VERSION
- See Also:
- Constant Field Values
-
rand
public final java.util.Random rand
-
svm_print_stdout
private LIBSVM.svm_print_interface svm_print_stdout
-
svm_print_string
private LIBSVM.svm_print_interface svm_print_string
-
svm_type_table
final java.lang.String[] svm_type_table
-
kernel_type_table
final java.lang.String[] kernel_type_table
-
param
private LIBSVM.svm_parameter param
-
prob
private LIBSVM.svm_problem prob
-
model
private LIBSVM.svm_model model
-
input_file_name
private java.lang.String input_file_name
-
model_file_name
private java.lang.String model_file_name
-
error_msg
private java.lang.String error_msg
-
cross_validation
private int cross_validation
-
nr_fold
private int nr_fold
-
svm_print_null
private LIBSVM.svm_print_interface svm_print_null
-
line
private java.lang.String line
-
lower
private double lower
-
upper
private double upper
-
y_lower
private double y_lower
-
y_upper
private double y_upper
-
y_scaling
private boolean y_scaling
-
feature_max
private double[] feature_max
-
feature_min
private double[] feature_min
-
y_max
private double y_max
-
y_min
private double y_min
-
max_index
private int max_index
-
num_nonzeros
private long num_nonzeros
-
new_num_nonzeros
private long new_num_nonzeros
-
-
Method Detail
-
info
void info(java.lang.String s)
-
solve_c_svc
private void solve_c_svc(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si, double Cp, double Cn)
-
solve_nu_svc
private void solve_nu_svc(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
-
solve_one_class
private void solve_one_class(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
-
solve_epsilon_svr
private void solve_epsilon_svr(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
-
solve_nu_svr
private void solve_nu_svr(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double[] alpha, LIBSVM.Solver.SolutionInfo si)
-
svm_train_one
LIBSVM.decision_function svm_train_one(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double Cp, double Cn)
-
sigmoid_train
private void sigmoid_train(int l, double[] dec_values, double[] labels, double[] probAB)
-
sigmoid_predict
private double sigmoid_predict(double decision_value, double A, double B)
-
multiclass_probability
private void multiclass_probability(int k, double[][] r, double[] p)
-
svm_binary_svc_probability
private void svm_binary_svc_probability(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, double Cp, double Cn, double[] probAB)
-
predict_one_class_probability
private double predict_one_class_probability(LIBSVM.svm_model model, double dec_value)
-
svm_one_class_probability
private int svm_one_class_probability(LIBSVM.svm_problem prob, LIBSVM.svm_model model, double[] prob_density_marks)
-
svm_svr_probability
private double svm_svr_probability(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param)
-
svm_group_classes
private void svm_group_classes(LIBSVM.svm_problem prob, int[] nr_class_ret, int[][] label_ret, int[][] start_ret, int[][] count_ret, int[] perm)
-
svm_train
public LIBSVM.svm_model svm_train(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param)
-
svm_cross_validation
public void svm_cross_validation(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param, int nr_fold, double[] target)
-
svm_get_svm_type
public int svm_get_svm_type(LIBSVM.svm_model model)
-
svm_get_nr_class
public int svm_get_nr_class(LIBSVM.svm_model model)
-
svm_get_labels
public void svm_get_labels(LIBSVM.svm_model model, int[] label)
-
svm_get_sv_indices
public void svm_get_sv_indices(LIBSVM.svm_model model, int[] indices)
-
svm_get_nr_sv
public int svm_get_nr_sv(LIBSVM.svm_model model)
-
svm_get_svr_probability
public double svm_get_svr_probability(LIBSVM.svm_model model)
-
powi
private double powi(double base, int times)
-
dot
double dot(LIBSVM.svm_node[] x, LIBSVM.svm_node[] y)
-
k_function
double k_function(LIBSVM.svm_node[] x, LIBSVM.svm_node[] y, LIBSVM.svm_parameter param)
-
svm_predict_values
public double svm_predict_values(LIBSVM.svm_model model, LIBSVM.svm_node[] x, double[] dec_values)
-
svm_predict
public double svm_predict(LIBSVM.svm_model model, LIBSVM.svm_node[] x)
-
svm_predict_probability
public double svm_predict_probability(LIBSVM.svm_model model, LIBSVM.svm_node[] x, double[] prob_estimates)
-
svm_save_model
public void svm_save_model(java.lang.String model_file_name, LIBSVM.svm_model model) throws java.io.IOException
- Throws:
java.io.IOException
-
read_model_header
private boolean read_model_header(java.io.BufferedReader fp, LIBSVM.svm_model model)
-
svm_load_model
public LIBSVM.svm_model svm_load_model(java.lang.String model_file_name) throws java.io.IOException
- Throws:
java.io.IOException
-
svm_load_model
public LIBSVM.svm_model svm_load_model(java.io.BufferedReader fp) throws java.io.IOException
- Throws:
java.io.IOException
-
svm_check_parameter
public java.lang.String svm_check_parameter(LIBSVM.svm_problem prob, LIBSVM.svm_parameter param)
-
svm_check_probability_model
public int svm_check_probability_model(LIBSVM.svm_model model)
-
svm_set_print_string_function
public void svm_set_print_string_function(LIBSVM.svm_print_interface print_func)
-
train_exit_with_help
private void train_exit_with_help()
-
do_cross_validation
private void do_cross_validation()
-
run_svm_train
public LIBSVM.svm_model run_svm_train(double[][] Xin, double[] y, java.lang.String[] argv) throws java.io.IOException
- Throws:
java.io.IOException
-
run_svm_train
public void run_svm_train(java.lang.String[] argv) throws java.io.IOException
- Throws:
java.io.IOException
-
atof
private double atof(java.lang.String s)
-
atoi
private int atoi(java.lang.String s)
-
parse_command_line
private void parse_command_line(java.lang.String[] argv, boolean haveFile)
-
read_XY
private void read_XY(double[][] Xin, double[] y)
-
read_problem
private void read_problem() throws java.io.IOException
- Throws:
java.io.IOException
-
predict
private void predict(java.io.BufferedReader input, java.io.DataOutputStream output, LIBSVM.svm_model model, int predict_probability) throws java.io.IOException
- Throws:
java.io.IOException
-
predict_exit_with_help
private void predict_exit_with_help()
-
run_svm_predict
public void run_svm_predict(java.lang.String[] argv) throws java.io.IOException
- Throws:
java.io.IOException
-
scale_exit_with_help
private void scale_exit_with_help()
-
rewind
private java.io.BufferedReader rewind(java.io.BufferedReader fp, java.lang.String filename) throws java.io.IOException
- Throws:
java.io.IOException
-
output_target
private void output_target(double value)
-
output
private void output(int index, double value)
-
readline
private java.lang.String readline(java.io.BufferedReader fp) throws java.io.IOException
- Throws:
java.io.IOException
-
run_svm_scale
public void run_svm_scale(java.lang.String[] argv) throws java.io.IOException
- Throws:
java.io.IOException
-
run_svm_toy
public void run_svm_toy(java.lang.String[] args)
-
runAlgorithm
public void runAlgorithm()
Description copied from class:AlgorithmBase
Actually runs the algorithm. Implemented by inheriting algorithms.- Specified by:
runAlgorithm
in classAlgorithmBase
-
-