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


Python RandomStreams.uniform方法代码示例

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


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

示例1: test_uniform_vector

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_uniform_vector(self):
        random = RandomStreams(utt.fetch_seed())
        low = tensor.dvector()
        high = tensor.dvector()
        out = random.uniform(low=low, high=high)
        assert out.ndim == 1
        f = function([low, high], out)

        low_val = [.1, .2, .3]
        high_val = [1.1, 2.2, 3.3]
        seed_gen = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))

        # Arguments of size (3,)
        val0 = f(low_val, high_val)
        numpy_val0 = numpy_rng.uniform(low=low_val, high=high_val)
        print('THEANO', val0)
        print('NUMPY', numpy_val0)
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        val1 = f(low_val[:-1], high_val[:-1])
        numpy_val1 = numpy_rng.uniform(low=low_val[:-1], high=high_val[:-1])
        print('THEANO', val1)
        print('NUMPY', numpy_val1)
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = function([low, high], random.uniform(low=low, high=high, size=(3,)))
        val2 = g(low_val, high_val)
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        numpy_val2 = numpy_rng.uniform(low=low_val, high=high_val, size=(3,))
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, low_val[:-1], high_val[:-1])
开发者ID:ChinaQuants,项目名称:Theano,代码行数:36,代码来源:test_shared_randomstreams.py

示例2: test_default_dtype

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_default_dtype(self):
        random = RandomStreams(utt.fetch_seed())
        low = tensor.dscalar()
        high = tensor.dscalar()

        # Should not silently downcast from low and high
        out0 = random.uniform(low=low, high=high, size=(42,))
        assert out0.dtype == 'float64'
        f0 = function([low, high], out0)
        val0 = f0(-2.1, 3.1)
        assert val0.dtype == 'float64'

        # Should downcast, since asked explicitly
        out1 = random.uniform(low=low, high=high, size=(42,), dtype='float32')
        assert out1.dtype == 'float32'
        f1 = function([low, high], out1)
        val1 = f1(-1.1, 1.1)
        assert val1.dtype == 'float32'

        # Should use floatX
        lowf = tensor.fscalar()
        highf = tensor.fscalar()
        outf = random.uniform(low=lowf, high=highf, size=(42,))
        assert outf.dtype == config.floatX
        ff = function([lowf, highf], outf)
        valf = ff(numpy.float32(-0.1), numpy.float32(0.3))
        assert valf.dtype == config.floatX
开发者ID:ChinaQuants,项目名称:Theano,代码行数:29,代码来源:test_shared_randomstreams.py

示例3: __init__

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def __init__(self, neurons, dimensions, count = 1, max_rate = (200, 300),
            intercept = (-1.0, 1.0), t_ref = 0.002, t_rc = 0.02, seed = None,
            type = 'lif', dt = 0.001, encoders = None, name = None, address = "localhost"):
        self.seed = seed
        self.neurons = neurons
        self.dimensions = dimensions
        self.count = count
        self.name = name
        self.address = address
        self.ticker_conn = None

        # create the neurons
        # TODO: handle different neuron types, which may have different parameters to pass in
        self.neuron = neuron.names[type]((count, self.neurons), t_rc = t_rc, t_ref = t_ref, dt = dt)

        # compute alpha and bias
        srng = RandomStreams(seed=seed)
        max_rates = srng.uniform([neurons], low=max_rate[0], high=max_rate[1])
        threshold = srng.uniform([neurons], low=intercept[0], high=intercept[1])
        alpha, self.bias = theano.function([], self.neuron.make_alpha_bias(max_rates,threshold))()
        self.bias = self.bias.astype('float32')

        # compute encoders
        self.encoders = make_encoders(neurons, dimensions, srng, encoders=encoders)
        self.encoders = (self.encoders.T * alpha).T

        # make default origin
        self.origin = dict(X=origin.Origin(self))
        self.accumulator = {}
开发者ID:LouisCastricato,项目名称:spike,代码行数:31,代码来源:ensemble.py

