Long Short Term Memory Time Series with Tensorflow

implements

  {BaseNeuralNetwork}

### Hierarchy

- BaseNeuralNetwork
  - LSTMTimeSeries
    - LSTMMultivariateTimeSeries

## Index

### Constructors

- constructor

### Properties

- compiled
- createDataset
- getInputShape
- getTimeseriesDataSet
- getTimeseriesShape
- layers
- model
- reshape
- settings
- tf
- tokenizer
- trained
- type
- xShape
- yShape

### Methods

- calculate
- exportConfiguration
- generateLayers
- importConfiguration
- loadModel
- predict
- saveModel
- train
- createDataset
- getInputShape
- getTimeseriesDataSet
- getTimeseriesShape
- reshape

## Constructors

### constructor

- new LSTMTimeSeries(options?: TensorScriptOptions, properties?: TensorScriptProperties): LSTMTimeSeries

- Overrides BaseNeuralNetwork.constructor

  - Defined in src/lstm_time_series.ts:102

  #### Parameters

  - ##### Default value options: TensorScriptOptions = {}

    neural network configuration and tensorflow model hyperparameters

  - ##### Optional properties: TensorScriptProperties

    extra instance properties

  #### Returns LSTMTimeSeries

## Properties

### compiled

compiled: boolean

Inherited from TensorScriptModelInterface.compiled

- Defined in src/model_interface.ts:136

### createDataset

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

- Defined in src/lstm_time_series.ts:100

#### Type declaration

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

  - #### Parameters

    - ##### Rest ...args: any[]

    #### Returns NestedArray<number>

### getInputShape

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

Inherited from TensorScriptModelInterface.getInputShape

- Defined in src/model_interface.ts:138

#### Type declaration

- - (...args: any[]): any

  - #### Parameters

    - ##### Rest ...args: any[]

    #### Returns any

### getTimeseriesDataSet

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

- Defined in src/lstm_time_series.ts:102

#### Type declaration

- - (...args: any[]): any

  - #### Parameters

    - ##### Rest ...args: any[]

    #### Returns any

### getTimeseriesShape

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

- Defined in src/lstm_time_series.ts:101

#### Type declaration

- - (...args: any[]): any

  - #### Parameters

    - ##### Rest ...args: any[]

    #### Returns any

### Optional layers

layers: TensorScriptSavedLayers

Overrides TensorScriptModelInterface.layers

- Defined in src/lstm_time_series.ts:16

### model

model: any

Inherited from TensorScriptModelInterface.model

- Defined in src/model_interface.ts:132

### reshape

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

Inherited from TensorScriptModelInterface.reshape

- Defined in src/model_interface.ts:137

#### Type declaration

- - (...args: any[]): any

  - #### Parameters

    - ##### Rest ...args: any[]

    #### Returns any

### settings

settings: TensorScriptOptions

Inherited from TensorScriptModelInterface.settings

- Defined in src/model_interface.ts:131

### tf

tf: any

Inherited from TensorScriptModelInterface.tf

- Defined in src/model_interface.ts:134

### tokenizer

tokenizer: any

Inherited from TensorScriptModelInterface.tokenizer

- Defined in src/model_interface.ts:133

### trained

trained: boolean

Inherited from TensorScriptModelInterface.trained

- Defined in src/model_interface.ts:135

### type

type: string

Inherited from TensorScriptModelInterface.type

- Defined in src/model_interface.ts:130

### Optional xShape

xShape: number[]

Inherited from TensorScriptModelInterface.xShape

- Defined in src/model_interface.ts:139

### Optional yShape

yShape: number[]

Inherited from TensorScriptModelInterface.yShape

- Defined in src/model_interface.ts:140

## Methods

### calculate

- calculate(x_matrix: Matrix | Vector | InputTextArray): any

- Overrides BaseNeuralNetwork.calculate

  - Defined in src/lstm_time_series.ts:240

  #### Parameters

  - ##### x_matrix: Matrix | Vector | InputTextArray

  #### Returns any

### exportConfiguration

- exportConfiguration(): TensorScriptContext

- Inherited from TensorScriptModelInterface.exportConfiguration

  - Defined in src/model_interface.ts:266

  #### Returns TensorScriptContext

### generateLayers

- generateLayers(this: TensorScriptLSTMModelContext, x_matrix: Matrix, y_matrix: Matrix, layers: TensorScriptSavedLayers): void

- Overrides BaseNeuralNetwork.generateLayers

  - Defined in src/lstm_time_series.ts:144

  Adds dense layers to tensorflow classification model

  override

  #### Parameters

  - ##### this: TensorScriptLSTMModelContext

  - ##### x_matrix: Matrix

    independent variables

  - ##### y_matrix: Matrix

    dependent variables

  - ##### layers: TensorScriptSavedLayers

    model dense layer parameters

  #### Returns void

### importConfiguration

