• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unittest_tools.fetch_seed函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中theano.tests.unittest_tools.fetch_seed函数的典型用法代码示例。如果您正苦于以下问题:Python fetch_seed函数的具体用法?Python fetch_seed怎么用?Python fetch_seed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_uniform_vector

    def test_uniform_vector(self):
        rng_R = random_state_type()
        low = tensor.vector()
        high = tensor.vector()
        post_r, out = uniform(rng_R, low=low, high=high)
        assert out.ndim == 1
        f = compile.function([rng_R, low, high], [post_r, out], accept_inplace=True)

        def as_floatX(thing):
            return numpy.asarray(thing, dtype=theano.config.floatX)

        low_val = as_floatX([0.1, 0.2, 0.3])
        high_val = as_floatX([1.1, 2.2, 3.3])
        rng = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(utt.fetch_seed())

        # Arguments of size (3,)
        rng0, val0 = f(rng, low_val, high_val)
        numpy_val0 = as_floatX(numpy_rng.uniform(low=low_val, high=high_val))
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        rng1, val1 = f(rng0, low_val[:-1], high_val[:-1])
        numpy_val1 = as_floatX(numpy_rng.uniform(low=low_val[:-1], high=high_val[:-1]))
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = compile.function([rng_R, low, high], uniform(rng_R, low=low, high=high, size=(3,)), accept_inplace=True)
        rng2, val2 = g(rng1, low_val, high_val)
        numpy_val2 = as_floatX(numpy_rng.uniform(low=low_val, high=high_val, size=(3,)))
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, rng2, low_val[:-1], high_val[:-1])
开发者ID:gokul-uf,项目名称:Theano,代码行数:32,代码来源:test_raw_random.py


示例2: test_permutation

    def test_permutation(self):
        # Test that raw_random.permutation generates the same results as numpy.
        rng_R = random_state_type()
        post_r, out = permutation(rng_R, size=(9,), n=6)
        f = compile.function(
                [compile.In(rng_R,
                    value=np.random.RandomState(utt.fetch_seed()),
                    update=post_r, mutable=True)],
                [out], accept_inplace=True)

        numpy_rng = np.random.RandomState(utt.fetch_seed())
        # Check over two calls to see if the random state is correctly updated.
        # numpy_rng.permutation outputs one vector at a time,
        # so we call it iteratively to generate all the samples.
        val0 = f()
        val1 = f()
        numpy_val0 = np.asarray([numpy_rng.permutation(6)
                                    for i in range(9)])
        numpy_val1 = np.asarray([numpy_rng.permutation(6)
                                    for i in range(9)])
        self.assertTrue(np.all(val0 == numpy_val0))
        self.assertTrue(np.all(val1 == numpy_val1))

        # Test that we can generate a list: have size=None or ().
        for ndim in [1, None]:
            post_r, out = permutation(rng_R, n=10, size=None, ndim=ndim)
            inp = compile.In(rng_R,
                             value=np.random.RandomState(utt.fetch_seed()),
                             update=post_r, mutable=True)
            f = theano.function([inp], out)
            o = f()
            assert o.shape == (10,)
            assert (np.sort(o) == np.arange(10)).all()
        # Wrong number of dimensions asked
        self.assertRaises(TypeError, permutation, rng_R, size=None, ndim=2)
开发者ID:DEVESHTARASIA,项目名称:Theano,代码行数:35,代码来源:test_raw_random.py


示例3: test_multinomial_vector

    def test_multinomial_vector(self):
        rng_R = random_state_type()
        n = tensor.lvector()
        pvals = tensor.matrix()
        post_r, out = multinomial(rng_R, n=n, pvals=pvals)
        assert out.ndim == 2
        f = compile.function([rng_R, n, pvals], [post_r, out], accept_inplace=True)

        n_val = [1, 2, 3]
        pvals_val = [[0.1, 0.9], [0.2, 0.8], [0.3, 0.7]]
        pvals_val = numpy.asarray(pvals_val, dtype=config.floatX)
        rng = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(utt.fetch_seed())

        # Arguments of size (3,)
        rng0, val0 = f(rng, n_val, pvals_val)
        numpy_val0 = numpy.asarray([numpy_rng.multinomial(n=nv, pvals=pv) for nv, pv in zip(n_val, pvals_val)])
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        rng1, val1 = f(rng0, n_val[:-1], pvals_val[:-1])
        numpy_val1 = numpy.asarray(
            [numpy_rng.multinomial(n=nv, pvals=pv) for nv, pv in zip(n_val[:-1], pvals_val[:-1])]
        )
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = compile.function([rng_R, n, pvals], multinomial(rng_R, n=n, pvals=pvals, size=(3,)), accept_inplace=True)
        rng2, val2 = g(rng1, n_val, pvals_val)
        numpy_val2 = numpy.asarray([numpy_rng.multinomial(n=nv, pvals=pv) for nv, pv in zip(n_val, pvals_val)])
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, rng2, n_val[:-1], pvals_val[:-1])
开发者ID:gokul-uf,项目名称:Theano,代码行数:32,代码来源:test_raw_random.py


