tf.truncated_normal 和 tf.random_normal 有什么区别? [英] What is difference between tf.truncated_normal and tf.random_normal?

查看:30
本文介绍了tf.truncated_normal 和 tf.random_normal 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tf.random_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) 从截断的正态分布中输出随机值.

我尝试使用谷歌搜索截断正态分布".不过没看懂.

解决方案


使用截断法线的目的是克服像 sigmoid 这样的 tome 函数的饱和(如果值太大/太小,神经元停止学习).

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) 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:

The values are drawn from a normal distribution with specified mean and standard deviation, discarding and re-drawing any samples that are more than two standard deviations from the mean.

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])

And now

plt.hist(a, 100, (-4.2, 4.2));
plt.hist(b, 100, (-4.2, 4.2));


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