- importConfiguration(configuration: TensorScriptContext): void

- Inherited from TensorScriptModelInterface.importConfiguration

  - Defined in src/model_interface.ts:277

  #### Parameters

  - ##### configuration: TensorScriptContext

  #### Returns void

### loadModel

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

- Inherited from TensorScriptModelInterface.loadModel

  - Defined in src/model_interface.ts:316

  Loads a saved tensoflow / keras model, this is an alias for

  see

    https://www.tensorflow.org/js/guide/save_load#loading_a_tfmodel

  #### Parameters

  - ##### options: string

    tensorflow load model options

  #### Returns Promise<any>

  tensorflow model

### predict

- predict(input_matrix: any[], options: PredictionOptions | undefined): Promise<any>

- Overrides TensorScriptModelInterface.predict

  - Defined in src/lstm_time_series.ts:246

  #### Parameters

  - ##### input_matrix: any[]

  - ##### options: PredictionOptions | undefined

  #### Returns Promise<any>

### saveModel

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

- Inherited from TensorScriptModelInterface.saveModel

  - Defined in src/model_interface.ts:329

  saves a tensorflow model, this is an alias for

  see

    https://www.tensorflow.org/js/guide/save_load#save_a_tfmodel

  #### Parameters

  - ##### options: string

    tensorflow save model options

  #### Returns Promise<any>

  tensorflow model

### train

- train(x_timeseries: any, y_timeseries: any, layers: any, x_test: any, y_test: any): Promise<any>

- Overrides BaseNeuralNetwork.train

  - Defined in src/lstm_time_series.ts:199

  #### Parameters

  - ##### x_timeseries: any

  - ##### y_timeseries: any

  - ##### layers: any

  - ##### x_test: any

  - ##### y_test: any

  #### Returns Promise<any>

### Static createDataset

- createDataset(dataset?: never[], look_back?: number): never[][][]

- - Defined in src/lstm_time_series.ts:39

  Creates dataset data

  example

    LSTMTimeSeries.createDataset([ [ 1, ], [ 2, ], [ 3, ], [ 4, ], [ 5, ], [ 6, ], [ 7, ], [ 8, ], [ 9, ], [ 10, ], ], 3) // => // [ // [ // [ [ 1 ], [ 2 ], [ 3 ] ], // [ [ 2 ], [ 3 ], [ 4 ] ], // [ [ 3 ], [ 4 ], [ 5 ] ], // [ [ 4 ], [ 5 ], [ 6 ] ], // [ [ 5 ], [ 6 ], [ 7 ] ], // [ [ 6 ], [ 7 ], [ 8 ] ], // ], //x_matrix // [ [ 4 ], [ 5 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ] ] //y_matrix // ]

  #### Parameters

  - ##### Default value dataset: never[] = []

    array of values

  - ##### Default value look_back: number = 1

    number of values in each feature

  #### Returns never[][][]

  returns x matrix and y matrix for model trainning

### Static getInputShape

- getInputShape(matrix?: any): Shape

- Inherited from TensorScriptModelInterface.getInputShape

  - Defined in src/model_interface.ts:247

  Returns the shape of an input matrix

  function
  example

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

  see

    {https://stackoverflow.com/questions/10237615/get-size-of-dimensions-in-array}

  #### Parameters

  - ##### Default value matrix: any = []

    input matrix

  #### Returns Shape

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

### Static getTimeseriesDataSet

- getTimeseriesDataSet(this: TensorScriptLSTMModelContext, timeseries: never[] | undefined, look_back: any): { xShape: number | number[]; x_matrix: number[] | number[][]; yShape: number | number[]; y_matrix: never[][] }

- - Defined in src/lstm_time_series.ts:83

  Returns data for predicting values

  #### Parameters

  - ##### this: TensorScriptLSTMModelContext

  - ##### timeseries: never[] | undefined

  - ##### look_back: any

  #### Returns { xShape: number | number[]; x_matrix: number[] | number[][]; yShape: number | number[]; y_matrix: never[][] }

  - ##### xShape: number | number[]

  - ##### x_matrix: number[] | number[][]

  - ##### yShape: number | number[]

  - ##### y_matrix: never[][]

### Static getTimeseriesShape

- getTimeseriesShape(this: TimeSeriesShapeContext, x_timeseries: NestedArray<any> | undefined): Shape

- - Defined in src/lstm_time_series.ts:64

  Reshape input to be [samples, time steps, features]

  example

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

  #### Parameters

  - ##### this: TimeSeriesShapeContext

  - ##### x_timeseries: NestedArray<any> | undefined

    dataset array of values

  #### Returns Shape

  returns proper timeseries forecasting shape

### Static reshape

- reshape(array: Vector, shape: Shape): Matrix | Vector

- Inherited from TensorScriptModelInterface.reshape

  - Defined in src/model_interface.ts:182

  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 Matrix | Vector

  returns a matrix with the defined shape