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


Python ndarray.norm方法代碼示例

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


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

示例1: create_neg

# 需要導入模塊: from mxnet import ndarray [as 別名]
# 或者: from mxnet.ndarray import norm [as 別名]
def create_neg(self, neg_head):
        gamma = self.gamma
        if neg_head:
            def fn(heads, relations, tails, num_chunks, chunk_size, neg_sample_size):
                relations = relations.reshape(num_chunks, -1, self.relation_dim)
                tails = tails - relations
                tails = tails.reshape(num_chunks, -1, 1, self.relation_dim)
                score = heads - tails
                return gamma - nd.norm(score, ord=1, axis=-1)
            return fn
        else:
            def fn(heads, relations, tails, num_chunks, chunk_size, neg_sample_size):
                relations = relations.reshape(num_chunks, -1, self.relation_dim)
                heads = heads - relations
                heads = heads.reshape(num_chunks, -1, 1, self.relation_dim)
                score = heads - tails
                return gamma - nd.norm(score, ord=1, axis=-1)
            return fn 
開發者ID:dmlc,項目名稱:dgl,代碼行數:20,代碼來源:score_fun.py

示例2: calc_potential

# 需要導入模塊: from mxnet import ndarray [as 別名]
# 或者: from mxnet.ndarray import norm [as 別名]
def calc_potential(exe, params, label_name, noise_precision, prior_precision):
    exe.copy_params_from(params)
    exe.forward(is_train=False)
    ret = 0.0
    ret += (nd.norm(
        exe.outputs[0] - exe.arg_dict[label_name]).asscalar() ** 2) / 2.0 * noise_precision
    for v in params.values():
        ret += (nd.norm(v).asscalar() ** 2) / 2.0 * prior_precision
    return ret 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:11,代碼來源:algos.py

示例3: norm_clipping

# 需要導入模塊: from mxnet import ndarray [as 別名]
# 或者: from mxnet.ndarray import norm [as 別名]
def norm_clipping(params_grad, threshold):
    assert isinstance(params_grad, dict)
    norm_val = numpy.sqrt(sum([nd.norm(grad).asnumpy()[0]**2 for grad in params_grad.values()]))
    # print('grad norm: %g' % norm_val)
    ratio = 1.0
    if norm_val > threshold:
        ratio = threshold / norm_val
        for grad in params_grad.values():
            grad *= ratio
    return norm_val 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:12,代碼來源:utils.py

示例4: batched_l2_dist

# 需要導入模塊: from mxnet import ndarray [as 別名]
# 或者: from mxnet.ndarray import norm [as 別名]
def batched_l2_dist(a, b):
    a_squared = nd.power(nd.norm(a, axis=-1), 2)
    b_squared = nd.power(nd.norm(b, axis=-1), 2)

    squared_res = nd.add(nd.linalg_gemm(
        a, nd.transpose(b, axes=(0, 2, 1)), nd.broadcast_axes(nd.expand_dims(b_squared, axis=-2), axis=1, size=a.shape[1]), alpha=-2
    ), nd.expand_dims(a_squared, axis=-1))
    res = nd.sqrt(nd.clip(squared_res, 1e-30, np.finfo(np.float32).max))
    return res 
開發者ID:dmlc,項目名稱:dgl,代碼行數:11,代碼來源:score_fun.py

示例5: batched_l1_dist

# 需要導入模塊: from mxnet import ndarray [as 別名]
# 或者: from mxnet.ndarray import norm [as 別名]
def batched_l1_dist(a, b):
    a = nd.expand_dims(a, axis=-2)
    b = nd.expand_dims(b, axis=-3)
    res = nd.norm(a - b, ord=1, axis=-1)
    return res 
開發者ID:dmlc,項目名稱:dgl,代碼行數:7,代碼來源:score_fun.py

示例6: edge_func

# 需要導入模塊: from mxnet import ndarray [as 別名]
# 或者: from mxnet.ndarray import norm [as 別名]
def edge_func(self, edges):
        head = edges.src['emb']
        tail = edges.dst['emb']
        rel = edges.data['emb']
        score = head + rel - tail
        return {'score': self.gamma - nd.norm(score, ord=self.dist_ord, axis=-1)} 
開發者ID:dmlc,項目名稱:dgl,代碼行數:8,代碼來源:score_fun.py


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