xgboost
data.h
Go to the documentation of this file.
1 
7 #ifndef XGBOOST_DATA_H_
8 #define XGBOOST_DATA_H_
9 
10 #include <dmlc/base.h>
11 #include <dmlc/data.h>
12 #include <dmlc/serializer.h>
13 #include <xgboost/base.h>
16 #include <xgboost/linalg.h>
17 #include <xgboost/span.h>
18 #include <xgboost/string_view.h>
19 
20 #include <algorithm>
21 #include <limits>
22 #include <memory>
23 #include <numeric>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 namespace xgboost {
29 // forward declare dmatrix.
30 class DMatrix;
31 
33 enum class DataType : uint8_t {
34  kFloat32 = 1,
35  kDouble = 2,
36  kUInt32 = 3,
37  kUInt64 = 4,
38  kStr = 5
39 };
40 
41 enum class FeatureType : uint8_t { kNumerical = 0, kCategorical = 1 };
42 
46 class MetaInfo {
47  public:
49  static constexpr uint64_t kNumField = 12;
50 
52  uint64_t num_row_{0}; // NOLINT
54  uint64_t num_col_{0}; // NOLINT
56  uint64_t num_nonzero_{0}; // NOLINT
63  std::vector<bst_group_t> group_ptr_; // NOLINT
80 
84  std::vector<std::string> feature_type_names;
88  std::vector<std::string> feature_names;
89  /*
90  * \brief Type of each feature. Automatically set when feature_type_names is specifed.
91  */
93  /*
94  * \brief Weight of each feature, used to define the probability of each feature being
95  * selected when using column sampling.
96  */
98 
100  MetaInfo() = default;
101  MetaInfo(MetaInfo&& that) = default;
102  MetaInfo& operator=(MetaInfo&& that) = default;
103  MetaInfo& operator=(MetaInfo const& that) = delete;
104 
108  void Validate(int32_t device) const;
109 
116  inline bst_float GetWeight(size_t i) const {
117  return weights_.Size() != 0 ? weights_.HostVector()[i] : 1.0f;
118  }
120  inline const std::vector<size_t>& LabelAbsSort() const {
121  if (label_order_cache_.size() == labels.Size()) {
122  return label_order_cache_;
123  }
124  label_order_cache_.resize(labels.Size());
125  std::iota(label_order_cache_.begin(), label_order_cache_.end(), 0);
126  const auto& l = labels.Data()->HostVector();
127  XGBOOST_PARALLEL_STABLE_SORT(label_order_cache_.begin(), label_order_cache_.end(),
128  [&l](size_t i1, size_t i2) {return std::abs(l[i1]) < std::abs(l[i2]);});
129 
130  return label_order_cache_;
131  }
133  void Clear();
138  void LoadBinary(dmlc::Stream* fi);
143  void SaveBinary(dmlc::Stream* fo) const;
151  void SetInfo(Context const& ctx, const char* key, const void* dptr, DataType dtype, size_t num);
157  void SetInfo(Context const& ctx, StringView key, StringView interface_str);
158 
159  void GetInfo(char const* key, bst_ulong* out_len, DataType dtype,
160  const void** out_dptr) const;
161 
162  void SetFeatureInfo(const char *key, const char **info, const bst_ulong size);
163  void GetFeatureInfo(const char *field, std::vector<std::string>* out_str_vecs) const;
164 
165  /*
166  * \brief Extend with other MetaInfo.
167  *
168  * \param that The other MetaInfo object.
169  *
170  * \param accumulate_rows Whether rows need to be accumulated in this function. If
171  * client code knows number of rows in advance, set this
172  * parameter to false.
173  * \param check_column Whether the extend method should check the consistency of
174  * columns.
175  */
176  void Extend(MetaInfo const& that, bool accumulate_rows, bool check_column);
177 
178  private:
179  void SetInfoFromHost(Context const& ctx, StringView key, Json arr);
180  void SetInfoFromCUDA(Context const& ctx, StringView key, Json arr);
181 
183  mutable std::vector<size_t> label_order_cache_;
184 };
185 
187 struct Entry {
193  Entry() = default;
201  inline static bool CmpValue(const Entry& a, const Entry& b) {
202  return a.fvalue < b.fvalue;
203  }
204  static bool CmpIndex(Entry const& a, Entry const& b) {
205  return a.index < b.index;
206  }
207  inline bool operator==(const Entry& other) const {
208  return (this->index == other.index && this->fvalue == other.fvalue);
209  }
210 };
211 
215 struct BatchParam {
217  int gpu_id {-1};
223  bool regen {false};
225  double sparse_thresh{std::numeric_limits<double>::quiet_NaN()};
226 
227  BatchParam() = default;
228  // GPU Hist
229  BatchParam(int32_t device, bst_bin_t max_bin)
230  : gpu_id{device}, max_bin{max_bin} {}
231  // Hist
234  // Approx
239  BatchParam(bst_bin_t max_bin, common::Span<float> hessian, bool regenerate)
240  : max_bin{max_bin}, hess{hessian}, regen{regenerate} {}
241 
242  bool operator!=(BatchParam const& other) const {
243  if (hess.empty() && other.hess.empty()) {
244  return gpu_id != other.gpu_id || max_bin != other.max_bin;
245  }
246  return gpu_id != other.gpu_id || max_bin != other.max_bin || hess.data() != other.hess.data();
247  }
248  bool operator==(BatchParam const& other) const {
249  return !(*this != other);
250  }
251 };
252 
255 
258 
259  Inst operator[](size_t i) const {
260  auto size = *(offset.data() + i + 1) - *(offset.data() + i);
261  return {data.data() + *(offset.data() + i),
262  static_cast<Inst::index_type>(size)};
263  }
264 
265  size_t Size() const { return offset.size() == 0 ? 0 : offset.size() - 1; }
266 };
267 
271 class SparsePage {
272  public:
273  // Offset for each row.
277 
278  size_t base_rowid {0};
279 
282 
284  return {offset.ConstHostSpan(), data.ConstHostSpan()};
285  }
286 
289  this->Clear();
290  }
291 
292  SparsePage(SparsePage const& that) = delete;
293  SparsePage(SparsePage&& that) = default;
294  SparsePage& operator=(SparsePage const& that) = delete;
295  SparsePage& operator=(SparsePage&& that) = default;
296  virtual ~SparsePage() = default;
297 
299  inline size_t Size() const {
300  return offset.Size() == 0 ? 0 : offset.Size() - 1;
301  }
302 
304  inline size_t MemCostBytes() const {
305  return offset.Size() * sizeof(size_t) + data.Size() * sizeof(Entry);
306  }
307 
309  inline void Clear() {
310  base_rowid = 0;
311  auto& offset_vec = offset.HostVector();
312  offset_vec.clear();
313  offset_vec.push_back(0);
314  data.HostVector().clear();
315  }
316 
318  inline void SetBaseRowId(size_t row_id) {
319  base_rowid = row_id;
320  }
321 
322  SparsePage GetTranspose(int num_columns, int32_t n_threads) const;
323 
327  void SortIndices(int32_t n_threads);
331  bool IsIndicesSorted(int32_t n_threads) const;
332 
333  void SortRows(int32_t n_threads);
334 
345  template <typename AdapterBatchT>
346  uint64_t Push(const AdapterBatchT& batch, float missing, int nthread);
347 
352  void Push(const SparsePage &batch);
357  void PushCSC(const SparsePage& batch);
358 };
359 
360 class CSCPage: public SparsePage {
361  public:
363  explicit CSCPage(SparsePage page) : SparsePage(std::move(page)) {}
364 };
365 
371  public:
372  std::shared_ptr<SparsePage const> page;
373  explicit ExtSparsePage(std::shared_ptr<SparsePage const> p) : page{std::move(p)} {}
374 };
375 
376 class SortedCSCPage : public SparsePage {
377  public:
379  explicit SortedCSCPage(SparsePage page) : SparsePage(std::move(page)) {}
380 };
381 
382 class EllpackPageImpl;
389 class EllpackPage {
390  public:
398 
405  explicit EllpackPage(DMatrix* dmat, const BatchParam& param);
406 
409 
411 
413  size_t Size() const;
414 
416  void SetBaseRowId(size_t row_id);
417 
418  const EllpackPageImpl* Impl() const { return impl_.get(); }
419  EllpackPageImpl* Impl() { return impl_.get(); }
420 
421  private:
422  std::unique_ptr<EllpackPageImpl> impl_;
423 };
424 
425 class GHistIndexMatrix;
426 
427 template<typename T>
429  public:
430  using iterator_category = std::forward_iterator_tag; // NOLINT
431  virtual ~BatchIteratorImpl() = default;
432  virtual const T& operator*() const = 0;
434  virtual bool AtEnd() const = 0;
435  virtual std::shared_ptr<T const> Page() const = 0;
436 };
437 
438 template<typename T>
440  public:
441  using iterator_category = std::forward_iterator_tag; // NOLINT
442  explicit BatchIterator(BatchIteratorImpl<T>* impl) { impl_.reset(impl); }
443  explicit BatchIterator(std::shared_ptr<BatchIteratorImpl<T>> impl) { impl_ = impl; }
444 
446  CHECK(impl_ != nullptr);
447  ++(*impl_);
448  return *this;
449  }
450 
451  const T& operator*() const {
452  CHECK(impl_ != nullptr);
453  return *(*impl_);
454  }
455 
456  bool operator!=(const BatchIterator&) const {
457  CHECK(impl_ != nullptr);
458  return !impl_->AtEnd();
459  }
460 
461  bool AtEnd() const {
462  CHECK(impl_ != nullptr);
463  return impl_->AtEnd();
464  }
465 
466  std::shared_ptr<T const> Page() const {
467  return impl_->Page();
468  }
469 
470  private:
471  std::shared_ptr<BatchIteratorImpl<T>> impl_;
472 };
473 
474 template<typename T>
475 class BatchSet {
476  public:
477  explicit BatchSet(BatchIterator<T> begin_iter) : begin_iter_(std::move(begin_iter)) {}
478  BatchIterator<T> begin() { return begin_iter_; } // NOLINT
479  BatchIterator<T> end() { return BatchIterator<T>(nullptr); } // NOLINT
480 
481  private:
482  BatchIterator<T> begin_iter_;
483 };
484 
485 struct XGBAPIThreadLocalEntry;
486 
490 class DMatrix {
491  public:
493  DMatrix() = default;
495  virtual MetaInfo& Info() = 0;
496  virtual void SetInfo(const char* key, const void* dptr, DataType dtype, size_t num) {
497  auto const& ctx = *this->Ctx();
498  this->Info().SetInfo(ctx, key, dptr, dtype, num);
499  }
500  virtual void SetInfo(const char* key, std::string const& interface_str) {
501  auto const& ctx = *this->Ctx();
502  this->Info().SetInfo(ctx, key, StringView{interface_str});
503  }
505  virtual const MetaInfo& Info() const = 0;
506 
513  virtual Context const* Ctx() const = 0;
514 
518  template <typename T>
520  template <typename T>
522  template <typename T>
523  bool PageExists() const;
524 
525  // the following are column meta data, should be able to answer them fast.
527  virtual bool SingleColBlock() const = 0;
529  virtual ~DMatrix();
530 
532  bool IsDense() const {
533  return Info().num_nonzero_ == Info().num_row_ * Info().num_col_;
534  }
535 
546  static DMatrix* Load(const std::string& uri,
547  bool silent,
548  bool load_row_split,
549  const std::string& file_format = "auto");
550 
563  template <typename AdapterT>
564  static DMatrix* Create(AdapterT* adapter, float missing, int nthread,
565  const std::string& cache_prefix = "");
566 
586  template <typename DataIterHandle, typename DMatrixHandle, typename DataIterResetCallback,
587  typename XGDMatrixCallbackNext>
588  static DMatrix* Create(DataIterHandle iter, DMatrixHandle proxy, std::shared_ptr<DMatrix> ref,
589  DataIterResetCallback* reset, XGDMatrixCallbackNext* next, float missing,
590  int nthread, bst_bin_t max_bin);
591 
610  template <typename DataIterHandle, typename DMatrixHandle,
611  typename DataIterResetCallback, typename XGDMatrixCallbackNext>
613  DataIterResetCallback *reset,
614  XGDMatrixCallbackNext *next, float missing,
615  int32_t nthread, std::string cache);
616 
620  static const size_t kPageSize = 32UL << 12UL;
621 
622  protected:
629 
630  virtual bool EllpackExists() const = 0;
631  virtual bool GHistIndexExists() const = 0;
632  virtual bool SparsePageExists() const = 0;
633 };
634 
635 template<>
637  return GetRowBatches();
638 }
639 
640 template <>
641 inline bool DMatrix::PageExists<EllpackPage>() const {
642  return this->EllpackExists();
643 }
644 
645 template <>
646 inline bool DMatrix::PageExists<GHistIndexMatrix>() const {
647  return this->GHistIndexExists();
648 }
649 
650 template<>
651 inline bool DMatrix::PageExists<SparsePage>() const {
652  return this->SparsePageExists();
653 }
654 
655 template<>
657  return GetColumnBatches();
658 }
659 
660 template<>
661 inline BatchSet<SortedCSCPage> DMatrix::GetBatches() {
662  return GetSortedColumnBatches();
663 }
664 
665 template<>
667  return GetEllpackBatches(param);
668 }
669 
670 template <>
672  return GetGradientIndex(param);
673 }
674 
675 template <>
676 inline BatchSet<ExtSparsePage> DMatrix::GetBatches() {
677  return GetExtBatches(BatchParam{});
678 }
679 } // namespace xgboost
680 
681 namespace dmlc {
683 
684 namespace serializer {
685 
686 template <>
687 struct Handler<xgboost::Entry> {
688  inline static void Write(Stream* strm, const xgboost::Entry& data) {
689  strm->Write(data.index);
690  strm->Write(data.fvalue);
691  }
692 
693  inline static bool Read(Stream* strm, xgboost::Entry* data) {
694  return strm->Read(&data->index) && strm->Read(&data->fvalue);
695  }
696 };
697 
698 } // namespace serializer
699 } // namespace dmlc
700 #endif // XGBOOST_DATA_H_
defines configuration macros of xgboost.
#define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z)
Definition: base.h:69
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
Definition: data.h:428
virtual BatchIteratorImpl & operator++()=0
std::forward_iterator_tag iterator_category
Definition: data.h:430
virtual std::shared_ptr< T const > Page() const =0
virtual bool AtEnd() const =0
virtual const T & operator*() const =0
virtual ~BatchIteratorImpl()=default
Definition: data.h:439
BatchIterator(std::shared_ptr< BatchIteratorImpl< T >> impl)
Definition: data.h:443
std::forward_iterator_tag iterator_category
Definition: data.h:441
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:442
const T & operator*() const
Definition: data.h:451
std::shared_ptr< T const > Page() const
Definition: data.h:466
BatchIterator & operator++()
Definition: data.h:445
bool operator!=(const BatchIterator &) const
Definition: data.h:456
bool AtEnd() const
Definition: data.h:461
Definition: data.h:475
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:477
BatchIterator< T > begin()
Definition: data.h:478
BatchIterator< T > end()
Definition: data.h:479
Definition: data.h:360
CSCPage()
Definition: data.h:362
CSCPage(SparsePage page)
Definition: data.h:363
Internal data structured used by XGBoost during training.
Definition: data.h:490
virtual BatchSet< SortedCSCPage > GetSortedColumnBatches()=0
virtual BatchSet< CSCPage > GetColumnBatches()=0
virtual BatchSet< SparsePage > GetRowBatches()=0
virtual void SetInfo(const char *key, std::string const &interface_str)
Definition: data.h:500
static const size_t kPageSize
Number of rows per page in external memory. Approximately 100MB per page for dataset with 100 feature...
Definition: data.h:620
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, std::shared_ptr< DMatrix > ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, int nthread, bst_bin_t max_bin)
Create a new Quantile based DMatrix used for histogram based algorithm.
static DMatrix * Load(const std::string &uri, bool silent, bool load_row_split, const std::string &file_format="auto")
Load DMatrix from URI.
bool PageExists() const
virtual ~DMatrix()
virtual destructor
virtual MetaInfo & Info()=0
meta information of the dataset
virtual void SetInfo(const char *key, const void *dptr, DataType dtype, size_t num)
Definition: data.h:496
virtual bool GHistIndexExists() const =0
XGBAPIThreadLocalEntry & GetThreadLocal() const
Get thread local memory for returning data from DMatrix.
virtual bool SparsePageExists() const =0
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, int32_t nthread, std::string cache)
Create an external memory DMatrix with callbacks.
virtual DMatrix * Slice(common::Span< int32_t const > ridxs)=0
virtual BatchSet< ExtSparsePage > GetExtBatches(BatchParam const &param)=0
virtual Context const * Ctx() const =0
Get the context object of this DMatrix. The context is created during construction of DMatrix with us...
virtual BatchSet< EllpackPage > GetEllpackBatches(const BatchParam &param)=0
virtual bool SingleColBlock() const =0
static DMatrix * Create(AdapterT *adapter, float missing, int nthread, const std::string &cache_prefix="")
Creates a new DMatrix from an external data adapter.
BatchSet< T > GetBatches()
Gets batches. Use range based for loop over BatchSet to access individual batches.
virtual const MetaInfo & Info() const =0
meta information of the dataset
BatchSet< T > GetBatches(const BatchParam &param)
virtual bool EllpackExists() const =0
virtual BatchSet< GHistIndexMatrix > GetGradientIndex(const BatchParam &param)=0
bool IsDense() const
Whether the matrix is dense.
Definition: data.h:532
DMatrix()=default
default constructor
A page stored in ELLPACK format.
Definition: data.h:389
const EllpackPageImpl * Impl() const
Definition: data.h:418
EllpackPageImpl * Impl()
Definition: data.h:419
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
EllpackPage()
Default constructor.
EllpackPage(EllpackPage &&that)
size_t Size() const
EllpackPage(DMatrix *dmat, const BatchParam &param)
Constructor from an existing DMatrix.
~EllpackPage()
Destructor.
Sparse page for exporting DMatrix. Same as SparsePage, just a different type to prevent being used in...
Definition: data.h:370
ExtSparsePage(std::shared_ptr< SparsePage const > p)
Definition: data.h:373
std::shared_ptr< SparsePage const > page
Definition: data.h:372
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:114
std::vector< T > & HostVector()
Data structure representing JSON format.
Definition: json.h:356
Meta information about dataset, always sit in memory.
Definition: data.h:46
linalg::Tensor< float, 2 > base_margin_
initialized margins, if specified, xgboost will start from this init margin can be used to specify in...
Definition: data.h:71
std::vector< std::string > feature_names
Name for each feature.
Definition: data.h:88
MetaInfo(MetaInfo &&that)=default
HostDeviceVector< bst_float > labels_upper_bound_
upper bound of the label, to be used for survival analysis (censored regression)
Definition: data.h:79
void Validate(int32_t device) const
Validate all metainfo.
uint64_t num_col_
number of columns in the data
Definition: data.h:54
std::vector< std::string > feature_type_names
Name of type for each feature provided by users. Eg. "int"/"float"/"i"/"q".
Definition: data.h:84
HostDeviceVector< bst_float > weights_
weights of each instance, optional
Definition: data.h:65
MetaInfo & operator=(MetaInfo const &that)=delete
void GetInfo(char const *key, bst_ulong *out_len, DataType dtype, const void **out_dptr) const
bst_float GetWeight(size_t i) const
Get weight of each instances.
Definition: data.h:116
HostDeviceVector< FeatureType > feature_types
Definition: data.h:92
void LoadBinary(dmlc::Stream *fi)
Load the Meta info from binary stream.
std::vector< bst_group_t > group_ptr_
the index of begin and end of a group needed when the learning task is ranking.
Definition: data.h:63
const std::vector< size_t > & LabelAbsSort() const
get sorted indexes (argsort) of labels by absolute value (used by cox loss)
Definition: data.h:120
HostDeviceVector< float > feature_weights
Definition: data.h:97
void GetFeatureInfo(const char *field, std::vector< std::string > *out_str_vecs) const
uint64_t num_row_
number of rows in the data
Definition: data.h:52
MetaInfo & operator=(MetaInfo &&that)=default
void Clear()
clear all the information
void Extend(MetaInfo const &that, bool accumulate_rows, bool check_column)
uint64_t num_nonzero_
number of nonzero entries in the data
Definition: data.h:56
MetaInfo Slice(common::Span< int32_t const > ridxs) const
linalg::Tensor< float, 2 > labels
label of each instance
Definition: data.h:58
void SaveBinary(dmlc::Stream *fo) const
Save the Meta info to binary stream.
MetaInfo()=default
default constructor
void SetInfo(Context const &ctx, const char *key, const void *dptr, DataType dtype, size_t num)
Set information in the meta info.
void SetInfo(Context const &ctx, StringView key, StringView interface_str)
Set information in the meta info with array interface.
static constexpr uint64_t kNumField
number of data fields in MetaInfo
Definition: data.h:49
HostDeviceVector< bst_float > labels_lower_bound_
lower bound of the label, to be used for survival analysis (censored regression)
Definition: data.h:75
void SetFeatureInfo(const char *key, const char **info, const bst_ulong size)
Definition: data.h:376
SortedCSCPage(SparsePage page)
Definition: data.h:379
SortedCSCPage()
Definition: data.h:378
In-memory storage unit of sparse batch, stored in CSR format.
Definition: data.h:271
void Push(const SparsePage &batch)
Push a sparse page.
SparsePage()
constructor
Definition: data.h:288
SparsePage GetTranspose(int num_columns, int32_t n_threads) const
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
Definition: data.h:318
uint64_t Push(const AdapterBatchT &batch, float missing, int nthread)
Pushes external data batch onto this page.
void PushCSC(const SparsePage &batch)
Push a SparsePage stored in CSC format.
bool IsIndicesSorted(int32_t n_threads) const
Check wether the column index is sorted.
virtual ~SparsePage()=default
void SortIndices(int32_t n_threads)
Sort the column index.
HostDeviceVector< Entry > data
the data of the segments
Definition: data.h:276
HostSparsePageView GetView() const
Definition: data.h:283
HostDeviceVector< bst_row_t > offset
Definition: data.h:274
SparsePage & operator=(SparsePage const &that)=delete
size_t MemCostBytes() const
Definition: data.h:304
void Clear()
clear the page
Definition: data.h:309
SparsePage(SparsePage const &that)=delete
size_t Size() const
Definition: data.h:299
void SortRows(int32_t n_threads)
SparsePage & operator=(SparsePage &&that)=default
SparsePage(SparsePage &&that)=default
size_t base_rowid
Definition: data.h:278
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:423
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:548
std::size_t index_type
Definition: span.h:427
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:553
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:560
HostDeviceVector< T > * Data()
Definition: linalg.h:778
size_t Size() const
Definition: linalg.h:774
void * DMatrixHandle
handle to DMatrix
Definition: c_api.h:50
int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
Definition: c_api.h:407
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:320
void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting external iterator.
Definition: c_api.h:412
A device-and-host vector abstraction layer.
Linear algebra related utilities.
Definition: data.h:681
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
Definition: intrusive_ptr.h:207
namespace of xgboost
Definition: base.h:110
uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:123
FeatureType
Definition: data.h:41
uint64_t bst_ulong
unsigned long integers
Definition: base.h:117
int32_t bst_bin_t
Type for histogram bin index.
Definition: base.h:125
DataType
data type accepted by xgboost interface
Definition: data.h:33
float bst_float
float type, used for storing statistics
Definition: base.h:119
static void Write(Stream *strm, const xgboost::Entry &data)
Definition: data.h:688
static bool Read(Stream *strm, xgboost::Entry *data)
Definition: data.h:693
Parameters for constructing batches.
Definition: data.h:215
int gpu_id
The GPU device to use.
Definition: data.h:217
common::Span< float > hess
Hessian, used for sketching with future approx implementation.
Definition: data.h:221
bst_bin_t max_bin
Maximum number of bins per feature for histograms.
Definition: data.h:219
bool regen
Whether should DMatrix regenerate the batch. Only used for GHistIndex.
Definition: data.h:223
bool operator==(BatchParam const &other) const
Definition: data.h:248
BatchParam(int32_t device, bst_bin_t max_bin)
Definition: data.h:229
bool operator!=(BatchParam const &other) const
Definition: data.h:242
double sparse_thresh
Parameter used to generate column matrix for hist.
Definition: data.h:225
BatchParam(bst_bin_t max_bin, common::Span< float > hessian, bool regenerate)
Get batch with sketch weighted by hessian. The batch will be regenerated if the span is changed,...
Definition: data.h:239
BatchParam(bst_bin_t max_bin, double sparse_thresh)
Definition: data.h:232
Element from a sparse vector.
Definition: data.h:187
XGBOOST_DEVICE Entry(bst_feature_t index, bst_float fvalue)
constructor with index and value
Definition: data.h:199
Entry()=default
default constructor
bst_feature_t index
feature index
Definition: data.h:189
static bool CmpIndex(Entry const &a, Entry const &b)
Definition: data.h:204
bst_float fvalue
feature value
Definition: data.h:191
bool operator==(const Entry &other) const
Definition: data.h:207
static bool CmpValue(const Entry &a, const Entry &b)
reversely compare feature values
Definition: data.h:201
Definition: generic_parameters.h:15
Definition: data.h:253
size_t Size() const
Definition: data.h:265
common::Span< Entry const > data
Definition: data.h:257
Inst operator[](size_t i) const
Definition: data.h:259
common::Span< bst_row_t const > offset
Definition: data.h:256
Definition: string_view.h:15
entry to to easily hold returning information
Definition: learner.h:44