當前位置: 首頁>>代碼示例>>Python>>正文


Python functions.linear方法代碼示例

本文整理匯總了Python中chainer.functions.linear方法的典型用法代碼示例。如果您正苦於以下問題:Python functions.linear方法的具體用法?Python functions.linear怎麽用?Python functions.linear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chainer.functions的用法示例。


在下文中一共展示了functions.linear方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def __call__(self, x):
        if self.mu.W.array is None:
            self.mu.W.initialize((self.out_size, numpy.prod(x.shape[1:])))
        if self.sigma.W.array is None:
            self.sigma.W.initialize((self.out_size, numpy.prod(x.shape[1:])))

        # use info of sigma.W to avoid strange error messages
        dtype = self.sigma.W.dtype
        out_size, in_size = self.sigma.W.shape

        eps = self._eps(in_size + out_size, dtype)
        eps_x = eps[:in_size]
        eps_y = eps[in_size:]
        W = muladd(self.sigma.W, self.xp.outer(eps_y, eps_x), self.mu.W)
        if self.nobias:
            return F.linear(x, W)
        else:
            b = muladd(self.sigma.b, eps_y, self.mu.b)
            return F.linear(x, W, b) 
開發者ID:chainer,項目名稱:chainerrl,代碼行數:21,代碼來源:noisy_linear.py

示例2: _step_rnn_tanh

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def _step_rnn_tanh(rnn, x, state):
    assert isinstance(rnn, L.NStepRNNTanh)
    assert len(rnn.ws) == 1
    assert len(rnn.bs) == 1
    assert len(rnn.ws[0]) == 2
    assert len(rnn.bs[0]) == 2
    if state is None:
        xp = rnn.xp
        h = xp.zeros((len(x), rnn.out_size), dtype=np.float32)
    else:
        h = state
    w0, w1 = rnn.ws[0]
    b0, b1 = rnn.bs[0]
    h = F.tanh(F.linear(x, w0, b0) + F.linear(h, w1, b1))
    return h, h 
開發者ID:chainer,項目名稱:chainerrl,代碼行數:17,代碼來源:test_stateless_recurrent_sequential.py

示例3: f

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def f(self, x):
        for i, (w, b) in enumerate(zip(self._lst_w, self._lst_b)):
            x = F.linear(x, w, b)
            if i != len(self._lst_w) - 1:
                x = F.tanh(x)
            else:
                return self._out_fn(x) 
開發者ID:openai,項目名稱:EPG,代碼行數:9,代碼來源:networks.py

示例4: __init__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def __init__(self, n_units, n_vocab, encoder, max_memory, hops):
        super(MemNN, self).__init__()

        with self.init_scope():
            self.embeds = chainer.ChainList()
            self.temporals = chainer.ChainList()

        normal = initializers.Normal()
        # Shares both embeded matrixes in adjacent layres
        for _ in six.moves.range(hops + 1):
            self.embeds.append(L.EmbedID(n_vocab, n_units, initialW=normal))
            self.temporals.append(
                L.EmbedID(max_memory, n_units, initialW=normal))

        self.memories = [
            Memory(self.embeds[i], self.embeds[i + 1],
                   self.temporals[i], self.temporals[i + 1], encoder)
            for i in six.moves.range(hops)
        ]
        # The question embedding is same as the input embedding of the
        # first layer
        self.B = self.embeds[0]
        # The answer prediction matrix W is same as the final output layer
        self.W = lambda u: F.linear(u, self.embeds[-1].W)

        self.encoder = encoder

        self.n_units = n_units
        self.max_memory = max_memory
        self.hops = hops 
開發者ID:chainer,項目名稱:chainer,代碼行數:32,代碼來源:memnn.py

示例5: test_LinearFunction

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def test_LinearFunction(self):
        W = numpy.random.uniform(-1, 1, (1, numpy.prod(self.x.shape[1:])))

        class Link(chainer.Chain):
            def __call__(self, x):
                return F.linear(x, W)

        assert_export_import_match(Link(), self.x) 
開發者ID:chainer,項目名稱:chainer,代碼行數:10,代碼來源:test_caffe.py

示例6: forward

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def forward(self, inputs, device):
        if self.nobias:
            x, W = inputs
            b = None
        else:
            x, W, b = inputs
        y = functions.linear(x, W, b, n_batch_axes=self.n_batch_axes)
        return y, 
開發者ID:chainer,項目名稱:chainer,代碼行數:10,代碼來源:test_linear.py

