Class LSTMMultivariateTimeSeries

Long Short Term Memory Multivariate Time Series with Tensorflow

Hierarchy

Constructors

Properties

compiled: boolean
createDataset: ((...args: any[]) => NestedArray<number>)

Type declaration

    • (...args: any[]): NestedArray<number>
    • Parameters

      • Rest ...args: any[]

      Returns NestedArray<number>

drop: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

getDropableColumns: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

getInputShape: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

getTimeseriesDataSet: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

getTimeseriesShape: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

layers?: TensorScriptSavedLayers
loss?: number
model: any
reshape: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

seriesToSupervised: ((...args: any[]) => number[])

Type declaration

    • (...args: any[]): number[]
    • Parameters

      • Rest ...args: any[]

      Returns number[]

settings: TensorScriptOptions
tf: any
tokenizer: any
trained: boolean
type: string
xShape?: number[]
yShape?: number[]

Methods

  • Predicts new dependent variables

    Returns

    returns tensorflow prediction

    Parameters

    • x_matrix: Matrix | Vector | InputTextArray

    Returns any

  • Adds dense layers to tensorflow classification model

    Parameters

    • x_matrix: Matrix

      independent variables

    • y_matrix: Matrix

      dependent variables

    • layers: TensorScriptSavedLayers

      model dense layer parameters

    Returns void

  • Returns prediction values from tensorflow model

    Returns

    predicted model values

    Parameters

    • input_matrix: Matrix | Vector | InputTextArray

      new test independent variables

    • options: PredictionOptions = {}

    Returns Promise<any>

  • Parameters

    • this: TensorScriptLSTMModelContext
    • x_timeseries: any
    • y_timeseries: any
    • layers: TensorScriptLayers
    • x_test: Matrix
    • y_test: Matrix

    Returns Promise<any>

  • Creates dataset data

    Example

    const ds = [
    [10, 20, 30, 40, 50, 60, 70, 80, 90,],
    [11, 21, 31, 41, 51, 61, 71, 81, 91,],
    [12, 22, 32, 42, 52, 62, 72, 82, 92,],
    [13, 23, 33, 43, 53, 63, 73, 83, 93,],
    [14, 24, 34, 44, 54, 64, 74, 84, 94,],
    [15, 25, 35, 45, 55, 65, 75, 85, 95,],
    [16, 26, 36, 46, 56, 66, 76, 86, 96,],
    [17, 27, 37, 47, 57, 67, 77, 87, 97,],
    [18, 28, 38, 48, 58, 68, 78, 88, 98,],
    [19, 29, 39, 49, 59, 69, 79, 89, 99,],
    ];
    LSTMMultivariateTimeSeries.createDataset(ds,1) // =>
    // [
    // [
    // [ 20, 30, 40, 50, 60, 70, 80, 90 ],
    // [ 21, 31, 41, 51, 61, 71, 81, 91 ],
    // [ 22, 32, 42, 52, 62, 72, 82, 92 ],
    // [ 23, 33, 43, 53, 63, 73, 83, 93 ],
    // [ 24, 34, 44, 54, 64, 74, 84, 94 ],
    // [ 25, 35, 45, 55, 65, 75, 85, 95 ],
    // [ 26, 36, 46, 56, 66, 76, 86, 96 ],
    // [ 27, 37, 47, 57, 67, 77, 87, 97 ],
    // [ 28, 38, 48, 58, 68, 78, 88, 98 ]
    // ], //x_matrix
    // [ 11, 12, 13, 14, 15, 16, 17, 18, 19 ], //y_matrix
    // 8 //features
    // ]

    Returns

    returns x matrix and y matrix for model trainning

    Parameters

    • this: TensorScriptModelContext
    • dataset: NestedArray<number[]> = []

      array of values

    • look_back: number = 1

      number of values in each feature

    Returns NestedArray<number>

  • Drops columns by array index

    Example

    const data = [ [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 11, 21, 31, 41, 51, 61, 71, 81, 91 ],
    [ 11, 21, 31, 41, 51, 61, 71, 81, 91, 12, 22, 32, 42, 52, 62, 72, 82, 92 ],
    [ 12, 22, 32, 42, 52, 62, 72, 82, 92, 13, 23, 33, 43, 53, 63, 73, 83, 93 ],
    [ 13, 23, 33, 43, 53, 63, 73, 83, 93, 14, 24, 34, 44, 54, 64, 74, 84, 94 ],
    [ 14, 24, 34, 44, 54, 64, 74, 84, 94, 15, 25, 35, 45, 55, 65, 75, 85, 95 ],
    [ 15, 25, 35, 45, 55, 65, 75, 85, 95, 16, 26, 36, 46, 56, 66, 76, 86, 96 ],
    [ 16, 26, 36, 46, 56, 66, 76, 86, 96, 17, 27, 37, 47, 57, 67, 77, 87, 97 ],
    [ 17, 27, 37, 47, 57, 67, 77, 87, 97, 18, 28, 38, 48, 58, 68, 78, 88, 98 ],
    [ 18, 28, 38, 48, 58, 68, 78, 88, 98, 19, 29, 39, 49, 59, 69, 79, 89, 99 ] ];
    const n_in = 1; //lookbacks
    const n_out = 1;
    const dropColumns = getDropableColumns(8, n_in, n_out); // =>[ 10, 11, 12, 13, 14, 15, 16, 17 ]
    const newdata = drop(data,dropColumns); //=> [
    // [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 11 ],
    // [ 11, 21, 31, 41, 51, 61, 71, 81, 91, 12 ],
    // [ 12, 22, 32, 42, 52, 62, 72, 82, 92, 13 ],
    // [ 13, 23, 33, 43, 53, 63, 73, 83, 93, 14 ],
    // [ 14, 24, 34, 44, 54, 64, 74, 84, 94, 15 ],
    // [ 15, 25, 35, 45, 55, 65, 75, 85, 95, 16 ],
    // [ 16, 26, 36, 46, 56, 66, 76, 86, 96, 17 ],
    // [ 17, 27, 37, 47, 57, 67, 77, 87, 97, 18 ],
    // [ 18, 28, 38, 48, 58, 68, 78, 88, 98, 19 ]
    //]

    Returns

    matrix with dropped columns

    Parameters

    • data: NestedArray<number[]>

      data set to drop columns

    • columns: number[]

      array of column indexes

    Returns number[] | NestedArray<number[]>

  • Calculates which columns to drop by index

    Todo

    support multiple iterations in the future, also only one output variable supported in column features * lookbacks -1

    Example

    const ds = [
    [10, 20, 30, 40, 50, 60, 70, 80, 90,],
    [11, 21, 31, 41, 51, 61, 71, 81, 91,],
    [12, 22, 32, 42, 52, 62, 72, 82, 92,],
    [13, 23, 33, 43, 53, 63, 73, 83, 93,],
    [14, 24, 34, 44, 54, 64, 74, 84, 94,],
    [15, 25, 35, 45, 55, 65, 75, 85, 95,],
    [16, 26, 36, 46, 56, 66, 76, 86, 96,],
    [17, 27, 37, 47, 57, 67, 77, 87, 97,],
    [18, 28, 38, 48, 58, 68, 78, 88, 98,],
    [19, 29, 39, 49, 59, 69, 79, 89, 99,],
    ];
    const n_in = 1; //lookbacks
    const n_out = 1;
    const dropped = getDropableColumns(8, n_in, n_out); //=> [ 10, 11, 12, 13, 14, 15, 16, 17 ]

    Returns

    array indexes to drop

    Parameters

    • features: number

      number of independent variables

    • n_in: number

      look backs

    • n_out: number

      future iterations (currently only 1 supported)

    Returns number[]

  • Returns the shape of an input matrix

    Function

    Example

    const input = [
    [ 0, 1, ],
    [ 1, 0, ],
    ];
    TensorScriptModelInterface.getInputShape(input) // => [2,2]

    See

    Returns

    returns the shape of a matrix (e.g. [2,2])

    Parameters

    • matrix: any = []

      input matrix

    Returns Shape

  • Returns data for predicting values

    Parameters

    • this: TensorScriptModelContext
    • timeseries: undefined | NestedArray<number[]>
    • look_back: any

    Returns { xShape: Shape; x_matrix: Matrix | Vector; yShape: Shape; y_matrix: Vector }

    • xShape: Shape
    • x_matrix: Matrix | Vector
    • yShape: Shape
    • y_matrix: Vector
  • Reshape input to be [samples, time steps, features]

    Example

    @override 
    LSTMTimeSeries.getTimeseriesShape([
    [ [ 1 ], [ 2 ], [ 3 ] ],
    [ [ 2 ], [ 3 ], [ 4 ] ],
    [ [ 3 ], [ 4 ], [ 5 ] ],
    [ [ 4 ], [ 5 ], [ 6 ] ],
    [ [ 5 ], [ 6 ], [ 7 ] ],
    [ [ 6 ], [ 7 ], [ 8 ] ],
    ]) //=> [6, 1, 3,]

    Returns

    returns proper timeseries forecasting shape

    Parameters

    • this: TensorScriptModelContext
    • x_timeseries: undefined | NestedArray<any>

      dataset array of values

    Returns any[]

  • Reshapes an array

    Function

    Example

    const array = [ 0, 1, 1, 0, ];
    const shape = [2,2];
    TensorScriptModelInterface.reshape(array,shape) // =>
    [
    [ 0, 1, ],
    [ 1, 0, ],
    ];

    Returns

    returns a matrix with the defined shape

    Parameters

    • array: Vector

      input array

    • shape: Shape

      shape array

    Returns Matrix | Vector

  • Converts data set to supervised labels for forecasting, the first column must be the dependent variable

    Example

    const ds = [
    [10, 20, 30, 40, 50, 60, 70, 80, 90,],
    [11, 21, 31, 41, 51, 61, 71, 81, 91,],
    [12, 22, 32, 42, 52, 62, 72, 82, 92,],
    [13, 23, 33, 43, 53, 63, 73, 83, 93,],
    [14, 24, 34, 44, 54, 64, 74, 84, 94,],
    [15, 25, 35, 45, 55, 65, 75, 85, 95,],
    [16, 26, 36, 46, 56, 66, 76, 86, 96,],
    [17, 27, 37, 47, 57, 67, 77, 87, 97,],
    [18, 28, 38, 48, 58, 68, 78, 88, 98,],
    [19, 29, 39, 49, 59, 69, 79, 89, 99,],
    ];
    const n_in = 1; //lookbacks
    const n_out = 1;
    const series = seriesToSupervised(ds, n_in, n_out); //=> [
    // [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 11, 21, 31, 41, 51, 61, 71, 81, 91 ],
    // [ 11, 21, 31, 41, 51, 61, 71, 81, 91, 12, 22, 32, 42, 52, 62, 72, 82, 92 ],
    // [ 12, 22, 32, 42, 52, 62, 72, 82, 92, 13, 23, 33, 43, 53, 63, 73, 83, 93 ],
    // [ 13, 23, 33, 43, 53, 63, 73, 83, 93, 14, 24, 34, 44, 54, 64, 74, 84, 94 ],
    // [ 14, 24, 34, 44, 54, 64, 74, 84, 94, 15, 25, 35, 45, 55, 65, 75, 85, 95 ],
    // [ 15, 25, 35, 45, 55, 65, 75, 85, 95, 16, 26, 36, 46, 56, 66, 76, 86, 96 ],
    // [ 16, 26, 36, 46, 56, 66, 76, 86, 96, 17, 27, 37, 47, 57, 67, 77, 87, 97 ],
    // [ 17, 27, 37, 47, 57, 67, 77, 87, 97, 18, 28, 38, 48, 58, 68, 78, 88, 98 ],
    // [ 18, 28, 38, 48, 58, 68, 78, 88, 98, 19, 29, 39, 49, 59, 69, 79, 89, 99 ]
    //];

    Todo

    support multiple future iterations

    Returns

    multivariate dataset for time series

    Parameters

    • data: number[]

      data set

    • n_in: number = 1

      look backs

    • n_out: number = 1

      future iterations (only 1 supported)

    Returns number[]