【问题标题】:Variational Autoencoder on Timeseries with LSTM in Keras在 Keras 中使用 LSTM 对时间序列进行变分自动编码器
【发布时间】:2018-11-25 04:57:34
【问题描述】:

我正在使用变分自动编码器 (VAE) 来检测时间序列中的异常。到目前为止,我使用了这个 tut https://blog.keras.io/building-autoencoders-in-keras.html 和这个 https://wiseodd.github.io/techblog/2016/12/10/variational-autoencoder/

不过,我在实施 VAE 时遇到了一些麻烦。 我有 77093 个样本,它们有 1 个维度。我使用 timesteps=100 进行预测。所以我重塑我的 x_train 如下:

x_train.shape = (77093, 100, 1)

型号:

inputs = Input(shape=(timesteps, input_dim))
encoded = LSTM(32)(inputs)

mu = Dense(1, activation='linear')(encoded)
log_sigma = Dense(1, activation='linear')(encoded)

z = Lambda(sample_z)([mu, log_sigma])

decoded = RepeatVector(timesteps)(z)
decoded = LSTM(1, return_sequences=True)(decoded)
decoded = LSTM(1)(decoded)

sequence_autoencoder = Model(inputs, decoded)

我的样本来自:

def sample_z(args):
  mu, log_sigma = args
  eps = K.random_normal(shape=(50, 1), mean=0., stddev=1.)
 return mu + K.exp(log_sigma / 2) * eps

模型编译。但不知道对不对。

1.) 我不太了解 RepeatVector 层以及是否有必要重复我的示例 z。但是如果我不使用 RepeatVector 层,LSTM-Layer 会抛出一个错误,因为它需要一个 3 dim 的输入。

2.)我对潜在变量的降维并不感到不满。导致我的 In_dim=1。究竟减少了什么?

提前致谢。

【问题讨论】:

标签: keras deep-learning lstm autoencoder inference


【解决方案1】:

我在下面回答了您的问题。我建议阅读更多关于 LSTM 的内容,例如colah's blog post。这将帮助您了解它的含义,并且您会发现您的问题与 LSTM 网络的内部工作原理有关。

1) 解码 LSTM 网络需要一些东西作为输入,就像您的编码 LSTM 使用数据集中的输入数据一样。您可以反馈解码 LSTM 的输出,我们只是重复编码器的潜在状态(正如您的代码 sn-p 所做的那样)。有几种可能的变化,但似乎大多数作品使用潜在向量来初始化解码 LSTM 中的隐藏状态,然后在进一步推出时将输出反馈到输入。 (参见例如Recurrent AE model for multidimensional time series representationVariational Recurrent Auto-encoders

2) 您的输入维度为 1,但超过 100 个时间步长。因此,您的实际输入尺寸为 100x1。如果您在 LSTM 中选择隐藏层的维度为 32,那么您的输入实际上会从 100x1 减少到 32。

如果您仍需要更多信息,有人在 GitHub 上发布了 similar question

【讨论】:

    猜你喜欢
    • 2019-04-29
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 2018-07-16
    • 1970-01-01
    • 2019-12-26
    • 2020-09-02
    相关资源
    最近更新 更多