示例7: test_1

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def test_1(self):
        with chainer.using_config('use_ideep', 'never'):
            n_batches = 1  # important
            in_dims = (2, 2)
            out_dim = 3
            x_shape = (n_batches,) + in_dims
            w_shape = (out_dim, numpy.prod(in_dims),)
            x = numpy.ones(x_shape, numpy.float32)
            w = numpy.ones(w_shape, numpy.float32)
            y = functions.linear(chainer.Variable(x), w)
            z = functions.sum(y)
            z.backward() 
開發者ID:chainer,項目名稱:chainer,代碼行數:14,代碼來源:test_linear.py

示例8: test_negative

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def test_negative(self):
        n_batch_axes = -1
        with pytest.raises(ValueError):
            functions.linear(self.x, self.W, n_batch_axes=n_batch_axes) 
開發者ID:chainer,項目名稱:chainer,代碼行數:6,代碼來源:test_linear.py

示例9: lstm_without_dropout

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def lstm_without_dropout(n_layer, dropout, hx, cx, ws, bs, xs):
    xws = [_stack_weight([w[2], w[0], w[1], w[3]]) for w in ws]
    hws = [_stack_weight([w[6], w[4], w[5], w[7]]) for w in ws]
    xbs = [_stack_weight([b[2], b[0], b[1], b[3]]) for b in bs]
    hbs = [_stack_weight([b[6], b[4], b[5], b[7]]) for b in bs]
    xs = [xs[i] for i in range(3)]
    ys = []
    for x in xs:
        cx_next = []
        hx_next = []
        for layer in range(n_layer):
            c = cx[layer]
            h = hx[layer]

            if layer != 0:
                # Only multiply ratio
                x = x * (1 / (1.0 - dropout))
            lstm_in = F.linear(x, xws[layer], xbs[layer]) + \
                F.linear(h, hws[layer], hbs[layer])
            c_new, h_new = F.lstm(c, lstm_in)
            cx_next.append(c_new)
            hx_next.append(h_new)
            x = h_new
        cx = cx_next
        hx = hx_next
        ys.append(x)
    cy = F.stack(cx)
    hy = F.stack(hx)
    return hy, cy, ys 
開發者ID:chainer,項目名稱:chainer,代碼行數:31,代碼來源:test_function_n_step_lstm.py

示例10: __call__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def __call__(self, x):
        out = F.linear(x, self.W, self.b)
        if self.scale is not None:
            out *= F.broadcast_to(self.scale[None], out.shape)
        return out 
開發者ID:chainer,項目名稱:models,代碼行數:7,代碼來源:lm_nets.py

示例11: __call__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def __call__(self, x):
        if self.rf == 1:
            size_out = x.shape[:-1] + (self.nf,)
            x = F.linear(x.reshape(-1, x.shape[-1]), self.w, self.b)
            x = x.reshape(*size_out)
        else:
            raise NotImplementedError
        return x 
開發者ID:chainer,項目名稱:models,代碼行數:10,代碼來源:model_py.py

示例12: __init__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def __init__(self, cfg, vocab=40990, n_ctx=512):
        super(Model, self).__init__()
        self.vocab = vocab
        with self.init_scope():
            self.embed = L.EmbedID(vocab, cfg.n_embd,
                                   initializers.Normal(scale=0.02))
            self.drop = lambda x: F.dropout(x, cfg.embd_pdrop)
            block = Block(n_ctx, cfg, scale=True)
            self.h = chainer.ChainList(*[copy.deepcopy(block)
                                         for _ in range(cfg.n_layer)])
        self.decoder = lambda x: F.linear(x, self.embed.W)
        # To reproduce the noise_shape parameter of TF implementation
        self.clf_dropout = lambda x: F.dropout(x, cfg.clf_pdrop) 
開發者ID:chainer,項目名稱:models,代碼行數:15,代碼來源:model_py.py

示例13: squared_distance_matrix

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import linear [as 別名]
def squared_distance_matrix(X):
    n = X.shape[0]
    XX = F.sum(X ** 2.0, axis=1)
    distances = -2.0 * F.linear(X, X)
    distances = distances + F.broadcast_to(XX, (n, n))
    distances = distances + F.broadcast_to(F.expand_dims(XX, 1), (n, n))
    return distances 
開發者ID:ronekko,項目名稱:deep_metric_learning,代碼行數:9,代碼來源:lifted_struct_loss.py


注:本文中的chainer.functions.linear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。