示例4: __init__

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def __init__(
        self,
        neurons,
        dimensions,
        tau_ref=0.002,
        tau_rc=0.02,
        max_rate=(200, 300),
        intercept=(-1.0, 1.0),
        radius=1.0,
        encoders=None,
        seed=None,
        neuron_type="lif",
        dt=0.001,
        array_count=1,
    ):
        """Create an population of neurons with NEF parameters on top
        
        :param int neurons: number of neurons in this population
        :param int dimensions: number of dimensions in signal these neurons represent 
        :param float tau_ref: refractory period of neurons in this population
        :param float tau_rc: RC constant 
        :param tuple max_rate: lower and upper bounds on randomly generate firing rates for neurons in this population
        :param tuple intercept: lower and upper bounds on randomly generated x offset
        :param float radius: 
        :param list encoders: set of possible preferred directions of neurons
        :param int seed: seed value for random number generator
        :param string neuron_type: type of neuron model to use, options = {'lif'}
        :param float dt: time step of neurons during update step
        :param int array_count: number of sub-populations - for network arrays
        """
        self.seed = seed
        self.neurons = neurons
        self.dimensions = dimensions
        self.array_count = array_count

        # create the neurons
        # TODO: handle different neuron types, which may have different parameters to pass in
        self.neuron = neuron.names[neuron_type]((array_count, self.neurons), tau_rc=tau_rc, tau_ref=tau_ref, dt=dt)

        # compute alpha and bias
        srng = RandomStreams(seed=seed)  # set up theano random number generator
        max_rates = srng.uniform([neurons], low=max_rate[0], high=max_rate[1])
        threshold = srng.uniform([neurons], low=intercept[0], high=intercept[1])
        alpha, self.bias = theano.function([], self.neuron.make_alpha_bias(max_rates, threshold))()
        self.bias = self.bias.astype("float32")  # force to 32 bit for consistency / speed

        # compute encoders
        self.encoders = make_encoders(neurons, dimensions, srng, encoders=encoders)
        self.encoders = (self.encoders.T * alpha).T  # combine encoders and gain for simplification

        # make default origin
        self.origin = dict(X=origin.Origin(self))  # creates origin with identity function

        self.accumulator = {}  # dictionary of accumulators tracking terminations with different pstc values
开发者ID:errord,项目名称:nengo,代码行数:56,代码来源:ensemble.py

示例5: test_mixed_shape

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_mixed_shape(self):
        # Test when the provided shape is a tuple of ints and scalar vars
        random = RandomStreams(utt.fetch_seed())
        shape0 = tensor.lscalar()
        shape = (shape0, 3)
        f = function([shape0], random.uniform(size=shape, ndim=2))
        assert f(2).shape == (2, 3)
        assert f(8).shape == (8, 3)

        g = function([shape0], random.uniform(size=shape))
        assert g(2).shape == (2, 3)
        assert g(8).shape == (8, 3)
开发者ID:ChinaQuants,项目名称:Theano,代码行数:14,代码来源:test_shared_randomstreams.py

示例6: common_init

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def common_init(self, mr, vr, sr, di, ce, node_id):
        """
        Initialization function used by the base class and subclasses.
        """

        self.MEANRATE = mr
        self.VARRATE = vr
        self.STARVRATE = sr
        self.DIMS = di
        self.CENTS = ce
        self.ID = node_id
        srng = RandomStreams(seed=100)
        rv_u = srng.uniform((self.CENTS, self.DIMS))
        f = function([], rv_u)
        self.mean = 2*f()
        #print self.mean
        var1 = T.dscalar('var1')
        var2 = T.dmatrix('var2')
        var3 = T.mul
        self.var = theanoScaMatMul(0.001,np.ones((self.CENTS, self.DIMS)))
        self.starv = np.ones((self.CENTS, 1))
        self.belief = np.zeros((1, self.CENTS))
        self.children = []
        self.last = np.zeros((1, self.DIMS))
        self.whitening = False
开发者ID:cosmoharrigan,项目名称:python-destin,代码行数:27,代码来源:Clustering.py

