The difference between Tf.random_normal and Tf.truncated_normal in TensorFlow

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.