xgboost
metric.h
前往此文件的文档。
1 
7 #ifndef XGBOOST_METRIC_H_
8 #define XGBOOST_METRIC_H_
9 
10 #include <dmlc/registry.h>
11 #include <xgboost/base.h>
12 #include <xgboost/data.h>
14 #include <xgboost/model.h>
15 
16 #include <functional>
17 #include <memory> // shared_ptr
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 namespace xgboost {
23 struct Context;
24 
29 class Metric : public Configurable {
30  protected
31  Context const* ctx_{nullptr};
32 
33  public
38  virtual void Configure(
39  const std::vector<std::pair<std::string, std::string> >&) {}
46  void LoadConfig(Json const&) override {}
53  void SaveConfig(Json* p_out) const override {
54  auto& out = *p_out;
55  out["name"] = String(this->Name());
56  }
57 
64  virtual double Evaluate(HostDeviceVector<bst_float> const& preds,
65  std::shared_ptr<DMatrix> p_fmat) = 0;
66 
68  virtual const char* Name() const = 0;
70  ~Metric() override = default;
79  static Metric* Create(const std::string& name, Context const* ctx);
80 };
81 
87 struct MetricReg
88  : public dmlc::FunctionRegEntryBase<MetricReg,
89  std::function<Metric* (const char*)> > {
90 };
91 
105 #define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
106  ::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
107  ::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
108 } // namespace xgboost
109 #endif // XGBOOST_METRIC_H_
为 xgboost 定义配置宏和基本类型。
表示 JSON 格式的数据结构。
定义: json.h:378
用于评估模型性能的评估指标接口。这与训练无关...
定义: metric.h:29
void SaveConfig(Json *p_out) const override
将配置保存到 JSON 对象。默认情况下,指标没有内部配置;覆盖此函数...
定义: metric.h:53
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &)
使用指定的参数配置 Metric。
定义: metric.h:38
void LoadConfig(Json const &) override
从 JSON 对象加载配置。默认情况下,指标没有内部配置;覆盖此函数...
定义: metric.h:46
virtual const char * Name() const =0
static Metric * Create(const std::string &name, Context const *ctx)
根据名称创建一个指标。
Context const * ctx_
定义: metric.h:31
~Metric() override=default
虚析构函数
virtual double Evaluate(HostDeviceVector< bst_float > const &preds, std::shared_ptr< DMatrix > p_fmat)=0
以 DMatrix 作为输入评估一个指标。
xgboost 的输入数据结构。
设备和主机向量抽象层。
定义 XGBoost 中不同组件的抽象接口。
多目标树的核心数据结构。
定义: base.h:89
JsonString String
定义: json.h:609
定义: model.h:31
XGBoost 的运行时上下文。包含线程和设备等信息。
定义: context.h:133
Metric 工厂函数的注册表条目。附加参数 const char* param 提供值...
定义: metric.h:89