Class ShapeletTransformLearningAlgorithm

  • All Implemented Interfaces:
    java.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>, java.util.concurrent.Callable<ShapeletTransformTSClassifier>, java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>, org.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,​ShapeletTransformTSClassifier>, org.api4.java.common.control.ICancelable, org.api4.java.common.control.ILoggingCustomizable, org.api4.java.common.event.IEventEmitter<java.lang.Object>, org.api4.java.common.event.IRelaxedEventEmitter

    public class ShapeletTransformLearningAlgorithm
    extends ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,​ShapeletTransformTSClassifier>
    Algorithm training a ShapeletTransform classifier as described in Jason Lines, Luke M. Davis, Jon Hills, and Anthony Bagnall. 2012. A shapelet transform for time series classification. In Proceedings of the 18th ACM SIGKDD international conference on Knowledge discovery and data mining (KDD '12). ACM, New York, NY, USA, 289-297.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ShapeletTransformTSClassifier call()
      Training procedure for ShapeletTransformTSClassifier using the training algorithm described in the paper.
      java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> clusterShapelets​(java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, int noClusters, long beginTime)
      Clusters the given shapelets into noClusters clusters (cf. algorithm 6 of the original paper).
      java.util.List<java.lang.Double> findDistances​(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet s, double[][] matrix)
      Function finding the minimum single squared Euclidean distance for each instance among all of its subsequences compared to the shapelet s.
      static java.util.Set<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> generateCandidates​(double[] data, int l, int candidateIndex)
      Function generation shapelet candidates for a given instance vector data, the length l and the candidate index which is used to identify the source of the shapelet's data.
      ShapeletTransformLearningAlgorithm.IShapeletTransformLearningAlgorithmConfig getConfig()
      ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy getMinDistanceSearchStrategy()
      static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> merge​(int k, java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> kShapelets, java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> shapelets)
      Function merging shapelet lists based on their quality scores.
      org.api4.java.algorithm.events.IAlgorithmEvent nextWithException()
      void registerListener​(java.lang.Object listener)
      static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> removeSelfSimilar​(java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> shapelets)
      Function removing self-similar shapelets from a list storing shapelet and their quality entries.
      void setMinDistanceSearchStrategy​(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy minDistanceSearchStrategy)
      static double[] shapeletTransform​(double[] instance, java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)
      Function transforming the given instance into the new feature space spanned by the shapelets.
      static ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 shapeletTransform​(ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataSet, java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets, org.api4.java.algorithm.Timeout timeout, long beginTime, ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)
      Performs a shapelet transform on a complete dataSet.
      • Methods inherited from class ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm

        cancel, getClassifier, hasNext, iterator, next
      • Methods inherited from class ai.libs.jaicore.basic.algorithm.AAlgorithm

        activate, announceTimeoutDetected, avoidReinterruptionOnShutdownOnCurrentThread, checkAndConductTermination, checkTermination, computeTimeoutAware, getActivationTime, getDeadline, getId, getInput, getListeners, getLoggerName, getNumCPUs, getRemainingTimeToDeadline, getState, getTimeout, getTimeoutPrecautionOffset, hasThreadBeenInterruptedDuringShutdown, interruptThreadAsPartOfShutdown, isCanceled, isShutdownInitialized, isStopCriterionSatisfied, isTimeoutDefined, isTimeouted, post, registerActiveThread, resolveShutdownInterruptOnCurrentThread, setConfig, setDeadline, setLoggerName, setMaxNumThreads, setNumCPUs, setState, setTimeout, setTimeout, setTimeoutPrecautionOffset, shutdown, terminate, unregisterActiveThread, unregisterThreadAndShutdown
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Method Detail

      • call

        public ShapeletTransformTSClassifier call()
                                           throws org.api4.java.algorithm.exceptions.AlgorithmException,
                                                  java.lang.InterruptedException
        Training procedure for ShapeletTransformTSClassifier using the training algorithm described in the paper.
        Returns:
        Returns the trained model
        Throws:
        org.api4.java.algorithm.exceptions.AlgorithmException - Thrown if the training could not be finished
        java.lang.InterruptedException
      • clusterShapelets

        public java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> clusterShapelets​(java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets,
                                                                                                                            int noClusters,
                                                                                                                            long beginTime)
                                                                                                                     throws java.lang.InterruptedException
        Clusters the given shapelets into noClusters clusters (cf. algorithm 6 of the original paper).
        Parameters:
        shapelets - Shapelets to be clustered.
        noClusters - Number of clusters to be used, i. e. the size of the output list
        beginTime - Begin time of the training execution used for the timeout checks
        Returns:
        Returns the clustered shapelets
        Throws:
        java.lang.InterruptedException - Thrown when a timeout occurred
      • merge

        public static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> merge​(int k,
                                                                                                                                                                    java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> kShapelets,
                                                                                                                                                                    java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> shapelets)
        Function merging shapelet lists based on their quality scores. Only the k best shapelets of the union of both lists are retained.
        Parameters:
        k - Number of elements to be retained
        kShapelets - The previous best shapelets
        shapelets - The new shapelets to be added to the top-k list
        Returns:
        Returns the list containing the k best shapelets only
      • removeSelfSimilar

        public static java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> removeSelfSimilar​(java.util.List<java.util.Map.Entry<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet,​java.lang.Double>> shapelets)
        Function removing self-similar shapelets from a list storing shapelet and their quality entries. See isSelfSimilar(Shapelet, Shapelet).
        Parameters:
        shapelets - Shapelets to be compared
        Returns:
        A sublist from the given shapelets list which does not contain any self-similar shapelets
      • findDistances

        public java.util.List<java.lang.Double> findDistances​(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet s,
                                                              double[][] matrix)
        Function finding the minimum single squared Euclidean distance for each instance among all of its subsequences compared to the shapelet s.
        Parameters:
        s - Shapelet which is compared to the instances
        matrix - Matrix storing the data instance vectors
        Returns:
        Returns the list of all minimum distances of the shapelet and all the instances
      • generateCandidates

        public static java.util.Set<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> generateCandidates​(double[] data,
                                                                                                                                    int l,
                                                                                                                                    int candidateIndex)
        Function generation shapelet candidates for a given instance vector data, the length l and the candidate index which is used to identify the source of the shapelet's data.
        Parameters:
        data - Data vector from which the values are extracted
        l - The length of the generated candidate shapelet
        candidateIndex - Instance index which is used to identify the generated shapelets
        Returns:
        Returns a set of shapelet candidates with the length l
      • shapeletTransform

        public static ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 shapeletTransform​(ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataSet,
                                                                                                                            java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets,
                                                                                                                            org.api4.java.algorithm.Timeout timeout,
                                                                                                                            long beginTime,
                                                                                                                            ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)
                                                                                                                     throws java.lang.InterruptedException
        Performs a shapelet transform on a complete dataSet. See ShapeletTransformLearningAlgorithm#shapeletTransform(double[], List).
        Parameters:
        dataSet - Data set to be transformed
        shapelets - Shapelets used as new feature dimensions
        timeout - Timeout compared to the current time difference to the beginTime
        beginTime - System time in ms when the training algorithm has started
        searchStrategy - Search strategy used to find the minimum distance from a shapelet to the time series
        Returns:
        Returns the transformed data set
        Throws:
        java.lang.InterruptedException - Thrown if there was a timeout
      • shapeletTransform

        public static double[] shapeletTransform​(double[] instance,
                                                 java.util.List<ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.Shapelet> shapelets,
                                                 ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy searchStrategy)
        Function transforming the given instance into the new feature space spanned by the shapelets. Uses the minimum squared Euclidean distance of the corresponding shapelets to the instance as feature values.
        Parameters:
        instance - The instance to be transformed
        shapelets - The shapelets to be used as new feature dimensions
        searchStrategy - Search strategy used to find the minimum distance from a shapelet to the time series
        Returns:
        Returns the transformed instance feature vector
      • getMinDistanceSearchStrategy

        public ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy getMinDistanceSearchStrategy()
        Returns:
        the minDistanceSearchStrategy
      • setMinDistanceSearchStrategy

        public void setMinDistanceSearchStrategy​(ai.libs.jaicore.ml.classification.singlelabel.timeseries.shapelets.search.AMinimumDistanceSearchStrategy minDistanceSearchStrategy)
        Parameters:
        minDistanceSearchStrategy - the minDistanceSearchStrategy to set
      • registerListener

        public void registerListener​(java.lang.Object listener)
        Specified by:
        registerListener in interface org.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,​ShapeletTransformTSClassifier>
        Specified by:
        registerListener in interface org.api4.java.common.event.IEventEmitter<java.lang.Object>
        Overrides:
        registerListener in class ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,​ShapeletTransformTSClassifier>
      • nextWithException

        public org.api4.java.algorithm.events.IAlgorithmEvent nextWithException()
        Specified by:
        nextWithException in interface org.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,​ShapeletTransformTSClassifier>
        Overrides:
        nextWithException in class ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,​ShapeletTransformTSClassifier>