<p>I have answered your questions below. I would suggest to read a little bit more about LSTMs, e.g. <a href="http://colah.github.io/posts/2015-08-Understanding-LSTMs/" rel="nofollow noreferrer">colah's blog post</a>. This will help you understand what it is about, and you will see that your questions are related to the inner workings of an LSTM network.</p>

<p>1) The decoding LSTM network needs something as an input, just as your encoding LSTM used the input data from your dataset. You could either feedback the output of your decoding LSTM, our just repeat the latent state from your encoder (as your code snippet is doing). There are several variations possible, but it seems like most works use the latent vector for initialization of the hidden state in the decoding LSTM, and then feedback the output to the input when rolling out further. (See e.g. <a href="https://openreview.net/pdf?id=r1cLblgCZ" rel="nofollow noreferrer">Recurrent AE model for multidimensional time series representation</a> and <a href="https://arxiv.org/abs/1412.6581" rel="nofollow noreferrer">Variational Recurrent Auto-encoders</a>)</p>

<p>2) Your input dimension is 1, but over 100 time steps. Thus your actual input dimension is 100x1. If you choose the dimension of your hidden layer in the LSTM to be 32, than your input effectively gets reduced from 100x1 to 32.</p>

<p>If you still require more information, someone posted a <a href="https://github.com/keras-team/keras/issues/5203" rel="nofollow noreferrer">similar question</a> on GitHub.</p>
Variational Autoencoder on Timeseries with LSTM in Keras
<p>I am working on a Variational Autoencoder (VAE) to detect anomalies in time series. So far I worked with this tut <a href="https://blog.keras.io/building-autoencoders-in-keras.html" rel="nofollow noreferrer">https://blog.keras.io/building-autoencoders-in-keras.html</a> and this <a href="https://wiseodd.github.io/techblog/2016/12/10/variational-autoencoder/" rel="nofollow noreferrer">https://wiseodd.github.io/techblog/2016/12/10/variational-autoencoder/</a>.</p>

<p>Still, I have some trouble while implementing the VAE.
I have 77093 samples which have 1 dimension. I use timesteps=100 to make predictions. So I reshape my x_train as follows:</p>

<pre><code>x_train.shape = (77093, 100, 1)
</code></pre>

<p>The model:</p>

<pre><code>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)
</code></pre>

<p>I sample from:</p>

<pre><code>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
</code></pre>

<p>The model compiles. But I dont know if it is correct.</p>

<p>1.) I dont really understand the RepeatVector Layer and if it is necessary to repeat my sample z. But if I dont use RepeatVector Layer the LSTM-Layer throws an error, because it expects a 3 dim Input.</p>

<p>2.)I am not sore about the dimension reduction in the latent variable. Cause my In_dim=1. What exactly gets reduced?</p>

<p>Thanks in advance.</p>