Class NearestNeighbourDescription

    • Field Detail

      • neighbourhoodSizeOption

        public IntOption neighbourhoodSizeOption
    • Constructor Detail

      • NearestNeighbourDescription

        public NearestNeighbourDescription()
      • NearestNeighbourDescription

        public NearestNeighbourDescription​(List<Instance> trainingSet)
        Constructor for a Nearest Neighbour Description classifier based on an argument training set of instances.
        Parameters:
        trainingSet - the instances on which to train the classifier
    • Method Detail

      • resetLearningImpl

        public void resetLearningImpl()
        Resets the implementation's parameters and data structures.
        Specified by:
        resetLearningImpl in class AbstractClassifier
      • 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 class AbstractClassifier
        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 interface Classifier
        Specified by:
        getVotesForInstance in class AbstractClassifier
        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 interface OneClassClassifier
        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 interface Learner<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 class AbstractClassifier
        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 class AbstractClassifier
        Parameters:
        out - the stringbuilder to add the description
        indent - 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 interface OneClassClassifier
        Parameters:
        trainingPoints - the Collection of instances on which to initialize the NN-d classifier.