jsat.classifiers.neuralnetwork
Class LVQ
- java.lang.Object
-
- jsat.classifiers.neuralnetwork.LVQ
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized
- Direct Known Subclasses:
- LVQLLC
public class LVQ extends java.lang.Object implements Classifier, Parameterized
Learning Vector Quantization (LVQ) is an algorithm that extendsSOMto 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.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classLVQ.LVQVersionThere are several LVQ versions, each one adding an additional case in which two LVs instead of one can be updated.
-
Field Summary
Fields Modifier and Type Field and Description static doubleDEFAULT_EPSThe default eps distance factor between the two wining vectors 0.3static intDEFAULT_ITERATIONSThe default number of iterations is 200static doubleDEFAULT_LEARNING_RATEThe default learning rate 0.1static LVQ.LVQVersionDEFAULT_LVQ_METHODThe default method of LVQ to use LVQ3static doubleDEFAULT_MSCALEThe default scaling factor for theLVQ.LVQVersion.LVQ3case is 0.30000000000000004static intDEFAULT_REPS_PER_CLASSThe default number of representatives per class is 3static SeedSelectionMethods.SeedSelectionDEFAULT_SEED_SELECTIONThe default seed selection method is SeedSelection.KPPstatic doubleDEFAULT_STOPPING_DISTThe default stopping distance for convergence is 0.001
-
Constructor Summary
Constructors Constructor and Description LVQ(DistanceMetric dm, int iterations)Creates a new LVQ instanceLVQ(DistanceMetric dm, int iterations, double learningRate, int representativesPerClass)Creates a new LVQ instanceLVQ(DistanceMetric dm, int iterations, double learningRate, int representativesPerClass, LVQ.LVQVersion lvqVersion, DecayRate learningDecay)Creates a new LVQ instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.LVQclone()DistanceMetricgetDistanceMetric()Returns the distance metric to usedoublegetEpsilonDistance()Sets the epsilon scale distance between learning vectors that may be allowed to two at a time.intgetIterations()Returns the number of iterations of the algorithm to applyDecayRategetLearningDecay()Returns the method used to decay the learning rate over each iterationdoublegetLearningRate()Returns the learning rate at which to apply updates during the algorithm.LVQ.LVQVersiongetLVQMethod()Returns the version of the LVQ algorithm to use.doublegetMScale()Returns the scale used for the LVQ 3 learning algorithm update set.intgetRepresentativesPerClass()Returns the number of representatives to create for each class.SeedSelectionMethods.SeedSelectiongetSeedSelection()Returns the method of seed selection useddoublegetStoppingDist()Returns the stopping distance used to terminate the algorithm earlyvoidsetDistanceMetric(DistanceMetric dm)Sets the distance used for learningvoidsetEpsilonDistance(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.voidsetIterations(int iterations)Sets the number of learning iterations that will occur.voidsetLearningDecay(DecayRate learningDecay)Sets the decay rate to apply to the learning rate.voidsetLearningRate(double learningRate)Sets the learning rate of the algorithm.voidsetLVQMethod(LVQ.LVQVersion lvqMethod)Sets the version of LVQ used.voidsetMScale(double mScale)When usingLVQ.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.voidsetRepresentativesPerClass(int representativesPerClass)Sets the number of representatives to create for each class.voidsetSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)Sets the seed selection method used to select the initial learning vectorsvoidsetStoppingDist(double stoppingDist)The algorithm terminates early if the learning vectors are only moving small distances.voidsetVecCollection(VectorCollection<VecPaired<Vec,java.lang.Integer>> vcf)Sets the vector collection factory to use when storing the final learning vectorsbooleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Field Detail
-
DEFAULT_ITERATIONS
public static final int DEFAULT_ITERATIONS
The default number of iterations is 200- See Also:
- Constant Field Values
-
DEFAULT_LEARNING_RATE
public static final double DEFAULT_LEARNING_RATE
The default learning rate 0.1- See Also:
- Constant Field Values
-
DEFAULT_EPS
public static final double DEFAULT_EPS
The default eps distance factor between the two wining vectors 0.3- See Also:
- Constant Field Values
-
DEFAULT_MSCALE
public static final double DEFAULT_MSCALE
The default scaling factor for theLVQ.LVQVersion.LVQ3case is 0.30000000000000004- See Also:
- Constant Field Values
-
DEFAULT_LVQ_METHOD
public static final LVQ.LVQVersion DEFAULT_LVQ_METHOD
The default method of LVQ to use LVQ3
-
DEFAULT_REPS_PER_CLASS
public static final int DEFAULT_REPS_PER_CLASS
The default number of representatives per class is 3- See Also:
- Constant Field Values
-
DEFAULT_STOPPING_DIST
public static final double DEFAULT_STOPPING_DIST
The default stopping distance for convergence is 0.001- See Also:
- Constant Field Values
-
DEFAULT_SEED_SELECTION
public static final SeedSelectionMethods.SeedSelection DEFAULT_SEED_SELECTION
The default seed selection method is SeedSelection.KPP
-
-
Constructor Detail
-
LVQ
public LVQ(DistanceMetric dm, int iterations)
Creates a new LVQ instance- Parameters:
dm- the distance metric to useiterations- the number of iterations to perform
-
LVQ
public LVQ(DistanceMetric dm, int iterations, double learningRate, int representativesPerClass)
Creates a new LVQ instance- Parameters:
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 class
-
LVQ
public LVQ(DistanceMetric dm, int iterations, double learningRate, int representativesPerClass, LVQ.LVQVersion lvqVersion, DecayRate learningDecay)
Creates a new LVQ instance- Parameters:
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 rate
-
-
Method Detail
-
setMScale
public void setMScale(double mScale)
When usingLVQ.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]- Parameters:
mScale- the multiplication factor to apply to the learning vectors
-
getMScale
public double getMScale()
Returns the scale used for the LVQ 3 learning algorithm update set.- Returns:
- a scale used during LVQ3
-
setEpsilonDistance
public 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. If they are too far apart, only one can be updated. It is recommended to use a value in the range [0.1, 0.3]- Parameters:
eps- the scale factor of the maximum distance for two learning vectors to be updated at the same time
-
getEpsilonDistance
public double getEpsilonDistance()
Sets the epsilon scale distance between learning vectors that may be allowed to two at a time.- Returns:
- the scale of the allowable distance between learning vectors when updating
-
setLearningRate
public void setLearningRate(double learningRate)
Sets the learning rate of the algorithm. It should be set in accordance withsetLearningDecay(jsat.math.decayrates.DecayRate).- Parameters:
learningRate- the learning rate to use
-
getLearningRate
public double getLearningRate()
Returns the learning rate at which to apply updates during the algorithm.- Returns:
- the learning rate to use
-
setLearningDecay
public void setLearningDecay(DecayRate learningDecay)
Sets the decay rate to apply to the learning rate.- Parameters:
learningDecay- the rate to decay the learning rate
-
getLearningDecay
public DecayRate getLearningDecay()
Returns the method used to decay the learning rate over each iteration- Returns:
- the decay rate used at each iteration
-
setIterations
public void setIterations(int iterations)
Sets the number of learning iterations that will occur.- Parameters:
iterations- the number of iterations for the algorithm to use
-
getIterations
public int getIterations()
Returns the number of iterations of the algorithm to apply- Returns:
- the number of iterations to perform
-
setRepresentativesPerClass
public void setRepresentativesPerClass(int representativesPerClass)
Sets the number of representatives to create for each class. It is possible to have an unbalanced number of representatives per class, but that is not currently supported. Increasing the number of representatives per class increases the complexity of the decision boundary that can be learned.- Parameters:
representativesPerClass- the number of representatives to create for each class
-
getRepresentativesPerClass
public int getRepresentativesPerClass()
Returns the number of representatives to create for each class.- Returns:
- the number of representatives to create for each class.
-
setLVQMethod
public void setLVQMethod(LVQ.LVQVersion lvqMethod)
Sets the version of LVQ used.- Parameters:
lvqMethod- the version of LVQ to use
-
getLVQMethod
public LVQ.LVQVersion getLVQMethod()
Returns the version of the LVQ algorithm to use.- Returns:
- the version of the LVQ algorithm to use.
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric dm)
Sets the distance used for learning- Parameters:
dm- the distance metric to use
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
Returns the distance metric to use- Returns:
- the distance metric to use
-
setStoppingDist
public void setStoppingDist(double stoppingDist)
The algorithm terminates early if the learning vectors are only moving small distances. The stopping distance is the minimum distance that one of the learning vectors must move for the algorithm to continue.- Parameters:
stoppingDist- the minimum distance for each learning vector to move
-
getStoppingDist
public double getStoppingDist()
Returns the stopping distance used to terminate the algorithm early- Returns:
- the stopping distance used toe nd the algorithm early
-
setSeedSelection
public void setSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)
Sets the seed selection method used to select the initial learning vectors- Parameters:
seedSelection- the method of initialing LVQ
-
getSeedSelection
public SeedSelectionMethods.SeedSelection getSeedSelection()
Returns the method of seed selection used- Returns:
- the method of seed selection used
-
setVecCollection
public void setVecCollection(VectorCollection<VecPaired<Vec,java.lang.Integer>> vcf)
Sets the vector collection factory to use when storing the final learning vectors- Parameters:
vcf- the vector collection factory to use
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public LVQ clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG