xgboost

categorical.h
Go to the documentation of this file.
1
5 #ifndef XGBOOST_COMMON_CATEGORICAL_H_
6 #define XGBOOST_COMMON_CATEGORICAL_H_
7
8 #include "xgboost/base.h"
9 #include "xgboost/data.h"
10 #include "xgboost/span.h"
11 #include "xgboost/parameter.h"
12 #include "bitfield.h"
13
14 namespace xgboost {
15 namespace common {
16 // Cast the categorical type.
17 template <typename T>
18 XGBOOST_DEVICE bst_cat_t AsCat(T const& v) {
19 return static_cast<bst_cat_t>(v);
20 }
21
22 /* \brief Whether is fidx a categorical feature.
23 *
24 * \param ft Feature type for all features.
25 * \param fidx Feature index.
26 * \return Whether feature pointed by fidx is categorical feature.
27 */
28 inline XGBOOST_DEVICE bool IsCat(Span<FeatureType const> ft, bst_feature_t fidx) {
29 return !ft.empty() && ft[fidx] == FeatureType::kCategorical;
30 }
31
32 /* \brief Whether should it traverse to left branch of a tree.
33 *
34 * For one hot split, go to left if it's NOT the matching category.
35 */
36 inline XGBOOST_DEVICE bool Decision(common::Span<uint32_t const> cats, bst_cat_t cat) {
37 auto pos = CLBitField32::ToBitPos(cat);
38 if (pos.int_pos >= cats.size()) {
39 return true;
40 }
41 CLBitField32 const s_cats(cats);
42 return !s_cats.Check(cat);
43 }
44
45 using CatBitField = LBitField32;
46 using KCatBitField = CLBitField32;
47 } // namespace common
48 } // namespace xgboost
49
50 #endif // XGBOOST_COMMON_CATEGORICAL_H_
bitfield.h
xgboost::BitFieldContainer
A non-owning type with auxiliary methods defined for manipulating bits.
Definition: bitfield.h:59
xgboost::common::Decision
XGBOOST_DEVICE bool Decision(common::Span< uint32_t const > cats, bst_cat_t cat)
Definition: categorical.h:36
parameter.h
macro for using C++11 enum class as DMLC parameter
base.h
defines configuration macros of xgboost.
xgboost::bst_feature_t
uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:123
xgboost::common::Span::empty
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:554
span.h
xgboost::BitFieldContainer::Check
XGBOOST_DEVICE bool Check(Pos pos_v) const
Definition: bitfield.h:168
xgboost::bst_cat_t
int32_t bst_cat_t
Categorical value type.
Definition: base.h:121
xgboost::CLBitField32
BitFieldContainer< uint32_t, LBitsPolicy< uint32_t, true >, true > CLBitField32
Definition: bitfield.h:228
xgboost::BitFieldContainer::ToBitPos
static XGBOOST_DEVICE Pos ToBitPos(value_type pos)
Definition: bitfield.h:76
xgboost::common::Span
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:142
data.h
The input data structure of xgboost.
xgboost::common::Span::size
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:547
xgboost::LBitField32
BitFieldContainer< uint32_t, LBitsPolicy< uint32_t > > LBitField32
Definition: bitfield.h:227
xgboost::common::IsCat
XGBOOST_DEVICE bool IsCat(Span< FeatureType const > ft, bst_feature_t fidx)
Definition: categorical.h:28
xgboost::FeatureType::kCategorical
@ kCategorical
XGBOOST_DEVICE
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
xgboost::common::AsCat
XGBOOST_DEVICE bst_cat_t AsCat(T const &v)
Definition: categorical.h:18
xgboost
namespace of xgboost
Definition: base.h:110