示例7: test_mixed_shape_bcastable

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_mixed_shape_bcastable(self):
        # Test when the provided shape is a tuple of ints and scalar vars
        random = RandomStreams(utt.fetch_seed())
        shape0 = tensor.lscalar()
        shape = (shape0, 1)
        u = random.uniform(size=shape, ndim=2)
        assert u.broadcastable == (False, True)
        f = function([shape0], u)
        assert f(2).shape == (2, 1)
        assert f(8).shape == (8, 1)

        v = random.uniform(size=shape)
        assert v.broadcastable == (False, True)
        g = function([shape0], v)
        assert g(2).shape == (2, 1)
        assert g(8).shape == (8, 1)
开发者ID:ChinaQuants,项目名称:Theano,代码行数:18,代码来源:test_shared_randomstreams.py

示例8: prediction

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def prediction(self, h, bias):
        srng = RandomStreams(seed=42)

        prop, mean_x, mean_y, std_x, std_y, rho, bernoulli = \
            self.compute_parameters(h, bias)

        mode = T.argmax(srng.multinomial(pvals=prop, dtype=prop.dtype), axis=1)

        v = T.arange(0, mean_x.shape[0])
        m_x = mean_x[v, mode]
        m_y = mean_y[v, mode]
        s_x = std_x[v, mode]
        s_y = std_y[v, mode]
        r = rho[v, mode]
        # cov = r * (s_x * s_y)

        normal = srng.normal((h.shape[0], 2))
        x = normal[:, 0]
        y = normal[:, 1]

        # x_n = T.shape_padright(s_x * x + cov * y + m_x)
        # y_n = T.shape_padright(s_y * y + cov * x + m_y)

        x_n = T.shape_padright(m_x + s_x * x)
        y_n = T.shape_padright(m_y + s_y * (x * r + y * T.sqrt(1.-r**2)))

        uniform = srng.uniform((h.shape[0],))
        pin = T.shape_padright(T.cast(bernoulli > uniform, floatX))

        return T.concatenate([x_n, y_n, pin], axis=1)
开发者ID:adbrebs,项目名称:handwriting,代码行数:32,代码来源:model.py

示例9: GP

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
class GP(object):
    def __init__(self,size=20,v0=1,v1=1,v2=1,r=1,time_step=10,alpha=2):
        self.lsize = size
        self.time = time_step
        self.dtype = theano.config.floatX
        self.v0 = theano.shared(np.cast[dtype](v0),name="v0")
        self.v1 = theano.shared(np.cast[dtype](v1),name="v1")
        self.v2 = theano.shared(np.cast[dtype](v2),name="v2")
        self.alpha = theano.shared(np.cast[dtype](alpha),name="alpha")
        self.gamma = theano.shared(np.cast[dtype](r),name="r")
        self.srng = RandomStreams(seed=234)
        self.DiffM = theano.shared(self.create_mat(self.time,self.lsize),name="diffM")
        self.params = [self.v0,self.gamma,self.alpha]
        self.sample = self.return_output(self.DiffM)
        
##This takes the difference matrix and samples from the GP and returns a signal
    def return_output(self,Dif):
        #Dif is theano.Tensor.matrix type
        Frac = Dif/self.gamma
        Cov = self.v0*T.pow(Frac,self.alpha)
        L = sin.cholesky(T.exp(-Cov))
        eps = self.srng.uniform((self.time,self.lsize))
        return T.dot(L,eps)

##This converts the noise signal into the basioc matrix required for Covariance calculation
    def create_mat(self,time,size):
        #noise is numpy type
        diffM = np.zeros(shape=(time,size))
        for i in range(0,size):
            for j in range(0,size):
                diffM[i,j] = i-j
        return np.abs(diffM)
开发者ID:amartya18x,项目名称:VideoGAN,代码行数:34,代码来源:GP.py

示例10: __init__

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def __init__(self, rng, train_input, test_input, n_in, n_out):

        # self.input = input.flatten(2)

        self.W = theano.shared(
            value=numpy.asarray(
                rng.uniform(
                    low=-numpy.sqrt(6. / (n_in + n_out)),
                    high=numpy.sqrt(6. / (n_in + n_out)),
                    size=(n_in, n_out)
                ),
                dtype=theano.config.floatX
            ),
            name='W',
            borrow=True
        )

        self.b = theano.shared(
            value=numpy.zeros((n_out,), dtype=theano.config.floatX),
            name='b',
            borrow=True
        )

        p = 0.5

        tmp_output = T.nnet.relu(T.dot(train_input.flatten(2), self.W) + self.b)
        srng = RandomStreams(rng.randint(1234))
        mask = (srng.uniform(size=tmp_output.shape) < p)/p

        self.train_output = tmp_output * mask
        self.test_output = T.nnet.relu(T.dot(test_input.flatten(2), self.W) + self.b)
        self.params = [self.W, self.b]
