- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试训练 序列到序列 一个简单的正弦波模型。目标是获得Nin
数据点和预测 Nout
下一个数据点。任务看起来很简单,模型对大频率的预测很好 freq
(y = sin(freq * x))。例如,对于 freq=4
,损失非常低,预测非常接近目标。然而,对于低频,预测是糟糕的。关于为什么模型失败的任何想法?
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, LSTM, RepeatVector, TimeDistributed, Dense
freq = 0.25
Nin, Nout = 14, 14
# Helper function to convert 1d data to (input, target) samples
def windowed_dataset(y, input_window = 5, output_window = 1, stride = 1, num_features = 1):
L = y.shape[0]
num_samples = (L - input_window - output_window) // stride + 1
X = np.zeros([input_window, num_samples, num_features])
Y = np.zeros([output_window, num_samples, num_features])
for ff in np.arange(num_features):
for ii in np.arange(num_samples):
start_x = stride * ii
end_x = start_x + input_window
X[:, ii, ff] = y[start_x:end_x, ff]
start_y = stride * ii + input_window
end_y = start_y + output_window
Y[:, ii, ff] = y[start_y:end_y, ff]
return X, Y
# The input shape is your sequence length and your token embedding size
inputs = Input(shape=(Nin, 1))
# Build a RNN encoder
encoder = LSTM(128, return_sequences=False)(inputs)
# Repeat the encoding for every input to the decoder
encoding_repeat = RepeatVector(Nout)(encoder)
# Pass your (5, 128) encoding to the decoder
decoder = LSTM(128, return_sequences=True)(encoding_repeat)
# Output each timestep into a fully connected layer
sequence_prediction = TimeDistributed(Dense(1, activation='linear'))(decoder)
model = Model(inputs, sequence_prediction)
model.compile('adam', 'mse') # Or categorical_crossentropy
y = np.sin(freq * np.linspace(0, 10, 1000))[:, None]
Ntr = int(0.8 * y.shape[0])
y_train, y_test = y[:Ntr], y[Ntr:]
from generate_dataset import *
stride = 1
N_features = 1
Xtrain, Ytrain = windowed_dataset(y_train, input_window=Nin, output_window=Nout, stride=stride,
num_features=N_features)
print(model.summary())
Xtrain, Ytrain = Xtrain.transpose(1, 0, 2), Ytrain.transpose(1, 0, 2)
print("Xtrain", Xtrain.shape)
model.fit(Xtrain, Ytrain, epochs=30)
plt.figure(); plt.plot(y, 'ro')
for Ns in arr([10, 50, 200, 400, 800, 1500, 3000]) // 10:
ypred = model.predict(Xtrain[[Ns]])
print("ypred", ypred.shape)
ypred = ypred[-1]
plt.figure()
plt.plot(ypred, 'ro')
plt.plot(Xtrain[Ns], 'm--')
plt.plot(Ytrain[Ns], 'k.')
plt.show()
exit()
最佳答案
我认为因为你得到的模式越少,它得到的模式就越少。
Ea 认为它是因为您在 X 输入上获得了一个模式来预测下一个输出。
尽管 al x(n) 输入的值略有增加,但几乎没有规律。
之前也发生了轻微的上涨,所以没有学到新的东西没有新的模式。
需要更长的训练时间才能将其视为经过的 x 波,算作一种模式。
如果您接受相同数量的培训,这很有趣。
但是跳过罪恶线,或者更容易,使用你好的工作模型,然后用分开的输入测试它。
ea:如果你用 5、10、15、20、25 等度数训练它。给训练过的网络 0.05 0.10 度(ea 只改变输入,但保持网络)。
假设序列训练器网络在具有语言文本预测等模式的数据上运行良好,但不适用于具有少量模式的数据。
---编辑-(评论回复太长)--
是的,很难调试神经网络,虽然我认为你必须回到基本原理,上升信号是一种模式,只有在训练中上升(足够)时才能检测到。 Rnn 和 lstms 在串行模式 ea asci 字符串中表现良好,对于测试用例而言,缓慢滑动的数字几乎不是在内存中可以引用的模式。也许你可以通过改变训练样本顺序来改进这里,所以在正弦波上随机取一个位置,因为内部的“缩小/接近”纠错可能会被说服到某个方向,导致它的最后 70 个样本上升,为什么 71下去。更好地处理它。
关于python - seq-to-seq LSTM 在低频简单正弦波上的性能不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67441084/
这是我的问题 1)我有动态y数组数据,使用该数组如何连续绘制波浪。 如果Y数组数据完整,则使用相同的y数组数据继续。 2)声音自动播放在该数组值是143.if我停止不停止。 这是我的代码:
网络上有太多使用 WiFi 或蓝牙传输数据的对讲机应用程序(至少我见过的所有应用程序),但没有一个使用内置天线通过 radio 波传输数据真正的对讲机设备。 是否有任何安全原因?还是限制作为发送器/接
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve this
我正在尝试着手研究 boost wave,但到目前为止,我的运气并不好。 我尝试了网站上的示例代码。如下: #include #include #include #include #inclu
我正在尝试使用 svg 编写一个 javascript 加载器。想法是,它是一个从下到上两侧均匀填充的圆圈,加载器的顶线是一个从左到右不断移动的正弦波。 我能够根据百分比为加载程序创建弧线,如下所示:
这个问题在这里已经有了答案: Is there a one-line function that generates a triangle wave? (8 个答案) 关闭 9 年前。 我试图用 A
当我在论坛中搜索时,我了解到要定位 GPS,我必须通过互联网连接或短信发送坐标。但据我所知,我们可以通过 radio 波进行通信,发送语音、图片、数据。我可以用它来获取数据吗? GPS 设备?因为业余
我是一名优秀的程序员,十分优秀!