示例4: test_ndim

    def test_ndim(self):
        """Test that the behaviour of 'ndim' optional parameter"""
        # 'ndim' is an optional integer parameter, specifying the length
        # of the 'shape', passed as a keyword argument.

        # ndim not specified, OK
        m1 = Module()
        m1.random = RandomStreams(utt.fetch_seed())
        m1.fn = Method([], m1.random.uniform((2,2)))
        made1 = m1.make()
        made1.random.initialize()

        # ndim specified, consistent with shape, OK
        m2 = Module()
        m2.random = RandomStreams(utt.fetch_seed())
        m2.fn = Method([], m2.random.uniform((2,2), ndim=2))
        made2 = m2.make()
        made2.random.initialize()

        val1 = made1.fn()
        val2 = made2.fn()
        assert numpy.all(val1 == val2)

        # ndim specified, inconsistent with shape, should raise ValueError
        m3 = Module()
        m3.random = RandomStreams(utt.fetch_seed())
        self.assertRaises(ValueError, m3.random.uniform, (2,2), ndim=1)
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:27,代码来源:test_randomstreams.py


示例5: test_broadcast_arguments

    def test_broadcast_arguments(self):
        m = Module()
        m.random = RandomStreams(utt.fetch_seed())
        low = tensor.vector()
        high = tensor.col()
        out = m.random.uniform(low=low, high=high)
        assert out.ndim == 2
        m.f = Method([low, high], out)
        made = m.make()
        made.random.initialize()

        rng_seed = numpy.random.RandomState(utt.fetch_seed()).randint(2**30)
        numpy_rng = numpy.random.RandomState(int(rng_seed))
        low_vals = [
                numpy.asarray([-5, .5, 0, 1], dtype=config.floatX),
                numpy.asarray([.9], dtype=config.floatX),
                numpy.asarray([-5, .5, 0, 1], dtype=config.floatX) ]
        high_vals = [
                numpy.asarray([[1.]], dtype=config.floatX),
                numpy.asarray([[1.], [1.1], [1.5]], dtype=config.floatX),
                numpy.asarray([[1.], [1.1], [1.5]], dtype=config.floatX) ]

        val0 = made.f(low_vals[0], high_vals[0])
        val1 = made.f(low_vals[1], high_vals[1])
        val2 = made.f(low_vals[2], high_vals[2])

        numpy_val0 = numpy_rng.uniform(low=low_vals[0], high=high_vals[0])
        numpy_val1 = numpy_rng.uniform(low=low_vals[1], high=high_vals[1])
        numpy_val2 = numpy_rng.uniform(low=low_vals[2], high=high_vals[2])

        assert numpy.allclose(val0, numpy_val0)
        assert numpy.allclose(val1, numpy_val1)
        assert numpy.allclose(val2, numpy_val2)
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:33,代码来源:test_randomstreams.py


示例6: test_no_inplace

    def test_no_inplace(self):
        """Test that when not running inplace, the RandomState is
        not updated"""
        rf = RandomFunction("uniform", tensor.dvector)
        rng_R = random_state_type()

        post_r, out = rf(rng_R, (3,), 0.0, 1.0)
        f = compile.function([rng_R], [post_r, out])
        rng = numpy.random.RandomState(utt.fetch_seed())

        rng0, val0 = f(rng)
        rng_ = numpy.random.RandomState(utt.fetch_seed())
        # rng should still be in a fresh state
        self.assertTrue(rng_R.type.values_eq(rng, rng_))
        # rng0 should be in an updated state
        self.assertFalse(rng_R.type.values_eq(rng, rng0))

        f2 = compile.function([compile.In(rng_R, value=rng, update=post_r, mutable=False)], [post_r, out])
        rng2, val2 = f2()
        # rng should be in a fresh state
        self.assertTrue(rng_R.type.values_eq(rng, rng_))
        # rng2 should be in an updated state
        self.assertFalse(rng_R.type.values_eq(rng, rng2))
        # The updated state should be the same for both functions
        self.assertTrue(rng_R.type.values_eq(rng2, rng0))

        rng3, val3 = f2()
        # rng2 should not have changed
        self.assertTrue(rng_R.type.values_eq(rng2, rng0))
        # rng3 should be an updated again version of rng2
        self.assertFalse(rng_R.type.values_eq(rng3, rng2))
        self.assertFalse(rng_R.type.values_eq(rng3, rng))
