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


Python functions.log方法代码示例

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


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

示例1: _compute_loss

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def _compute_loss(self, exp_batch, errors_out=None):
        """Compute a loss of categorical DQN."""
        y, t = self._compute_y_and_t(exp_batch)
        # Minimize the cross entropy
        # y is clipped to avoid log(0)
        eltwise_loss = -t * F.log(F.clip(y, 1e-10, 1.))

        if errors_out is not None:
            del errors_out[:]
            # The loss per example is the sum of the atom-wise loss
            # Prioritization by KL-divergence
            delta = F.sum(eltwise_loss, axis=1)
            delta = cuda.to_cpu(delta.array)
            for e in delta:
                errors_out.append(e)

        if 'weights' in exp_batch:
            return compute_weighted_value_loss(
                eltwise_loss, y.shape[0], exp_batch['weights'],
                batch_accumulator=self.batch_accumulator)
        else:
            return compute_value_loss(
                eltwise_loss, batch_accumulator=self.batch_accumulator) 
开发者ID:chainer,项目名称:chainerrl,代码行数:25,代码来源:categorical_dqn.py

示例2: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def __init__(self, Vi, Ei, Hi, Vo, Eo, Ho, Ha, Hl, attn_cls=attention.AttentionModule, init_orth=False, use_bn_length=0,
                 encoder_cell_type=rnn_cells.LSTMCell,
                 decoder_cell_type=rnn_cells.LSTMCell,
                 lexical_probability_dictionary=None, lex_epsilon=1e-3,
                 use_goto_attention=False
                 ):
        log.info("constructing encoder decoder with Vi:%i Ei:%i Hi:%i Vo:%i Eo:%i Ho:%i Ha:%i Hl:%i" %
                 (Vi, Ei, Hi, Vo, Eo, Ho, Ha, Hl))
        super(EncoderDecoder, self).__init__(
            enc=encoders.make_encoder(Vi, Ei, Hi, init_orth=init_orth, use_bn_length=use_bn_length,
                                      cell_type=encoder_cell_type),
            dec=decoder_cells.Decoder(Vo, Eo, Ho, Ha, 2 * Hi, Hl, attn_cls=attn_cls, init_orth=init_orth,
                                      cell_type=decoder_cell_type, use_goto_attention=use_goto_attention)
        )
        self.Vo = Vo
        self.lexical_probability_dictionary = lexical_probability_dictionary
        self.lex_epsilon = lex_epsilon 
开发者ID:fabiencro,项目名称:knmt,代码行数:19,代码来源:encoder_decoder.py

示例3: get_gaussian_params

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def get_gaussian_params(self, x):
        h = F.tanh(self.l1(x))
        h = self.l2(h)

        pi = h[:, :self.gaussian_mixtures]
        mu_var_dim = self.gaussian_mixtures * self.input_dim
        mu = h[:, self.gaussian_mixtures:self.gaussian_mixtures + mu_var_dim]
        log_var = h[:, self.gaussian_mixtures + mu_var_dim:]

        n_batch = x.shape[0]

        # mixing coefficients
        pi = F.reshape(pi, (n_batch, self.gaussian_mixtures))
        pi = F.softmax(pi, axis=1)

        # mean
        mu = F.reshape(mu, (n_batch, self.gaussian_mixtures, self.input_dim))

        # log variance
        log_var = F.reshape(
            log_var, (n_batch, self.gaussian_mixtures, self.input_dim))

        return pi, mu, log_var 
开发者ID:chainer,项目名称:models,代码行数:25,代码来源:mdn.py

示例4: sample_discrete_actions

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def sample_discrete_actions(batch_probs):
    """Sample a batch of actions from a batch of action probabilities.

    Args:
        batch_probs (ndarray): batch of action probabilities BxA
    Returns:
        ndarray consisting of sampled action indices
    """
    xp = chainer.cuda.get_array_module(batch_probs)
    return xp.argmax(
        xp.log(batch_probs) + xp.random.gumbel(size=batch_probs.shape),
        axis=1).astype(np.int32, copy=False) 
