SciLib.Neuro.SVM
Class SVM

java.lang.Object
  extended by SciLib.Neuro.SVM.SVM
All Implemented Interfaces:
SMO
Direct Known Subclasses:
BSVM, DAGSVM, OAOSVM, OAASVM

public class SVM
extends java.lang.Object
implements SMO


Field Summary
protected  vector alpha
           
protected  double B
           
protected  double b_low
           
protected  double b_up
           
protected  boolean binary
           
protected  double C
           
protected  double eps
           
protected  vector error_cache
           
protected  FileHandler file
           
 int GACV1
           
protected  int i_low
           
protected  int i_up
           
 int JHB
           
protected  Kernel K
           
protected  int M
           
protected  int N
          variables
protected  matrix patterns
           
protected  boolean sparse
           
protected  vector sv
           
protected  integerVector svIndex
           
protected  integerVector targets
           
protected  double tolerance
           
 
Constructor Summary
SVM(FileHandler file, boolean binary, boolean sparse)
          Constructor - you must define Kernel
SVM(FileHandler file, Kernel K, boolean binary, boolean sparse)
          Constructor
SVM(matrix patterns, integerVector targets, Kernel K)
          Constructor
 
Method Summary
protected  void computeB()
          compute the the threshold value b
 void crossValidation(int k, double startLog2C, int cs, double startLambda, int ls, double a, double b)
           
 double f(int k)
          compute the decision function without the threshold value b
 double f(vector x)
          compute the decision function without the threshold value b
 vector getAlpha()
          get alpha vector
 double getB()
          get threshold value b
 double getC()
          get the value of C
 double getEpsi()
          get the epsilon parameter of SVM
 FileHandler getFile()
          get the object that handles data files
 Kernel getKernel()
          get kernel K
 int getNoOfSV()
          get the number of SVs
 matrix getPatterns()
          get patterns matrix when data is not sparse
 vector getSV()
          get support vectors
 integerVector getSVIndex()
          get indices of SVs
 integerVector getTargets()
          get targets vector of training data
 double getTolerance()
          get the tolerance of SVM
protected  void initialize(FileHandler file)
           
 void initiateParameter(double startlog2C, double startlog2Lambda, int cs, int ls, vector cp, vector lp)
           
 boolean isBinary()
          check if data is binary
protected  boolean isInI0I1I2(int i)
          check if index i is in Iup or in Ilow
protected  boolean isInI0I3I4(int i)
           
protected  boolean isInI1I2(int i)
           
protected  boolean isInI3I4(int i)
           
 boolean isSparse()
          check if data is sparse
 void LOOValidation(int type, double[] cPar, double[] lambdaPar, double a, double b)
           
 void LOOValidation(int type, double startLog2C, int cs, double startLambda, int ls, double a, double b)
           
