500
。
首先,我尝试了两个具有10个单元的密集层。model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='tanh'),
tf.keras.layers.Dense(10, activation='tanh'),
tf.keras.layers.Dense(1),
tfp.layers.DistributionLambda(lambda t: tfd.Normal(loc=t, scale=1.))
])
训练时使用如下的负对数似然损失函数:
model.compile(optimizer=tf.optimizers.Adam(learning_rate=0.01), loss=neg_log_likelihood)
model.fit(x, y, epochs=50)
接下来,我尝试了使用 DenseVariational
的类似环境。
model = tf.keras.Sequential([
tfp.layers.DenseVariational(
10, activation='tanh', make_posterior_fn=posterior,
make_prior_fn=prior, kl_weight=1/N, kl_use_exact=True),
tfp.layers.DenseVariational(
10, activation='tanh', make_posterior_fn=posterior,
make_prior_fn=prior, kl_weight=1/N, kl_use_exact=True),
tfp.layers.DenseVariational(
1, activation='tanh', make_posterior_fn=posterior,
make_prior_fn=prior, kl_weight=1/N, kl_use_exact=True),
tfp.layers.DistributionLambda(lambda t: tfd.Normal(loc=t, scale=1.))
])
由于参数数量翻倍,我已经尝试增加数据集大小和/或epoch大小,多达100倍都没有成功。通常的结果如下所示。
我的问题是,如何获得与 Dense
层相当的 DenseVariational
结果?我也听说它对初始值很敏感。在这里是完整代码的链接。欢迎提出任何建议。