Class LearnPatternSimilarityLearningAlgorithm

  • All Implemented Interfaces:
    java.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>, java.util.concurrent.Callable<LearnPatternSimilarityClassifier>, java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>, org.api4.java.algorithm.IAlgorithm<ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2,​LearnPatternSimilarityClassifier>, 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 LearnPatternSimilarityLearningAlgorithm
    extends ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm<java.lang.Integer,​LearnPatternSimilarityClassifier>
    Algorithm training a LearnPatternSimilarityClassifier as described in Baydogan, Mustafa & Runger, George. (2015). Time series representation and similarity based on local autopatterns. Data Mining and Knowledge Discovery. 30. 1-34. 10.1007/s10618-015-0425-y.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      LearnPatternSimilarityClassifier call()
      Training procedure for a LearnPatternSimilarityClassifier.
      static void collectLeafCounts​(int[] leafNodeCountsForInstance, weka.core.Instance instance, AccessibleRandomTree regTree)
      Function collecting the leaf counts for the given instance as predicted by regTree.
      void generateSegmentsAndDifferencesForTree​(int[] segments, int[] segmentsDifference, int length, int timeSeriesLength, java.util.Random random)
      Method generating the segment start indices and the segment difference locations randomly using random.
      static weka.core.Instance generateSubseriesFeatureInstance​(double[] instValues, int[] segments, int[] segmentsDifference, int len)
      Function generating subseries feature instances based on the given segments and segmentsDifference matrices.
      static weka.core.Instances generateSubseriesFeaturesInstances​(java.util.List<weka.core.Attribute> attributes, int length, int[] segments, int[] segmentsDifference, double[][] dataMatrix)
      Function generating a dataset storing the features being generated as described in the original paper.
      LearnPatternSimilarityLearningAlgorithm.IPatternSimilarityConfig getConfig()  
      AccessibleRandomTree initializeRegressionTree​(int numInstances)
      Initializes a new instance of RandomRegressionTree.
      • Methods inherited from class ai.libs.jaicore.ml.classification.singlelabel.timeseries.learner.ASimplifiedTSCLearningAlgorithm

        cancel, getClassifier, hasNext, iterator, next, nextWithException, registerListener
      • 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
    • Constructor Detail

      • LearnPatternSimilarityLearningAlgorithm

        public LearnPatternSimilarityLearningAlgorithm​(LearnPatternSimilarityLearningAlgorithm.IPatternSimilarityConfig config,
                                                       LearnPatternSimilarityClassifier model,
                                                       ai.libs.jaicore.ml.classification.singlelabel.timeseries.dataset.TimeSeriesDataset2 dataset)
        Standard constructor.
        Parameters:
        seed - See LearnPatternSimilarityLearningAlgorithm#seed.
        numTrees - See LearnPatternSimilarityLearningAlgorithm#numTrees.
        maxTreeDepth - See LearnPatternSimilarityLearningAlgorithm#maxTreeDepth.
        numSegments - See LearnPatternSimilarityLearningAlgorithm#numSegments.
    • Method Detail

      • call

        public LearnPatternSimilarityClassifier call()
                                              throws org.api4.java.algorithm.exceptions.AlgorithmException,
                                                     org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException
        Training procedure for a LearnPatternSimilarityClassifier. At first, it generates randomly subsequences (segments) and subsequence difference locations used for feature generation. The generated features are used to train a forest of RandomRegressionTree models. The predicted leaf nodes are stored in the model for a 1NN search for an equally generated prediction leaf node matrix.
        Throws:
        org.api4.java.algorithm.exceptions.AlgorithmException
        org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException
      • generateSegmentsAndDifferencesForTree

        public void generateSegmentsAndDifferencesForTree​(int[] segments,
                                                          int[] segmentsDifference,
                                                          int length,
                                                          int timeSeriesLength,
                                                          java.util.Random random)
        Method generating the segment start indices and the segment difference locations randomly using random. This method used the length to specify the interval being generated. LearnPatternSimilarityLearningAlgorithm#numSegments * 2 many indices are generated. The start indices can only be between [0, timeSeriesLength - length] and the segment differences can only between [0, timeSeriesLength - length -1] (-1 due to the fact that the next index is used for the difference calculation).
        Parameters:
        segments - Segment start indices used for feature generation
        segmentsDifference - Segment difference start indices used for feature generation
        length - The length of the segments
        timeSeriesLength - The total length of the complete time series
        random - Generator for the random numbers
      • initializeRegressionTree

        public AccessibleRandomTree initializeRegressionTree​(int numInstances)
        Initializes a new instance of RandomRegressionTree.
        Parameters:
        numInstances - The number of instance used for latter training (used for setting the minimum number of instances per leaf)
        Returns:
        Returns the initialized tree
      • collectLeafCounts

        public static void collectLeafCounts​(int[] leafNodeCountsForInstance,
                                             weka.core.Instance instance,
                                             AccessibleRandomTree regTree)
                                      throws org.api4.java.ai.ml.core.exception.PredictionException
        Function collecting the leaf counts for the given instance as predicted by regTree. The result is stored at the induced leaf node index in leafNodeCountsForInstance.
        Parameters:
        leafNodeCountsForInstance - The vector storing the frequencies for each leaf node of the tree being the last node within the prediction
        instance - The given Weka instance which is fed to the regTree
        regTree - The regression tree used for prediction
        Throws:
        org.api4.java.ai.ml.core.exception.PredictionException - Thrown if the random regression tree could not predict anything for the given instance
      • generateSubseriesFeaturesInstances

        public static weka.core.Instances generateSubseriesFeaturesInstances​(java.util.List<weka.core.Attribute> attributes,
                                                                             int length,
                                                                             int[] segments,
                                                                             int[] segmentsDifference,
                                                                             double[][] dataMatrix)
        Function generating a dataset storing the features being generated as described in the original paper. The segments and segmentsDifference indices are used to extract subsequences of the given dataMatrix and generating value differences, respectively.
        Parameters:
        attributes - The attributes used by Weka to create the dataset
        length - The length considered for the feature generation
        segments - Segment start indices used for feature generation
        segmentsDifference - Segment difference start indices used for feature generation
        dataMatrix - Matrix storing the instance values used for feature generation
        Returns:
        Returns Weka instances storing the generated features
      • generateSubseriesFeatureInstance

        public static weka.core.Instance generateSubseriesFeatureInstance​(double[] instValues,
                                                                          int[] segments,
                                                                          int[] segmentsDifference,
                                                                          int len)
        Function generating subseries feature instances based on the given segments and segmentsDifference matrices. The len parameter indicates which subsequence instance is generated within this call. The values are extracted and used for calculation (for difference) from instValues.
        Parameters:
        instValues - Instance values used for feature generation
        segments - Segment start indices used for feature generation
        segmentsDifference - Segment difference start indices used for feature generation
        len - Current length (is added to the segment and segment difference locations)
        Returns:
        Returns a Weka instance storing the generated features