当前位置: 首页>>代码示例>>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;未经允许,请勿转载。