开发者ID:gokul-uf,项目名称:Theano,代码行数:32,代码来源:test_raw_random.py


示例7: test_binomial_vector

    def test_binomial_vector(self):
        rng_R = random_state_type()
        n = tensor.lvector()
        prob = tensor.vector()
        post_r, out = binomial(rng_R, n=n, p=prob)
        assert out.ndim == 1
        f = compile.function([rng_R, n, prob], [post_r, out],
                             accept_inplace=True)

        n_val = [1, 2, 3]
        prob_val = numpy.asarray([.1, .2, .3], dtype=config.floatX)
        rng = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(utt.fetch_seed())

        # Arguments of size (3,)
        rng0, val0 = f(rng, n_val, prob_val)
        numpy_val0 = numpy_rng.binomial(n=n_val, p=prob_val)
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        rng1, val1 = f(rng0, n_val[:-1], prob_val[:-1])
        numpy_val1 = numpy_rng.binomial(n=n_val[:-1], p=prob_val[:-1])
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = compile.function([rng_R, n, prob],
                binomial(rng_R, n=n, p=prob, size=(3,)),
                accept_inplace=True)
        rng2, val2 = g(rng1, n_val, prob_val)
        numpy_val2 = numpy_rng.binomial(n=n_val, p=prob_val, size=(3,))
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, rng2, n_val[:-1], prob_val[:-1])
开发者ID:SamuelZeng,项目名称:Theano,代码行数:32,代码来源:test_raw_random.py


示例8: test_infer_shape

 def test_infer_shape(self):
     if not imported_scipy:
         raise SkipTest("Scipy needed for the Cholesky op.")
     rng = numpy.random.RandomState(utt.fetch_seed())
     A = theano.tensor.matrix()
     b = theano.tensor.matrix()
     self._compile_and_check([A, b],  # theano.function inputs
                             [self.op(A, b)],  # theano.function outputs
                             # A must be square
                             [numpy.asarray(rng.rand(5, 5),
                                            dtype=config.floatX),
                              numpy.asarray(rng.rand(5, 1),
                                            dtype=config.floatX)],
                             self.op_class,
                             warn=False)
     rng = numpy.random.RandomState(utt.fetch_seed())
     A = theano.tensor.matrix()
     b = theano.tensor.vector()
     self._compile_and_check([A, b],  # theano.function inputs
                             [self.op(A, b)],  # theano.function outputs
                             # A must be square
                             [numpy.asarray(rng.rand(5, 5),
                                            dtype=config.floatX),
                              numpy.asarray(rng.rand(5),
                                            dtype=config.floatX)],
                             self.op_class,
                             warn=False)
开发者ID:gyenney,项目名称:Tools,代码行数:27,代码来源:test_slinalg.py


示例9: test_random_integers

    def test_random_integers(self):
        """Test that raw_random.random_integers generates the same
        results as numpy."""
        # Check over two calls to see if the random state is correctly updated.
        rng_R = random_state_type()
        # Use non-default parameters, and larger dimensions because of
        # the integer nature of the result
        post_r, out = random_integers(rng_R, (11, 8), -3, 16)

        f = compile.function(
                [compile.In(rng_R,
                    value=numpy.random.RandomState(utt.fetch_seed()),
                    update=post_r, mutable=True)],
                [out], accept_inplace=True)

        numpy_rng = numpy.random.RandomState(utt.fetch_seed())
        val0 = f()
        val1 = f()
        numpy_val0 = numpy_rng.random_integers(-3, 16, size=(11, 8))
        numpy_val1 = numpy_rng.random_integers(-3, 16, size=(11, 8))
        print val0
        print numpy_val0
        print val1
        print numpy_val1
        self.assertTrue(numpy.allclose(val0, numpy_val0))
        self.assertTrue(numpy.allclose(val1, numpy_val1))
