使用 Conv1d 自动筛选 Python/Keras 中的时间序列

Autofilter for Time Series in Python/Keras using Conv1d

它可能看起来像很多代码,但大部分代码都是注释或格式化以使其更具可读性。

给定:
如果我定义我感兴趣的变量,"sequence",如下:

# define input sequence
np.random.seed(988) 

#make numbers 1 to 100
sequence = np.arange(0,10, dtype=np.float16)

#shuffle the numbers
sequence = sequence[np.random.permutation(len(sequence))]

#augment the sequence with itself
sequence = np.tile(sequence,[15]).flatten().transpose()

#scale for Relu
sequence = (sequence - sequence.min()) / (sequence.max()-sequence.min())

sequence

# reshape input into [samples, timesteps, features]
n_in = len(sequence)
sequence = sequence.reshape((1, n_in, 1))

问题:
我如何在 Keras 的自动编码器中使用 conv1d 以合理的准确度估计此序列?

如果 conv1d 不适合这个问题,你能告诉我编码器-解码器更合适的层类型是什么吗?

更多信息:
关于数据的要点:

我尝试了其他层的编码器和解码器部分(LSTM、Dense、多层密集)来预测,它们一直在 0.0833 左右的 mse 处达到 "wall"...这是 a 的方差均匀分布介于 0 和 1 之间。对我来说,一个好的自动编码器在这个简单的问题上应该能够至少达到 99.9% 的准确率,所以 'mse' 大大低于 1%。

我无法让 conv1d 工作,因为我弄乱了输入。似乎没有很好的例子来说明如何让它工作,而且我对这个整体架构还很陌生,所以它对我来说并不明显。

链接:

通过使用您的方法创建一个包含 1000 个样本的数据集,我能够使用 Conv1d 获得一个非常好的自动编码器模型:

LEN_SEQ = 10

x = Input(shape=(n_in, 1), name="input")
h = Conv1D(filters=50, kernel_size=LEN_SEQ, activation="relu", padding='same', name='Conv1')(x)
h = MaxPooling1D(pool_size=2, name='Maxpool1')(h)
h = Conv1D(filters=150, kernel_size=LEN_SEQ, activation="relu", padding='same', name='Conv2')(h)
h = MaxPooling1D(pool_size=2,  name="Maxpool2")(h)
y = Conv1D(filters=150, kernel_size=LEN_SEQ, activation="relu", padding='same', name='conv-decode1')(h)
y = UpSampling1D(size=2, name='upsampling1')(y)
y = Conv1D(filters=50, kernel_size=LEN_SEQ, activation="relu", padding='same', name='conv-decode2')(y)
y = UpSampling1D(size=2, name='upsampling2')(y)
y = Conv1D(filters=1, kernel_size=LEN_SEQ, activation="relu", padding='same', name='conv-decode3')(y)

AutoEncoder = Model(inputs=x, outputs=y, name='AutoEncoder')

AutoEncoder.compile(optimizer='adadelta', loss='mse')

AutoEncoder.fit(sequence, sequence, batch_size=32, epochs=50)

最后一个纪元输出:

Epoch 50/50
1000/1000 [==============================] - 4s 4ms/step - loss: 0.0104

测试新数据:

array([[[0.5557],
        [0.8887],
        [0.778 ],
        [0.    ],
        [0.4443],
        [1.    ],
        [0.3333],
        [0.2222],
        [0.1111],
        [0.6665],
        [...]

预测:

array([[[0.56822747],
        [0.8906583 ],
        [0.89267206],
        [0.        ],
        [0.5023574 ],
        [1.0665314 ],
        [0.37099048],
        [0.28558862],
        [0.05782872],
        [0.6886021 ],
        [...]

有些舍入问题,但非常接近!

是您要找的吗?