    import {LSTMMultivariateTimeSeries} from 'tensorscript/lib/lstm_multivariate_time_series.mjs'

public class | source

# LSTMMultivariateTimeSeries

#### Extends:

lib/deep_learning.js~BaseNeuralNetwork → LSTMTimeSeries → LSTMMultivariateTimeSeries

#### Indirect Implements:

- BaseNeuralNetwork

Long Short Term Memory Multivariate Time Series with Tensorflow

#### Test:

- LSTMMultivariateTimeSeries

## Static Method Summary

Static Public Methods
public static | createDataset(dataset: Array<Array<number>, look_back: Number): [Array<Array<number>>,Array<number>] Creates dataset data |
public static | drop(data: Array<Array<number>>, columns: Array<number>): Array<Array<number>> Drops columns by array index |
public static | getDropableColumns(features: number, n_in: number, n_out: number): Array<number> Calculates which columns to drop by index |
public static | getTimeseriesDataSet(timeseries: *, look_back: *) Returns data for predicting values |
public static | getTimeseriesShape(x_timeseries: Array<Array<number>): Array<Array<number>> Reshape input to be [samples, time steps, features] |
public static | seriesToSupervised(data: Array<Array<number>>, n_in: number, n_out: number): Array<Array<number>> Converts data set to supervised labels for forecasting, the first column must be the dependent variable |

## Constructor Summary

Public Constructor
public | constructor(options: {layers: Array<Object>, compile: Object, fit: Object}, properties: *) |

## Member Summary

Public Members
public | createDataset |
public | drop |
public | getDropableColumns |
public | getTimeseriesDataSet |
public | getTimeseriesShape |
public | layers |
public | model |
public | seriesToSupervised |
public | xShape |
public | yShape |

## Method Summary

Public Methods
public | generateLayers(x_matrix: Array<Array<number>>, y_matrix: Array<Array<number>>, layers: Array<Object>, x_test: Array<Array<number>>, y_test: Array<Array<number>>) Adds dense layers to tensorflow classification model |
public | async train(x_timeseries: *, y_timeseries: *, layers: *, x_test: *, y_test: *) |

## Inherited Summary

From class LSTMTimeSeries
public static | createDataset(dataset: Array<Array<number>, look_back: Number): [Array<Array<number>>,Array<number>] Creates dataset data |
public static | getTimeseriesDataSet(timeseries: *, look_back: *) Returns data for predicting values |
public static | getTimeseriesShape(x_timeseries: Array<Array<number>): Array<Array<number>> Reshape input to be [samples, time steps, features] |
public | createDataset |
public | getTimeseriesDataSet |
public | getTimeseriesShape |
public | layers |
public | model |
public | xShape |
public | yShape |
public | calculate() |
public | generateLayers(x_matrix: Array<Array<number>>, y_matrix: Array<Array<number>>, layers: Array<Object>, x_test: Array<Array<number>>, y_test: Array<Array<number>>) Adds dense layers to tensorflow classification model |
public | async predict() |
public | async train() |

## Static Public Methods

### public static createDataset(dataset: Array<Array<number>, look_back: Number): [Array<Array<number>>,Array<number>] source

Creates dataset data

#### Override:

LSTMTimeSeries#createDataset

#### Params:

Name | Type | Attribute | Description
dataset | Array<Array<number> |  | array of values
look_back | Number |  | number of values in each feature

#### Return:

[Array<Array<number>>,Array<number>] | returns x matrix and y matrix for model trainning

#### 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
    // ]

### public static drop(data: Array<Array<number>>, columns: Array<number>): Array<Array<number>> source

Drops columns by array index

#### Params:

Name | Type | Attribute | Description
data | Array<Array<number>> |  | data set to drop columns
columns | Array<number> |  | array of column indexes

#### Return:

Array<Array<number>> | matrix with dropped columns

#### 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 ]
    //]

### public static getDropableColumns(features: number, n_in: number, n_out: number): Array<number> source

Calculates which columns to drop by index

#### Params:

Name | Type | Attribute | Description
features | number |  | number of independent variables
n_in | number |  | look backs
n_out | number |  | future iterations (currently only 1 supported)

#### Return:

Array<number> | array indexes to drop

#### 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 ]

#### TODO:

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

### public static getTimeseriesDataSet(timeseries: *, look_back: *) source

Returns data for predicting values

#### Override:

LSTMTimeSeries#getTimeseriesDataSet

#### Params:

Name | Type | Attribute | Description
timeseries | * |  |
look_back | * |  |

### public static getTimeseriesShape(x_timeseries: Array<Array<number>): Array<Array<number>> source

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

#### Override:

LSTMTimeSeries#getTimeseriesShape

#### Params:

Name | Type | Attribute | Description
x_timeseries | Array<Array<number> |  | dataset array of values

#### Return:

Array<Array<number>> | returns proper timeseries forecasting shape

#### Example:

### public static seriesToSupervised(data: Array<Array<number>>, n_in: number, n_out: number): Array<Array<number>> source

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

#### Params:

Name | Type | Attribute | Description
data | Array<Array<number>> |  | data set
n_in | number |  | look backs
n_out | number |  | future iterations (only 1 supported)

#### Return:

Array<Array<number>> | multivariate dataset for time series

#### 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

## Public Constructors

### public constructor(options: {layers: Array<Object>, compile: Object, fit: Object}, properties: *) source

#### Override:

LSTMTimeSeries#constructor

#### Params:

Name | Type | Attribute | Description
options | {layers: Array<Object>, compile: Object, fit: Object} |  | neural network configuration and tensorflow model hyperparameters
properties | * |  | extra instance properties

#### Test:

- LSTMMultivariateTimeSeries constructor

## Public Members

### public createDataset source

Creates dataset data

#### Override:

LSTMTimeSeries#createDataset

#### Test:

- LSTMMultivariateTimeSeries static createDataset

### public drop source

#### Test:

- LSTMMultivariateTimeSeries static drop

### public getDropableColumns source

#### Test:

- LSTMMultivariateTimeSeries static getDropableColumns

### public getTimeseriesDataSet source

Returns data for predicting values

#### Override:

LSTMTimeSeries#getTimeseriesDataSet

#### Test:

- LSTMMultivariateTimeSeries static getTimeseriesDataSet

### public getTimeseriesShape source

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

#### Override:

LSTMTimeSeries#getTimeseriesShape

#### Test:

- LSTMMultivariateTimeSeries static getTimeseriesShape

### public layers source

#### Override:

LSTMTimeSeries#layers

### public model source

#### Override:

LSTMTimeSeries#model

### public seriesToSupervised source

#### Test:

- LSTMMultivariateTimeSeries static seriesToSupervised

### public xShape source

#### Override:

LSTMTimeSeries#xShape

### public yShape source

#### Override:

LSTMTimeSeries#yShape

## Public Methods

### public generateLayers(x_matrix: Array<Array<number>>, y_matrix: Array<Array<number>>, layers: Array<Object>, x_test: Array<Array<number>>, y_test: Array<Array<number>>) source

Adds dense layers to tensorflow classification model

#### Override:

LSTMTimeSeries#generateLayers

#### Params:

Name | Type | Attribute | Description
x_matrix | Array<Array<number>> |  | independent variables
y_matrix | Array<Array<number>> |  | dependent variables
layers | Array<Object> |  | model dense layer parameters
x_test | Array<Array<number>> |  | validation data independent variables
y_test | Array<Array<number>> |  | validation data dependent variables

#### Test:

- LSTMMultivariateTimeSeries generateLayers

### public async train(x_timeseries: *, y_timeseries: *, layers: *, x_test: *, y_test: *) source

#### Override:

LSTMTimeSeries#train

#### Params:

Name | Type | Attribute | Description
x_timeseries | * |  |
y_timeseries | * |  |
layers | * |  |
x_test | * |  |
y_test | * |  |

#### Test:

- LSTMMultivariateTimeSeries async train