4#ifndef XGBOOST_METRIC_AUC_H_
5#define XGBOOST_METRIC_AUC_H_
13#include "../collective/communicator-inl.h"
14#include "../common/common.h"
15#include "../common/threading_utils.h"
19#include "xgboost/span.h"
26XGBOOST_DEVICE inline double TrapezoidArea(
double x0,
double x1,
double y0,
double y1) {
27 return std::abs(x0 - x1) * (y0 + y1) * 0.5f;
32std::tuple<double, double, double> GPUBinaryROCAUC(common::Span<float const> predts,
33 MetaInfo
const &info, std::int32_t device,
34 std::shared_ptr<DeviceAUCCache> *p_cache);
36double GPUMultiClassROCAUC(Context
const *ctx, common::Span<float const> predts,
37 MetaInfo
const &info, std::shared_ptr<DeviceAUCCache> *p_cache,
38 std::size_t n_classes);
40std::pair<double, std::uint32_t> GPURankingAUC(Context
const *ctx, common::Span<float const> predts,
42 std::shared_ptr<DeviceAUCCache> *cache);
47std::tuple<double, double, double> GPUBinaryPRAUC(common::Span<float const> predts,
48 MetaInfo
const &info, std::int32_t device,
49 std::shared_ptr<DeviceAUCCache> *p_cache);
51double GPUMultiClassPRAUC(Context
const *ctx, common::Span<float const> predts,
52 MetaInfo
const &info, std::shared_ptr<DeviceAUCCache> *p_cache,
53 std::size_t n_classes);
55std::pair<double, std::uint32_t> GPURankingPRAUC(Context
const *ctx,
56 common::Span<float const> predts,
58 std::shared_ptr<DeviceAUCCache> *cache);
61XGBOOST_DEVICE inline double CalcH(
double fp_a,
double fp_b,
double tp_a,
63 return (fp_b - fp_a) / (tp_b - tp_a);
66XGBOOST_DEVICE inline double CalcB(
double fp_a,
double h,
double tp_a,
double total_pos) {
67 return (fp_a - h * tp_a) / total_pos;
72XGBOOST_DEVICE inline double CalcDeltaPRAUC(
double fp_prev,
double fp,
73 double tp_prev,
double tp,
75 double pr_prev = tp_prev / total_pos;
76 double pr = tp / total_pos;
78 double h{0}, a{0}, b{0};
84 h = detail::CalcH(fp_prev, fp, tp_prev, tp);
86 b = detail::CalcB(fp_prev, h, tp_prev, total_pos);
91 area = (pr - pr_prev -
92 b / a * (std::log(a * pr + b) - std::log(a * pr_prev + b))) /
95 area = (pr - pr_prev) / a;
101inline void InvalidGroupAUC() {
102 LOG(INFO) <<
"Invalid group with less than 3 samples is found on worker "
104 <<
"least 2 pairs of samples.";
108 XGBOOST_DEVICE bool operator()(
float y) {
return y < 0.0f || y > 1.0f; }
111inline void InvalidLabels() {
112 LOG(FATAL) <<
"PR-AUC supports only binary relevance for learning to rank.";
Copyright 2015-2023 by XGBoost Contributors.
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition base.h:64
Copyright 2015-2023 by XGBoost Contributors.
detail namespace with internal helper functions
Definition json.hpp:249
int GetRank()
Get rank of current process.
Definition communicator-inl.h:76
namespace of xgboost
Definition base.h:90
Copyright 2014-2023 by XGBoost Contributors.