Ejemplo n.º 1
0
def gumbel_like(x, loc=0.0, scale=1.0, seed=auto_select, name=''):
    """gumbel_like(x, mean=0.0, scale=1.0, seed=auto_select, name='')
    Generates samples from the Gumbel distribution with location `loc` and scale `scale`.

    Args:
        x: cntk variable (input, output, parameter, or constant) from which to copy the shape, data type, and dynamic axes.
        loc (float): location of the distribution
        scale (float): scale of the distribution
        seed (int): pseudo random number generator seed (default: automatically select a unique seed)
        name (str, optional): the name of the Function instance in the network

    Returns:
        :class:`~cntk.ops.functions.Function`

    Examples:
        >>> x = C.constant(np.zeros((2,3,4), dtype=np.float32))
        >>> g = C.random.gumbel_like(x, seed=98052)
        >>> s = g.eval(device=C.cpu()) # explicitly setting cpu because this is tested on multiple platforms; leave it unspecified in your code
        >>> np.round(s, 4)
        array([[[-0.9877, -0.5223,  0.4259, -1.0196],
                [ 5.4352,  1.5861,  5.0608,  2.0668],
                [-0.2135,  1.0139,  3.1217, -1.4834]],
        <BLANKLINE>
               [[ 0.4507,  0.6325,  2.1682,  0.4463],
                [-0.6583,  0.1147, -0.3144, -0.7925],
                [ 1.9773, -0.3627, -0.4566, -0.2368]]], dtype=float32)

    See also:
        `The Gumbel-Max Trick
        <https://hips.seas.harvard.edu/blog/2013/04/06/the-gumbel-max-trick-for-discrete-distributions/>`_.
    """
    from cntk.cntk_py import gumbel_random_like
    x = sanitize_input(x)
    return gumbel_random_like(x, loc, scale, seed, name)
Ejemplo n.º 2
0
def gumbel_like(x, loc=0.0, scale=1.0, seed=auto_select, name=''):
    """gumbel_like(x, mean=0.0, scale=1.0, seed=auto_select, name='')
    Generates samples from the Gumbel distribution with location `loc` and scale `scale`.

    Args:
        x: cntk variable (input, output, parameter, or constant) from which to copy the shape, data type, and dynamic axes.
        loc (float): location of the distribution
        scale (float): scale of the distribution
        seed (int): pseudo random number generator seed (default: automatically select a unique seed)
        name (str, optional): the name of the Function instance in the network

    Returns:
        :class:`~cntk.ops.functions.Function`

    Examples:
        >>> x = C.constant(np.zeros((2,3,4), dtype=np.float32))
        >>> g = C.random.gumbel_like(x, seed=98052)
        >>> s = g.eval(device=C.cpu()) # explicitly setting cpu because this is tested on multiple platforms; leave it unspecified in your code
        >>> np.round(s, 4)
        array([[[-0.9877, -0.5223,  0.4259, -1.0196],
                [ 5.4352,  1.5861,  5.0608,  2.0668],
                [-0.2135,  1.0139,  3.1217, -1.4834]],
        <BLANKLINE>
               [[ 0.4507,  0.6325,  2.1682,  0.4463],
                [-0.6583,  0.1147, -0.3144, -0.7925],
                [ 1.9773, -0.3627, -0.4566, -0.2368]]], dtype=float32)

    See also:
        `The Gumbel-Max Trick
        <https://hips.seas.harvard.edu/blog/2013/04/06/the-gumbel-max-trick-for-discrete-distributions/>`_.
    """
    from cntk.cntk_py import gumbel_random_like
    x = sanitize_input(x)
    return gumbel_random_like(x, loc, scale, seed, name)