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


Python tensor.matrices函数代码示例

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


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

示例1: __init__

    def __init__(self,
                gen_params, # dictionary of generative model parameters
                GEN_MODEL,  # class that inherits from GenerativeModel
                rec_params, # dictionary of approximate posterior ("recognition model") parameters
                REC_MODEL, # class that inherits from RecognitionModel
                xDim=2, # dimensionality of latent state
                yDim=2 # dimensionality of observations
                ):

        # instantiate rng's
        self.srng = RandomStreams(seed=234)
        self.nrng = np.random.RandomState(124)

        #---------------------------------------------------------
        ## actual model parameters
        self.X, self.Y = T.matrices('X','Y')   # symbolic variables for the data

        self.xDim   = xDim
        self.yDim   = yDim

        # instantiate our prior & recognition models
        self.mrec   = REC_MODEL(rec_params, self.Y, self.xDim, self.yDim, self.srng, self.nrng)
        self.mprior = GEN_MODEL(gen_params, self.xDim, self.yDim, srng=self.srng, nrng = self.nrng)

        self.isTrainingRecognitionModel = True;
        self.isTrainingGenerativeModel = True;
开发者ID:dhern,项目名称:vilds,代码行数:26,代码来源:SGVB.py

示例2: _gpu_matrix_dot

    def _gpu_matrix_dot(matrix_a, matrix_b, matrix_c=None):
        """
        Performs matrix multiplication.
        Attempts to use the GPU if it's available. If the matrix multiplication
        is too big to fit on the GPU, this falls back to the CPU after throwing
        a warning.
        Parameters
        ----------
        matrix_a : WRITEME
        matrix_b : WRITEME
        matrix_c : WRITEME
        """
        if not hasattr(ZCA._gpu_matrix_dot, 'theano_func'):
            ma, mb = T.matrices('A', 'B')
            mc = T.dot(ma, mb)
            ZCA._gpu_matrix_dot.theano_func = \
                theano.function([ma, mb], mc, allow_input_downcast=True)

        theano_func = ZCA._gpu_matrix_dot.theano_func

        try:
            if matrix_c is None:
                return theano_func(matrix_a, matrix_b)
            else:
                matrix_c[...] = theano_func(matrix_a, matrix_b)
                return matrix_c
        except MemoryError:
            warnings.warn('Matrix multiplication too big to fit on GPU. '
                          'Re-doing with CPU. Consider using '
                          'THEANO_FLAGS="device=cpu" for your next '
                          'preprocessor run')
            return np.dot(matrix_a, matrix_b, matrix_c)
开发者ID:ColaWithIce,项目名称:Mozi,代码行数:32,代码来源:preprocessor.py

示例3: sample_parallel

def sample_parallel():
    print "並列"
    x, y = T.matrices("a", "b")
    diff = x - y
    abs_diff = abs(diff)
    diff_sq = diff**2
    # 2つの行列を入力, 3つの行列のベクトルを出力
    f = theano.function([x, y], [diff, abs_diff, diff_sq])
    print f([[0,1],[2,3]], [[10,11],[12,13]])
    print
开发者ID:norikinishida,项目名称:snippets,代码行数:10,代码来源:sample.py

示例4: test_grad

 def test_grad(self, cls_ofg):
     x, y, z = T.matrices('xyz')
     e = x + y * z
     op = cls_ofg([x, y, z], [e])
     f = op(x, y, z)
     f = f - T.grad(T.sum(f), y)
     fn = function([x, y, z], f)
     xv = np.ones((2, 2), dtype=config.floatX)
     yv = np.ones((2, 2), dtype=config.floatX) * 3
     zv = np.ones((2, 2), dtype=config.floatX) * 5
     assert np.all(11.0 == fn(xv, yv, zv))
开发者ID:Faruk-Ahmed,项目名称:Theano,代码行数:11,代码来源:test_builders.py

示例5: test_grad

 def test_grad(self):
     x, y, z = T.matrices('xyz')
     e = x + y * z
     op = OpFromGraph([x, y, z], [e], mode='FAST_RUN', grad_depth=2)
     f = op(x, y, z)
     f = f - T.grad(T.sum(f), y)
     fn = function([x, y, z], f)
     xv = numpy.ones((2, 2), dtype=config.floatX)
     yv = numpy.ones((2, 2), dtype=config.floatX)*3
     zv = numpy.ones((2, 2), dtype=config.floatX)*5
     assert numpy.all(11.0 == fn(xv, yv, zv))
开发者ID:LixinZhang,项目名称:Theano,代码行数:11,代码来源:test_builders.py

