Medial Code Documentation
Loading...
Searching...
No Matches
metric_common.h
Go to the documentation of this file.
1
5#ifndef XGBOOST_METRIC_METRIC_COMMON_H_
6#define XGBOOST_METRIC_METRIC_COMMON_H_
7
8#include <limits>
9#include <memory> // shared_ptr
10#include <string>
11
12#include "../collective/aggregator.h"
13#include "../collective/communicator-inl.h"
14#include "../common/common.h"
15#include "xgboost/metric.h"
16
17namespace xgboost {
18struct Context;
19// Metric that doesn't need to cache anything based on input data.
20class MetricNoCache : public Metric {
21 public:
22 virtual double Eval(HostDeviceVector<float> const &predts, MetaInfo const &info) = 0;
23
24 double Evaluate(HostDeviceVector<float> const &predts, std::shared_ptr<DMatrix> p_fmat) final {
25 double result{0.0};
26 auto const &info = p_fmat->Info();
27 collective::ApplyWithLabels(info, &result, sizeof(double),
28 [&] { result = this->Eval(predts, info); });
29 return result;
30 }
31};
32
33namespace metric {
34// Ranking config to be used on device and host
36 public:
37 // Parsed from metric name, the top-n number of instances within a group after
38 // ranking to use for evaluation.
39 unsigned topn{std::numeric_limits<unsigned>::max()};
40 std::string name;
41 bool minus{false};
42};
43
45 double residue_sum_{0};
46 double weights_sum_{0};
47
48 public:
50 XGBOOST_DEVICE PackedReduceResult(double residue, double weight)
51 : residue_sum_{residue}, weights_sum_{weight} {}
52
54 PackedReduceResult operator+(PackedReduceResult const &other) const {
55 return PackedReduceResult{residue_sum_ + other.residue_sum_, weights_sum_ + other.weights_sum_};
56 }
57 PackedReduceResult &operator+=(PackedReduceResult const &other) {
58 this->residue_sum_ += other.residue_sum_;
59 this->weights_sum_ += other.weights_sum_;
60 return *this;
61 }
62 [[nodiscard]] double Residue() const { return residue_sum_; }
63 [[nodiscard]] double Weights() const { return weights_sum_; }
64};
65
66} // namespace metric
67} // namespace xgboost
68
69#endif // XGBOOST_METRIC_METRIC_COMMON_H_
Definition host_device_vector.h:87
Meta information about dataset, always sit in memory.
Definition data.h:48
Definition metric_common.h:20
double Evaluate(HostDeviceVector< float > const &predts, std::shared_ptr< DMatrix > p_fmat) final
Evaluate a metric with DMatrix as input.
Definition metric_common.h:24
interface of evaluation metric used to evaluate model performance. This has nothing to do with traini...
Definition metric.h:29
Definition metric_common.h:44
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition base.h:64
void ApplyWithLabels(MetaInfo const &info, void *buffer, size_t size, Function &&function)
Apply the given function where the labels are.
Definition aggregator.h:36
namespace of xgboost
Definition base.h:90
Definition metric_common.h:35
Copyright 2014-2023 by XGBoost Contributors.