1, Tf.truncated_normal use method
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.
The resulting value is subject to a normal distribution with the specified mean and standard deviation, and if the resulting value is greater than the average 2 standard deviation, the selection is discarded.
In a normal distribution curve, the area within the horizontal axis (μ-σ,μ+σ) is 68.268949%.
The area within the transverse range (μ-2σ,μ+2σ) is 95.449974%.
The area within the transverse range (μ-3σ,μ+3σ) is 99.73002%.
The probability that x falls on the (μ-3σ,μ+3σ) is less than 3 per thousand, the actual problem often thinks that the corresponding event is not going to happen, basically can take the interval (μ-3σ,μ+3σ) as the random variable x actual possible range, which is called the "3σ" principle of normal distribution.
In Tf.truncated_normal, if X is taken outside the interval (μ-2σ,μ+2σ), the selection is made again. This ensures that the generated values are near the mean value.
Parameters:
Shape: A one-dimensional tensor, also a tensor of output.
Mean: The mean value of the normal distribution.
StdDev: Standard deviation of normal distribution.
Dtype: The type of output.
Seed: An integer that, when set, is the same as the random number generated each time.
Name: Names of operations
2, Tf.random_normal use method
Tf.random_normal (Shape, mean=0.0, stddev=1.0, Dtype=tf.float32, Seed=none, Name=none)
The
outputs random values from a normal distribution.
Parameters:
shape: one-dimensional tensor, also the output tensor.
mean: The mean value of a normal distribution.
StdDev: Standard deviation of the normal distribution.
dtype: type of output.
seed: An integer that, when set, is the same as the random number generated each time.
Name: The name of the operation.
Code
A = tf. Variable (Tf.random_normal ([2,2],seed=1))
B = tf. Variable (Tf.truncated_normal ([2,2],seed=2))
init = Tf.global_variables_initializer ()
with TF. Session () as Sess:
sess.run (init)
print (Sess.run (a))
Print (Sess.run (b))
Output:
[[-0.81131822 1.48459876]
[0.06532937-2.44270396]]
[[- 0.85811085-0.19662298]
[0.13895047-1.22127688]]