|
|
@ -10427,47 +10427,58 @@ def gaussian_random(shape,
|
|
|
|
dtype='float32',
|
|
|
|
dtype='float32',
|
|
|
|
name=None):
|
|
|
|
name=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Generate a random tensor whose data is drawn from a Gaussian distribution.
|
|
|
|
This OP returns a Tensor filled with random values sampled from a Gaussian
|
|
|
|
|
|
|
|
distribution, with ``shape`` and ``dtype``.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
shape(list|tuple|Variable): Shape of the Tensor to be created. The data
|
|
|
|
shape(list|tuple|Tensor): The shape of the output Tensor. If ``shape``
|
|
|
|
type is ``int32`` or ``int64`` . If ``shape`` is a list or tuple,
|
|
|
|
is a list or tuple, the elements of it should be integers or Tensors
|
|
|
|
the elements of it should be integers or Tensors with shape [1]. If
|
|
|
|
(with the shape [1], and the data type int32 or int64). If ``shape``
|
|
|
|
``shape`` is a Variable, it should be an 1-D Tensor .
|
|
|
|
is a Tensor, it should be a 1-D Tensor(with the data type int32 or
|
|
|
|
mean(float): Mean of the random tensor, defaults to 0.0.
|
|
|
|
int64).
|
|
|
|
std(float): Standard deviation of the random tensor, defaults to 1.0.
|
|
|
|
mean(float|int, optional): Mean of the output tensor, default is 0.0.
|
|
|
|
seed(int): ${seed_comment}
|
|
|
|
std(float|int, optional): Standard deviation of the output tensor, default
|
|
|
|
dtype(np.dtype|core.VarDesc.VarType|str, optional): Data type of the output
|
|
|
|
is 1.0.
|
|
|
|
tensor, which can be float32, float64. Default is float32.
|
|
|
|
seed(int, optional): ${seed_comment}
|
|
|
|
name(str, optional): Normally there is no need for user to set this property.
|
|
|
|
dtype(str|np.dtype|core.VarDesc.VarType, optional): The data type of
|
|
|
|
For more information, please refer to :ref:`api_guide_Name` .
|
|
|
|
the output Tensor. Supported data types: float32, float64.
|
|
|
|
Default is None.
|
|
|
|
Default is float32.
|
|
|
|
|
|
|
|
name(str, optional): The default value is None. Normally there is no
|
|
|
|
|
|
|
|
need for user to set this property. For more information, please
|
|
|
|
|
|
|
|
refer to :ref:`api_guide_Name`.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
Variable: Random tensor whose data is drawn from a Gaussian distribution, dtype: flaot32 or float64 as specified.
|
|
|
|
Tensor: A Tensor filled with random values sampled from a Gaussian
|
|
|
|
|
|
|
|
distribution, with ``shape`` and ``dtype``.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
|
|
|
|
|
|
|
# example 1:
|
|
|
|
# example 1:
|
|
|
|
# attr shape is a list which doesn't contain tensor Variable.
|
|
|
|
# attr shape is a list which doesn't contain Tensor.
|
|
|
|
result_1 = fluid.layers.gaussian_random(shape=[3, 4])
|
|
|
|
result_1 = fluid.layers.gaussian_random(shape=[3, 4])
|
|
|
|
|
|
|
|
# [[-0.31261674, 1.8736548, -0.6274357, 0.96988016],
|
|
|
|
|
|
|
|
# [-0.12294637, 0.9554768, 1.5690808, -1.2894802 ],
|
|
|
|
|
|
|
|
# [-0.60082096, -0.61138713, 1.5345167, -0.21834975]]
|
|
|
|
|
|
|
|
|
|
|
|
# example 2:
|
|
|
|
# example 2:
|
|
|
|
# attr shape is a list which contains tensor Variable.
|
|
|
|
# attr shape is a list which contains Tensor.
|
|
|
|
dim_1 = fluid.layers.fill_constant([1],"int64",3)
|
|
|
|
dim_1 = fluid.layers.fill_constant([1], "int64", 2)
|
|
|
|
dim_2 = fluid.layers.fill_constant([1],"int32",5)
|
|
|
|
dim_2 = fluid.layers.fill_constant([1], "int32", 3)
|
|
|
|
result_2 = fluid.layers.gaussian_random(shape=[dim_1, dim_2])
|
|
|
|
result_2 = fluid.layers.gaussian_random(shape=[dim_1, dim_2])
|
|
|
|
|
|
|
|
# [[ 0.51398206, -0.3389769, 0.23597084],
|
|
|
|
|
|
|
|
# [ 1.0388143, -1.2015356, -1.0499583 ]]
|
|
|
|
|
|
|
|
|
|
|
|
# example 3:
|
|
|
|
# example 3:
|
|
|
|
# attr shape is a Variable, the data type must be int64 or int32.
|
|
|
|
# attr shape is a Tensor, the data type must be int64 or int32.
|
|
|
|
var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64")
|
|
|
|
var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64")
|
|
|
|
result_3 = fluid.layers.gaussian_random(var_shape)
|
|
|
|
result_3 = fluid.layers.gaussian_random(var_shape)
|
|
|
|
var_shape_int32 = fluid.data(name='var_shape_int32', shape=[2], dtype="int32")
|
|
|
|
# if var_shape's value is [2, 3]
|
|
|
|
result_4 = fluid.layers.gaussian_random(var_shape_int32)
|
|
|
|
# result_3 is:
|
|
|
|
|
|
|
|
# [[-0.12310527, 0.8187662, 1.923219 ]
|
|
|
|
|
|
|
|
# [ 0.70721835, 0.5210541, -0.03214082]]
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
@ -10509,8 +10520,10 @@ def gaussian_random(shape,
|
|
|
|
|
|
|
|
|
|
|
|
if in_dygraph_mode():
|
|
|
|
if in_dygraph_mode():
|
|
|
|
shape = utils._convert_shape_to_list(shape)
|
|
|
|
shape = utils._convert_shape_to_list(shape)
|
|
|
|
return core.ops.gaussian_random('shape', shape, 'mean', mean, 'std',
|
|
|
|
return core.ops.gaussian_random('shape', shape, 'mean',
|
|
|
|
std, 'seed', seed, 'dtype', dtype)
|
|
|
|
float(mean), 'std',
|
|
|
|
|
|
|
|
float(std), 'seed', seed, 'dtype',
|
|
|
|
|
|
|
|
dtype)
|
|
|
|
|
|
|
|
|
|
|
|
check_type(shape, 'shape', (list, tuple, Variable), 'gaussian_random/randn')
|
|
|
|
check_type(shape, 'shape', (list, tuple, Variable), 'gaussian_random/randn')
|
|
|
|
check_dtype(dtype, 'dtype', ['float32', 'float64'], 'gaussian_random/randn')
|
|
|
|
check_dtype(dtype, 'dtype', ['float32', 'float64'], 'gaussian_random/randn')
|
|
|
@ -14917,8 +14930,8 @@ def gather_tree(ids, parents):
|
|
|
|
def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
|
|
|
|
def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
|
|
|
|
name=None):
|
|
|
|
name=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This OP initializes a variable with random values sampled from a
|
|
|
|
This OP returns a Tensor filled with random values sampled from a uniform
|
|
|
|
uniform distribution in the range [min, max).
|
|
|
|
distribution in the range [``min``, ``max``), with ``shape`` and ``dtype``.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
::
|
|
|
|
::
|
|
|
@ -14930,30 +14943,33 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
|
|
|
|
result=[[0.8505902, 0.8397286]]
|
|
|
|
result=[[0.8505902, 0.8397286]]
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
shape (list|tuple|Variable): The shape of the output Tensor, if the
|
|
|
|
shape(list|tuple|Tensor): The shape of the output Tensor. If ``shape``
|
|
|
|
shape is a list or tuple, its elements can be an integer or a
|
|
|
|
is a list or tuple, the elements of it should be integers or Tensors
|
|
|
|
Tensor with the shape [1], and the type of the Tensor must be
|
|
|
|
(with the shape [1], and the data type int32 or int64). If ``shape``
|
|
|
|
int32 or int64. If the shape is a Variable, it is a 1-D Tensor, and
|
|
|
|
is a Tensor, it should be a 1-D Tensor(with the data type int32 or
|
|
|
|
the type of the Tensor must be int32 or int64.
|
|
|
|
int64).
|
|
|
|
dtype(np.dtype|core.VarDesc.VarType|str, optional): The type of the
|
|
|
|
dtype(str|np.dtype|core.VarDesc.VarType, optional): The data type of
|
|
|
|
output Tensor. Supported data types: float32, float64. Default: float32.
|
|
|
|
the output Tensor. Supported data types: float32, float64.
|
|
|
|
min (float, optional): The lower bound on the range of random values
|
|
|
|
Default is float32.
|
|
|
|
to generate, the min is included in the range. Default -1.0.
|
|
|
|
min(float|int, optional): The lower bound on the range of random values
|
|
|
|
max (float, optional): The upper bound on the range of random values
|
|
|
|
to generate, ``min`` is included in the range. Default is -1.0.
|
|
|
|
to generate, the max is excluded in the range. Default 1.0.
|
|
|
|
max(float|int, optional): The upper bound on the range of random values
|
|
|
|
seed (int, optional): Random seed used for generating samples. 0 means
|
|
|
|
to generate, ``max`` is excluded in the range. Default is 1.0.
|
|
|
|
|
|
|
|
seed(int, optional): Random seed used for generating samples. 0 means
|
|
|
|
use a seed generated by the system. Note that if seed is not 0,
|
|
|
|
use a seed generated by the system. Note that if seed is not 0,
|
|
|
|
this operator will always generate the same random numbers every
|
|
|
|
this operator will always generate the same random numbers every
|
|
|
|
time. Default 0.
|
|
|
|
time. Default is 0.
|
|
|
|
name(str, optional): The default value is None. Normally there is no
|
|
|
|
name(str, optional): The default value is None. Normally there is no
|
|
|
|
need for user to set this property. For more information, please
|
|
|
|
need for user to set this property. For more information, please
|
|
|
|
refer to :ref:`api_guide_Name`.
|
|
|
|
refer to :ref:`api_guide_Name`.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
Variable: A Tensor of the specified shape filled with uniform_random values.
|
|
|
|
Tensor: A Tensor filled with random values sampled from a uniform
|
|
|
|
|
|
|
|
distribution in the range [``min``, ``max``), with ``shape`` and ``dtype``.
|
|
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
Raises:
|
|
|
|
TypeError: The shape type should be list or tuple or variable.
|
|
|
|
TypeError: If ``shape`` is not list, tuple, Tensor.
|
|
|
|
|
|
|
|
TypeError: If ``dtype`` is not float32, float64.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
@ -14961,21 +14977,28 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
|
|
|
|
|
|
|
# example 1:
|
|
|
|
# example 1:
|
|
|
|
# attr shape is a list which doesn't contain tensor Variable.
|
|
|
|
# attr shape is a list which doesn't contain Tensor.
|
|
|
|
result_1 = fluid.layers.uniform_random(shape=[3, 4])
|
|
|
|
result_1 = fluid.layers.uniform_random(shape=[3, 4])
|
|
|
|
|
|
|
|
# [[ 0.84524226, 0.6921872, 0.56528175, 0.71690357],
|
|
|
|
|
|
|
|
# [-0.34646994, -0.45116323, -0.09902662, -0.11397249],
|
|
|
|
|
|
|
|
# [ 0.433519, 0.39483607, -0.8660099, 0.83664286]]
|
|
|
|
|
|
|
|
|
|
|
|
# example 2:
|
|
|
|
# example 2:
|
|
|
|
# attr shape is a list which contains tensor Variable.
|
|
|
|
# attr shape is a list which contains Tensor.
|
|
|
|
dim_1 = fluid.layers.fill_constant([1],"int64",3)
|
|
|
|
dim_1 = fluid.layers.fill_constant([1], "int64", 2)
|
|
|
|
dim_2 = fluid.layers.fill_constant([1],"int32",5)
|
|
|
|
dim_2 = fluid.layers.fill_constant([1], "int32", 3)
|
|
|
|
result_2 = fluid.layers.uniform_random(shape=[dim_1, dim_2])
|
|
|
|
result_2 = fluid.layers.uniform_random(shape=[dim_1, dim_2])
|
|
|
|
|
|
|
|
# [[-0.9951253, 0.30757582, 0.9899647 ],
|
|
|
|
|
|
|
|
# [ 0.5864527, 0.6607096, -0.8886161 ]]
|
|
|
|
|
|
|
|
|
|
|
|
# example 3:
|
|
|
|
# example 3:
|
|
|
|
# attr shape is a Variable, the data type must be int64 or int32.
|
|
|
|
# attr shape is a Tensor, the data type must be int64 or int32.
|
|
|
|
var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64")
|
|
|
|
var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64")
|
|
|
|
result_3 = fluid.layers.uniform_random(var_shape)
|
|
|
|
result_3 = fluid.layers.uniform_random(var_shape)
|
|
|
|
var_shape_int32 = fluid.data(name='var_shape_int32', shape=[2], dtype="int32")
|
|
|
|
# if var_shape's value is [2, 3]
|
|
|
|
result_4 = fluid.layers.uniform_random(var_shape_int32)
|
|
|
|
# result_3 is:
|
|
|
|
|
|
|
|
# [[-0.8517412, -0.4006908, 0.2551912 ],
|
|
|
|
|
|
|
|
# [ 0.3364414, 0.36278176, -0.16085452]]
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if not isinstance(dtype, core.VarDesc.VarType):
|
|
|
|
if not isinstance(dtype, core.VarDesc.VarType):
|
|
|
|