我正在研究变分自动编码器(VAE)来检测时间序列中的异常。到目前为止,我使用了这个tut https://blog.keras.io/building-autoencoders-in-keras.html和这个https://wiseodd.github.io/techblog/2016/12/10/variational-autoencoder/。
尽管如此,我在实施VAE时遇到了一些麻烦。我有77093个样本,其中包含1个维度。我使用timeteps = 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 Layer,如果有必要重复我的样本z。但是如果我不使用RepeatVector Layer,LSTM-Layer会抛出一个错误,因为它需要一个3 dim输入。
2.)我对潜在变量的维数减少并不感到痛苦。因为我的In_dim = 1。究竟减少了什么?
提前致谢。
我在下面回答了你的问题。我建议您阅读更多有关LSTM的信息,例如: colah's blog post。这将有助于您了解它的含义,您将看到您的问题与LSTM网络的内部工作有关。
1)解码LSTM网络需要某些东西作为输入,就像您的编码LSTM使用来自数据集的输入数据一样。您可以反馈解码LSTM的输出,我们只需从您的编码器重复潜在状态(正如您的代码片段所做的那样)。有几种可能的变化,但似乎大多数工作使用潜在向量来初始化解码LSTM中的隐藏状态,然后在进一步推出时将输出反馈给输入。 (参见例如Recurrent AE model for multidimensional time series representation和Variational Recurrent Auto-encoders)
2)您的输入维度为1,但超过100个时间步长。因此,您的实际输入维度为100x1。如果您选择LSTM中隐藏图层的尺寸为32,则输入有效地从100x1减少到32。
如果您仍然需要更多信息,有人在GitHub上发布了similar question。