MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / CalMaxDCGAtK

Method CalMaxDCGAtK

src/metric/dcg_calculator.cpp:53–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53double DCGCalculator::CalMaxDCGAtK(data_size_t k, const label_t* label, data_size_t num_data) {
54 double ret = 0.0f;
55 // counts for all labels
56 std::vector<data_size_t> label_cnt(label_gain_.size(), 0);
57 for (data_size_t i = 0; i < num_data; ++i) {
58 ++label_cnt[static_cast<int>(label[i])];
59 }
60 int top_label = static_cast<int>(label_gain_.size()) - 1;
61
62 if (k > num_data) { k = num_data; }
63 // start from top label, and accumulate DCG
64 for (data_size_t j = 0; j < k; ++j) {
65 while (top_label > 0 && label_cnt[top_label] <= 0) {
66 top_label -= 1;
67 }
68 if (top_label < 0) {
69 break;
70 }
71 ret += discount_[j] * label_gain_[top_label];
72 label_cnt[top_label] -= 1;
73 }
74 return ret;
75}
76
77void DCGCalculator::CalMaxDCG(const std::vector<data_size_t>& ks,
78 const label_t* label,

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected