我正在从 deeplearning.ai
学习神经网络中的正则化类(class)。在 dropout 正则化中,教授说如果应用 dropout,计算的激活值将小于未应用 dropout 时(测试时)。所以我们需要扩展激活以保持测试阶段更简单。
我明白这个事实,但我不明白缩放是如何完成的。这是一个用于实现反向 dropout 的代码示例。
keep_prob = 0.8 # 0 <= keep_prob <= 1
l = 3 # this code is only for layer 3
# the generated number that are less than 0.8 will be dropped. 80% stay, 20% dropped
d3 = np.random.rand(a[l].shape[0], a[l].shape[1]) < keep_prob
a3 = np.multiply(a3,d3) # keep only the values in d3
# increase a3 to not reduce the expected value of output
# (ensures that the expected value of a3 remains the same) - to solve the scaling problem
a3 = a3 / keep_prob
在上面的代码中,为什么激活被除以
0.8
或将节点保留在层中的概率( keep_prob
)?任何数字示例都会有所帮助。
最佳答案
在花了一些时间了解倒退辍学后,我自己得到了答案。这是直觉:
我们以概率 keep_prob
保留任何层中的神经元.比方说 kepp_prob = 0.6
.这意味着关闭任何层中 40% 的神经元。如果在关闭 40% 的神经元之前该层的原始输出是 x
,然后在应用 40% dropout 后,它将是 减少了 0.4 * x
.所以现在是 x - 0.4x = 0.6x
.
为了保持原始输出(期望值),我们需要将输出除以 keep_prob
(或 0.6
在这里)。
关于machine-learning - 反转 dropout 如何补偿 dropout 的影响并保持期望值不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57193633/