Package moa.classifiers.oneclass
Class NearestNeighbourDescription
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- moa.classifiers.oneclass.NearestNeighbourDescription
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,MultiClassClassifier
,OneClassClassifier
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
public class NearestNeighbourDescription extends AbstractClassifier implements Classifier, OneClassClassifier
Implements David Tax's Nearest Neighbour Description method described in Section 3.4.2 of D. M. J. Tax, “One-Class Classification: Concept-learning in the absence of counter-examples,” Delft University of Technology, 2001 with adaptations for the data stream environment.- Author:
- Richard Hugh Moulton
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description IntOption
neighbourhoodSizeOption
FloatOption
thresholdOption
-
Fields inherited from class moa.classifiers.AbstractClassifier
classifierRandom, modelContext, randomSeed, randomSeedOption, trainingWeightSeenByModel
-
Fields inherited from class moa.options.AbstractOptionHandler
config
-
-
Constructor Summary
Constructors Constructor Description NearestNeighbourDescription()
NearestNeighbourDescription(List<Instance> trainingSet)
Constructor for a Nearest Neighbour Description classifier based on an argument training set of instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getAnomalyScore(Instance inst)
Returns the anomaly score for an argument instance based on the distance from it to its nearest neighbour compared to the distance from its nearest neighbour to the neighbour's nearest neighbour.void
getModelDescription(StringBuilder out, int indent)
Returns a string representation of the model.protected Measurement[]
getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.String
getPurposeString()
Dictionary with option texts and objectsdouble[]
getVotesForInstance(Instance inst)
Calculates the distance between the argument instance and its nearest neighbour as well as the distance between that nearest neighbour and its own nearest neighbour.void
initialize(Collection<Instance> trainingPoints)
Initializes the Nearest Neighbour Distance (NN-d) classifier with the argument training points.boolean
isRandomizable()
Nearest Neighbour Description is not randomizable.void
resetLearningImpl()
Resets the implementation's parameters and data structures.void
trainOnInstanceImpl(Instance inst)
The classifier adds the argument instance to its neighbourhood.-
Methods inherited from class moa.classifiers.AbstractClassifier
contextIsCompatible, copy, correctlyClassifies, defineImmutableCapabilities, getAttributeNameString, getAWTRenderer, getClassLabelString, getClassNameString, getDescription, getModel, getModelContext, getModelMeasurements, getNominalValueString, getPredictionForInstance, getPredictionForInstance, getSubClassifiers, getSublearners, getVotesForInstance, modelAttIndexToInstanceAttIndex, modelAttIndexToInstanceAttIndex, prepareForUseImpl, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance, trainOnInstance
-
Methods inherited from class moa.options.AbstractOptionHandler
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
-
Methods inherited from class moa.AbstractMOAObject
copy, measureByteSize, measureByteSize, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface moa.gui.AWTRenderable
getAWTRenderer
-
Methods inherited from interface moa.capabilities.CapabilitiesHandler
getCapabilities
-
Methods inherited from interface moa.classifiers.Classifier
copy, correctlyClassifies, getPredictionForInstance, getSubClassifiers, trainOnInstance
-
Methods inherited from interface moa.learners.Learner
getModel, getModelContext, getModelMeasurements, getPredictionForInstance, getSublearners, getVotesForInstance, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance
-
Methods inherited from interface moa.MOAObject
getDescription, measureByteSize
-
Methods inherited from interface moa.options.OptionHandler
getCLICreationString, getOptions, prepareForUse, prepareForUse
-
-
-
-
Field Detail
-
neighbourhoodSizeOption
public IntOption neighbourhoodSizeOption
-
thresholdOption
public FloatOption thresholdOption
-
-
Method Detail
-
getPurposeString
public String getPurposeString()
Description copied from class:AbstractOptionHandler
Dictionary with option texts and objects- Specified by:
getPurposeString
in interfaceOptionHandler
- Overrides:
getPurposeString
in classAbstractClassifier
- Returns:
- the string with the purpose of this object
-
resetLearningImpl
public void resetLearningImpl()
Resets the implementation's parameters and data structures.- Specified by:
resetLearningImpl
in classAbstractClassifier
-
trainOnInstanceImpl
public void trainOnInstanceImpl(Instance inst)
The classifier adds the argument instance to its neighbourhood. If the neighbourhood is full, then the FixedLengthList removes the oldest instance in it to accommodate the new instance.- Specified by:
trainOnInstanceImpl
in classAbstractClassifier
- Parameters:
inst
- the instance to be used for training
-
getVotesForInstance
public double[] getVotesForInstance(Instance inst)
Calculates the distance between the argument instance and its nearest neighbour as well as the distance between that nearest neighbour and its own nearest neighbour. The ratio of these distances is compared to the threshold value, tau, and converted into a vote score.- Specified by:
getVotesForInstance
in interfaceClassifier
- Specified by:
getVotesForInstance
in classAbstractClassifier
- Parameters:
inst
- the instance to get votes for.- Returns:
- the votes for the instance's label [normal, outlier]
-
getAnomalyScore
public double getAnomalyScore(Instance inst)
Returns the anomaly score for an argument instance based on the distance from it to its nearest neighbour compared to the distance from its nearest neighbour to the neighbour's nearest neighbour.- Specified by:
getAnomalyScore
in interfaceOneClassClassifier
- Parameters:
inst
- the argument instance- Returns:
- d(inst, instNN) / d(instNN, instNNNN)
-
isRandomizable
public boolean isRandomizable()
Nearest Neighbour Description is not randomizable.- Specified by:
isRandomizable
in interfaceLearner<Example<Instance>>
- Returns:
- true if the learner needs a random seed.
-
getModelMeasurementsImpl
protected Measurement[] getModelMeasurementsImpl()
Description copied from class:AbstractClassifier
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
getModelMeasurementsImpl
in classAbstractClassifier
- Returns:
- an array of measurements to be used in evaluation tasks
-
getModelDescription
public void getModelDescription(StringBuilder out, int indent)
Description copied from class:AbstractClassifier
Returns a string representation of the model.- Specified by:
getModelDescription
in classAbstractClassifier
- Parameters:
out
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
initialize
public void initialize(Collection<Instance> trainingPoints)
Initializes the Nearest Neighbour Distance (NN-d) classifier with the argument training points.- Specified by:
initialize
in interfaceOneClassClassifier
- Parameters:
trainingPoints
- the Collection of instances on which to initialize the NN-d classifier.
-
-