Package libai.nn.supervised
Class SVM
- java.lang.Object
-
- libai.nn.NeuralNetwork
-
- libai.nn.supervised.SupervisedLearning
-
- libai.nn.supervised.SVM
-
- All Implemented Interfaces:
java.io.Serializable
public class SVM extends SupervisedLearning
Implementation of the SVM using the SMO algorithm. Based on the original implementation of:
X. Jiang and H. Yu. SVM-JAVA: A Java implementation of the SMO (Sequential Minimal Optimization) for training SVM.
Department of Computer Science and Engineering, Pohang University of Science and Technology (POSTECH), http://iis.hwanjoyu.org/svm-java, 2008. The code was adapted to the data structures and architecture of the libai. Some little optimization was made.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
PARAM_C
static int
PARAM_EPSILON
static int
PARAM_TOLERANCE
protected static SymmetricSign
ssign
-
Fields inherited from class libai.nn.NeuralNetwork
plotter, progress, random
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
error(Column[] patterns, Column[] answers, int offset, int length)
Calculates the mean quadratic error.void
setTrainingParam(int param, double paramValue)
Column
simulate(Column pattern)
Calculates the output for thepattern
.void
simulate(Column pattern, Column result)
Calculates the output for thepattern
and left the result inresult
.void
train(Column[] patterns, Column[] answers, double alpha, int epochs, int offset, int length, double minerror)
Trains this neural network with the list ofpatterns
and the expectedanswers
.protected void
validatePreconditions(Column[] patterns, Column[] answers, int epochs, int offset, int length, double minerror)
-
Methods inherited from class libai.nn.NeuralNetwork
error, euclideanDistance2, euclideanDistance2, gaussian, getDefaultRandomGenerator, getPlotter, getProgressBar, initializeProgressBar, open, open, open, save, setPlotter, setProgressBar, train, train
-
-
-
-
Field Detail
-
PARAM_C
public static final int PARAM_C
- See Also:
- Constant Field Values
-
PARAM_EPSILON
public static final int PARAM_EPSILON
- See Also:
- Constant Field Values
-
PARAM_TOLERANCE
public static final int PARAM_TOLERANCE
- See Also:
- Constant Field Values
-
ssign
protected static final SymmetricSign ssign
-
-
Method Detail
-
setTrainingParam
public void setTrainingParam(int param, double paramValue)
-
validatePreconditions
protected void validatePreconditions(Column[] patterns, Column[] answers, int epochs, int offset, int length, double minerror)
- Overrides:
validatePreconditions
in classSupervisedLearning
-
train
public void train(Column[] patterns, Column[] answers, double alpha, int epochs, int offset, int length, double minerror)
Description copied from class:NeuralNetwork
Trains this neural network with the list ofpatterns
and the expectedanswers
.Use the learning rate
alpha
for manyepochs
. Takelength
patterns from the positionoffset
until theminerror
is reached.patterns
andanswers
must be arrays of non-null
column matrices- Specified by:
train
in classNeuralNetwork
- Parameters:
patterns
- The patterns to be learned.answers
- The expected answers.alpha
- The learning rate.epochs
- The maximum number of iterationsoffset
- The first pattern positionlength
- How many patterns will be used.minerror
- The minimal error expected.
-
simulate
public Column simulate(Column pattern)
Description copied from class:NeuralNetwork
Calculates the output for thepattern
.- Specified by:
simulate
in classNeuralNetwork
- Parameters:
pattern
- Pattern to use as input.- Returns:
- The output for the neural network.
-
simulate
public void simulate(Column pattern, Column result)
Description copied from class:NeuralNetwork
Calculates the output for thepattern
and left the result inresult
.- Specified by:
simulate
in classNeuralNetwork
- Parameters:
pattern
- Pattern to use as input.result
- The output for the input.
-
error
public double error(Column[] patterns, Column[] answers, int offset, int length)
Description copied from class:NeuralNetwork
Calculates the mean quadratic error. It is the standard error metric for neural networks. Just a few networks needs a different type of error metric.patterns
andanswers
must be arrays of non-null
column matricesNOTE: Assertions of the dimensions are made with
assert
statement. You must enable this on runtime to be effective.- Overrides:
error
in classNeuralNetwork
- Parameters:
patterns
- The array with the patterns to testanswers
- The array with the expected answers for the patterns.offset
- The initial position inside the array.length
- How many patterns must be taken from the offset.- Returns:
- The mean quadratic error.
-
-