开发者ID:SamuelZeng,项目名称:Theano,代码行数:26,代码来源:test_raw_random.py


示例10: test_binomial_vector

    def test_binomial_vector(self):
        random = RandomStreams(utt.fetch_seed())
        n = tensor.lvector()
        prob = tensor.vector()
        out = random.binomial(n=n, p=prob)
        assert out.ndim == 1
        f = function([n, prob], out)

        n_val = [1, 2, 3]
        prob_val = numpy.asarray([.1, .2, .3], dtype=config.floatX)
        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(n_val, prob_val)
        numpy_val0 = numpy_rng.binomial(n=n_val, p=prob_val)
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        val1 = f(n_val[:-1], prob_val[:-1])
        numpy_val1 = numpy_rng.binomial(n=n_val[:-1], p=prob_val[:-1])
        assert numpy.all(val1 == numpy_val1)

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


示例11: test_normal_vector

    def test_normal_vector(self):
        random = RandomStreams(utt.fetch_seed())
        avg = tensor.dvector()
        std = tensor.dvector()
        out = random.normal(avg=avg, std=std)
        assert out.ndim == 1
        f = function([avg, std], out)

        avg_val = [1, 2, 3]
        std_val = [.1, .2, .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(avg_val, std_val)
        numpy_val0 = numpy_rng.normal(loc=avg_val, scale=std_val)
        assert numpy.allclose(val0, numpy_val0)

        # arguments of size (2,)
        val1 = f(avg_val[:-1], std_val[:-1])
        numpy_val1 = numpy_rng.normal(loc=avg_val[:-1], scale=std_val[:-1])
        assert numpy.allclose(val1, numpy_val1)

        # Specifying the size explicitly
        g = function([avg, std], random.normal(avg=avg, std=std, size=(3,)))
        val2 = g(avg_val, std_val)
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        numpy_val2 = numpy_rng.normal(loc=avg_val, scale=std_val, size=(3,))
        assert numpy.allclose(val2, numpy_val2)
        self.assertRaises(ValueError, g, avg_val[:-1], std_val[:-1])
开发者ID:ChinaQuants,项目名称:Theano,代码行数:30,代码来源:test_shared_randomstreams.py


示例12: test_random_integers_vector

    def test_random_integers_vector(self):
        rng_R = random_state_type()
        low = tensor.lvector()
        high = tensor.lvector()
        post_r, out = random_integers(rng_R, low=low, high=high)
        assert out.ndim == 1
        f = compile.function([rng_R, low, high], [post_r, out],
                             accept_inplace=True)

        low_val = [100, 200, 300]
        high_val = [110, 220, 330]
        rng = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(utt.fetch_seed())

        # Arguments of size (3,)
        rng0, val0 = f(rng, low_val, high_val)
        numpy_val0 = numpy.asarray([numpy_rng.random_integers(low=lv, high=hv)
            for lv, hv in zip(low_val, high_val)])
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        rng1, val1 = f(rng0, low_val[:-1], high_val[:-1])
        numpy_val1 = numpy.asarray([numpy_rng.random_integers(low=lv, high=hv)
            for lv, hv in zip(low_val[:-1], high_val[:-1])])
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = compile.function([rng_R, low, high],
                random_integers(rng_R, low=low, high=high, size=(3,)),
                accept_inplace=True)
        rng2, val2 = g(rng1, low_val, high_val)
        numpy_val2 = numpy.asarray([numpy_rng.random_integers(low=lv, high=hv)
            for lv, hv in zip(low_val, high_val)])
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, rng2, low_val[:-1], high_val[:-1])
开发者ID:SamuelZeng,项目名称:Theano,代码行数:35,代码来源:test_raw_random.py


示例13: test_uniform_vector

    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,代码行数:34,代码来源:test_shared_randomstreams.py


