7 #ifndef XGBOOST_DATA_H_ 
 8 #define XGBOOST_DATA_H_ 
 10 #include <dmlc/base.h> 
 12 #include <dmlc/serializer.h>  
 161  const void** out_dptr) 
const;
 
 164  void GetFeatureInfo(
const char *field, std::vector<std::string>* out_str_vecs) 
const;
 
 214  [[nodiscard]] CatContainer 
const* 
Cats() 
const;
 
 215  [[nodiscard]] CatContainer* 
Cats();
 
 216  [[nodiscard]] std::shared_ptr<CatContainer const> 
CatsShared() 
const;
 
 220  void Cats(std::shared_ptr<CatContainer> cats);
 
 227  mutable std::vector<size_t> label_order_cache_;
 
 228  bool has_categorical_{
false};
 
 230  std::shared_ptr<CatContainer> cats_;
 
 255  return (this->index == other.
index && this->fvalue == other.
fvalue);
 
 332  p.forbid_regen = 
false;
 
 382  [[nodiscard]] 
size_t Size()
 const {
 
 396  offset_vec.push_back(0);
 
 397  data.HostVector().clear();
 
 418  void Reindex(uint64_t feature_offset, int32_t n_threads);
 
 432  template <
typename AdapterBatchT>
 
 433  bst_idx_t Push(AdapterBatchT 
const& batch, 
float missing, std::int32_t nthread);
 
 459  std::shared_ptr<SparsePage const> 
page;
 
 470 class GHistIndexMatrix;
 
 479  [[nodiscard]] 
virtual bool AtEnd() 
const = 0;
 
 480  virtual std::shared_ptr<T const> 
Page() 
const = 0;
 
 491  CHECK(impl_ != 
nullptr);
 
 497  CHECK(impl_ != 
nullptr);
 
 504  CHECK(impl_ != 
nullptr);
 
 505  return impl_->AtEnd();
 
 508  [[nodiscard]] std::shared_ptr<T const> 
Page()
 const {
 
 509  return impl_->Page();
 
 513  std::shared_ptr<BatchIteratorImpl<T>> impl_;
 
 527 struct XGBAPIThreadLocalEntry;
 
 579  virtual void SetInfo(
const char* key, std::string 
const& interface_str) {
 
 580  auto const& ctx = *this->
Ctx();
 
 597  template <
typename T>
 
 599  template <
typename T>
 
 601  template <
typename T>
 
 603  template <
typename T>
 
 612  [[nodiscard]] 
virtual std::int32_t 
NumBatches()
 const { 
return 1; }
 
 644  template <
typename AdapterT>
 
 646  const std::string& cache_prefix = 
"",
 
 672  std::int32_t nthread, 
bst_bin_t max_bin, std::int64_t max_quantile_blocks);
 
 706  bst_bin_t max_bin, std::int64_t max_quantile_blocks,
 
 722  [[nodiscard]] CatContainer 
const* 
Cats()
 const { 
return this->
CatsShared().get(); }
 
 723  [[nodiscard]] std::shared_ptr<CatContainer const> 
CatsShared()
 const {
 
 747 inline bool DMatrix::PageExists<EllpackPage>()
 const {
 
 752 inline bool DMatrix::PageExists<GHistIndexMatrix>()
 const {
 
 757 inline bool DMatrix::PageExists<SparsePage>()
 const {
 
 787 inline BatchSet<ExtSparsePage> 
DMatrix::GetBatches(Context 
const* ctx, BatchParam 
const& param) {
 
 797 namespace serializer {
 
 802  strm->Write(data.
index);
 
 807  return strm->Read(&data->
index) && strm->Read(&data->
fvalue);
 
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:64
virtual BatchIteratorImpl & operator++()=0
std::forward_iterator_tag iterator_category
Definition: data.h:475
virtual std::shared_ptr< T const > Page() const =0
virtual bool AtEnd() const =0
virtual const T & operator*() const =0
virtual ~BatchIteratorImpl()=default
BatchIterator(std::shared_ptr< BatchIteratorImpl< T >> impl)
Definition: data.h:488
std::forward_iterator_tag iterator_category
Definition: data.h:486
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:487
const T & operator*() const
Definition: data.h:496
std::shared_ptr< T const > Page() const
Definition: data.h:508
BatchIterator & operator++()
Definition: data.h:490
bool operator!=(const BatchIterator &) const
Definition: data.h:501
bool AtEnd() const
Definition: data.h:503
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:519
BatchIterator< T > begin()
Definition: data.h:520
BatchIterator< T > end()
Definition: data.h:521
CSCPage()
Definition: data.h:449
CSCPage(SparsePage page)
Definition: data.h:450
内部数据结构,由XGBoost用于保存所有外部数据。
Definition: data.h:573
CatContainer const * Cats() const
用于类别字符串表示的访问器。
Definition: data.h:722
virtual BatchSet< EllpackPage > GetEllpackBatches(Context const *ctx, BatchParam const ¶m)=0
static DMatrix * Load(const std::string &uri, bool silent=true, DataSplitMode data_split_mode=DataSplitMode::kRow)
从URI加载DMatrix。
virtual BatchSet< SparsePage > GetRowBatches()=0
virtual BatchSet< GHistIndexMatrix > GetGradientIndex(Context const *ctx, BatchParam const ¶m)=0
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, ExtMemConfig const &config)
使用回调创建外部内存DMatrix。
virtual void SetInfo(const char *key, std::string const &interface_str)
Definition: data.h:579
virtual BatchSet< ExtSparsePage > GetExtBatches(Context const *ctx, BatchParam const ¶m)=0
BatchSet< T > GetBatches(Context const *ctx)
virtual MetaInfo & Info()=0
数据集的元信息
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, std::shared_ptr< DMatrix > ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, std::int32_t nthread, bst_bin_t max_bin, std::int64_t max_quantile_blocks)
创建用于基于直方图的算法的新的基于分位数的DMatrix。
static DMatrix * Create(AdapterT *adapter, float missing, int nthread, const std::string &cache_prefix="", DataSplitMode data_split_mode=DataSplitMode::kRow)
从外部数据适配器创建新的DMatrix。
virtual DMatrix * SliceCol(int num_slices, int slice_id)=0
按列切分DMatrix。
virtual bool GHistIndexExists() const =0
XGBAPIThreadLocalEntry & GetThreadLocal() const
获取DMatrix返回数据的线程局部内存。
virtual bool SparsePageExists() const =0
virtual DMatrix * Slice(common::Span< int32_t const > ridxs)=0
virtual Context const * Ctx() const =0
获取此DMatrix的上下文对象。上下文是在DMatrix使用...构造时创建的
BatchSet< T > GetBatches()
获取批次。使用基于范围的for循环遍历BatchSet以访问单个批次。
virtual const MetaInfo & Info() const =0
数据集的元信息
virtual bool EllpackExists() const =0
bool SingleColBlock() const
Definition: data.h:611
virtual BatchSet< CSCPage > GetColumnBatches(Context const *ctx)=0
virtual BatchSet< SortedCSCPage > GetSortedColumnBatches(Context const *ctx)=0
BatchSet< T > GetBatches(Context const *ctx, const BatchParam ¶m)
std::shared_ptr< CatContainer const > CatsShared() const
Definition: data.h:723
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, std::shared_ptr< DMatrix > ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, bst_bin_t max_bin, std::int64_t max_quantile_blocks, ExtMemConfig const &config)
使用回调创建外部内存分位数DMatrix。
virtual std::int32_t NumBatches() const
Definition: data.h:612
bool IsDense() const
矩阵是否是稠密的。
Definition: data.h:619
用于导出DMatrix的稀疏页面。与SparsePage相同,只是类型不同,以防止在...中使用
Definition: data.h:457
ExtSparsePage(std::shared_ptr< SparsePage const > p)
Definition: data.h:460
std::shared_ptr< SparsePage const > page
Definition: data.h:459
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:116
std::vector< T > & HostVector()
表示JSON格式的数据结构。
Definition: json.h:392
SortedCSCPage(SparsePage page)
Definition: data.h:466
SortedCSCPage()
Definition: data.h:465
稀疏批次的内存存储单元,以CSR格式存储。
Definition: data.h:354
void Push(const SparsePage &batch)
推送稀疏页面。
SparsePage()
构造函数
Definition: data.h:371
SparsePage GetTranspose(int num_columns, int32_t n_threads) const
void SetBaseRowId(size_t row_id)
设置此页面的基本行ID。
Definition: data.h:401
void Reindex(uint64_t feature_offset, int32_t n_threads)
使用偏移量重新索引列索引。
void PushCSC(const SparsePage &batch)
推送以CSC格式存储的SparsePage。
bool IsIndicesSorted(int32_t n_threads) const
检查列索引是否已排序。
virtual ~SparsePage()=default
void SortIndices(int32_t n_threads)
排序列索引。
HostDeviceVector< Entry > data
段的数据
Definition: data.h:359
HostSparsePageView GetView() const
Definition: data.h:366
SparsePage & operator=(SparsePage const &that)=delete
size_t MemCostBytes() const
Definition: data.h:387
void Clear()
清除页面
Definition: data.h:392
SparsePage(SparsePage const &that)=delete
size_t Size() const
Definition: data.h:382
void SortRows(int32_t n_threads)
bst_idx_t Push(AdapterBatchT const &batch, float missing, std::int32_t nthread)
将外部数据批次推送到此页面。
HostDeviceVector< bst_idx_t > offset
Definition: data.h:357
SparsePage & operator=(SparsePage &&that)=default
SparsePage(SparsePage &&that)=default
size_t base_rowid
Definition: data.h:361
span类实现,基于ISO++20 span<T>。接口应相同。
Definition: span.h:431
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:550
std::size_t index_type
Definition: span.h:435
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:555
DECLARE_FIELD_ENUM_CLASS(xgboost::DataSplitMode)
void * DMatrixHandle
DMatrix 句柄
定义: c_api.h:50
int XGDMatrixCallbackNext(DataIterHandle iter)
获取下一批数据的回调函数原型。
Definition: c_api.h:470
void * DataIterHandle
外部数据迭代器的句柄
定义: c_api.h:368
void DataIterResetCallback(DataIterHandle handle)
重置外部迭代器的回调函数原型。
Definition: c_api.h:475
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
Definition: intrusive_ptr.h:207
集成目标、gbm和评估的学习器接口。这是用户面临的XGB...
Definition: base.h:97
FeatureType
Definition: data.h:41
std::int32_t bst_bin_t
直方图 bin 索引的类型。我们有时使用 -1 表示无效 bin。
Definition: base.h:111
std::uint64_t bst_idx_t
数据行索引(样本)的类型。
Definition: base.h:115
DataSplitMode
Definition: data.h:43
std::uint32_t bst_feature_t
数据列(特征)索引的类型。
Definition: base.h:107
DataType
xgboost接口接受的数据类型
Definition: data.h:33
std::uint64_t bst_ulong
无符号长整数
Definition: base.h:101
float bst_float
浮点类型,用于存储统计信息
Definition: base.h:103
static void Write(Stream *strm, const xgboost::Entry &data)
Definition: data.h:801
static bool Read(Stream *strm, xgboost::Entry *data)
Definition: data.h:806
用于构造直方图索引批次的参数。
Definition: data.h:262
bool forbid_regen
禁止重新生成梯度索引。用于内部验证。
Definition: data.h:279
bst_bin_t max_bin
每个特征的最大 bin 数量,用于直方图。
Definition: data.h:266
common::Span< float const > hess
Hessian,用于未来近似实现中的草图。
Definition: data.h:270
bool regen
我们是否应该强制DMatrix重新生成批次。仅用于GHistIndex。
Definition: data.h:275
bool ParamNotEqual(BatchParam const &other) const
Definition: data.h:312
BatchParam()=default
精确或其他不需要直方图的。
bool prefetch_copy
用于GPU外部内存。是否将数据复制到设备。
Definition: data.h:289
double sparse_thresh
用于生成直方图列矩阵的参数。
Definition: data.h:283
bool Initialized() const
Definition: data.h:323
BatchParam(bst_bin_t max_bin, common::Span< float const > hessian, bool regenerate)
由近似树方法使用。
Definition: data.h:309
BatchParam MakeCache() const
为DMatrix制作一个自身的副本,以描述其现有索引是如何生成的。
Definition: data.h:327
BatchParam(bst_bin_t max_bin, double sparse_thresh)
由直方图树方法使用。
Definition: data.h:301
std::int32_t n_prefetch_batches
外部内存预取的批次数。
Definition: data.h:293
XGBoost的运行时上下文。包含线程和设备等信息。
Definition: context.h:133
设备序号的类型。该类型被打包成32位,以便在查看类型(如lin...)时高效使用
Definition: context.h:34
稀疏向量中的元素。
Definition: data.h:234
XGBOOST_DEVICE Entry(bst_feature_t index, bst_float fvalue)
带索引和值的构造函数
Definition: data.h:246
bst_feature_t index
特征索引
Definition: data.h:236
static bool CmpIndex(Entry const &a, Entry const &b)
Definition: data.h:251
bst_float fvalue
特征值
Definition: data.h:238
bool operator==(const Entry &other) const
Definition: data.h:254
static bool CmpValue(const Entry &a, const Entry &b)
反向比较特征值
Definition: data.h:248
ExtMemConfig(std::string cache, bool on_host, float h_ratio, std::int64_t min_cache, float missing, std::int32_t n_threads)
Definition: data.h:550
ExtMemConfig & SetParamsForTest(float _hw_decomp_ratio, bool _allow_decomp_fallback)
Definition: data.h:559
std::int32_t n_threads
Definition: data.h:543
std::int64_t min_cache_page_bytes
Definition: data.h:539
bool on_host
Definition: data.h:534
bool allow_decomp_fallback
Definition: data.h:547
float cache_host_ratio
Definition: data.h:536
float missing
Definition: data.h:541
std::string cache
Definition: data.h:532
float hw_decomp_ratio
Definition: data.h:545
size_t Size() const
Definition: data.h:348
Inst operator[](std::size_t i) const
Definition: data.h:343
common::Span< bst_idx_t const > offset
Definition: data.h:340
common::Span< Entry const > data
Definition: data.h:341
Definition: string_view.h:16