|
1 | 1 | /**
|
2 |
| - * Copyright 2020-2023 by XGBoost contributors |
| 2 | + * Copyright 2020-2025, XGBoost contributors |
3 | 3 | */
|
4 | 4 | #include "rank_metric.h"
|
5 | 5 |
|
|
10 | 10 | #include <array> // for array
|
11 | 11 | #include <cmath> // for log, sqrt
|
12 | 12 | #include <functional> // for less, greater
|
13 |
| -#include <limits> // for numeric_limits |
14 | 13 | #include <map> // for operator!=, _Rb_tree_const_iterator
|
15 | 14 | #include <memory> // for allocator, unique_ptr, shared_ptr, __shared_...
|
16 | 15 | #include <numeric> // for accumulate
|
|
22 | 21 | #include "../collective/aggregator.h" // for ApplyWithLabels
|
23 | 22 | #include "../common/algorithm.h" // for ArgSort, Sort
|
24 | 23 | #include "../common/linalg_op.h" // for cbegin, cend
|
25 |
| -#include "../common/math.h" // for CmpFirst |
26 | 24 | #include "../common/optional_weight.h" // for OptionalWeights, MakeOptionalWeights
|
27 | 25 | #include "dmlc/common.h" // for OMPException
|
28 | 26 | #include "metric_common.h" // for MetricNoCache, GPUMetric, PackedReduceResult
|
@@ -250,10 +248,6 @@ class EvalRankWithCache : public Metric {
|
250 | 248 | }
|
251 | 249 | param_.UpdateAllowUnknown(Args{});
|
252 | 250 | }
|
253 |
| - void Configure(Args const&) override { |
254 |
| - // do not configure, otherwise the ndcg param will be forced into the same as the one in |
255 |
| - // objective. |
256 |
| - } |
257 | 251 | void LoadConfig(Json const& in) override {
|
258 | 252 | if (IsA<Null>(in)) {
|
259 | 253 | return;
|
@@ -365,6 +359,18 @@ class EvalNDCG : public EvalRankWithCache<ltr::NDCGCache> {
|
365 | 359 | public:
|
366 | 360 | using EvalRankWithCache::EvalRankWithCache;
|
367 | 361 |
|
| 362 | + void Configure(Args const& args) override { |
| 363 | + // do not configure, otherwise the ndcg param like top-k will be forced into the same |
| 364 | + // as the one in objective. The metric has its own syntax for parameter. |
| 365 | + for (auto const& [key, value] : args) { |
| 366 | + // Make a special case for the exp gain parameter, which is not exposed in the |
| 367 | + // metric configuration syntax. |
| 368 | + if (key == "ndcg_exp_gain") { |
| 369 | + this->param_.UpdateAllowUnknown(Args{{key, value}}); |
| 370 | + } |
| 371 | + } |
| 372 | + } |
| 373 | + |
368 | 374 | double Eval(HostDeviceVector<float> const& preds, MetaInfo const& info,
|
369 | 375 | std::shared_ptr<ltr::NDCGCache> p_cache) override {
|
370 | 376 | if (ctx_->IsCUDA()) {
|
|
0 commit comments