示例14: test_normal_vector

    def test_normal_vector(self):
        m = Module()
        m.random = RandomStreams(utt.fetch_seed())
        avg = tensor.vector()
        std = tensor.vector()
        out = m.random.normal(avg=avg, std=std)
        assert out.ndim == 1
        m.f = Method([avg, std], out)
        # Specifying the size explicitly
        m.g = Method([avg, std],
                m.random.normal(avg=avg, std=std, size=(3,)))
        made = m.make()
        made.random.initialize()

        avg_val = [1, 2, 3]
        std_val = numpy.asarray([.1, .2, .3], dtype=config.floatX)
        seed_gen = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))

        # Arguments of size (3,)
        val0 = made.f(avg_val, std_val)
        numpy_val0 = numpy_rng.normal(loc=avg_val, scale=std_val)
        assert numpy.allclose(val0, numpy_val0)

        # arguments of size (2,)
        val1 = made.f(avg_val[:-1], std_val[:-1])
        numpy_val1 = numpy_rng.normal(loc=avg_val[:-1], scale=std_val[:-1])
        assert numpy.allclose(val1, numpy_val1)

        # Specifying the size explicitly
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        val2 = made.g(avg_val, std_val)
        numpy_val2 = numpy_rng.normal(loc=avg_val, scale=std_val, size=(3,))
        assert numpy.allclose(val2, numpy_val2)
        self.assertRaises(ValueError, made.g, avg_val[:-1], std_val[:-1])
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:35,代码来源:test_randomstreams.py


示例15: test_binomial_vector

    def test_binomial_vector(self):
        m = Module()
        m.random = RandomStreams(utt.fetch_seed())
        n = tensor.lvector()
        prob = tensor.vector()
        out = m.random.binomial(n=n, p=prob)
        assert out.ndim == 1
        m.f = Method([n, prob], out)
        # Specifying the size explicitly
        m.g = Method([n, prob],
                m.random.binomial(n=n, p=prob, size=(3,)))
        made = m.make()
        made.random.initialize()

        n_val = [1, 2, 3]
        prob_val = numpy.asarray([.1, .2, .3], dtype=config.floatX)
        seed_gen = numpy.random.RandomState(utt.fetch_seed())
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))

        # Arguments of size (3,)
        val0 = made.f(n_val, prob_val)
        numpy_val0 = numpy_rng.binomial(n=n_val, p=prob_val)
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        val1 = made.f(n_val[:-1], prob_val[:-1])
        numpy_val1 = numpy_rng.binomial(n=n_val[:-1], p=prob_val[:-1])
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        val2 = made.g(n_val, prob_val)
        numpy_val2 = numpy_rng.binomial(n=n_val, p=prob_val, size=(3,))
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, made.g, n_val[:-1], prob_val[:-1])
开发者ID:HaniAlmousli,项目名称:Theano,代码行数:35,代码来源:test_randomstreams.py


示例16: test_uniform_vector

    def test_uniform_vector(self):
        m = Module()
        m.random = RandomStreams(utt.fetch_seed())
        low = tensor.vector()
        high = tensor.vector()
        out = m.random.uniform(low=low, high=high)
        assert out.ndim == 1
        m.f = Method([low, high], out)
        # Specifying the size explicitly
        m.g = Method([low, high],
                m.random.uniform(low=low, high=high, size=(3,)))
        made = m.make()
        made.random.initialize()

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

        # Arguments of size (3,)
        val0 = made.f(low_val, high_val)
        numpy_val0 = numpy_rng.uniform(low=low_val, high=high_val)
        assert numpy.allclose(val0, numpy_val0)

        # arguments of size (2,)
        val1 = made.f(low_val[:-1], high_val[:-1])
        numpy_val1 = numpy_rng.uniform(low=low_val[:-1], high=high_val[:-1])
        assert numpy.allclose(val1, numpy_val1)

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


示例17: test_gpu4_gibbs_chain

    def test_gpu4_gibbs_chain(self):
        rng = numpy.random.RandomState(utt.fetch_seed())
        v_vsample = numpy.array(rng.binomial(1, .5, size=(3, 20),),
                                dtype='float32')
        vsample = theano.shared(v_vsample)
        trng = theano.sandbox.rng_mrg.MRG_RandomStreams(
                                utt.fetch_seed())

        def f(vsample_tm1):
            return trng.binomial(vsample_tm1.shape, n=1, p=0.3,
                                 dtype='float32') * vsample_tm1

        theano_vsamples, updates = theano.scan(f,
                                               [],
                                               vsample,
                                               [],
                                               n_steps=10,
                                               truncate_gradient=-1,
                                               go_backwards=False,
                                               mode=mode_with_gpu)
        my_f = theano.function([],
                               theano_vsamples[-1],
                               updates=updates,
                               allow_input_downcast=True,
                               mode=mode_with_gpu)

        # I leave this to tested by debugmode, this test was anyway
        # more of does the graph compile kind of test
        t_result = my_f()
