Class TimeSeriesUtils


  • public class TimeSeriesUtils
    extends Object
    • Method Detail

      • movingAverage

        public static INDArray movingAverage​(INDArray toAvg,
                                             int n)
        Calculate a moving average given the length
        Parameters:
        toAvg - the array to average
        n - the length of the moving window
        Returns:
        the moving averages for each row
      • reshapeTimeSeriesMaskToVector

        public static INDArray reshapeTimeSeriesMaskToVector​(INDArray timeSeriesMask)
        Reshape time series mask arrays. This should match the assumptions (f order, etc) in RnnOutputLayer
        Parameters:
        timeSeriesMask - Mask array to reshape to a column vector
        Returns:
        Mask array as a column vector
      • reshapeTimeSeriesMaskToVector

        public static INDArray reshapeTimeSeriesMaskToVector​(INDArray timeSeriesMask,
                                                             LayerWorkspaceMgr workspaceMgr,
                                                             ArrayType arrayType)
        Reshape time series mask arrays. This should match the assumptions (f order, etc) in RnnOutputLayer
        Parameters:
        timeSeriesMask - Mask array to reshape to a column vector
        Returns:
        Mask array as a column vector
      • reshapeTimeSeriesMaskToCnn4dMask

        public static INDArray reshapeTimeSeriesMaskToCnn4dMask​(INDArray timeSeriesMask,
                                                                LayerWorkspaceMgr workspaceMgr,
                                                                ArrayType arrayType)
        Reshape time series mask arrays. This should match the assumptions (f order, etc) in RnnOutputLayer This reshapes from [X,1] to [X,1,1,1] suitable for per-example masking in CNNs
        Parameters:
        timeSeriesMask - Mask array to reshape for CNN per-example masking
        Returns:
        Mask array as 4D CNN mask array: [X, 1, 1, 1]
      • reshapeVectorToTimeSeriesMask

        public static INDArray reshapeVectorToTimeSeriesMask​(INDArray timeSeriesMaskAsVector,
                                                             int minibatchSize)
        Reshape time series mask arrays. This should match the assumptions (f order, etc) in RnnOutputLayer
        Parameters:
        timeSeriesMaskAsVector - Mask array to reshape to a column vector
        Returns:
        Mask array as a column vector
      • reshapeCnnMaskToTimeSeriesMask

        public static INDArray reshapeCnnMaskToTimeSeriesMask​(INDArray timeSeriesMaskAsCnnMask,
                                                              int minibatchSize)
        Reshape CNN-style 4d mask array of shape [seqLength*minibatch,1,1,1] to time series mask [mb,seqLength] This should match the assumptions (f order, etc) in RnnOutputLayer
        Parameters:
        timeSeriesMaskAsCnnMask - Mask array to reshape
        Returns:
        Sequence mask array - [minibatch, sequenceLength]
      • reshapePerOutputTimeSeriesMaskTo2d

        public static INDArray reshapePerOutputTimeSeriesMaskTo2d​(INDArray perOutputTimeSeriesMask)
      • reshape2dTo3d

        public static INDArray reshape2dTo3d​(INDArray in,
                                             int miniBatchSize)
      • reverseTimeSeries

        public static INDArray reverseTimeSeries​(INDArray in)
        Reverse an input time series along the time dimension
        Parameters:
        in - Input activations to reverse, with shape [minibatch, size, timeSeriesLength]
        Returns:
        Reversed activations
      • reverseTimeSeries

        public static INDArray reverseTimeSeries​(INDArray in,
                                                 LayerWorkspaceMgr workspaceMgr,
                                                 ArrayType arrayType)
        Reverse an input time series along the time dimension
        Parameters:
        in - Input activations to reverse, with shape [minibatch, size, timeSeriesLength]
        Returns:
        Reversed activations
      • reverseTimeSeriesMask

        public static INDArray reverseTimeSeriesMask​(INDArray mask)
        Reverse a (per time step) time series mask, with shape [minibatch, timeSeriesLength]
        Parameters:
        mask - Mask to reverse along time dimension
        Returns:
        Mask after reversing
      • reverseTimeSeriesMask

        public static INDArray reverseTimeSeriesMask​(INDArray mask,
                                                     LayerWorkspaceMgr workspaceMgr,
                                                     ArrayType arrayType)
        Reverse a (per time step) time series mask, with shape [minibatch, timeSeriesLength]
        Parameters:
        mask - Mask to reverse along time dimension
        Returns:
        Mask after reversing
      • pullLastTimeSteps

        public static Pair<INDArray,​int[]> pullLastTimeSteps​(INDArray pullFrom,
                                                                   INDArray mask)
        Extract out the last time steps (2d array from 3d array input) accounting for the mask layer, if present.
        Parameters:
        pullFrom - Input time series array (rank 3) to pull the last time steps from
        mask - Mask array (rank 2). May be null
        Returns:
        2d array of the last time steps
      • pullLastTimeSteps

        public static Pair<INDArray,​int[]> pullLastTimeSteps​(INDArray pullFrom,
                                                                   INDArray mask,
                                                                   LayerWorkspaceMgr workspaceMgr,
                                                                   ArrayType arrayType)
        Extract out the last time steps (2d array from 3d array input) accounting for the mask layer, if present.
        Parameters:
        pullFrom - Input time series array (rank 3) to pull the last time steps from
        mask - Mask array (rank 2). May be null
        Returns:
        2d array of the last time steps
      • getFormatFromRnnLayer

        public static RNNFormat getFormatFromRnnLayer​(Layer layer)
        Get the RNNFormat from the RNN layer, accounting for the presence of wrapper layers like Bidirectional, LastTimeStep, etc
        Parameters:
        layer - Layer to get the RNNFormat from