xgboost
tree_updater.h
前往此文件文档。
1 
8 #ifndef XGBOOST_TREE_UPDATER_H_
9 #define XGBOOST_TREE_UPDATER_H_
10 
11 #include <dmlc/registry.h>
12 #include <xgboost/base.h> // 用于 Args, GradientPair
13 #include <xgboost/data.h> // DMatrix
14 #include <xgboost/host_device_vector.h> // 用于 HostDeviceVector
15 #include <xgboost/linalg.h> // 用于 VectorView
16 #include <xgboost/model.h> // 用于 Configurable
17 #include <xgboost/span.h> // 用于 Span
18 #include <xgboost/tree_model.h> // 用于 RegTree
19 
20 #include <functional> // 用于 function
21 #include <string> // 用于 string
22 #include <vector> // 用于 vector
23 
24 namespace xgboost {
25 namespace tree {
26 struct TrainParam;
27 }
28 
29 class Json;
30 struct Context;
31 struct ObjInfo;
32 
36 class TreeUpdater : public Configurable {
37  protected
38  Context const* ctx_ = nullptr;
39 
40  public
41  explicit TreeUpdater(const Context* ctx) : ctx_(ctx) {}
43  ~TreeUpdater() override = default;
48  virtual void Configure(const Args& args) = 0;
55  [[nodiscard]] virtual bool CanModifyTree() const { return false; }
60  [[nodiscard]] virtual bool HasNodePosition() const { return false; }
74  virtual void Update(tree::TrainParam const* param, linalg::Matrix<GradientPair>* gpair,
76  const std::vector<RegTree*>& out_trees) = 0;
77 
88  virtual bool UpdatePredictionCache(const DMatrix* /*data*/,
89  linalg::MatrixView<float> /*out_preds*/) {
90  return false;
91  }
92 
93  [[nodiscard]] virtual char const* Name() const = 0;
94 
101  static TreeUpdater* Create(const std::string& name, Context const* ctx, ObjInfo const* task);
102 };
103 
108  : public dmlc::FunctionRegEntryBase<
109  TreeUpdaterReg, std::function<TreeUpdater*(Context const* ctx, ObjInfo const* task)>> {};
110 
123 #define XGBOOST_REGISTER_TREE_UPDATER(UniqueId, Name) \
124  static DMLC_ATTRIBUTE_UNUSED ::xgboost::TreeUpdaterReg& \
125  __make_ ## TreeUpdaterReg ## _ ## UniqueId ## __ = \
126  ::dmlc::Registry< ::xgboost::TreeUpdaterReg>::Get()->__REGISTER__(Name)
127 
128 } // namespace xgboost
129 #endif // XGBOOST_TREE_UPDATER_H_
为 xgboost 定义配置宏和基本类型。
内部数据结构,由XGBoost用于保存所有外部数据。
Definition: data.h:573
表示JSON格式的数据结构。
Definition: json.h:392
树更新模块接口,用于执行树的更新。
定义: tree_updater.h:36
Context const * ctx_
定义: tree_updater.h:38
~TreeUpdater() override=default
虚析构函数
virtual bool UpdatePredictionCache(const DMatrix *, linalg::MatrixView< float >)
判断更新器是否对给定数据集有足够的了解,以便快速更新预测缓存...
定义: tree_updater.h:88
static TreeUpdater * Create(const std::string &name, Context const *ctx, ObjInfo const *task)
根据名称创建树更新器。
virtual bool CanModifyTree() const
此更新器是否可用于更新现有树。
定义: tree_updater.h:55
virtual bool HasNodePosition() const
Update中的out_position是否有效。这决定了是否可以使用自适应树。
定义: tree_updater.h:60
TreeUpdater(const Context *ctx)
定义: tree_updater.h:41
virtual void Update(tree::TrainParam const *param, linalg::Matrix< GradientPair > *gpair, DMatrix *data, common::Span< HostDeviceVector< bst_node_t >> out_position, const std::vector< RegTree * > &out_trees)=0
对树模型执行更新
virtual void Configure(const Args &args)=0
使用给定参数初始化更新器。
virtual char const * Name() const =0
span类实现,基于ISO++20 span<T>。接口应相同。
Definition: span.h:431
具有静态类型和维度的张量视图。它实现了索引和切片。
定义: linalg.h:277
一个张量存储。要将其用于切片等其他功能,首先需要获取一个视图...
定义: linalg.h:745
xgboost 的输入数据结构。
设备与主机向量抽象层。
线性代数相关工具。
定义 XGBoost 中不同组件的抽象接口。
集成目标、gbm和评估的学习器接口。这是用户面临的XGB...
Definition: base.h:97
std::vector< std::pair< std::string, std::string > > Args
定义: base.h:324
定义: model.h:28
XGBoost的运行时上下文。包含线程和设备等信息。
Definition: context.h:133
目标返回的结构体,用于确定当前任务。此结构体未被任何算法使用...
定义: task.h:24
树更新器的注册表项。
定义: tree_updater.h:109