jsat.classifiers.knn
Class DANN
- java.lang.Object
-
- jsat.classifiers.knn.DANN
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized
public class DANN extends java.lang.Object implements Classifier, Parameterized
DANN is an implementation of Discriminant Adaptive Nearest Neighbor. DANN has a fixed O(n) classification time. At each classification, DANN uses a large set of points to iteratively create and adjust a distance metic that reflects the separability of classes at a localized level. This increases the work considerably over a normalNearestNeighbourclassifier. The localized metric is similar to theMahalanobisDistance
Because DANN builds its own metric, it is not possible to provide one. TheVectorCollectionFactoryallowed in the constructor is to accelerate the first convergence step. In homogeneous areas of the data set, queries can be answered in O(log n) if the vector collection supports it.
See: Hastie, T.,&Tibshirani, R. (1996). Discriminant adaptive nearest neighbor classification. IEEE Transactions on Pattern Analysis and Machine Intelligence, 18(6), 607–616. doi:10.1109/34.506411- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleDEFAULT_EPSThe default regularization used when building a metric is 1.0static intDEFAULT_ITERATIONSThe default number of iterations for creating the metric is 1static intDEFAULT_KThe default number of neighbors to use when classifying is 1static intDEFAULT_KNThe default number of neighbors to use when building a metric is 40.
-
Constructor Summary
Constructors Constructor and Description DANN()Creates a new DANN classifierDANN(int kn, int k)Creates a new DANN classifierDANN(int kn, int k, double eps)Creates a new DANN classifierDANN(int kn, int k, double eps, int maxIterations, VectorCollection<VecPaired<Vec,java.lang.Integer>> vcf)Creates a new DANN classifierDANN(int kn, int k, double eps, VectorCollection<VecPaired<Vec,java.lang.Integer>> vcf)Creates a new DANN classifier
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.Classifierclone()doublegetEpsilon()Returns the regularization parameter that is applied to the diagonal of the matrix when creating each new metric.intgetK()Returns the number of nearest neighbors to use when predictingintgetKn()Returns the number of nearest neighbors to use when adapting the distance metricintgetMaxIterations()Returns the number of times the distance metric will be updated.static DistributionguessK(DataSet d)Guesses the distribution to use for the number of neighbors to considerstatic DistributionguessKn(DataSet d)Guesses the distribution to use for the number of neighbors to considervoidsetEpsilon(double eps)Sets the regularization to apply the the diagonal of the scatter matrix when creating each new metric.voidsetK(int k)Sets the number of nearest neighbors to use when predictingvoidsetKn(int kn)Sets the number of nearest neighbors to use when adapting the distance metric.voidsetMaxIterations(int maxIterations)Sets the number of times a new distance metric will be created for each query.booleansupportsWeightedData()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_KN
public static final int DEFAULT_KN
The default number of neighbors to use when building a metric is 40.- See Also:
- Constant Field Values
-
DEFAULT_K
public static final int DEFAULT_K
The default number of neighbors to use when classifying is 1- See Also:
- Constant Field Values
-
DEFAULT_EPS
public static final double DEFAULT_EPS
The default regularization used when building a metric is 1.0- See Also:
- Constant Field Values
-
DEFAULT_ITERATIONS
public static final int DEFAULT_ITERATIONS
The default number of iterations for creating the metric is 1- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DANN
public DANN()
Creates a new DANN classifier
-
DANN
public DANN(int kn, int k)Creates a new DANN classifier- Parameters:
kn- the number of neighbors to use in casting a net to build a new metrick- the number of neighbors to use with the final metric in classification
-
DANN
public DANN(int kn, int k, double eps)Creates a new DANN classifier- Parameters:
kn- the number of neighbors to use in casting a net to build a new metrick- the number of neighbors to use with the final metric in classificationeps- the regularization to add to the metric creation
-
DANN
public DANN(int kn, int k, double eps, VectorCollection<VecPaired<Vec,java.lang.Integer>> vcf)Creates a new DANN classifier- Parameters:
kn- the number of neighbors to use in casting a net to build a new metrick- the number of neighbors to use with the final metric in classificationeps- the regularization to add to the metric creationvcf- the default vector collection that will be used for initial neighbor search
-
DANN
public DANN(int kn, int k, double eps, int maxIterations, VectorCollection<VecPaired<Vec,java.lang.Integer>> vcf)Creates a new DANN classifier- Parameters:
kn- the number of neighbors to use in casting a net to build a new metrick- the number of neighbors to use with the final metric in classificationeps- the regularization to add to the metric creationmaxIterations- the maximum number of times to adjust the metric for each classificationvcf- the default vector collection that will be used for initial neighbor search
-
-
Method Detail
-
setK
public void setK(int k)
Sets the number of nearest neighbors to use when predicting- Parameters:
k- the number of neighbors
-
getK
public int getK()
Returns the number of nearest neighbors to use when predicting- Returns:
- the number of neighbors used for classification
-
setKn
public void setKn(int kn)
Sets the number of nearest neighbors to use when adapting the distance metric. At each iteration of the algorithm, a new distance metric will be created. A larger number of neighbors is used to create a net of points, around which the metric will be adapted.- Parameters:
kn- the number of neighbors to use
-
getKn
public int getKn()
Returns the number of nearest neighbors to use when adapting the distance metric- Returns:
- the number of neighbors used to adapt the metric
-
setMaxIterations
public void setMaxIterations(int maxIterations)
Sets the number of times a new distance metric will be created for each query. The metric should converge quickly. For this reason, and do to a lack of performance difference, it is highly recommended to use the default of 1 iteration.- Parameters:
maxIterations- the maximum number of times the metric will be updated
-
getMaxIterations
public int getMaxIterations()
Returns the number of times the distance metric will be updated.- Returns:
- the number of iterations the metric will be updated
-
setEpsilon
public void setEpsilon(double eps)
Sets the regularization to apply the the diagonal of the scatter matrix when creating each new metric.- Parameters:
eps- the regularization value
-
getEpsilon
public double getEpsilon()
Returns the regularization parameter that is applied to the diagonal of the matrix when creating each new metric.- Returns:
- the regularization used.
-
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 Classifier clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
guessK
public static Distribution guessK(DataSet d)
Guesses the distribution to use for the number of neighbors to consider- Parameters:
d- the dataset to get the guess for- Returns:
- the guess for the K parameter
-
guessKn
public static Distribution guessKn(DataSet d)
Guesses the distribution to use for the number of neighbors to consider- Parameters:
d- the dataset to get the guess for- Returns:
- the guess for the Kn parameter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG