当前位置: 首页>>代码示例>>Python>>正文


Python rng_mrg.MRG_RandomStreams方法代码示例

本文整理汇总了Python中theano.sandbox.rng_mrg.MRG_RandomStreams方法的典型用法代码示例。如果您正苦于以下问题:Python rng_mrg.MRG_RandomStreams方法的具体用法?Python rng_mrg.MRG_RandomStreams怎么用?Python rng_mrg.MRG_RandomStreams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.sandbox.rng_mrg的用法示例。


在下文中一共展示了rng_mrg.MRG_RandomStreams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: call

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def call(self,x,training=None):
        deta1 = 0.3
        deta2 = 0.3
        deta3 = 0.3
        seed = np.random.randint(1, 10e6)
        rng = RandomStreams(seed=seed)
        theta1 = rng.uniform(size=(x.shape[0],1),low=-deta1,high=deta1,dtype='float32')
        theta2 = rng.uniform(size=(x.shape[0],1),low=-deta2,high=deta2,dtype='float32')
        theta3 = rng.uniform(size=(x.shape[0],1),low=-deta3,high=deta3,dtype='float32')
        theta = K.concatenate([theta1,theta2,theta3],axis=-1)
        theta = K.tile(theta,x.shape[1])
        theta = theta.reshape((x.shape[0], x.shape[1], 3))

        theta = theta.reshape((theta.shape[0]*theta.shape[1], theta.shape[2]))
        M = _fusion(theta)
        output = _transform_rot(M, x)

        return K.in_train_phase(output,x,training = training) 
开发者ID:microsoft,项目名称:View-Adaptive-Neural-Networks-for-Skeleton-based-Human-Action-Recognition,代码行数:20,代码来源:transform_rnn.py

示例2: test_select_distinct

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def test_select_distinct(self):
        """
        Tests that multinomial_wo_replacement always selects distinct elements
        """
        th_rng = RandomStreams(12345)

        p = tensor.fmatrix()
        n = tensor.iscalar()
        m = th_rng.multinomial_wo_replacement(pvals=p, n=n)

        f = function([p, n], m, allow_input_downcast=True)

        n_elements = 1000
        all_indices = range(n_elements)
        numpy.random.seed(12345)
        for i in [5, 10, 50, 100, 500, n_elements]:
            pvals = numpy.random.randint(1, 100, (1, n_elements)).astype(config.floatX)
            pvals /= pvals.sum(1)
            res = f(pvals, i)
            res = numpy.squeeze(res)
            assert len(res) == i
            assert numpy.all(numpy.in1d(numpy.unique(res), all_indices)), res 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:24,代码来源:test_multinomial_wo_replacement.py

示例3: test_fail_select_alot

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def test_fail_select_alot(self):
        """
        Tests that multinomial_wo_replacement fails when asked to sample more
        elements than the actual number of elements
        """
        th_rng = RandomStreams(12345)

        p = tensor.fmatrix()
        n = tensor.iscalar()
        m = th_rng.multinomial_wo_replacement(pvals=p, n=n)

        f = function([p, n], m, allow_input_downcast=True)

        n_elements = 100
        n_selected = 200
        numpy.random.seed(12345)
        pvals = numpy.random.randint(1, 100, (1, n_elements)).astype(config.floatX)
        pvals /= pvals.sum(1)
        self.assertRaises(ValueError, f, pvals, n_selected) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:test_multinomial_wo_replacement.py

示例4: test_random_state_transfer

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def test_random_state_transfer():
    """
    Test that random state can be transferred from one theano graph to another.

    """
    class Graph:
        def __init__(self, seed=123):
            self.rng = MRG_RandomStreams(seed)
            self.y = self.rng.uniform(size=(1,))
    g1 = Graph(seed=123)
    f1 = theano.function([], g1.y)
    g2 = Graph(seed=987)
    f2 = theano.function([], g2.y)

    g2.rng.rstate = g1.rng.rstate
    for (su1, su2) in zip(g1.rng.state_updates, g2.rng.state_updates):
        su2[0].set_value(su1[0].get_value())

    numpy.testing.assert_array_almost_equal(f1(), f2(), decimal=6) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:test_rng_mrg.py

示例5: __init__

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def __init__(self, rng, std = 0.1, ndim=0, avg =0, shape_fn=None):
        """
        """
        assert rng is not None, "random number generator should not be empty!"
        super(GaussianNoise, self).__init__(0, 0, rng)

        self.std = scale
        self.avg = self.avg
        self.ndim = ndim
        self.shape_fn = shape_fn
        if self.shape_fn:
            # Name is not important as it is not a parameter of the model
            self.noise_term = theano.shared(numpy.zeros((2,)*ndim,
                                                    dtype=theano.config.floatX),
                                        name='ndata')
            self.noise_params += [self.noise_term]
            self.noise_params_shape_fn += [shape_fn]
        self.trng = RandomStreams(rng.randint(1e5)) 
开发者ID:pascanur,项目名称:GroundHog,代码行数:20,代码来源:ff_layers.py

示例6: __init__

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def __init__(self, lr=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-8, save=False, rng=None, *args, **kwargs):
        print('args=%s' % str(args))
        print('kwargs=%s' % str(kwargs))
        super(Adam, self).__init__(**kwargs)
        self.__dict__.update(locals())
        print(locals())

        # if 'iterations' in kwargs:
        #     print('iterations=%s' % str(kwargs['iterations']))
        #     self.iterations = shared_scalar(kwargs['iterations'],  name='iteration')
        # else:
        #     print('iterations not set')
        #     self.iterations = shared_scalar(0,  name='iteration')
        self.iterations = shared_scalar(0, name='iteration')
        self.lr         = shared_scalar(lr, name='lr')
        # self.rng        = MRG_RandomStreams(use_cuda=True)
        self.noise      = []
        self.forget     = dict()
        # self.rng        = rng
        self.beta_1     = beta_1
        self.beta_2     = beta_2
        self.epsilon    = epsilon

        self.add(self.iterations)
        self.add(self.lr) 
开发者ID:memray,项目名称:seq2seq-keyphrase,代码行数:27,代码来源:optimizers.py

示例7: test_deterministic

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def test_deterministic():
    seed = utt.fetch_seed()
    sample_size = (10, 20)

    test_use_cuda = [False]
    if cuda_available:
        test_use_cuda.append(True)

    for use_cuda in test_use_cuda:
        # print 'use_cuda =', use_cuda
        R = MRG_RandomStreams(seed=seed, use_cuda=use_cuda)
        u = R.uniform(size=sample_size)
        f = theano.function([], u)

        fsample1 = f()
        fsample2 = f()
        assert not numpy.allclose(fsample1, fsample2)

        R2 = MRG_RandomStreams(seed=seed, use_cuda=use_cuda)
        u2 = R2.uniform(size=sample_size)
        g = theano.function([], u2)
        gsample1 = g()
        gsample2 = g()
        assert numpy.allclose(fsample1, gsample1)
        assert numpy.allclose(fsample2, gsample2) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:27,代码来源:test_rng_mrg.py

示例8: test_GPU_nstreams_limit

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def test_GPU_nstreams_limit():
    """
    Verify that a ValueError is raised when n_streams
    is greater than 2**20 on GPU. This is the value of
    (NUM_VECTOR_OP_THREADS_PER_BLOCK * NUM_VECTOR_OP_BLOCKS).

    """
    if not cuda_available:
        raise SkipTest('Optional package cuda not available')

    seed = 12345
    R = MRG_RandomStreams(seed=seed, use_cuda=True)

    def eval_uniform(size, nstreams):
        if theano.config.mode == "FAST_COMPILE":
            mode = "FAST_RUN"
        else:
            mode = copy.copy(theano.compile.get_default_mode())
            mode.check_py_code = False
        out = R.uniform(size=size, nstreams=nstreams, dtype='float32')
        f = theano.function([], out, mode=mode)
        return f()

    eval_uniform((10,), 2**20)
    assert_raises(ValueError, eval_uniform, (10,), 2**20 + 1) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:27,代码来源:test_rng_mrg.py

示例9: dropout

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def dropout(x, level, noise_shape=None, seed=None):
    '''Sets entries in `x` to zero at random,
    while scaling the entire tensor.

    # Arguments
        x: tensor
        level: fraction of the entries in the tensor
            that will be set to 0.
        noise_shape: shape for randomly generated keep/drop flags,
            must be broadcastable to the shape of `x`
        seed: random seed to ensure determinism.
    '''
    if level < 0. or level >= 1:
        raise ValueError('Dropout level must be in interval [0, 1[.')
    if seed is None:
        seed = np.random.randint(1, 10e6)

    rng = RandomStreams(seed=seed)
    retain_prob = 1. - level

    if noise_shape is None:
        random_tensor = rng.binomial(x.shape, p=retain_prob, dtype=x.dtype)
    else:
        random_tensor = rng.binomial(noise_shape, p=retain_prob, dtype=x.dtype)
        random_tensor = T.patternbroadcast(random_tensor, [dim == 1 for dim in noise_shape])

    x *= random_tensor
    x /= retain_prob
    return x 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:31,代码来源:theano_backend.py

示例10: random_normal

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def random_normal(shape, mean=0.0, std=1.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    return rng.normal(size=shape, avg=mean, std=std, dtype=dtype) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:9,代码来源:theano_backend.py

示例11: random_uniform

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def random_uniform(shape, low=0.0, high=1.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    return rng.uniform(shape, low=low, high=high, dtype=dtype) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:9,代码来源:theano_backend.py

示例12: random_binomial

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def random_binomial(shape, p=0.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    return rng.binomial(shape, p=p, dtype=dtype)

# Theano implementation of CTC
# Used with permission from Shawn Tan
# https://github.com/shawntan/
# Note that tensorflow's native CTC code is significantly
# faster than this 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:15,代码来源:theano_backend.py

示例13: __init__

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def __init__(self, mu, logsigma, rng=None, **kwargs):
        self.rng = rng if rng else RandomStreams(nn.random.get_rng().randint(1,2147462579))
        super(GaussianSampleLayer, self).__init__([mu, logsigma], **kwargs) 
开发者ID:Lasagne,项目名称:Recipes,代码行数:5,代码来源:variational_autoencoder.py

示例14: __init__

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def __init__(self, mlp, noise = "gaussian", monitor_ll = False, ll_n_samples = 100, ll_sigma = 0.2):
        Model.__init__(self)
        self.__dict__.update(locals())
        del self.self
        self.theano_rng = MRG_RandomStreams(2014 * 5 + 27) 
开发者ID:goodfeli,项目名称:adversarial,代码行数:7,代码来源:__init__.py

示例15: set_input_space

# 需要导入模块: from theano.sandbox import rng_mrg [as 别名]
# 或者: from theano.sandbox.rng_mrg import MRG_RandomStreams [as 别名]
def set_input_space(self, space):
        assert isinstance(space, VectorSpace)
        self.input_space = space
        self.output_space = VectorSpace(space.dim + self.new_dim)
        self.theano_rng = MRG_RandomStreams(self.mlp.rng.randint(2 ** 16)) 
开发者ID:goodfeli,项目名称:adversarial,代码行数:7,代码来源:__init__.py


注:本文中的theano.sandbox.rng_mrg.MRG_RandomStreams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。