This function normalizes a matrix of features using precomputed means and standard deviations. The function automatically runs load.scaler to read the standard deviations and means of the features, which are organized into a list object named data.scaler.LSTM. These means and standard deviations are computed from the 1,000,000 datasets data.datasets.LSTM for training the pre-trained Long Short Term Memory (LSTM) Network.

normalizor(features)

Arguments

features

A numeric matrix where each row represents an observation and each column represents a feature.

Value

A matrix of the same dimensions as features, where each feature has been normalized.

Details

The function applies z-score normalization to each element in the features matrix. It uses the scaler object, which is expected to contain precomputed means and standard deviations for each feature. The normalized value for each element is computed as: $$z = \frac{x - \mu}{\sigma}$$ where \(x\) is the original value, \(\mu\) is the mean, and \(\sigma\) is the standard deviation.

Examples

library(LSTMfactors)
set.seed(123)

##Take the data.DAPCS dataset as an example.
data(data.DAPCS)

response <- as.matrix(data.DAPCS[, 3:22]) ## loading data

# \donttest{
## Run extractor.feature function
features <- extractor.feature(response)

features.nor <- normalizor(features)
print(features.nor)
#>         [,1]        [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
#> [1,] 2.18344 -0.04520005 0.2192709 -1.036707 -1.095279 -1.178967 -1.162617
#>           [,8]      [,9]     [,10]    [,11]    [,12]     [,13]     [,14]
#> [1,] -1.186283 -1.146434 -1.152663 2.599042 0.376832 0.8007375 -1.073844
#>          [,15]     [,16]     [,17]     [,18]     [,19]     [,20]
#> [1,] -1.313303 -1.645909 -1.981317 -2.439333 -3.025141 -4.012727
#> attr(,"class")
#> [1] "features.LSTM"
# }