tf.truncated_normal和tf.random_normal有什么区别? [英] What is difference between tf.truncated_normal and tf.random_normal?
问题描述
tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
从正态分布中输出随机值.
tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
outputs random values from a normal distribution.
tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
从截断的正态分布中输出随机值.
tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
outputs random values from a truncated normal distribution.
我尝试使用谷歌搜索截断正态分布".但是了解不多.
I tried googling 'truncated normal distribution'. But didn't understand much.
推荐答案
The documentation says it all: For truncated normal distribution:
生成的值遵循具有指定均值的正态分布 和标准偏差,除了大小更大的值 超过2个标准差的平均值将被删除并重新选择.
The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked.
通过自己绘制图表,很可能很容易理解差异(%magic是因为我使用jupyter笔记本):
Most probably it is easy to understand the difference by plotting the graph for yourself (%magic is because I use jupyter notebook):
import tensorflow as tf
import matplotlib.pyplot as plt
%matplotlib inline
n = 500000
A = tf.truncated_normal((n,))
B = tf.random_normal((n,))
with tf.Session() as sess:
a, b = sess.run([A, B])
现在
plt.hist(a, 100, (-4.2, 4.2));
plt.hist(b, 100, (-4.2, 4.2));
使用截断法线的目的是克服Sigmoid之类的tome功能的饱和(如果该值太大/太小,神经元就会停止学习).
The point for using truncated normal is to overcome saturation of tome functions like sigmoid (where if the value is too big/small, the neuron stops learning).
这篇关于tf.truncated_normal和tf.random_normal有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!