TF中的随机数
Tensorflow中提供了若干算子来生成均匀分布、正态分布的随机数,或者实现随机排列、随机挑选等功能。
Operations |
Functions |
tf.random_normal |
Outputs random values from a normal distribution. 正态分布 |
tf.truncated_normal
|
Outputs random values from a truncated normal distribution. 截断的正态分布,偏离大于2倍标准差的数会被丢弃再重新选择 |
tf.random_uniform |
Outputs random values from a uniform distribution. 均匀分布[min,max) |
tf.random_shuffle |
Randomly shuffles a tensor along its first dimension. 第一维随机排列 |
tf.multinomial |
Slices a portion out of input tensor at a uniformly chosen offset. 从输入数据value中随机剪切大小为size的部分数据 |
tf.random_gamma |
Draws samples from each of the given Gamma distribution(s). 伽马分布 |
Tensorflow中也通过设置randomseed来产生不同的随机序列。需要注意的是,TF中有两种级别的random seed,一个是operation-level,一个是graph-level,都会影响随机数生成:
- op-level: 在调用上述表格中的算子时,可以显式指定seed参数,若seed参数相同,则在同一张graph里,每次运行生结果相同;若不指定seed