示例6: test_connection_pattern

    def test_connection_pattern(self, cls_ofg):
        # Basic case
        x, y, z = T.matrices('xyz')
        out1 = x * y
        out2 = y * z

        op1 = cls_ofg([x, y, z], [out1, out2])
        results = op1.connection_pattern(None)
        expect_result = [[True, False],
                         [True, True],
                         [False, True]]
        assert results == expect_result

        # Graph with ops that don't have a 'full' connection pattern
        # and with ops that have multiple outputs
        m, n, p, q = T.matrices('mnpq')
        o1, o2 = op1(m, n, p)
        out1, out2 = op1(o1, q, o2)
        op2 = cls_ofg([m, n, p, q], [out1, out2])

        results = op2.connection_pattern(None)
        expect_result = [[True, False],
                         [True, True],
                         [False, True],
                         [True, True]]
        assert results == expect_result

        # Inner graph where some computation doesn't rely on explicit inputs
        srng = RandomStreams(seed=234)
        rv_u = srng.uniform((2, 2))
        x, y = T.matrices('xy')
        out1 = x + rv_u
        out2 = y + 3
        out3 = 3 + rv_u
        op3 = cls_ofg([x, y], [out1, out2, out3])

        results = op3.connection_pattern(None)
        expect_result = [[True, False, False],
                         [False, True, False],
                         [True, False, True]]
        assert results == expect_result
开发者ID:Faruk-Ahmed,项目名称:Theano,代码行数:41,代码来源:test_builders.py

示例7: test_grad_grad

 def test_grad_grad(self):
     x, y, z = T.matrices('xyz')
     e = x + y * z
     op = OpFromGraph([x, y, z], [e])
     f = op(x, y, z)
     f = f - T.grad(T.sum(f), y)
     f = f - T.grad(T.sum(f), y)
     fn = function([x, y, z], f)
     xv = numpy.ones((2, 2), dtype=config.floatX)
     yv = numpy.ones((2, 2), dtype=config.floatX) * 3
     zv = numpy.ones((2, 2), dtype=config.floatX) * 5
     assert numpy.allclose(6.0, fn(xv, yv, zv))
开发者ID:Azrael1,项目名称:Theano,代码行数:12,代码来源:test_builders.py

示例8: _build

 def _build(self):
     if self._debug:
         theano.config.compute_test_value = 'warn'
     X,W = T.matrices('X','W')
     if self._debug:
         X.tag.test_value = np.random.rand(3,1)
         W.tag.test_value = np.random.rand(5,3)
     Z = T.dot(W,X)
     A = self._activation(Z)
     self._fpropagate = function([X, W],A)
     self._layers = []
     self._generate_initial_weights()
开发者ID:throoze,项目名称:usbrain,代码行数:12,代码来源:usbrain.py

示例9: __init__

    def __init__(self, shape):
        self.in_size, self.out_size = shape

        self.W = init_weights(shape)
        self.b = init_bias(self.out_size)

        self.gW = init_gradws(shape)
        self.gb = init_bias(self.out_size)

        D, X = T.matrices("D", "X")
        def _active(X):
            return T.nnet.sigmoid(T.dot(X, self.W) + self.b)
        self.active = theano.function(inputs = [X], outputs = _active(X))
        
        def _derive(D, X):
            return D * ((1 - X) * X)
        self.derive = theano.function(
            inputs = [D, X],
            outputs = _derive(D, X)
        )

        def _propagate(D):
            return T.dot(D, self.W.T)
        self.propagate = theano.function(inputs = [D], outputs = _propagate(D))

        x, dy = T.rows("x","dy")
        updates_grad = [(self.gW, self.gW + T.dot(x.T, dy)),
               (self.gb, self.gb + dy)]
        self.grad = theano.function(
            inputs = [x, dy],
            updates = updates_grad
        )

        updates_clear = [
               (self.gW, self.gW * 0),
               (self.gb, self.gb * 0)]
        self.clear_grad = theano.function(
            inputs = [],
            updates = updates_clear
        )

        lr = T.scalar()
        t = T.scalar()
        updates_w = [
               (self.W, self.W - self.gW * lr / t),
               (self.b, self.b - self.gb * lr / t)]
        self.update = theano.function(
            inputs = [lr, t],
            updates = updates_w
        )
开发者ID:iamsile,项目名称:rnn-theano-cpu-run,代码行数:50,代码来源:logistic_layer.py

示例10: test_straightforward

 def test_straightforward(self):
     x, y, z = T.matrices('xyz')
     e = x + y * z
     op = OpFromGraph([x, y, z], [e], mode='FAST_RUN')
     f = op(x, y, z) - op(y, z, x)  # (1+3*5=array of 16) - (3+1*5=array of 8)
     fn = function([x, y, z], f)
     xv = numpy.ones((2, 2), dtype=config.floatX)
     yv = numpy.ones((2, 2), dtype=config.floatX)*3
     zv = numpy.ones((2, 2), dtype=config.floatX)*5
     #print function, function.__module__
     #print fn.maker.fgraph.toposort()
     fn(xv, yv, zv)
     assert numpy.all(8.0 == fn(xv, yv, zv))
     assert numpy.all(8.0 == fn(xv, yv, zv))
开发者ID:LixinZhang,项目名称:Theano,代码行数:14,代码来源:test_builders.py

