Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused DCGCalculator::CalDCGAtK() #4650

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions include/LightGBM/metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ class DCGCalculator {
*/
static void Init(const std::vector<double>& label_gain);

/*!
* \brief Calculate the DCG score at position k
* \param k The position to evaluate
* \param label Pointer of label
* \param score Pointer of score
* \param num_data Number of data
* \return The DCG score
*/
static double CalDCGAtK(data_size_t k, const label_t* label,
const double* score, data_size_t num_data);

/*!
* \brief Calculate the DCG score at multi position
* \param ks The positions to evaluate
Expand Down
21 changes: 0 additions & 21 deletions src/metric/dcg_calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,6 @@ void DCGCalculator::CalMaxDCG(const std::vector<data_size_t>& ks,
}
}


double DCGCalculator::CalDCGAtK(data_size_t k, const label_t* label,
const double* score, data_size_t num_data) {
// get sorted indices by score
std::vector<data_size_t> sorted_idx(num_data);
for (data_size_t i = 0; i < num_data; ++i) {
sorted_idx[i] = i;
}
std::stable_sort(sorted_idx.begin(), sorted_idx.end(),
[score](data_size_t a, data_size_t b) {return score[a] > score[b]; });

if (k > num_data) { k = num_data; }
double dcg = 0.0f;
// calculate dcg
for (data_size_t i = 0; i < k; ++i) {
data_size_t idx = sorted_idx[i];
dcg += label_gain_[static_cast<int>(label[idx])] * discount_[i];
}
return dcg;
}

void DCGCalculator::CalDCG(const std::vector<data_size_t>& ks, const label_t* label,
const double * score, data_size_t num_data, std::vector<double>* out) {
// get sorted indices by score
Expand Down