MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / truncated_normal

Method truncated_normal

tensorflow/python/ops/stateful_random_ops.py:422–454  ·  view source on GitHub ↗

Outputs random values from a truncated normal distribution. 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. Args: shape

(self, shape,
                       mean=0.0,
                       stddev=1.0,
                       dtype=dtypes.float32,
                       name=None)

Source from the content-addressed store, hash-verified

420 self.state.handle, self.algorithm, shape, dtype=dtype)
421
422 def truncated_normal(self, shape,
423 mean=0.0,
424 stddev=1.0,
425 dtype=dtypes.float32,
426 name=None):
427 """Outputs random values from a truncated normal distribution.
428
429 The generated values follow a normal distribution with specified mean and
430 standard deviation, except that values whose magnitude is more than
431 2 standard deviations from the mean are dropped and re-picked.
432
433 Args:
434 shape: A 1-D integer Tensor or Python array. The shape of the output
435 tensor.
436 mean: A 0-D Tensor or Python value of type `dtype`. The mean of the
437 truncated normal distribution.
438 stddev: A 0-D Tensor or Python value of type `dtype`. The standard
439 deviation of the normal distribution, before truncation.
440 dtype: The type of the output.
441 name: A name for the operation (optional).
442
443 Returns:
444 A tensor of the specified shape filled with random truncated normal
445 values.
446 """
447 with ops.name_scope(
448 name, "truncated_normal", [shape, mean, stddev]) as name:
449 shape_tensor = _shape_tensor(shape)
450 mean_tensor = ops.convert_to_tensor(mean, dtype=dtype, name="mean")
451 stddev_tensor = ops.convert_to_tensor(stddev, dtype=dtype, name="stddev")
452 rnd = self._truncated_normal(shape_tensor, dtype=dtype)
453 mul = rnd * stddev_tensor
454 return math_ops.add(mul, mean_tensor, name=name)
455
456 def _uniform(self, shape, dtype):
457 return gen_stateful_random_ops.stateful_uniform(

Callers

nothing calls this directly

Calls 4

_truncated_normalMethod · 0.95
_shape_tensorFunction · 0.85
name_scopeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected