Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LSTMMultivariateTimeSeries

Long Short Term Memory Multivariate Time Series with Tensorflow

Hierarchy

Index

Constructors

constructor

  • Parameters

    • options: TensorScriptOptions = ...

      neural network configuration and tensorflow model hyperparameters

    • Optional properties: TensorScriptProperties

      extra instance properties

    Returns LSTMMultivariateTimeSeries

Properties

compiled

compiled: boolean

createDataset

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

Type declaration

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

      • Rest ...args: any[]

      Returns NestedArray<number>

drop

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

Type declaration

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

      • Rest ...args: any[]

      Returns any

getDropableColumns

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

Type declaration

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

      • Rest ...args: any[]

      Returns any

getInputShape

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

Type declaration

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

      • Rest ...args: any[]

      Returns any

getTimeseriesDataSet

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

Type declaration

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

      • Rest ...args: any[]

      Returns any

getTimeseriesShape

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

Type declaration

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

      • Rest ...args: any[]

      Returns any

Optional layers

layers: TensorScriptSavedLayers

Optional loss

loss: number

model

model: any

reshape

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

Type declaration

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

      • Rest ...args: any[]

      Returns any

seriesToSupervised

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

Type declaration

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

      • Rest ...args: any[]

      Returns number[]

settings

settings: TensorScriptOptions

tf

tf: any

tokenizer

tokenizer: any

trained

trained: boolean

type

type: string

Optional xShape

xShape: number[]

Optional yShape

yShape: number[]

Methods

calculate

  • calculate(x_matrix: Vector | Matrix | InputTextArray): any
  • Parameters

    • x_matrix: Vector | Matrix | InputTextArray

    Returns any

exportConfiguration

  • exportConfiguration(): TensorScriptContext

generateLayers

  • generateLayers(x_matrix: Matrix, y_matrix: Matrix, layers: TensorScriptSavedLayers): void
  • Adds dense layers to tensorflow classification model

    override

    Parameters

    • x_matrix: Matrix

      independent variables

    • y_matrix: Matrix

      dependent variables

    • layers: TensorScriptSavedLayers

      model dense layer parameters

    Returns void

importConfiguration

  • importConfiguration(configuration: TensorScriptContext): void
  • Parameters

    • configuration: TensorScriptContext

    Returns void

loadModel

  • loadModel(options: string): Promise<any>

predict

  • predict(input_matrix: Vector | Matrix | InputTextArray, options?: PredictionOptions): Promise<any>
  • Parameters

    • input_matrix: Vector | Matrix | InputTextArray
    • options: PredictionOptions = ...

    Returns Promise<any>

saveModel

  • saveModel(options: string): Promise<any>

train

  • train(x_timeseries: any, y_timeseries: any, layers: TensorScriptLayers, x_test: Matrix, y_test: Matrix): Promise<any>
  • override

    Parameters

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

    Returns Promise<any>

Static createDataset

  • createDataset(dataset: NestedArray<number[]>, look_back?: number): NestedArray<number>
  • 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 // ]

    override

    Parameters

    • dataset: NestedArray<number[]>

      array of values

    • look_back: number = ...

      number of values in each feature

    Returns NestedArray<number>

    returns x matrix and y matrix for model trainning

Static drop

  • drop(data: NestedArray<number[]>, columns: number[]): number[] | 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 ] //]

    Parameters

    • data: NestedArray<number[]>

      data set to drop columns

    • columns: number[]

      array of column indexes

    Returns number[] | NestedArray<number[]>

    matrix with dropped columns

Static getDropableColumns

  • getDropableColumns(features: number, n_in: number, n_out: number): 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 ]

    Parameters

    • features: number

      number of independent variables

    • n_in: number

      look backs

    • n_out: number

      future iterations (currently only 1 supported)

    Returns number[]

    array indexes to drop

Static getInputShape

  • getInputShape(matrix?: any): Shape

Static getTimeseriesDataSet

  • getTimeseriesDataSet(timeseries: NestedArray<number[]>, look_back: any): { xShape: Shape; x_matrix: Vector | Matrix; yShape: Shape; y_matrix: Vector }
  • Returns data for predicting values

    override

    Parameters

    • timeseries: NestedArray<number[]>
    • look_back: any

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

    • xShape: Shape
    • x_matrix: Vector | Matrix
    • yShape: Shape
    • y_matrix: Vector

Static getTimeseriesShape

  • getTimeseriesShape(x_timeseries: NestedArray<any>): any[]
  • 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,]

    Parameters

    • x_timeseries: NestedArray<any>

      dataset array of values

    Returns any[]

    returns proper timeseries forecasting shape

Static reshape

  • reshape(array: Vector, shape: Shape): Vector | Matrix
  • Reshapes an array

    function
    example

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

    Parameters

    • array: Vector

      input array

    • shape: Shape

      shape array

    Returns Vector | Matrix

    returns a matrix with the defined shape

Static seriesToSupervised

  • seriesToSupervised(data: number[], n_in?: number, n_out?: number): number[]
  • 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

    Parameters

    • data: number[]

      data set

    • n_in: number = 1

      look backs

    • n_out: number = 1

      future iterations (only 1 supported)

    Returns number[]

    multivariate dataset for time series