Medial Code Documentation
Loading...
Searching...
No Matches
test_lambdarank_obj.h
1
4#ifndef XGBOOST_OBJECTIVE_TEST_LAMBDARANK_OBJ_H_
5#define XGBOOST_OBJECTIVE_TEST_LAMBDARANK_OBJ_H_
6#include <gtest/gtest.h>
7#include <xgboost/data.h> // for MetaInfo
8#include <xgboost/host_device_vector.h> // for HostDeviceVector
9#include <xgboost/linalg.h> // for All
10#include <xgboost/objective.h> // for ObjFunction
11
12#include <memory> // for shared_ptr, make_shared
13#include <numeric> // for iota
14#include <vector> // for vector
15
16#include "../../../src/common/ranking_utils.h" // for LambdaRankParam, MAPCache
17#include "../../../src/objective/lambdarank_obj.h" // for MAPStat
18#include "../helpers.h" // for EmptyDMatrix
19
20namespace xgboost::obj {
21void TestMAPStat(Context const* ctx);
22
23inline void TestNDCGJsonIO(Context const* ctx) {
24 std::unique_ptr<xgboost::ObjFunction> obj{ObjFunction::Create("rank:ndcg", ctx)};
25
26 obj->Configure(Args{});
27 Json j_obj{Object()};
28 obj->SaveConfig(&j_obj);
29
30 ASSERT_EQ(get<String>(j_obj["name"]), "rank:ndcg");
31 auto const& j_param = j_obj["lambdarank_param"];
32
33 ASSERT_EQ(get<String>(j_param["ndcg_exp_gain"]), "1");
34 ASSERT_EQ(get<String>(j_param["lambdarank_num_pair_per_sample"]),
35 std::to_string(ltr::LambdaRankParam::NotSet()));
36}
37
38void TestNDCGGPair(Context const* ctx);
39
40void TestUnbiasedNDCG(Context const* ctx);
41
42void TestMAPGPair(Context const* ctx);
43
47void InitMakePairTest(Context const* ctx, MetaInfo* out_info, HostDeviceVector<float>* out_predt);
48} // namespace xgboost::obj
49#endif // XGBOOST_OBJECTIVE_TEST_LAMBDARANK_OBJ_H_
static ObjFunction * Create(const std::string &name, Context const *ctx)
Create an objective function according to name.
Definition objective.cc:20
A device-and-host vector abstraction layer.
Copyright 2015-2023 by XGBoost Contributors.
Copyright 2021-2023 by XGBoost Contributors.
Copyright 2022-2023 by XGBoost contributors.
Definition custom_obj.cc:13
void InitMakePairTest(Context const *ctx, MetaInfo *out_info, HostDeviceVector< float > *out_predt)
Initialize test data for make pair tests.
Definition test_lambdarank_obj.cc:148
Copyright 2014-2023 by XGBoost Contributors.