Class ShotgunEnsembleClassifier


  • public class ShotgunEnsembleClassifier
    extends ASimplifiedTSClassifier<java.lang.Integer>
    Implementation of Shotgun Ensemble Classifier as published in "Towards Time Series Classfication without Human Preprocessing" by Patrick Schäfer (2014). The Shotgun Classifier is based 1-NN and the Shotgun Distance. The Shotgun Ensemble Algorithm ShotgunEnsembleAlgoritm determines for specific window lengths the number of correct predicitions on the training data using the leave-one-out technique. The bestScore is the highest number of correct predicitions over all window lengths. Given a factor in (0,1], the window lengths where correct * factor > bestScore are used in an ensemble of Shotgun Classifiers to create an overall predicition.
    • Field Detail

      • factor

        protected double factor
        Factor used to determine whether or not to include a window length into the overall predicition.
      • values

        protected double[][] values
        Value matrix containing the time series instances. Set by algorithm.
      • targets

        protected int[] targets
        Target values for the instances. Set by the algorithm.
      • nearestNeighborClassifier

        protected NearestNeighborClassifier nearestNeighborClassifier
        The nearest neighbor classifier used for prediction. Set by the algorithm.
      • windows

        protected java.util.ArrayList<ai.libs.jaicore.basic.sets.Pair<java.lang.Integer,​java.lang.Integer>> windows
        Holds pairs of (number of correct predictions, window length) obtained in training phase.
      • bestScore

        protected int bestScore
        The best score. States the highest number of correct predicitions for every window length used in training phase (leave-one-out).
    • Constructor Detail

      • ShotgunEnsembleClassifier

        public ShotgunEnsembleClassifier​(int minWindowLength,
                                         int maxWindowLength,
                                         boolean meanNormalization,
                                         double factor)
        Creates a Shotgun Ensemble classifier.
        Parameters:
        algorithm - The training algorithm.
        factor - Factor used to determine whether or not to include a window length into the overall predicition.
    • Method Detail

      • calculateWindowLengthPredictions

        protected java.util.Map<java.lang.Integer,​java.lang.Integer> calculateWindowLengthPredictions​(double[] testInstance)
                                                                                                     throws PredictionException
        Calculates predicitions for a test instance using 1NN with Shotgun Distance and different window lengths.
        Parameters:
        testInstance - The test instance.
        Returns:
        Map of (window length, prediciton) pairs.
        Throws:
        PredictionException
      • mostFrequentLabelFromWindowLengthPredicitions

        protected java.lang.Integer mostFrequentLabelFromWindowLengthPredicitions​(java.util.Map<java.lang.Integer,​java.lang.Integer> windowLengthPredicitions)
        Returns the most frequent predicition given a Map of (window length, prediciton) pairs.
        Parameters:
        windowLengthPredicitions - Map of (window length, prediciton) pairs.
        Returns:
        The most frequent predicition.
      • calculateWindowLengthPredictions

        protected java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> calculateWindowLengthPredictions​(TimeSeriesDataset dataset)
                                                                                                                     throws PredictionException
        Calculates predicitions for a test dataset using 1NN with Shotgun Distance and different window lengths.
        Parameters:
        dataset - The dataset to predict for.
        Returns:
        Map of (window length, predicitions) pairs.
        Throws:
        PredictionException
      • mostFrequentLabelsFromWindowLengthPredicitions

        protected java.util.List<java.lang.Integer> mostFrequentLabelsFromWindowLengthPredicitions​(java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> windowLengthPredicitions)
        Returns for each instance the most frequent predicitions as contained in a Map of (window length, list of prediciton for each instance) pairs.
        Parameters:
        windowLengthPredicitions - Map of (window length, list of prediciton for each instance) pairs.
        Returns:
        The most frequent predicition for each instace.
      • predict

        public java.lang.Integer predict​(double[] univInstance)
                                  throws PredictionException
        Predicts on univariate instance.
        Specified by:
        predict in class ASimplifiedTSClassifier<java.lang.Integer>
        Parameters:
        univInstance - The univariate instance.
        Returns:
        Class prediction for the instance.
        Throws:
        PredictionException - If something fails during the prediction process.
      • setValues

        protected void setValues​(double[][] values)
        Sets the value matrix.
        Parameters:
        values -
      • setTargets

        protected void setTargets​(int[] targets)
        Sets the targets.
        Parameters:
        targets -
      • setWindows

        protected void setWindows​(java.util.ArrayList<ai.libs.jaicore.basic.sets.Pair<java.lang.Integer,​java.lang.Integer>> windows)
        Sets the windows and also retreives and sets the @see #bestScore from these windows.
        Parameters:
        windows -
        See Also:
        windows