public class LVQ extends Object implements Classifier, Parameterized
SOM
to take advantage of label information to perform classification. It creates
a number of representatives, or learning vectors, for each class. The LVs are
then updated iteratively to push away from the wrong class and pull closer to
the correct class. LVQ is equivalent to a type of 2 layer neural network.Modifier and Type | Class and Description |
---|---|
static class |
LVQ.LVQVersion
There are several LVQ versions, each one adding an additional case in
which two LVs instead of one can be updated.
|
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_EPS
The default eps distance factor between the two wining vectors
0.3
|
static int |
DEFAULT_ITERATIONS
The default number of iterations is 200
|
static double |
DEFAULT_LEARNING_RATE
The default learning rate 0.1
|
static LVQ.LVQVersion |
DEFAULT_LVQ_METHOD
The default method of LVQ to use LVQ3
|
static double |
DEFAULT_MSCALE
The default scaling factor for the
LVQ.LVQVersion.LVQ3 case is
0.30000000000000004 |
static int |
DEFAULT_REPS_PER_CLASS
The default number of representatives per class is
3
|
static SeedSelectionMethods.SeedSelection |
DEFAULT_SEED_SELECTION
The default seed selection method is SeedSelection.KPP
|
static double |
DEFAULT_STOPPING_DIST
The default stopping distance for convergence is
0.001
|
protected DistanceMetric |
dm
The distance metric to use
|
protected VectorCollection<VecPaired<Vec,Integer>> |
vc
Contains the Learning vectors paired with their index in the weights array
|
protected int[] |
weightClass
Array of the class that each learning vector represents
|
protected Vec[] |
weights
Array containing the learning vectors
|
protected int[] |
wins
Records the number of times each neuron won and was off the correct class
during training.
|
Modifier | Constructor and Description |
---|---|
|
LVQ(DistanceMetric dm,
int iterations)
Creates a new LVQ instance
|
|
LVQ(DistanceMetric dm,
int iterations,
double learningRate,
int representativesPerClass)
Creates a new LVQ instance
|
|
LVQ(DistanceMetric dm,
int iterations,
double learningRate,
int representativesPerClass,
LVQ.LVQVersion lvqVersion,
DecayRate learningDecay)
Creates a new LVQ instance
|
protected |
LVQ(LVQ toCopy)
Copy Constructor
|
Modifier and Type | Method and Description |
---|---|
CategoricalResults |
classify(DataPoint data)
Performs classification on the given data point.
|
LVQ |
clone() |
protected boolean |
epsClose(double minDist,
double minDist2)
Returns true if the two distance values are within an acceptable epsilon
ratio of each other.
|
DistanceMetric |
getDistanceMetric()
Returns the distance metric to use
|
double |
getEpsilonDistance()
Sets the epsilon scale distance between learning vectors that may be
allowed to two at a time.
|
int |
getIterations()
Returns the number of iterations of the algorithm to apply
|
DecayRate |
getLearningDecay()
Returns the method used to decay the learning rate over each iteration
|
double |
getLearningRate()
Returns the learning rate at which to apply updates during the algorithm.
|
LVQ.LVQVersion |
getLVQMethod()
Returns the version of the LVQ algorithm to use.
|
double |
getMScale()
Returns the scale used for the LVQ 3 learning algorithm update set.
|
Parameter |
getParameter(String paramName)
Returns the parameter with the given name.
|
List<Parameter> |
getParameters()
Returns the list of parameters that can be altered for this learner.
|
int |
getRepresentativesPerClass()
Returns the number of representatives to create for each class.
|
SeedSelectionMethods.SeedSelection |
getSeedSelection()
Returns the method of seed selection used
|
double |
getStoppingDist()
Returns the stopping distance used to terminate the algorithm early
|
void |
setDistanceMetric(DistanceMetric dm)
Sets the distance used for learning
|
void |
setEpsilonDistance(double eps)
Sets the epsilon multiplier that controls the maximum distance two
learning vectors can be from each other in order to be updated at the
same time.
|
void |
setIterations(int iterations)
Sets the number of learning iterations that will occur.
|
void |
setLearningDecay(DecayRate learningDecay)
Sets the decay rate to apply to the learning rate.
|
void |
setLearningRate(double learningRate)
Sets the learning rate of the algorithm.
|
void |
setLVQMethod(LVQ.LVQVersion lvqMethod)
Sets the version of LVQ used.
|
void |
setMScale(double mScale)
When using
LVQ.LVQVersion.LVQ3 , a 3rd case exists where up to two
learning vectors can be updated at the same time if they have the same
class. |
void |
setRepresentativesPerClass(int representativesPerClass)
Sets the number of representatives to create for each class.
|
void |
setSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)
Sets the seed selection method used to select the initial learning vectors
|
void |
setStoppingDist(double stoppingDist)
The algorithm terminates early if the learning vectors are only moving
small distances.
|
void |
setVecCollectionFactory(VectorCollectionFactory<VecPaired<Vec,Integer>> vcf)
Sets the vector collection factory to use when storing the final learning vectors
|
boolean |
supportsWeightedData()
Indicates whether the model knows how to train using weighted data points.
|
void |
trainC(ClassificationDataSet dataSet)
Trains the classifier and constructs a model for classification using the
given data set.
|
void |
trainC(ClassificationDataSet dataSet,
ExecutorService threadPool)
Trains the classifier and constructs a model for classification using the
given data set.
|
public static final int DEFAULT_ITERATIONS
public static final double DEFAULT_LEARNING_RATE
public static final double DEFAULT_EPS
public static final double DEFAULT_MSCALE
LVQ.LVQVersion.LVQ3
case is
0.30000000000000004public static final LVQ.LVQVersion DEFAULT_LVQ_METHOD
public static final int DEFAULT_REPS_PER_CLASS
public static final double DEFAULT_STOPPING_DIST
public static final SeedSelectionMethods.SeedSelection DEFAULT_SEED_SELECTION
protected DistanceMetric dm
protected Vec[] weights
protected int[] weightClass
protected int[] wins
protected VectorCollection<VecPaired<Vec,Integer>> vc
public LVQ(DistanceMetric dm, int iterations)
dm
- the distance metric to useiterations
- the number of iterations to performpublic LVQ(DistanceMetric dm, int iterations, double learningRate, int representativesPerClass)
dm
- the distance metric to useiterations
- the number of iterations to performlearningRate
- the learning rate to use when updatingrepresentativesPerClass
- the number of representatives to create
for each classpublic LVQ(DistanceMetric dm, int iterations, double learningRate, int representativesPerClass, LVQ.LVQVersion lvqVersion, DecayRate learningDecay)
dm
- the distance metric to useiterations
- the number of iterations to performlearningRate
- the learning rate to use when updatingrepresentativesPerClass
- the number of representatives to create
for each classlvqVersion
- the version of LVQ to uselearningDecay
- the amount of decay to apply to the learning rateprotected LVQ(LVQ toCopy)
toCopy
- version to copypublic void setMScale(double mScale)
LVQ.LVQVersion.LVQ3
, a 3rd case exists where up to two
learning vectors can be updated at the same time if they have the same
class. To avoid over fitting, an additional regularizing weight is placed
upon the learning rate for their update. THis sets the additional
multiplied. It is suggested to use a value in the range of [0.1, 0.5]mScale
- the multiplication factor to apply to the learning vectorspublic double getMScale()
public void setEpsilonDistance(double eps)
eps
- the scale factor of the maximum distance for two learning
vectors to be updated at the same timepublic double getEpsilonDistance()
public void setLearningRate(double learningRate)
setLearningDecay(jsat.math.decayrates.DecayRate)
.learningRate
- the learning rate to usepublic double getLearningRate()
public void setLearningDecay(DecayRate learningDecay)
learningDecay
- the rate to decay the learning ratepublic DecayRate getLearningDecay()
public void setIterations(int iterations)
iterations
- the number of iterations for the algorithm to usepublic int getIterations()
public void setRepresentativesPerClass(int representativesPerClass)
representativesPerClass
- the number of representatives to create
for each classpublic int getRepresentativesPerClass()
public void setLVQMethod(LVQ.LVQVersion lvqMethod)
lvqMethod
- the version of LVQ to usepublic LVQ.LVQVersion getLVQMethod()
public void setDistanceMetric(DistanceMetric dm)
dm
- the distance metric to usepublic DistanceMetric getDistanceMetric()
public void setStoppingDist(double stoppingDist)
stoppingDist
- the minimum distance for each learning vector to movepublic double getStoppingDist()
public void setSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)
seedSelection
- the method of initialing LVQpublic SeedSelectionMethods.SeedSelection getSeedSelection()
public List<Parameter> getParameters()
Parameterized
getParameters
in interface Parameterized
public Parameter getParameter(String paramName)
Parameterized
getParameter
in interface Parameterized
paramName
- the name of the parameter to obtainpublic void setVecCollectionFactory(VectorCollectionFactory<VecPaired<Vec,Integer>> vcf)
vcf
- the vector collection factory to usepublic CategoricalResults classify(DataPoint data)
Classifier
classify
in interface Classifier
data
- the data point to classifyprotected boolean epsClose(double minDist, double minDist2)
minDist
- the first distanceminDist2
- the second distancepublic void trainC(ClassificationDataSet dataSet, ExecutorService threadPool)
Classifier
trainC
in interface Classifier
dataSet
- the data set to train onthreadPool
- the source of threads to use.public void trainC(ClassificationDataSet dataSet)
Classifier
trainC
in interface Classifier
dataSet
- the data set to train onpublic boolean supportsWeightedData()
Classifier
supportsWeightedData
in interface Classifier
public LVQ clone()
clone
in interface Classifier
clone
in class Object
Copyright © 2017. All rights reserved.