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


Python functions.sqrt方法代码示例

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


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

示例1: feature_vector_normalization

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def feature_vector_normalization(x, eps=1e-8):
    # x: (B, C, H, W)
    alpha = 1.0 / F.sqrt(F.mean(x * x, axis=1, keepdims=True) + eps)
    return F.broadcast_to(alpha, x.data.shape) * x 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:6,代码来源:pggan.py

示例2: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def __init__(self, in_ch, out_ch, ksize, stride, pad, nobias=False, gain=np.sqrt(2), lrmul=1):
        w = chainer.initializers.Normal(1.0/lrmul)  # equalized learning rate
        self.inv_c = gain * np.sqrt(1.0 / (in_ch * ksize ** 2))
        self.inv_c = self.inv_c * lrmul
        super(EqualizedConv2d, self).__init__()
        with self.init_scope():
            self.c = L.Convolution2D(in_ch, out_ch, ksize, stride, pad, initialW=w, nobias=nobias) 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:9,代码来源:pggan.py

示例3: minibatch_std

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def minibatch_std(x):
    m = F.mean(x, axis=0, keepdims=True)
    v = F.mean((x - F.broadcast_to(m, x.shape)) * (x - F.broadcast_to(m, x.shape)), axis=0, keepdims=True)
    std = F.mean(F.sqrt(v + 1e-8), keepdims=True)
    std = F.broadcast_to(std, (x.shape[0], 1, x.shape[2], x.shape[3]))
    return F.concat([x, std], axis=1) 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:8,代码来源:pggan.py

示例4: forward

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

示例5: main

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [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

示例6: rsqrt

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def rsqrt(x, dtype):
    return numpy.reciprocal(numpy.sqrt(x, dtype=dtype), dtype=dtype) 
开发者ID:chainer,项目名称:chainer,代码行数:4,代码来源:test_sqrt.py

示例7: get_bbox_side_lengths

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def get_bbox_side_lengths(self, grids):
        x0, x1, x2, y0, y1, y2 = self.get_corners(grids)

        width = F.sqrt(
            F.square(x1 - x0) + F.square(y1 - y0)
        )

        height = F.sqrt(
            F.square(x2 - x0) + F.square(y2 - y0)
        )
        return width, height 
开发者ID:Bartzi,项目名称:see,代码行数:13,代码来源:loss_metrics.py

示例8: get_normalized_vector

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def get_normalized_vector(d, xp=None, shape=None):
    if shape is None:
        shape = tuple(range(1, len(d.shape)))
    d_norm = d
    if xp is not None:
        d_norm = d / (1e-12 + xp.max(xp.abs(d), shape, keepdims=True))
        d_norm = d_norm / xp.sqrt(1e-6 + xp.sum(d_norm ** 2, shape, keepdims=True))
    else:
        d_term = 1e-12 + F.max(F.absolute(d), shape, keepdims=True)
        d_norm = d / F.broadcast_to(d_term, d.shape)
        d_term = F.sqrt(1e-6 + F.sum(d ** 2, shape, keepdims=True))
        d_norm = d / F.broadcast_to(d_term, d.shape)
    return d_norm 
开发者ID:chainer,项目名称:models,代码行数:15,代码来源:net.py

示例9: get_normalized_vector

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def get_normalized_vector(d, xp=None):
    shape = tuple(range(1, len(d.shape)))
    if xp is not None:
        d /= (1e-12 + xp.max(xp.abs(d), shape, keepdims=True))
        d /= xp.sqrt(1e-6 + xp.sum(d ** 2, shape, keepdims=True))
    else:
        d_term = 1e-12 + F.max(F.absolute(d), shape, keepdims=True)
        d /= F.broadcast_to(d_term, d.shape)
        d_term = F.sqrt(1e-6 + F.sum(d ** 2, shape, keepdims=True))
        d /= F.broadcast_to(d_term, d.shape)
    return d 
开发者ID:chainer,项目名称:models,代码行数:13,代码来源:lm_nets.py

示例10: norm_by_freq

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def norm_by_freq(self, freq):
        word_embs = self.W
        mean = F.sum(freq * word_embs, axis=0, keepdims=True)
        mean = F.broadcast_to(mean, word_embs.shape)
        var = F.sum(freq * ((word_embs - mean) ** 2), axis=0, keepdims=True)
        var = F.broadcast_to(var, word_embs.shape)

        stddev = F.sqrt(1e-6 + var)
        word_embs_norm = (word_embs - mean) / stddev
        return word_embs_norm 
开发者ID:chainer,项目名称:models,代码行数:12,代码来源:lm_nets.py

示例11: negative_log_likelihood

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def negative_log_likelihood(self, x, y):
        pi, mu, log_var = self.get_gaussian_params(x)

        # Likelihood over different Gaussians
        y = F.tile(y[:, None, :], (1, self.gaussian_mixtures, 1))
        pi = F.tile(F.expand_dims(pi, 2), (1, 1, self.input_dim))
        
        squared_sigma = F.exp(log_var)
        sigma = F.sqrt(squared_sigma)
        prob = F.sum(pi * distributions.Normal(mu, sigma).prob(y), axis=1)
        
        negative_log_likelihood = -F.log(prob)
        return F.mean(negative_log_likelihood) 
开发者ID:chainer,项目名称:models,代码行数:15,代码来源:mdn.py

示例12: gelu

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def gelu(x):
    return 0.5 * x * (1 + F.tanh(math.sqrt(2 / math.pi)
                                 * (x + 0.044715 * (x ** 3)))) 
开发者ID:chainer,项目名称:models,代码行数:5,代码来源:model_py.py

示例13: _attn

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def _attn(self, q, k, v):
        w = F.batch_matmul(q.reshape(-1, *q.shape[-2:]),
                           k.reshape(-1, *k.shape[-2:]))
        if self.scale:
            w = w / math.sqrt(v.shape[-1])
        # TF implem method: mask_attn_weights
        w = w * self.b.array[0] + -1e9 * (1 - self.b.array[0])
        w = F.softmax(w, axis=2)
        w = self.attn_dropout(w)
        return F.batch_matmul(w, v.reshape(-1, *v.shape[-2:]))\
                .reshape(v.shape[0], v.shape[1], v.shape[2], -1) 
开发者ID:chainer,项目名称:models,代码行数:13,代码来源:model_py.py

示例14: feature_vector_normalization

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def feature_vector_normalization(x, eps=1e-8):
    # x: (B, C, H, W)
    alpha = 1.0 / F.sqrt(F.mean(x*x, axis=1, keepdims=True) + eps)
    return F.broadcast_to(alpha, x.data.shape) * x 
开发者ID:pfnet-research,项目名称:chainer-gan-lib,代码行数:6,代码来源:net.py

示例15: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import sqrt [as 别名]
def __init__(self, in_ch, out_ch, ksize, stride, pad):
        w = chainer.initializers.Normal(1.0) # equalized learning rate
        self.inv_c = np.sqrt(2.0/(in_ch*ksize**2))
        super(EqualizedConv2d, self).__init__()
        with self.init_scope():
            self.c = L.Convolution2D(in_ch, out_ch, ksize, stride, pad, initialW=w) 
开发者ID:pfnet-research,项目名称:chainer-gan-lib,代码行数:8,代码来源:net.py


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