开发者ID:yangli625,项目名称:ReId_theano,代码行数:34,代码来源:Layer.py

示例11: test_vector_arguments

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_vector_arguments(self):
        random = RandomStreams(utt.fetch_seed())
        low = tensor.dvector()
        out = random.uniform(low=low, high=1)
        assert out.ndim == 1
        f = function([low], out)

        seed_gen = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        val0 = f([-5, .5, 0, 1])
        val1 = f([.9])
        numpy_val0 = numpy_rng.uniform(low=[-5, .5, 0, 1], high=1)
        numpy_val1 = numpy_rng.uniform(low=[.9], high=1)
        assert numpy.all(val0 == numpy_val0)
        assert numpy.all(val1 == numpy_val1)

        high = tensor.vector()
        outb = random.uniform(low=low, high=high)
        assert outb.ndim == 1
        fb = function([low, high], outb)

        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        val0b = fb([-4., -2], [-1, 0])
        val1b = fb([-4.], [-1])
        numpy_val0b = numpy_rng.uniform(low=[-4., -2], high=[-1, 0])
        numpy_val1b = numpy_rng.uniform(low=[-4.], high=[-1])
        assert numpy.all(val0b == numpy_val0b)
        assert numpy.all(val1b == numpy_val1b)
        self.assertRaises(ValueError, fb, [-4., -2], [-1, 0, 1])
        # TODO: do we want that?
        #self.assertRaises(ValueError, fb, [-4., -2], [-1])

        size = tensor.lvector()
        outc = random.uniform(low=low, high=high, size=size, ndim=1)
        fc = function([low, high, size], outc)

        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        val0c = fc([-4., -2], [-1, 0], [2])
        val1c = fc([-4.], [-1], [1])
        numpy_val0c = numpy_rng.uniform(low=[-4., -2], high=[-1, 0])
        numpy_val1c = numpy_rng.uniform(low=[-4.], high=[-1])
        assert numpy.all(val0c == numpy_val0c)
        assert numpy.all(val1c == numpy_val1c)
        self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [1])
        self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [1, 2])
        self.assertRaises(ValueError, fc, [-4., -2], [-1, 0], [2, 1])
        self.assertRaises(ValueError, fc, [-4., -2], [-1], [1])
开发者ID:ChinaQuants,项目名称:Theano,代码行数:49,代码来源:test_shared_randomstreams.py

示例12: test_default_updates

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_default_updates(self):
        # Basic case: default_updates
        random_a = RandomStreams(utt.fetch_seed())
        out_a = random_a.uniform((2, 2))
        fn_a = function([], out_a)
        fn_a_val0 = fn_a()
        fn_a_val1 = fn_a()
        assert not numpy.all(fn_a_val0 == fn_a_val1)

        nearly_zeros = function([], out_a + out_a - 2 * out_a)
        assert numpy.all(abs(nearly_zeros()) < 1e-5)

        # Explicit updates #1
        random_b = RandomStreams(utt.fetch_seed())
        out_b = random_b.uniform((2, 2))
        fn_b = function([], out_b, updates=random_b.updates())
        fn_b_val0 = fn_b()
        fn_b_val1 = fn_b()
        assert numpy.all(fn_b_val0 == fn_a_val0)
        assert numpy.all(fn_b_val1 == fn_a_val1)

        # Explicit updates #2
        random_c = RandomStreams(utt.fetch_seed())
        out_c = random_c.uniform((2, 2))
        fn_c = function([], out_c, updates=[out_c.update])
        fn_c_val0 = fn_c()
        fn_c_val1 = fn_c()
        assert numpy.all(fn_c_val0 == fn_a_val0)
        assert numpy.all(fn_c_val1 == fn_a_val1)

        # No updates at all
        random_d = RandomStreams(utt.fetch_seed())
        out_d = random_d.uniform((2, 2))
        fn_d = function([], out_d, no_default_updates=True)
        fn_d_val0 = fn_d()
        fn_d_val1 = fn_d()
        assert numpy.all(fn_d_val0 == fn_a_val0)
        assert numpy.all(fn_d_val1 == fn_d_val0)

        # No updates for out
        random_e = RandomStreams(utt.fetch_seed())
        out_e = random_e.uniform((2, 2))
        fn_e = function([], out_e, no_default_updates=[out_e.rng])
        fn_e_val0 = fn_e()
        fn_e_val1 = fn_e()
        assert numpy.all(fn_e_val0 == fn_a_val0)
        assert numpy.all(fn_e_val1 == fn_e_val0)