static integerVector makeTargets(int k, integerVector targets)
           
 int misclassified(matrix p, integerVector t)
           
 void readSVs(java.lang.String alphaFile, vector sv, integerVector svIndex)
           
 void setB(double b)
          set the threshold b of SVM
 void setC(double C)
          set the parameter C of SVM
 void setEpsi(double eps)
          set the epsilon of SVM
 void setFile(FileHandler file)
          set the object that handles data files
 void setKernel(Kernel K)
          set the kernel of SVM
 void setN(int n)
           
 void setTolerance(double tolerance)
          set the tolerance of SVM
 double testing(FileHandler testFile)
           
 double testing(FileHandler testFile, double a, double b)
           
 double testing(FileHandler testFile, java.lang.String alphaFile)
           
 double testing(FileHandler testFile, java.lang.String alphaFile, double a, double b)
           
 void training(java.lang.String alphaFile)
           
 void training(java.lang.String alphaFile, double a, double b)
           
 void writeReport(java.lang.String fileName, java.lang.String header)
          write report about svm
 void writeResultToFile(java.lang.String fileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

N

protected int N
variables


M

protected int M

binary

protected boolean binary

sparse

protected boolean sparse

C

protected double C

B

protected double B

tolerance

protected double tolerance

eps

protected double eps

alpha

protected vector alpha

error_cache

protected vector error_cache

file

protected FileHandler file

K

protected Kernel K

patterns

protected matrix patterns

targets

protected integerVector targets

sv

protected vector sv

svIndex

protected integerVector svIndex

b_up

protected double b_up

b_low

protected double b_low

i_up

protected int i_up

i_low

protected int i_low

JHB

public final int JHB
See Also:
Constant Field Values

GACV1

public final int GACV1
See Also:
Constant Field Values
Constructor Detail

SVM

public SVM(FileHandler file,
           Kernel K,
           boolean binary,
           boolean sparse)
Constructor

Parameters:
file - the file that handles training data, FileHandler
K - the kernel of SVM, Kernel
binary - the data is binary or not, boolean
sparse - the data is sparse or not, boolean

SVM

public SVM(FileHandler file,
           boolean binary,
           boolean sparse)
Constructor - you must define Kernel

Parameters:
file - the file that handles training data, FileHandler
binary - the data is binary or not, boolean
sparse - the data is sparse or not, boolean

SVM

public SVM(matrix patterns,
           integerVector targets,
           Kernel K)
Constructor

Parameters:
patterns - the training data, a matrix
targets - the labels of taining patterns, an integerVector
K - the kernel of SVM, Kernel
Method Detail

initialize

protected void initialize(FileHandler file)

isBinary

public boolean isBinary()
check if data is binary

Returns:
true or false

isSparse

public boolean isSparse()
check if data is sparse

Returns:
true or false

getAlpha

public vector getAlpha()
get alpha vector

Returns:
alpha the dual variables - alpha vector

getB

public double getB()
get threshold value b

Returns:
the threshold value, a double

getKernel

public Kernel getKernel()
get kernel K

Returns:
K the Kernel using in SVM, a Kernel

getFile

public FileHandler getFile()
get the object that handles data files

Returns:
file a FileHandler

getPatterns

public matrix getPatterns()
get patterns matrix when data is not sparse

Returns:
patterns a matrix

getTargets

public integerVector getTargets()
get targets vector of training data

Returns:
targets a vector

setFile

public void setFile(FileHandler file)
set the object that handles data files

Parameters:
file - a FileHandler

setKernel

public void setKernel(Kernel K)
set the kernel of SVM

Parameters:
K - a Kernel

setB

public void setB(double b)
set the threshold b of SVM

Parameters:
b - a double

setTolerance

public void setTolerance(double tolerance)
set the tolerance of SVM

Parameters:
tolerance - a double

setEpsi

public void setEpsi(double eps)
set the epsilon of SVM

Parameters:
eps - a double

setC

public void setC(double C)
set the parameter C of SVM

Parameters:
C - a double

setN

public void setN(int n)

getTolerance

public double getTolerance()
get the tolerance of SVM

Returns:
a double

getEpsi

public double getEpsi()
get the epsilon parameter of SVM

Returns:
a double

getC

public double getC()
get the value of C

Returns:
a double

getNoOfSV

public int getNoOfSV()
get the number of SVs

Returns:
an int

getSV

public vector getSV()
get support vectors

Returns:
a vector

getSVIndex

public integerVector getSVIndex()
get indices of SVs

Returns:
an integerVector

writeResultToFile

public void writeResultToFile(java.lang.String fileName)

readSVs

public void readSVs(java.lang.String alphaFile,
                    vector sv,
                    integerVector svIndex)

isInI0I1I2

protected boolean isInI0I1I2(int i)
check if index i is in Iup or in Ilow

Parameters:
i - the index i
Returns:
a boolean

isInI0I3I4

protected boolean isInI0I3I4(int i)

isInI1I2

protected boolean isInI1I2(int i)

isInI3I4

protected boolean isInI3I4(int i)

computeB

protected void computeB()
compute the the threshold value b


writeReport

public void writeReport(java.lang.String fileName,
                        java.lang.String header)
write report about svm

Parameters:
fileName - fileName for store the report
header - the header string

makeTargets

public static integerVector makeTargets(int k,
                                        integerVector targets)

f

public double f(int k)
compute the decision function without the threshold value b

Parameters:
k - the index of the input data from the training set

f

public double f(vector x)
compute the decision function without the threshold value b

Parameters:
x - the input vector

initiateParameter

public void initiateParameter(double startlog2C,
                              double startlog2Lambda,
                              int cs,
                              int ls,
                              vector cp,
                              vector lp)

training

public void training(java.lang.String alphaFile)
Specified by:
training in interface SMO

training

public void training(java.lang.String alphaFile,
                     double a,
                     double b)
Specified by:
training in interface SMO

testing

public double testing(FileHandler testFile)
Specified by:
testing in interface SMO

testing

public double testing(FileHandler testFile,
                      java.lang.String alphaFile)
Specified by:
testing in interface SMO

testing

public double testing(FileHandler testFile,
                      double a,
                      double b)
Specified by:
testing in interface SMO

testing

public double testing(FileHandler testFile,
                      java.lang.String alphaFile,
                      double a,
                      double b)
Specified by:
testing in interface SMO

misclassified

public int misclassified(matrix p,
                         integerVector t)
Specified by:
misclassified in interface SMO

crossValidation

public void crossValidation(int k,
                            double startLog2C,
                            int cs,
                            double startLambda,
                            int ls,
                            double a,
                            double b)
Specified by:
crossValidation in interface SMO

LOOValidation

public void LOOValidation(int type,
                          double startLog2C,
                          int cs,
                          double startLambda,
                          int ls,
                          double a,
                          double b)
Specified by:
LOOValidation in interface SMO

LOOValidation

public void LOOValidation(int type,
                          double[] cPar,
                          double[] lambdaPar,
                          double a,
                          double b)
Specified by:
LOOValidation in interface SMO