开发者ID:317070,项目名称:Theano,代码行数:29,代码来源:test_scan.py


示例18: test_random_integers_vector

    def test_random_integers_vector(self):
        random = RandomStreams(utt.fetch_seed())
        low = tensor.lvector()
        high = tensor.lvector()
        out = random.random_integers(low=low, high=high)
        assert out.ndim == 1
        f = function([low, high], out)

        low_val = [100, 200, 300]
        high_val = [110, 220, 330]
        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.asarray([numpy_rng.randint(low=lv, high=hv+1)
            for lv, hv in zip(low_val, high_val)])
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        val1 = f(low_val[:-1], high_val[:-1])
        numpy_val1 = numpy.asarray([numpy_rng.randint(low=lv, high=hv+1)
            for lv, hv in zip(low_val[:-1], high_val[:-1])])
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = function([low, high], random.random_integers(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.asarray([numpy_rng.randint(low=lv, high=hv+1)
            for lv, hv in zip(low_val, high_val)])
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, low_val[:-1], high_val[:-1])
开发者ID:ChinaQuants,项目名称:Theano,代码行数:33,代码来源:test_shared_randomstreams.py


示例19: test_choice

    def test_choice(self):
        """Test that raw_random.choice generates the same
        results as numpy."""
        # numpy.random.choice is only available for numpy versions >= 1.7
        major, minor, _ = numpy.version.short_version.split('.')
        if (int(major), int(minor)) < (1, 7):
            raise utt.SkipTest('choice requires at NumPy version >= 1.7 '
                               '(%s)' % numpy.__version__)
        
        # Check over two calls to see if the random state is correctly updated.
        rng_R = random_state_type()
        # Use non-default parameters, and larger dimensions because of
        # the integer nature of the result
        post_r, out = choice(rng_R, (11, 8), 10, 1, 0)

        f = compile.function(
                [compile.In(rng_R,
                    value=numpy.random.RandomState(utt.fetch_seed()),
                    update=post_r, mutable=True)],
                [out], accept_inplace=True)

        numpy_rng = numpy.random.RandomState(utt.fetch_seed())
        val0 = f()
        val1 = f()
        numpy_val0 = numpy_rng.choice(10, (11, 8), True, None)
        numpy_val1 = numpy_rng.choice(10, (11, 8), True, None)
        print val0
        print numpy_val0
        print val1
        print numpy_val1
        self.assertTrue(numpy.allclose(val0, numpy_val0))
        self.assertTrue(numpy.allclose(val1, numpy_val1))
开发者ID:317070,项目名称:Theano,代码行数:32,代码来源:test_raw_random.py


示例20: test_multinomial_vector

    def test_multinomial_vector(self):
        random = RandomStreams(utt.fetch_seed())
        n = tensor.lvector()
        pvals = tensor.matrix()
        out = random.multinomial(n=n, pvals=pvals)
        assert out.ndim == 2
        f = function([n, pvals], out)

        n_val = [1, 2, 3]
        pvals_val = [[.1, .9], [.2, .8], [.3, .7]]
        pvals_val = numpy.asarray(pvals_val, dtype=config.floatX)
        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(n_val, pvals_val)
        numpy_val0 = numpy.asarray([numpy_rng.multinomial(n=nv, pvals=pv)
            for nv, pv in zip(n_val, pvals_val)])
        assert numpy.all(val0 == numpy_val0)

        # arguments of size (2,)
        val1 = f(n_val[:-1], pvals_val[:-1])
        numpy_val1 = numpy.asarray([numpy_rng.multinomial(n=nv, pvals=pv)
            for nv, pv in zip(n_val[:-1], pvals_val[:-1])])
        assert numpy.all(val1 == numpy_val1)

        # Specifying the size explicitly
        g = function([n, pvals], random.multinomial(n=n, pvals=pvals, size=(3,)))
        val2 = g(n_val, pvals_val)
        numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
        numpy_val2 = numpy.asarray([numpy_rng.multinomial(n=nv, pvals=pv)
            for nv, pv in zip(n_val, pvals_val)])
        assert numpy.all(val2 == numpy_val2)
        self.assertRaises(ValueError, g, n_val[:-1], pvals_val[:-1])
开发者ID:ChinaQuants,项目名称:Theano,代码行数:34,代码来源:test_shared_randomstreams.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unittest_tools.seed_rng函数代码示例发布时间:2022-05-27
下一篇:
Python unittest_tools.assert_allclose函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap