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


Python bottleneck.argpartsort方法代码示例

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


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

示例1: recall_at_multiple_ks_batch

# 需要导入模块: import bottleneck [as 别名]
# 或者: from bottleneck import argpartsort [as 别名]
def recall_at_multiple_ks_batch(train_data, heldout_data, Et, Eb, user_idx,
                                topks, vad_data):
    batch_users = user_idx.stop - user_idx.start

    X_pred = rec_eval._make_prediction(train_data, Et, Eb, user_idx,
                                       batch_users, vad_data=vad_data)
    recalls = np.empty((len(topks), batch_users))
    for i, k in enumerate(topks):
        idx = bn.argpartsort(-X_pred, k, axis=1)
        X_pred_binary = np.zeros_like(X_pred, dtype=bool)
        X_pred_binary[np.arange(batch_users)[:, np.newaxis], idx[:, :k]] = True

        X_true_binary = (heldout_data[user_idx] > 0).toarray()
        tmp = (np.logical_and(X_true_binary,
                              X_pred_binary).sum(axis=1)).astype(np.float32)
        recalls[i] = tmp / X_true_binary.sum(axis=1)
    return recalls 
开发者ID:dawenl,项目名称:content_wmf,代码行数:19,代码来源:evaluation.py

示例2: precision_at_k_batch

# 需要导入模块: import bottleneck [as 别名]
# 或者: from bottleneck import argpartsort [as 别名]
def precision_at_k_batch(train_data, heldout_data, Et, Eb, user_idx,
                         k=20, normalize=True, vad_data=None):
    batch_users = user_idx.stop - user_idx.start

    X_pred = _make_prediction(train_data, Et, Eb, user_idx,
                              batch_users, vad_data=vad_data)
    idx = bn.argpartsort(-X_pred, k, axis=1)
    X_pred_binary = np.zeros_like(X_pred, dtype=bool)
    X_pred_binary[np.tile(np.arange(batch_users), (k, 1)).T, idx[:, :k]] = True

    X_true_binary = (heldout_data[user_idx] > 0).toarray()
    tmp = (np.logical_and(X_true_binary, X_pred_binary).sum(axis=1)).astype(
        np.float32)

    if normalize:
        precision = tmp / np.minimum(k, X_true_binary.sum(axis=1))
    else:
        precision = tmp / k
    return precision 
开发者ID:dawenl,项目名称:content_wmf,代码行数:21,代码来源:rec_eval.py

示例3: recall_at_k_batch

# 需要导入模块: import bottleneck [as 别名]
# 或者: from bottleneck import argpartsort [as 别名]
def recall_at_k_batch(train_data, heldout_data, Et, Eb, user_idx,
                      k=20, vad_data=None):
    batch_users = user_idx.stop - user_idx.start

    X_pred = _make_prediction(train_data, Et, Eb, user_idx,
                              batch_users, vad_data=vad_data)
    idx = bn.argpartsort(-X_pred, k, axis=1)
    X_pred_binary = np.zeros_like(X_pred, dtype=bool)
    X_pred_binary[np.tile(np.arange(batch_users), (k, 1)).T, idx[:, :k]] = True

    X_true_binary = (heldout_data[user_idx] > 0).toarray()
    tmp = (np.logical_and(X_true_binary, X_pred_binary).sum(axis=1)).astype(
        np.float32)

    recall = tmp / X_true_binary.sum(axis=1)
    return recall 
开发者ID:dawenl,项目名称:content_wmf,代码行数:18,代码来源:rec_eval.py

示例4: argsort

# 需要导入模块: import bottleneck [as 别名]
# 或者: from bottleneck import argpartsort [as 别名]
def argsort(x, topn=None):
        """Return indices of the `topn` greatest elements in numpy array `x`, in order."""
        if topn is None:
            topn = x.size
        if topn <= 0:
            return []
        if topn >= x.size:
            return numpy.argsort(x)[::-1]
        biggest = bottleneck.argpartsort(x, x.size - topn)[-topn:]
        # the indices in `biggest` are not sorted by magnitude => sort & return
        return biggest.take(numpy.argsort(x.take(biggest))[::-1]) 
开发者ID:largelymfs,项目名称:topical_word_embeddings,代码行数:13,代码来源:matutils.py

示例5: argpartition

# 需要导入模块: import bottleneck [as 别名]
# 或者: from bottleneck import argpartsort [as 别名]
def argpartition(a, kth, axis=-1):
            return bottleneck.argpartsort(a, kth, axis) 
开发者ID:julianser,项目名称:hred-latent-piecewise,代码行数:4,代码来源:numpy_compat.py

示例6: batch_gensample_model

# 需要导入模块: import bottleneck [as 别名]
# 或者: from bottleneck import argpartsort [as 别名]
def batch_gensample_model(in_queue, out_queue, f_init, f_next, k, gpulock, n_resample, minlen, maxlen, bleulowerbound = 0.25):
    while True:
        req = in_queue.get()
        if req is None:
            break
        x, x_mask, tosample_seqs_x, tosample_seqs_y, fixed_seqs_x, fixed_seqs_y = preprocess_data(req[1], req[2], minlen, maxlen)
        XX, YY = fixed_seqs_x, fixed_seqs_y
        assert len(XX) == len(YY), 'len(XX) NE len(YY)'
        WW = [1.] * len(XX)
        resample_counter = 0
        if x is not None:
            samples, scores = beam_search_sample(f_init, f_next, x, x_mask, gpulock, k, maxlen)
            resample_size = len(tosample_seqs_x)
            for idx in xrange(resample_size):
                bleu_scores = []
                str_tt = [str(y) for y in tosample_seqs_y]
                for ii in xrange(len(samples[idx])):
                    str_ss = [str(x) for x in samples[idx][ii]]
                    bleu_scores.append( nt.bleu([str_tt], str_ss, [0.25] * 4) )
                sorted_id = bottleneck.argpartsort(-numpy.array(bleu_scores, dtype = 'float32'), n = n_resample)[:n_resample]

                start_idx = 0

                if bleu_scores[sorted_id[0]] < 0.999:
                    XX.append(tosample_seqs_x[idx])
                    YY.append(tosample_seqs_y[idx])
                    WW.append(1.)
                    start_idx = 1

                for ii in xrange(start_idx, n_resample):
                    if bleu_scores[sorted_id[ii]] < bleulowerbound:
                        break
                    XX.append(tosample_seqs_x[idx])
                    YY.append(samples[idx][sorted_id[ii]])
                    WW.append(bleu_scores[sorted_id[ii]])
                    resample_counter += 1

        out_queue.put((req[0], XX, YY, WW, resample_counter))
    out_queue.put(None)
    print 'Process %d Finish One' % os.getpid()
    return 
开发者ID:microsoft,项目名称:DualLearning,代码行数:43,代码来源:Util_basic.py


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