开发者ID:chainer,项目名称:chainerrl,代码行数:14,代码来源:distribution.py

示例5: log_prob

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def log_prob(self, x):
        """Compute log p(x).

        Returns:
            chainer.Variable
        """
        raise NotImplementedError() 
开发者ID:chainer,项目名称:chainerrl,代码行数:9,代码来源:distribution.py

示例6: all_log_prob

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def all_log_prob(self):
        with chainer.force_backprop_mode():
            if self.min_prob > 0:
                return F.log(self.all_prob)
            else:
                return F.log_softmax(self.beta * self.logits) 
开发者ID:chainer,项目名称:chainerrl,代码行数:8,代码来源:distribution.py

示例7: _eltwise_gaussian_log_likelihood

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def _eltwise_gaussian_log_likelihood(x, mean, var, ln_var):
    # log N(x|mean,var)
    #   = -0.5log(2pi) - 0.5log(var) - (x - mean)**2 / (2*var)
    return -0.5 * np.log(2 * np.pi) - \
        0.5 * ln_var - \
        ((x - mean) ** 2) / (2 * var) 
开发者ID:chainer,项目名称:chainerrl,代码行数:8,代码来源:distribution.py

示例8: entropy

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def entropy(self):
        # Differential entropy of Gaussian is:
        #   0.5 * (log(2 * pi * var) + 1)
        #   = 0.5 * (log(2 * pi) + log var + 1)
        with chainer.force_backprop_mode():
            return 0.5 * self.mean.array.shape[1] * (np.log(2 * np.pi) + 1) + \
                0.5 * F.sum(self.ln_var, axis=1) 
开发者ID:chainer,项目名称:chainerrl,代码行数:9,代码来源:distribution.py

示例9: _tanh_forward_log_det_jacobian

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def _tanh_forward_log_det_jacobian(x):
    """Compute log|det(dy/dx)| except summation where y=tanh(x)."""
    # For the derivation of this formula, see:
    # https://github.com/tensorflow/probability/blob/master/tensorflow_probability/python/bijectors/tanh.py  # NOQA
    return 2. * (np.log(2.) - x - F.softplus(-2. * x)) 
开发者ID:chainer,项目名称:chainerrl,代码行数:7,代码来源:distribution.py

示例10: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def __init__(self, mean, var):
        self.mean = _wrap_by_variable(mean)
        self.var = _wrap_by_variable(var)
        self.ln_var = F.log(var) 
开发者ID:chainer,项目名称:chainerrl,代码行数:6,代码来源:distribution.py

示例11: initialize_embeddings

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def initialize_embeddings(self, src_emb=None, tgt_emb=None, no_unk_src=False, no_unk_tgt=False):
        if src_emb is None and tgt_emb is None:
            log.warn("called initialize_embeddings with 2 None args")
            
        if src_emb is not None:
            self.enc.initialize_embeddings(src_emb, no_unk=no_unk_src)
            
        if tgt_emb is not None:
            self.dec.initialize_embeddings(tgt_emb, no_unk=no_unk_tgt) 
开发者ID:fabiencro,项目名称:knmt,代码行数:11,代码来源:encoder_decoder.py

示例12: compute_logits

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def compute_logits(self, new_states, concatenated, attn):
        new_output_state = new_states[-1]

        all_concatenated = F.concat((concatenated, new_output_state))
        logits = self.decoder_chain.lin_o(self.decoder_chain.maxo(all_concatenated))

        if self.lexicon_probability_matrix is not None:
            current_mb_size = new_output_state.data.shape[0]
            assert self.mb_size is None or current_mb_size <= self.mb_size
            lexicon_probability_matrix = self.lexicon_probability_matrix[:current_mb_size]

            # Just making sure data shape is as expected
            attn_mb_size, max_source_length_attn = attn.data.shape
            assert attn_mb_size == current_mb_size
            lex_mb_size, max_source_length_lexicon, v_size_lexicon = lexicon_probability_matrix.shape
            assert max_source_length_lexicon == max_source_length_attn
            assert logits.data.shape == (current_mb_size, v_size_lexicon)

            if self.demux:
                assert lex_mb_size == 1
                weighted_lex_probs = F.reshape(
                    matmul_constant(attn, lexicon_probability_matrix.reshape(lexicon_probability_matrix.shape[1],
                                                                             lexicon_probability_matrix.shape[2])),
                    logits.data.shape)
            else:
                assert lex_mb_size == current_mb_size

    #                 weighted_lex_probs = F.reshape(
    #                         F.batch_matmul(attn, ConstantFunction(lexicon_probability_matrix)(), transa = True),
    #                                                logits.data.shape)

                weighted_lex_probs = F.reshape(
                    batch_matmul_constant(attn, lexicon_probability_matrix, transa=True),
                    logits.data.shape)

            logits += F.log(weighted_lex_probs + self.lex_epsilon)
        return logits 
开发者ID:fabiencro,项目名称:knmt,代码行数:39,代码来源:decoder_cells.py

示例13: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def forward(self, x):
        y1 = F.log(x)
        return y1 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:5,代码来源:MathMisc.py

示例14: main

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def main():
    np.random.seed(314)

    x = np.random.rand(6, 4).astype(np.float32)
    s_int = np.array(-10)
    s_float = np.array(10.0)

    testtools.generate_testcase(Sin(), [x], subname='sin')
    testtools.generate_testcase(Sinh(), [x], subname='sinh')
    testtools.generate_testcase(Sign(), [x], subname='sign')
    testtools.generate_testcase(Cos(), [x], subname='cos')
    testtools.generate_testcase(Cosh(), [x], subname='cosh')
    testtools.generate_testcase(Tan(), [x], subname='tan')
    testtools.generate_testcase(Tanh(), [x], subname='tanh')
    testtools.generate_testcase(ArcSin(), [x], subname='arcsin')
    testtools.generate_testcase(ArcCos(), [x], subname='arccos')
    testtools.generate_testcase(ArcTan(), [x], subname='arctan')
    testtools.generate_testcase(Exp(), [x], subname='exp')
    testtools.generate_testcase(Log(), [x], subname='log')
    testtools.generate_testcase(Clip(), [x], subname='clip')
    testtools.generate_testcase(ClipNp(), [x], subname='clip_np')
    testtools.generate_testcase(Abs(), [x], subname='abs')
    testtools.generate_testcase(AbsNp(), [x], subname='abs_np')
    testtools.generate_testcase(Sqrt(), [x], subname='sqrt')
    testtools.generate_testcase(Round(), [x], subname='round')
    testtools.generate_testcase(AbsBuiltin(), [x], subname='abs_builtin')
    testtools.generate_testcase(AbsBuiltin(), [s_float], subname='abs_builtin_scalar_float')
    testtools.generate_testcase(AbsBuiltin(), [s_int], subname='abs_builtin_scalar_int') 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:30,代码来源:MathMisc.py

示例15: listnet

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import log [as 别名]
def listnet(x, t):
    """
    The Top-1 approximated ListNet loss as in Cao et al (2006), Learning to
    Rank: From Pairwise Approach to Listwise Approach

    :param x: The activation of the previous layer
    :param t: The target labels
    :return: The loss
    """

    # ListNet top-1 reduces to a softmax and simple cross entropy
    st = F.softmax(t, axis=0)
    sx = F.softmax(x, axis=0)
    return -F.mean(st * F.log(sx)) 
开发者ID:rjagerman,项目名称:shoelace,代码行数:16,代码来源:listwise.py


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