f4beaac559e00a3676d942dc7e8fea69efc01cfe,catalyst/metrics/hitrate.py,,hitrate,#Any#Any#Any#,8

Before Change



    _, indices_for_sort = outputs.sort(descending=True, dim=-1)
    true_sorted_by_preds = torch.gather(
        targets, dim=-1, index=indices_for_sort
    )
    true_sorted_by_pred_shrink = true_sorted_by_preds[:, :k]
    hits = torch.sum(true_sorted_by_pred_shrink, dim=1) / k
    return hits


__all__ = ["hitrate"]

After Change


    targets_sort_by_outputs = process_recsys_components(outputs, targets)
    for k in topk:
        k = min(outputs.size(1), k)
        hits_score = torch.sum(targets_sort_by_outputs[:, :k], dim=1) / k
        results.append(torch.mean(hits_score))

    return results
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: catalyst-team/catalyst
Commit Name: f4beaac559e00a3676d942dc7e8fea69efc01cfe
Time: 2020-11-30
Author: raveforlive@gmail.com
File Name: catalyst/metrics/hitrate.py
Class Name:
Method Name: hitrate


Project Name: NifTK/NiftyNet
Commit Name: 25508c13627f06510f3cab96d742360b0187640a
Time: 2019-06-29
Author: carole.sudre@kcl.ac.uk
File Name: tests/windows_aggregator_grid_v2_test.py
Class Name: GridSamplesAggregatorTest
Method Name: test_init_2d_mo


Project Name: NifTK/NiftyNet
Commit Name: 16120dfa28abb4ee21d6beb04bf235633e413bfa
Time: 2019-06-08
Author: carole.sudre@kcl.ac.uk
File Name: tests/windows_aggregator_grid_v2_test.py
Class Name: GridSamplesAggregatorTest
Method Name: test_init_2d_mo