public abstract class LibSvmSolver extends Object implements BinaryLearningAlgorithm
Further details can be found in:
[CC Chang & CJ Lin, 2011] 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.
and
http://www.csie.ntu.edu.tw/~cjlin/libsvm/
Modifier and Type | Class and Description |
---|---|
protected class |
LibSvmSolver.Pair
The pair of indices i and j that are selected as working set
|
Modifier and Type | Field and Description |
---|---|
protected int[] |
active_set
The set of active examples with 0 < alpha[i] < get_C(i)
|
protected int |
active_size
The number of active examples with 0 < alpha[i] < get_C(i)
|
protected float[] |
alpha
The weight \(\alpha\) of the Support Vectors
|
protected it.uniroma2.sag.kelp.learningalgorithm.classification.libsvm.solver.LibSvmSolver.AlphaStatus[] |
alpha_status
The status of each example
|
protected float |
cn
The regularization parameter of negative examples
|
protected float |
cp
The regularization parameter of positive examples
|
protected static boolean |
doShrinking
A boolean value to apply shrinking
|
protected float |
eps
Tolerance of termination criterion
|
protected Example[] |
examples
The input examples
|
protected float[] |
G
Gradient
|
protected float[] |
G_bar
Gradient bar
|
protected Kernel |
kernel
The Kernel function between examples, i.e.
|
protected int |
l
Total number of Support Vectors
|
protected Label |
label
The label to be learned by the classifier
|
protected static int |
logIteration
The number of iteration to be accomplished to print info in the standard
output
|
protected float[] |
p |
protected float[] |
QD
Q-MATRIX is derived from kernel matrix: Q_{ij}=y_{i}*y_{j}*K_{ij}
|
protected static int |
shrinkingIteration
Number of iterations to be accomplished before shrinking
|
protected static float |
TAU
A small positive constant to
|
protected boolean |
unshrink |
protected int[] |
y
The integer label \(\pm 1\) of the training example
|
Constructor and Description |
---|
LibSvmSolver() |
LibSvmSolver(Kernel kernel,
float Cp,
float Cn) |
Modifier and Type | Method and Description |
---|---|
protected abstract float |
calculate_rho() |
protected abstract void |
do_shrinking()
Apply the shrinking step
|
protected float[] |
get_QD()
For each example i, it return the K_ii score
|
protected float |
get_Qij(int i,
int j) |
float |
getCn() |
float |
getCp() |
float |
getEps() |
Kernel |
getKernel() |
Label |
getLabel() |
List<Label> |
getLabels()
Returns the labels representing the concept to be learned.
|
protected void |
info(String msg) |
protected boolean |
is_free(int i)
Check if 0 < alpha[i] < get_C(i)
|
protected boolean |
is_lower_bound(int i)
Check if alpha[i] <= 0
|
protected boolean |
is_upper_bound(int i)
Check if alpha[i] >= get_C(i)
|
protected float |
kernel(Example exA,
Example exB)
This function embeds the call to the kernel function
|
protected void |
reconstruct_gradient()
Reconstruct inactive elements of G from G_bar and free variables
|
protected abstract int |
select_working_set(LibSvmSolver.Pair pair)
Select the working set in each iteration.
|
void |
setC(float c) |
void |
setCn(float cn) |
void |
setCp(float cp) |
void |
setEps(float eps) |
void |
setLabel(Label label) |
void |
setLabels(List<Label> labels)
Sets the labels representing the concept to be learned.
|
SvmSolution |
solve(int l_,
Dataset dataset,
float[] p_,
int[] y_,
float[] initial_alpha)
It solves the SMO algorithm in [CC Chang & CJ Lin, 2011]
min 0.5(\alpha^T Q \alpha) + p^T \alpha
y^T \alpha = \delta
y_i = +1 or -1 0 <= alpha_i <= Cp for y_i = 1 0 <= alpha_i <= Cn for y_i = -1 Given: Q, p, y, Cp, Cn, and an initial feasible point \alpha l is the size of vectors and matrices eps is the stopping tolerance solution will be put in \alpha, objective value will be put in obj |
protected void |
swap_index(int i,
int j)
Swap the info of two examples
|
protected void |
swap(Example[] array,
int i,
int j) |
protected void |
swap(float[] array,
int i,
int j) |
protected void |
swap(int[] array,
int i,
int j) |
protected void |
swap(it.uniroma2.sag.kelp.learningalgorithm.classification.libsvm.solver.LibSvmSolver.AlphaStatus[] array,
int i,
int j) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
duplicate, getPredictionFunction, learn, reset
protected float cp
protected float cn
protected Kernel kernel
protected Label label
protected boolean unshrink
protected int l
protected int[] y
protected Example[] examples
protected float[] alpha
protected float[] p
protected float[] QD
protected it.uniroma2.sag.kelp.learningalgorithm.classification.libsvm.solver.LibSvmSolver.AlphaStatus[] alpha_status
protected int[] active_set
protected int active_size
protected float[] G
protected float[] G_bar
protected static final float TAU
protected static final int shrinkingIteration
protected static final int logIteration
protected float eps
protected static final boolean doShrinking
public LibSvmSolver()
public LibSvmSolver(Kernel kernel, float Cp, float Cn)
kernel
- The kernel functionCp
- The regularization parameter for positive examplesCn
- The regularization parameter for negative examplesprotected abstract float calculate_rho()
protected abstract void do_shrinking()
protected float[] get_QD()
protected float get_Qij(int i, int j)
public float getCn()
public float getCp()
public Kernel getKernel()
public Label getLabel()
getLabel
in interface BinaryLearningAlgorithm
public List<Label> getLabels()
LearningAlgorithm
getLabels
in interface BinaryLearningAlgorithm
getLabels
in interface LearningAlgorithm
protected void info(String msg)
protected boolean is_free(int i)
i
- the index of the exampleprotected boolean is_lower_bound(int i)
i
- the index of the exampleprotected boolean is_upper_bound(int i)
i
- the index of the exampleprotected float kernel(Example exA, Example exB)
exA
- exB
- protected void reconstruct_gradient()
protected abstract int select_working_set(LibSvmSolver.Pair pair)
pair
- The Q_ij to be evaluatedpublic void setCn(float cn)
cn
- The regularization parameter for positive examplespublic void setCp(float cp)
cp
- The regularization parameter for negative examplespublic void setC(float c)
c
- The regularization parameter for both positive and negative examplespublic void setLabel(Label label)
setLabel
in interface BinaryLearningAlgorithm
public void setLabels(List<Label> labels)
LearningAlgorithm
setLabels
in interface BinaryLearningAlgorithm
setLabels
in interface LearningAlgorithm
labels
- the labels representing the concept to be learnedpublic SvmSolution solve(int l_, Dataset dataset, float[] p_, int[] y_, float[] initial_alpha)
l_
- the size of input examplesdataset
- the datasetp_
- y_
- the labels of the examplesinitial_alpha
- the initial \(\alpha\) valuespublic float getEps()
public void setEps(float eps)
eps
- tolerance of termination criterion (default 0.001)protected void swap(it.uniroma2.sag.kelp.learningalgorithm.classification.libsvm.solver.LibSvmSolver.AlphaStatus[] array, int i, int j)
protected void swap(Example[] array, int i, int j)
protected void swap(float[] array, int i, int j)
protected void swap(int[] array, int i, int j)
protected void swap_index(int i, int j)
i
- the first example indexj
- the second example indexCopyright © 2018 Semantic Analytics Group @ Uniroma2. All rights reserved.