开发者ID:ChinaQuants,项目名称:Theano,代码行数:49,代码来源:test_shared_randomstreams.py

示例13: __init__

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def __init__(self, input, rescale, recentre):
        srng = RandomStreams(seed=234)

        self.input = input

        dequantize_input = input + srng.uniform(size=input.shape, low=-0.5/255, high=0.5/255)

        self.output = rescale * (dequantize_input - recentre)
开发者ID:amarshah,项目名称:theano_fun,代码行数:10,代码来源:AE_perfect2.py

示例14: test_binomial_from_uniform_cpu

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
    def test_binomial_from_uniform_cpu(self):
        #Test using numpy
        rng = np.random.RandomState(42)
        probs = rng.rand(10)

        seed = 1337
        nb_samples = 1000000
        rng = np.random.RandomState(seed)
        success1 = np.zeros(len(probs))
        for i in range(nb_samples):
            success1 += rng.binomial(n=1, p=probs)

        rng = np.random.RandomState(seed)
        success2 = np.zeros(len(probs))
        for i in range(nb_samples):
            success2 += (rng.rand(len(probs)) < probs).astype('int')

        success1 = success1 / nb_samples
        success2 = success2 / nb_samples

        assert_array_almost_equal(success1, success2)

        #Test using Theano's default RandomStreams
        theano_rng = RandomStreams(1337)
        rng_bin = theano_rng.binomial(size=probs.shape, n=1, p=probs, dtype=theano.config.floatX)
        success1 = np.zeros(len(probs))
        for i in range(nb_samples):
            success1 += rng_bin.eval()

        theano_rng = RandomStreams(1337)
        rng_bin = theano_rng.uniform(size=probs.shape, dtype=theano.config.floatX) < probs
        success2 = np.zeros(len(probs))
        for i in range(nb_samples):
            success2 += rng_bin.eval()

        assert_array_almost_equal(success1/nb_samples, success2/nb_samples)

        #Test using Theano's sandbox MRG RandomStreams
        theano_rng = MRG_RandomStreams(1337)
        success1 = theano_rng.binomial(size=probs.shape, n=1, p=probs, dtype=theano.config.floatX)

        theano_rng = MRG_RandomStreams(1337)
        success2 = theano_rng.uniform(size=probs.shape, dtype=theano.config.floatX) < probs

        assert_array_equal(success1.eval(), success2.eval())
开发者ID:MarcCote,项目名称:iRBM,代码行数:47,代码来源:test_rbm.py

示例15: expr

# 需要导入模块: from theano.tensor.shared_randomstreams import RandomStreams [as 别名]
# 或者: from theano.tensor.shared_randomstreams.RandomStreams import uniform [as 别名]
 def expr(self, model, data, **kwargs):
     """
     Overwrites the Cost.expr so we can inject our theano.Op.  
     """
     space,source = self.get_data_specs(model)
     space.validate(data)
     #really no point to using these random values.  Could be zeros
     srng = RandomStreams(seed=234)
     return OverwriteOp(self.cost,model)(srng.uniform(low=0.0,high=1000.0,dtype=theano.config.floatX),data)
开发者ID:KennethPierce,项目名称:MLResearch,代码行数:11,代码来源:notheano.py


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