示例11: test_size_changes

 def test_size_changes(self):
     x, y, z = T.matrices('xyz')
     e = T.dot(x, y)
     op = OpFromGraph([x, y], [e], mode='FAST_RUN')
     f = op(x, op(y, z))
     fn = function([x, y, z], f)
     xv = numpy.ones((2, 3), dtype=config.floatX)
     yv = numpy.ones((3, 4), dtype=config.floatX)*3
     zv = numpy.ones((4, 5), dtype=config.floatX)*5
     res = fn(xv, yv, zv)
     assert res.shape == (2, 5)
     assert numpy.all(180.0 == res)
     res = fn(xv, yv, zv)
     assert res.shape == (2, 5)
     assert numpy.all(180.0 == res)
开发者ID:LixinZhang,项目名称:Theano,代码行数:15,代码来源:test_builders.py

示例12: test_size_changes

 def test_size_changes(self, cls_ofg):
     x, y, z = T.matrices('xyz')
     e = T.dot(x, y)
     op = cls_ofg([x, y], [e])
     f = op(x, op(y, z))
     fn = function([x, y, z], f)
     xv = np.ones((2, 3), dtype=config.floatX)
     yv = np.ones((3, 4), dtype=config.floatX) * 3
     zv = np.ones((4, 5), dtype=config.floatX) * 5
     res = fn(xv, yv, zv)
     assert res.shape == (2, 5)
     assert np.all(180.0 == res)
     res = fn(xv, yv, zv)
     assert res.shape == (2, 5)
     assert np.all(180.0 == res)
开发者ID:Faruk-Ahmed,项目名称:Theano,代码行数:15,代码来源:test_builders.py

示例13: test_straightforward

    def test_straightforward(self, cls_ofg):
        x, y, z = T.matrices('xyz')
        e = x + y * z
        op = cls_ofg([x, y, z], [e])
        # (1+3*5=array of 16) - (3+1*5=array of 8)
        f = op(x, y, z) - op(y, z, x)

        fn = function([x, y, z], f)
        xv = np.ones((2, 2), dtype=config.floatX)
        yv = np.ones((2, 2), dtype=config.floatX) * 3
        zv = np.ones((2, 2), dtype=config.floatX) * 5
        # print function, function.__module__
        # print fn.maker.fgraph.toposort()
        fn(xv, yv, zv)
        assert np.all(8.0 == fn(xv, yv, zv))
        assert np.all(8.0 == fn(xv, yv, zv))
开发者ID:Faruk-Ahmed,项目名称:Theano,代码行数:16,代码来源:test_builders.py

示例14: test_shared

    def test_shared(self, cls_ofg):
        x, y, z = T.matrices('xyz')
        s = shared(np.random.rand(2, 2).astype(config.floatX))
        e = x + y * z + s
        op = cls_ofg([x, y, z], [e])
        # (1+3*5=array of 16) - (3+1*5=array of 8)
        f = op(x, y, z) - op(y, z, x)

        fn = function([x, y, z], f)
        xv = np.ones((2, 2), dtype=config.floatX)
        yv = np.ones((2, 2), dtype=config.floatX) * 3
        zv = np.ones((2, 2), dtype=config.floatX) * 5
        # print function, function.__module__
        # print fn.maker.fgraph.toposort()
        assert np.allclose(8.0, fn(xv, yv, zv))
        assert np.allclose(8.0, fn(xv, yv, zv))
开发者ID:Faruk-Ahmed,项目名称:Theano,代码行数:16,代码来源:test_builders.py

示例15: __init__

    def __init__(self, shape, X):
        prefix = "Softmax_"
        self.in_size, self.out_size = shape
        self.W = init_weights(shape, prefix + "W")
        self.b = init_bias(self.out_size, prefix + "b")

        self.gW = init_gradws(shape, prefix + "gW")
        self.gb = init_bias(self.out_size, prefix + "gb")

        D = T.matrices("D")
        self.X = X
        def _active(X):
            return T.nnet.softmax(T.dot(X, self.W) + self.b)
        self.active = theano.function(inputs = [self.X], outputs = _active(self.X))

        def _propagate(D):
            return T.dot(D, self.W.T)
        self.propagate = theano.function(inputs = [D], outputs = _propagate(D))

        x, dy = T.rows("x","dy")
        updates_grad = [(self.gW, self.gW + T.dot(x.T, dy)),
               (self.gb, self.gb + dy)]
        self.grad = theano.function(
            inputs = [x, dy],
            updates = updates_grad
        )

        updates_clear = [
               (self.gW, self.gW * 0),
               (self.gb, self.gb * 0)]
        self.clear_grad = theano.function(
            inputs = [],
            updates = updates_clear
        )

        lr = T.scalar()
        t = T.scalar()
        updates_w = [
               (self.W, self.W - self.gW * lr / t),
               (self.b, self.b - self.gb * lr / t)]
        self.update = theano.function(
            inputs = [lr, t],
            updates = updates_w
        )

        self.params = [self.W, self.b]
开发者ID:iamsile,项目名称:rnn-theano-cpu-run,代码行数:46,代码来源:softmax_layer.py


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